@0xsequence/hooks 5.0.9 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/contexts/ConfigContext.d.ts +3 -0
- package/dist/cjs/contexts/ConfigContext.d.ts.map +1 -1
- package/dist/cjs/contexts/ConfigContext.js +4 -1
- package/dist/cjs/contexts/ConfigContext.js.map +1 -1
- package/dist/cjs/hooks/API/useAPIClient.d.ts +37 -0
- package/dist/cjs/hooks/API/useAPIClient.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useAPIClient.js +40 -4
- package/dist/cjs/hooks/API/useAPIClient.js.map +1 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.d.ts +43 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.js +51 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.js.map +1 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.d.ts +48 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.js +56 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.js.map +1 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.d.ts +37 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.js +37 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.js.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapPrices.d.ts +69 -1
- package/dist/cjs/hooks/Combination/useGetSwapPrices.d.ts.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapPrices.js +70 -14
- package/dist/cjs/hooks/Combination/useGetSwapPrices.js.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapQuote.d.ts +74 -3
- package/dist/cjs/hooks/Combination/useGetSwapQuote.d.ts.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapQuote.js +76 -5
- package/dist/cjs/hooks/Combination/useGetSwapQuote.js.map +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistory.d.ts +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistory.js +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.d.ts +66 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.d.ts.map +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.js +66 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.js.map +1 -1
- package/dist/cjs/hooks/Indexer/useIndexerClient.d.ts +98 -0
- package/dist/cjs/hooks/Indexer/useIndexerClient.d.ts.map +1 -1
- package/dist/cjs/hooks/Indexer/useIndexerClient.js +104 -6
- package/dist/cjs/hooks/Indexer/useIndexerClient.js.map +1 -1
- package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.d.ts.map +1 -1
- package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.js +3 -4
- package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.d.ts +61 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.js +61 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.d.ts +89 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.js +89 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.d.ts +83 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.js +83 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useMetadataClient.d.ts +36 -0
- package/dist/cjs/hooks/Metadata/useMetadataClient.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useMetadataClient.js +39 -4
- package/dist/cjs/hooks/Metadata/useMetadataClient.js.map +1 -1
- package/dist/cjs/hooks/useConfig.d.ts +45 -0
- package/dist/cjs/hooks/useConfig.d.ts.map +1 -1
- package/dist/cjs/hooks/useConfig.js +45 -0
- package/dist/cjs/hooks/useConfig.js.map +1 -1
- package/dist/cjs/tests/Combination/useGetSwapQuote.test.js +3 -3
- package/dist/cjs/tests/Combination/useGetSwapQuote.test.js.map +1 -1
- package/dist/cjs/tests/handlers.d.ts.map +1 -1
- package/dist/cjs/tests/handlers.js +14 -0
- package/dist/cjs/tests/handlers.js.map +1 -1
- package/dist/esm/contexts/ConfigContext.d.ts +3 -0
- package/dist/esm/contexts/ConfigContext.d.ts.map +1 -1
- package/dist/esm/contexts/ConfigContext.js +5 -2
- package/dist/esm/contexts/ConfigContext.js.map +1 -1
- package/dist/esm/hooks/API/useAPIClient.d.ts +37 -0
- package/dist/esm/hooks/API/useAPIClient.d.ts.map +1 -1
- package/dist/esm/hooks/API/useAPIClient.js +40 -4
- package/dist/esm/hooks/API/useAPIClient.js.map +1 -1
- package/dist/esm/hooks/API/useGetCoinPrices.d.ts +43 -1
- package/dist/esm/hooks/API/useGetCoinPrices.d.ts.map +1 -1
- package/dist/esm/hooks/API/useGetCoinPrices.js +51 -1
- package/dist/esm/hooks/API/useGetCoinPrices.js.map +1 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.d.ts +48 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.d.ts.map +1 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.js +56 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.js.map +1 -1
- package/dist/esm/hooks/API/useGetExchangeRate.d.ts +37 -1
- package/dist/esm/hooks/API/useGetExchangeRate.d.ts.map +1 -1
- package/dist/esm/hooks/API/useGetExchangeRate.js +37 -1
- package/dist/esm/hooks/API/useGetExchangeRate.js.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapPrices.d.ts +69 -1
- package/dist/esm/hooks/Combination/useGetSwapPrices.d.ts.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapPrices.js +71 -15
- package/dist/esm/hooks/Combination/useGetSwapPrices.js.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapQuote.d.ts +74 -3
- package/dist/esm/hooks/Combination/useGetSwapQuote.d.ts.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapQuote.js +77 -6
- package/dist/esm/hooks/Combination/useGetSwapQuote.js.map +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistory.d.ts +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistory.js +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.d.ts +66 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.d.ts.map +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.js +66 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.js.map +1 -1
- package/dist/esm/hooks/Indexer/useIndexerClient.d.ts +98 -0
- package/dist/esm/hooks/Indexer/useIndexerClient.d.ts.map +1 -1
- package/dist/esm/hooks/Indexer/useIndexerClient.js +104 -6
- package/dist/esm/hooks/Indexer/useIndexerClient.js.map +1 -1
- package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.d.ts.map +1 -1
- package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.js +3 -4
- package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.js.map +1 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.d.ts +61 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.js +61 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.js.map +1 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.d.ts +89 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.js +89 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.js.map +1 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.d.ts +83 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.js +83 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.js.map +1 -1
- package/dist/esm/hooks/Metadata/useMetadataClient.d.ts +36 -0
- package/dist/esm/hooks/Metadata/useMetadataClient.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useMetadataClient.js +39 -4
- package/dist/esm/hooks/Metadata/useMetadataClient.js.map +1 -1
- package/dist/esm/hooks/useConfig.d.ts +45 -0
- package/dist/esm/hooks/useConfig.d.ts.map +1 -1
- package/dist/esm/hooks/useConfig.js +45 -0
- package/dist/esm/hooks/useConfig.js.map +1 -1
- package/dist/esm/tests/Combination/useGetSwapQuote.test.js +4 -4
- package/dist/esm/tests/Combination/useGetSwapQuote.test.js.map +1 -1
- package/dist/esm/tests/handlers.d.ts.map +1 -1
- package/dist/esm/tests/handlers.js +14 -0
- package/dist/esm/tests/handlers.js.map +1 -1
- package/package.json +3 -3
|
@@ -8,10 +8,13 @@ export interface SequenceHooksEnv {
|
|
|
8
8
|
export interface SequenceHooksConfigProviderValue {
|
|
9
9
|
projectAccessKey: string;
|
|
10
10
|
env?: Partial<SequenceHooksEnv>;
|
|
11
|
+
jwt?: string;
|
|
11
12
|
}
|
|
12
13
|
export interface SequenceHooksConfig {
|
|
13
14
|
projectAccessKey: string;
|
|
14
15
|
env: Required<SequenceHooksEnv>;
|
|
16
|
+
jwt: string | undefined;
|
|
17
|
+
setJWT: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
15
18
|
}
|
|
16
19
|
export declare const SequenceHooksContext: import("react").Context<SequenceHooksConfig | null>;
|
|
17
20
|
interface SequenceHooksProviderProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigContext.d.ts","sourceRoot":"","sources":["../../../src/contexts/ConfigContext.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,gCAAgC;IAC/C,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"ConfigContext.d.ts","sourceRoot":"","sources":["../../../src/contexts/ConfigContext.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,gCAAgC;IAC/C,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAA;IAC/B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IACvB,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;CACjE;AAUD,eAAO,MAAM,oBAAoB,qDAAkD,CAAA;AAEnF,UAAU,0BAA0B;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,EAAE,gCAAgC,CAAA;CACzC;AAED,eAAO,MAAM,qBAAqB,GAAI,OAAO,0BAA0B,4CActE,CAAA"}
|
|
@@ -13,12 +13,15 @@ const defaultEnv = {
|
|
|
13
13
|
};
|
|
14
14
|
exports.SequenceHooksContext = (0, react_1.createContext)(null);
|
|
15
15
|
const SequenceHooksProvider = (props) => {
|
|
16
|
+
const [jwt, setJWT] = (0, react_1.useState)(props.config.jwt);
|
|
16
17
|
const config = {
|
|
17
18
|
...props.config,
|
|
18
19
|
env: {
|
|
19
20
|
...defaultEnv,
|
|
20
21
|
...props.config.env
|
|
21
|
-
}
|
|
22
|
+
},
|
|
23
|
+
jwt,
|
|
24
|
+
setJWT
|
|
22
25
|
};
|
|
23
26
|
return (0, jsx_runtime_1.jsx)(exports.SequenceHooksContext.Provider, { value: config, children: props.children });
|
|
24
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigContext.js","sourceRoot":"","sources":["../../../src/contexts/ConfigContext.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;AAEZ,
|
|
1
|
+
{"version":3,"file":"ConfigContext.js","sourceRoot":"","sources":["../../../src/contexts/ConfigContext.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;AAEZ,iCAA+C;AAuB/C,MAAM,UAAU,GAA+B;IAC7C,iBAAiB,EAAE,8BAA8B;IACjD,WAAW,EAAE,+BAA+B;IAC5C,MAAM,EAAE,0BAA0B;IAClC,UAAU,EAAE,8BAA8B;IAC1C,aAAa,EAAE,gCAAgC;CAChD,CAAA;AAEY,QAAA,oBAAoB,GAAG,IAAA,qBAAa,EAA6B,IAAI,CAAC,CAAA;AAO5E,MAAM,qBAAqB,GAAG,CAAC,KAAiC,EAAE,EAAE;IACzE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,IAAA,gBAAQ,EAAqB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAEpE,MAAM,MAAM,GAAwB;QAClC,GAAG,KAAK,CAAC,MAAM;QACf,GAAG,EAAE;YACH,GAAG,UAAU;YACb,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG;SACpB;QACD,GAAG;QACH,MAAM;KACP,CAAA;IAED,OAAO,uBAAC,4BAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YAAG,KAAK,CAAC,QAAQ,GAAiC,CAAA;AACvG,CAAC,CAAA;AAdY,QAAA,qBAAqB,yBAcjC"}
|
|
@@ -1,3 +1,40 @@
|
|
|
1
1
|
import { SequenceAPIClient } from '@0xsequence/api';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to access the Sequence API client instance.
|
|
4
|
+
*
|
|
5
|
+
* This hook provides a memoized instance of the Sequence API client that can be used
|
|
6
|
+
* to interact with Sequence services. The client is configured with the project's
|
|
7
|
+
* access key and environment-specific API URL.
|
|
8
|
+
*
|
|
9
|
+
* The API client provides access to various Sequence services including:
|
|
10
|
+
* - Exchange rates and pricing
|
|
11
|
+
* - Token swaps and quotes
|
|
12
|
+
* - Wallet linking and management
|
|
13
|
+
* - Token metadata and balances
|
|
14
|
+
*
|
|
15
|
+
* The client instance is memoized based on the project access key, meaning a new
|
|
16
|
+
* instance is only created when the access key changes.
|
|
17
|
+
*
|
|
18
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useAPIClient} for more detailed documentation.
|
|
19
|
+
*
|
|
20
|
+
* @returns {SequenceAPIClient} A configured instance of the Sequence API client
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const apiClient = useAPIClient()
|
|
25
|
+
*
|
|
26
|
+
* // Get exchange rates
|
|
27
|
+
* const rate = await apiClient.getExchangeRate({ toCurrency: 'EUR' })
|
|
28
|
+
*
|
|
29
|
+
* // Get swap quote
|
|
30
|
+
* const quote = await apiClient.getSwapQuote({
|
|
31
|
+
* chainId: 1,
|
|
32
|
+
* userAddress: '0x...',
|
|
33
|
+
* sellCurrencyAddress: '0x...',
|
|
34
|
+
* buyCurrencyAddress: '0x...',
|
|
35
|
+
* sellAmount: '1000000000000000000'
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
2
39
|
export declare const useAPIClient: () => SequenceAPIClient;
|
|
3
40
|
//# sourceMappingURL=useAPIClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAPIClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAKnD,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"useAPIClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAKnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,YAAY,yBAQxB,CAAA"}
|
|
@@ -4,12 +4,48 @@ exports.useAPIClient = void 0;
|
|
|
4
4
|
const api_1 = require("@0xsequence/api");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const useConfig_1 = require("../useConfig");
|
|
7
|
+
/**
|
|
8
|
+
* Hook to access the Sequence API client instance.
|
|
9
|
+
*
|
|
10
|
+
* This hook provides a memoized instance of the Sequence API client that can be used
|
|
11
|
+
* to interact with Sequence services. The client is configured with the project's
|
|
12
|
+
* access key and environment-specific API URL.
|
|
13
|
+
*
|
|
14
|
+
* The API client provides access to various Sequence services including:
|
|
15
|
+
* - Exchange rates and pricing
|
|
16
|
+
* - Token swaps and quotes
|
|
17
|
+
* - Wallet linking and management
|
|
18
|
+
* - Token metadata and balances
|
|
19
|
+
*
|
|
20
|
+
* The client instance is memoized based on the project access key, meaning a new
|
|
21
|
+
* instance is only created when the access key changes.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useAPIClient} for more detailed documentation.
|
|
24
|
+
*
|
|
25
|
+
* @returns {SequenceAPIClient} A configured instance of the Sequence API client
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const apiClient = useAPIClient()
|
|
30
|
+
*
|
|
31
|
+
* // Get exchange rates
|
|
32
|
+
* const rate = await apiClient.getExchangeRate({ toCurrency: 'EUR' })
|
|
33
|
+
*
|
|
34
|
+
* // Get swap quote
|
|
35
|
+
* const quote = await apiClient.getSwapQuote({
|
|
36
|
+
* chainId: 1,
|
|
37
|
+
* userAddress: '0x...',
|
|
38
|
+
* sellCurrencyAddress: '0x...',
|
|
39
|
+
* buyCurrencyAddress: '0x...',
|
|
40
|
+
* sellAmount: '1000000000000000000'
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
7
44
|
const useAPIClient = () => {
|
|
8
|
-
const { projectAccessKey, env } = (0, useConfig_1.useConfig)();
|
|
45
|
+
const { projectAccessKey, jwt, env } = (0, useConfig_1.useConfig)();
|
|
9
46
|
const apiClient = (0, react_1.useMemo)(() => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}, [projectAccessKey]);
|
|
47
|
+
return new api_1.SequenceAPIClient(env.apiUrl, projectAccessKey, jwt);
|
|
48
|
+
}, [projectAccessKey, jwt]);
|
|
13
49
|
return apiClient;
|
|
14
50
|
};
|
|
15
51
|
exports.useAPIClient = useAPIClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAPIClient.js","sourceRoot":"","sources":["../../../../src/hooks/API/useAPIClient.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,iCAA+B;AAE/B,4CAAwC;
|
|
1
|
+
{"version":3,"file":"useAPIClient.js","sourceRoot":"","sources":["../../../../src/hooks/API/useAPIClient.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,iCAA+B;AAE/B,4CAAwC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACI,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,qBAAS,GAAE,CAAA;IAElD,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC7B,OAAO,IAAI,uBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAA;IACjE,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;IAE3B,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AARY,QAAA,YAAY,gBAQxB"}
|
|
@@ -1,7 +1,49 @@
|
|
|
1
1
|
import { Token } from '@0xsequence/api';
|
|
2
2
|
import { HooksOptions } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook to fetch current prices for a list of tokens.
|
|
5
|
+
*
|
|
6
|
+
* This hook uses React Query to fetch and cache token prices from the Sequence API.
|
|
7
|
+
* Prices are automatically refreshed every minute to ensure they stay current.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetCoinPrices} for more detailed documentation.
|
|
10
|
+
*
|
|
11
|
+
* @param tokens - Array of tokens to get prices for. Each token must include:
|
|
12
|
+
* - chainId: The chain ID where the token exists
|
|
13
|
+
* - contractAddress: The token's contract address (use ZERO_ADDRESS for native tokens)
|
|
14
|
+
*
|
|
15
|
+
* @param options - Optional configuration options:
|
|
16
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
17
|
+
* - disabled: Whether to disable the query
|
|
18
|
+
*
|
|
19
|
+
* @returns React Query result object containing:
|
|
20
|
+
* - data: Array of token prices when available
|
|
21
|
+
* - isLoading: Whether the initial request is in progress
|
|
22
|
+
* - error: Any error that occurred
|
|
23
|
+
* - isError: Whether an error occurred
|
|
24
|
+
* - isSuccess: Whether the request was successful
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { data: prices, isLoading, error } = useGetCoinPrices([
|
|
29
|
+
* {
|
|
30
|
+
* chainId: 1,
|
|
31
|
+
* contractAddress: ZERO_ADDRESS // ETH
|
|
32
|
+
* },
|
|
33
|
+
* {
|
|
34
|
+
* chainId: 137,
|
|
35
|
+
* contractAddress: '0x...' // USDC on Polygon
|
|
36
|
+
* }
|
|
37
|
+
* ])
|
|
38
|
+
*
|
|
39
|
+
* if (isLoading) {
|
|
40
|
+
* return <div>Loading prices...</div>
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* if (prices) {
|
|
44
|
+
* console.log('ETH price:', prices[0].price.value)
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
5
47
|
*/
|
|
6
48
|
export declare const useGetCoinPrices: (tokens: Token[], options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<import("@0xsequence/api").TokenPrice[], Error>;
|
|
7
49
|
//# sourceMappingURL=useGetCoinPrices.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCoinPrices.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCoinPrices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAI1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"useGetCoinPrices.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCoinPrices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAI1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAsB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,KAAK,EAAE,EAAE,UAAU,YAAY,kGAUvE,CAAA"}
|
|
@@ -4,6 +4,14 @@ exports.useGetCoinPrices = void 0;
|
|
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
const useAPIClient_1 = require("./useAPIClient");
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to fetch coin prices from the Sequence API.
|
|
9
|
+
*
|
|
10
|
+
* @param apiClient - The Sequence API client instance
|
|
11
|
+
* @param tokens - Array of tokens to get prices for, each containing chainId and contractAddress
|
|
12
|
+
* @returns Array of token prices, or empty array if no tokens provided
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
7
15
|
const getCoinPrices = async (apiClient, tokens) => {
|
|
8
16
|
if (tokens.length === 0) {
|
|
9
17
|
return [];
|
|
@@ -12,7 +20,49 @@ const getCoinPrices = async (apiClient, tokens) => {
|
|
|
12
20
|
return res?.tokenPrices || [];
|
|
13
21
|
};
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
23
|
+
* Hook to fetch current prices for a list of tokens.
|
|
24
|
+
*
|
|
25
|
+
* This hook uses React Query to fetch and cache token prices from the Sequence API.
|
|
26
|
+
* Prices are automatically refreshed every minute to ensure they stay current.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetCoinPrices} for more detailed documentation.
|
|
29
|
+
*
|
|
30
|
+
* @param tokens - Array of tokens to get prices for. Each token must include:
|
|
31
|
+
* - chainId: The chain ID where the token exists
|
|
32
|
+
* - contractAddress: The token's contract address (use ZERO_ADDRESS for native tokens)
|
|
33
|
+
*
|
|
34
|
+
* @param options - Optional configuration options:
|
|
35
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
36
|
+
* - disabled: Whether to disable the query
|
|
37
|
+
*
|
|
38
|
+
* @returns React Query result object containing:
|
|
39
|
+
* - data: Array of token prices when available
|
|
40
|
+
* - isLoading: Whether the initial request is in progress
|
|
41
|
+
* - error: Any error that occurred
|
|
42
|
+
* - isError: Whether an error occurred
|
|
43
|
+
* - isSuccess: Whether the request was successful
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* const { data: prices, isLoading, error } = useGetCoinPrices([
|
|
48
|
+
* {
|
|
49
|
+
* chainId: 1,
|
|
50
|
+
* contractAddress: ZERO_ADDRESS // ETH
|
|
51
|
+
* },
|
|
52
|
+
* {
|
|
53
|
+
* chainId: 137,
|
|
54
|
+
* contractAddress: '0x...' // USDC on Polygon
|
|
55
|
+
* }
|
|
56
|
+
* ])
|
|
57
|
+
*
|
|
58
|
+
* if (isLoading) {
|
|
59
|
+
* return <div>Loading prices...</div>
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* if (prices) {
|
|
63
|
+
* console.log('ETH price:', prices[0].price.value)
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
16
66
|
*/
|
|
17
67
|
const useGetCoinPrices = (tokens, options) => {
|
|
18
68
|
const apiClient = (0, useAPIClient_1.useAPIClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCoinPrices.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCoinPrices.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAkD;AAGlD,iDAA6C;AAE7C,MAAM,aAAa,GAAG,KAAK,EAAE,SAA4B,EAAE,MAAe,EAAE,EAAE;IAC5E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAErD,OAAO,GAAG,EAAE,WAAW,IAAI,EAAE,CAAA;AAC/B,CAAC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"useGetCoinPrices.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCoinPrices.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAkD;AAGlD,iDAA6C;AAE7C;;;;;;;GAOG;AACH,MAAM,aAAa,GAAG,KAAK,EAAE,SAA4B,EAAE,MAAe,EAAE,EAAE;IAC5E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAErD,OAAO,GAAG,EAAE,WAAW,IAAI,EAAE,CAAA;AAC/B,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACI,MAAM,gBAAgB,GAAG,CAAC,MAAe,EAAE,OAAsB,EAAE,EAAE;IAC1E,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAA;IAEhC,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,gBAAgB,EAAE,MAAM,EAAE,OAAO,CAAC;QACxD,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC;QAC/C,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,SAAS;QACzB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ;KACjD,CAAC,CAAA;AACJ,CAAC,CAAA;AAVY,QAAA,gBAAgB,oBAU5B"}
|
|
@@ -1,7 +1,54 @@
|
|
|
1
1
|
import { Token } from '@0xsequence/api';
|
|
2
2
|
import { HooksOptions } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook to fetch current market prices for NFTs/collectibles.
|
|
5
|
+
*
|
|
6
|
+
* This hook uses React Query to fetch and cache collectible prices from the Sequence API.
|
|
7
|
+
* Prices are automatically refreshed every minute to ensure they stay current.
|
|
8
|
+
* Used in various UI components to display NFT valuations, particularly in collection views
|
|
9
|
+
* and transaction details.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetCollectiblePrices} for more detailed documentation.
|
|
12
|
+
*
|
|
13
|
+
* @param tokens - Array of tokens to get prices for. Each token must include:
|
|
14
|
+
* - chainId: The chain ID where the NFT exists
|
|
15
|
+
* - contractAddress: The NFT collection's contract address
|
|
16
|
+
* - tokenId: The specific token ID within the collection
|
|
17
|
+
*
|
|
18
|
+
* @param options - Optional configuration options:
|
|
19
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
20
|
+
* - disabled: Whether to disable the query
|
|
21
|
+
*
|
|
22
|
+
* @returns React Query result object containing:
|
|
23
|
+
* - data: Array of token prices when available, each containing:
|
|
24
|
+
* - price: The price for the collection
|
|
25
|
+
* - price24hChange: The price change for the collection in the last 24 hours (if available)
|
|
26
|
+
* - floorPrice: The floor price for the collection (if available)
|
|
27
|
+
* - buyPrice: Current market buy price (if available)
|
|
28
|
+
* - sellPrice: Current market sell price (if available)
|
|
29
|
+
* - isLoading: Whether the initial request is in progress
|
|
30
|
+
* - error: Any error that occurred
|
|
31
|
+
* - isError: Whether an error occurred
|
|
32
|
+
* - isSuccess: Whether the request was successful
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* const { data: prices, isLoading } = useGetCollectiblePrices([
|
|
37
|
+
* {
|
|
38
|
+
* chainId: 1,
|
|
39
|
+
* contractAddress: '0x...', // NFT collection address
|
|
40
|
+
* tokenId: '123' // Specific NFT ID
|
|
41
|
+
* }
|
|
42
|
+
* ])
|
|
43
|
+
*
|
|
44
|
+
* if (isLoading) {
|
|
45
|
+
* return <div>Loading prices...</div>
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* if (prices?.[0]) {
|
|
49
|
+
* console.log('Price:', prices[0].price.value)
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
5
52
|
*/
|
|
6
53
|
export declare const useGetCollectiblePrices: (tokens: Token[], options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<import("@0xsequence/api").TokenPrice[], Error>;
|
|
7
54
|
//# sourceMappingURL=useGetCollectiblePrices.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCollectiblePrices.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCollectiblePrices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAI1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"useGetCollectiblePrices.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCollectiblePrices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAI1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAsB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,KAAK,EAAE,EAAE,UAAU,YAAY,kGAU9E,CAAA"}
|
|
@@ -4,6 +4,14 @@ exports.useGetCollectiblePrices = void 0;
|
|
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
const useAPIClient_1 = require("./useAPIClient");
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to fetch collectible prices from the Sequence API.
|
|
9
|
+
*
|
|
10
|
+
* @param apiClient - The Sequence API client instance
|
|
11
|
+
* @param tokens - Array of tokens to get prices for. Each token should include chainId, contractAddress, and tokenId
|
|
12
|
+
* @returns Array of token prices with floor, buy, and sell prices, or empty array if no tokens provided
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
7
15
|
const getCollectiblePrices = async (apiClient, tokens) => {
|
|
8
16
|
if (tokens.length === 0) {
|
|
9
17
|
return [];
|
|
@@ -12,7 +20,54 @@ const getCollectiblePrices = async (apiClient, tokens) => {
|
|
|
12
20
|
return res?.tokenPrices || [];
|
|
13
21
|
};
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
23
|
+
* Hook to fetch current market prices for NFTs/collectibles.
|
|
24
|
+
*
|
|
25
|
+
* This hook uses React Query to fetch and cache collectible prices from the Sequence API.
|
|
26
|
+
* Prices are automatically refreshed every minute to ensure they stay current.
|
|
27
|
+
* Used in various UI components to display NFT valuations, particularly in collection views
|
|
28
|
+
* and transaction details.
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetCollectiblePrices} for more detailed documentation.
|
|
31
|
+
*
|
|
32
|
+
* @param tokens - Array of tokens to get prices for. Each token must include:
|
|
33
|
+
* - chainId: The chain ID where the NFT exists
|
|
34
|
+
* - contractAddress: The NFT collection's contract address
|
|
35
|
+
* - tokenId: The specific token ID within the collection
|
|
36
|
+
*
|
|
37
|
+
* @param options - Optional configuration options:
|
|
38
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
39
|
+
* - disabled: Whether to disable the query
|
|
40
|
+
*
|
|
41
|
+
* @returns React Query result object containing:
|
|
42
|
+
* - data: Array of token prices when available, each containing:
|
|
43
|
+
* - price: The price for the collection
|
|
44
|
+
* - price24hChange: The price change for the collection in the last 24 hours (if available)
|
|
45
|
+
* - floorPrice: The floor price for the collection (if available)
|
|
46
|
+
* - buyPrice: Current market buy price (if available)
|
|
47
|
+
* - sellPrice: Current market sell price (if available)
|
|
48
|
+
* - isLoading: Whether the initial request is in progress
|
|
49
|
+
* - error: Any error that occurred
|
|
50
|
+
* - isError: Whether an error occurred
|
|
51
|
+
* - isSuccess: Whether the request was successful
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const { data: prices, isLoading } = useGetCollectiblePrices([
|
|
56
|
+
* {
|
|
57
|
+
* chainId: 1,
|
|
58
|
+
* contractAddress: '0x...', // NFT collection address
|
|
59
|
+
* tokenId: '123' // Specific NFT ID
|
|
60
|
+
* }
|
|
61
|
+
* ])
|
|
62
|
+
*
|
|
63
|
+
* if (isLoading) {
|
|
64
|
+
* return <div>Loading prices...</div>
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* if (prices?.[0]) {
|
|
68
|
+
* console.log('Price:', prices[0].price.value)
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
16
71
|
*/
|
|
17
72
|
const useGetCollectiblePrices = (tokens, options) => {
|
|
18
73
|
const apiClient = (0, useAPIClient_1.useAPIClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCollectiblePrices.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCollectiblePrices.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAkD;AAGlD,iDAA6C;AAE7C,MAAM,oBAAoB,GAAG,KAAK,EAAE,SAA4B,EAAE,MAAe,EAAE,EAAE;IACnF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAE5D,OAAO,GAAG,EAAE,WAAW,IAAI,EAAE,CAAA;AAC/B,CAAC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"useGetCollectiblePrices.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCollectiblePrices.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAkD;AAGlD,iDAA6C;AAE7C;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,KAAK,EAAE,SAA4B,EAAE,MAAe,EAAE,EAAE;IACnF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAE5D,OAAO,GAAG,EAAE,WAAW,IAAI,EAAE,CAAA;AAC/B,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACI,MAAM,uBAAuB,GAAG,CAAC,MAAe,EAAE,OAAsB,EAAE,EAAE;IACjF,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAA;IAEhC,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,uBAAuB,EAAE,MAAM,EAAE,OAAO,CAAC;QAC/D,OAAO,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,SAAS,EAAE,MAAM,CAAC;QACtD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,SAAS;QACzB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ;KACjD,CAAC,CAAA;AACJ,CAAC,CAAA;AAVY,QAAA,uBAAuB,2BAUnC"}
|
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
import { HooksOptions } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Hook to fetch current exchange rates from USD to other currencies.
|
|
4
|
+
*
|
|
5
|
+
* This hook uses React Query to fetch and cache exchange rates from the Sequence API.
|
|
6
|
+
* Rates are automatically refreshed every 10 minutes to ensure they stay current.
|
|
7
|
+
* Used throughout the wallet widget and checkout components to display fiat values
|
|
8
|
+
* for tokens and NFTs.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetExchangeRate} for more detailed documentation.
|
|
11
|
+
*
|
|
12
|
+
* @param toCurrency - The target currency code (e.g., 'EUR', 'GBP', 'JPY').
|
|
13
|
+
* If 'USD' is provided, returns 1 as the conversion rate.
|
|
14
|
+
*
|
|
15
|
+
* @param options - Optional configuration options:
|
|
16
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
17
|
+
* - disabled: Whether to disable the query
|
|
18
|
+
*
|
|
19
|
+
* @returns React Query result object containing:
|
|
20
|
+
* - data: The exchange rate value from USD to the target currency
|
|
21
|
+
* - isLoading: Whether the initial request is in progress
|
|
22
|
+
* - error: Any error that occurred
|
|
23
|
+
* - isError: Whether an error occurred
|
|
24
|
+
* - isSuccess: Whether the request was successful
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { data: rate = 1, isLoading } = useGetExchangeRate('EUR')
|
|
29
|
+
*
|
|
30
|
+
* // Convert USD amount to EUR
|
|
31
|
+
* const usdAmount = 100
|
|
32
|
+
* const eurAmount = usdAmount * rate
|
|
33
|
+
*
|
|
34
|
+
* if (isLoading) {
|
|
35
|
+
* return <div>Loading rates...</div>
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* console.log(`${usdAmount} USD = ${eurAmount} EUR`)
|
|
39
|
+
* ```
|
|
4
40
|
*/
|
|
5
41
|
export declare const useGetExchangeRate: (toCurrency: string, options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<number, Error>;
|
|
6
42
|
//# sourceMappingURL=useGetExchangeRate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetExchangeRate.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useGetExchangeRate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C
|
|
1
|
+
{"version":3,"file":"useGetExchangeRate.d.ts","sourceRoot":"","sources":["../../../../src/hooks/API/useGetExchangeRate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,EAAE,UAAU,YAAY,kEAkB5E,CAAA"}
|
|
@@ -5,7 +5,43 @@ const react_query_1 = require("@tanstack/react-query");
|
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
const useAPIClient_1 = require("./useAPIClient");
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Hook to fetch current exchange rates from USD to other currencies.
|
|
9
|
+
*
|
|
10
|
+
* This hook uses React Query to fetch and cache exchange rates from the Sequence API.
|
|
11
|
+
* Rates are automatically refreshed every 10 minutes to ensure they stay current.
|
|
12
|
+
* Used throughout the wallet widget and checkout components to display fiat values
|
|
13
|
+
* for tokens and NFTs.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetExchangeRate} for more detailed documentation.
|
|
16
|
+
*
|
|
17
|
+
* @param toCurrency - The target currency code (e.g., 'EUR', 'GBP', 'JPY').
|
|
18
|
+
* If 'USD' is provided, returns 1 as the conversion rate.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Optional configuration options:
|
|
21
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
22
|
+
* - disabled: Whether to disable the query
|
|
23
|
+
*
|
|
24
|
+
* @returns React Query result object containing:
|
|
25
|
+
* - data: The exchange rate value from USD to the target currency
|
|
26
|
+
* - isLoading: Whether the initial request is in progress
|
|
27
|
+
* - error: Any error that occurred
|
|
28
|
+
* - isError: Whether an error occurred
|
|
29
|
+
* - isSuccess: Whether the request was successful
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const { data: rate = 1, isLoading } = useGetExchangeRate('EUR')
|
|
34
|
+
*
|
|
35
|
+
* // Convert USD amount to EUR
|
|
36
|
+
* const usdAmount = 100
|
|
37
|
+
* const eurAmount = usdAmount * rate
|
|
38
|
+
*
|
|
39
|
+
* if (isLoading) {
|
|
40
|
+
* return <div>Loading rates...</div>
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* console.log(`${usdAmount} USD = ${eurAmount} EUR`)
|
|
44
|
+
* ```
|
|
9
45
|
*/
|
|
10
46
|
const useGetExchangeRate = (toCurrency, options) => {
|
|
11
47
|
const apiClient = (0, useAPIClient_1.useAPIClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetExchangeRate.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetExchangeRate.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEhD,+CAAkD;AAGlD,iDAA6C;AAE7C
|
|
1
|
+
{"version":3,"file":"useGetExchangeRate.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetExchangeRate.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEhD,+CAAkD;AAGlD,iDAA6C;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACI,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAE,OAAsB,EAAE,EAAE;IAC/E,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAA;IAEhC,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC;QAC9D,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;gBACzB,OAAO,CAAC,CAAA;YACV,CAAC;YAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;YAE3D,OAAO,GAAG,CAAC,YAAY,CAAC,KAAK,CAAA;QAC/B,CAAC;QACD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,SAAS,GAAG,EAAE;QAC9B,OAAO,EAAE,CAAC,CAAC,UAAU,IAAI,CAAC,OAAO,EAAE,QAAQ;KAC5C,CAAC,CAAA;AACJ,CAAC,CAAA;AAlBY,QAAA,kBAAkB,sBAkB9B"}
|
|
@@ -4,11 +4,27 @@ import { HooksOptions } from '../../types';
|
|
|
4
4
|
interface Balance {
|
|
5
5
|
balance: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Type representing a swap price with additional currency information
|
|
9
|
+
*
|
|
10
|
+
* @property price - The swap price information from the API
|
|
11
|
+
* @property info - Contract information for the currency, including name, symbol, decimals, etc.
|
|
12
|
+
* @property balance - The user's balance of this currency
|
|
13
|
+
*/
|
|
7
14
|
export type SwapPricesWithCurrencyInfo = {
|
|
8
15
|
price: SwapPrice;
|
|
9
16
|
info: ContractInfo | undefined;
|
|
10
17
|
balance: Balance;
|
|
11
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Arguments for the useGetSwapPrices hook
|
|
21
|
+
*
|
|
22
|
+
* @property userAddress - The address of the user's wallet
|
|
23
|
+
* @property buyCurrencyAddress - The address of the currency to buy
|
|
24
|
+
* @property buyAmount - The amount of currency to buy (in base units)
|
|
25
|
+
* @property chainId - The chain ID where the swap will occur
|
|
26
|
+
* @property withContractInfo - Whether to fetch additional contract info for each currency
|
|
27
|
+
*/
|
|
12
28
|
export interface UseGetSwapPricesArgs {
|
|
13
29
|
userAddress: string;
|
|
14
30
|
buyCurrencyAddress: string;
|
|
@@ -17,7 +33,59 @@ export interface UseGetSwapPricesArgs {
|
|
|
17
33
|
withContractInfo?: boolean;
|
|
18
34
|
}
|
|
19
35
|
/**
|
|
20
|
-
*
|
|
36
|
+
* Hook to fetch available swap prices for a given currency pair.
|
|
37
|
+
*
|
|
38
|
+
* This hook provides functionality to:
|
|
39
|
+
* - Get swap prices for a specified currency and amount
|
|
40
|
+
* - Fetch token information and balances for available swap options
|
|
41
|
+
* - Support both native tokens and ERC20 tokens
|
|
42
|
+
* - Handle currency conversions and price formatting
|
|
43
|
+
*
|
|
44
|
+
* The hook automatically handles:
|
|
45
|
+
* - Native token address normalization (between 0x0 and 0xEEE...)
|
|
46
|
+
* - Contract information fetching (name, symbol, decimals, etc.)
|
|
47
|
+
* - Error handling for failed API calls or balance fetches
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapPrices} for more detailed documentation.
|
|
50
|
+
*
|
|
51
|
+
* @param args - Configuration object for the swap prices query {@link UseGetSwapPricesArgs}
|
|
52
|
+
* @param options - Optional configuration for the hook behavior {@link HooksOptions}
|
|
53
|
+
*
|
|
54
|
+
* @returns A React Query result object containing:
|
|
55
|
+
* - data: Array of {@link SwapPricesWithCurrencyInfo} objects
|
|
56
|
+
* - isLoading: Whether the query is in progress
|
|
57
|
+
* - isError: Whether an error occurred
|
|
58
|
+
* - error: Any error that occurred
|
|
59
|
+
* - Other standard React Query properties
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* import { useGetSwapPrices } from '@0xsequence/hooks'
|
|
64
|
+
*
|
|
65
|
+
* function SwapComponent() {
|
|
66
|
+
* const { data: swapPrices, isLoading } = useGetSwapPrices({
|
|
67
|
+
* userAddress: '0x123...',
|
|
68
|
+
* buyCurrencyAddress: '0x456...',
|
|
69
|
+
* buyAmount: '1000000000000000000', // 1 token in base units
|
|
70
|
+
* chainId: 1,
|
|
71
|
+
* withContractInfo: true
|
|
72
|
+
* })
|
|
73
|
+
*
|
|
74
|
+
* if (isLoading) return <div>Loading...</div>
|
|
75
|
+
*
|
|
76
|
+
* return (
|
|
77
|
+
* <div>
|
|
78
|
+
* {swapPrices?.map(swap => (
|
|
79
|
+
* <div key={swap.info?.address}>
|
|
80
|
+
* Token: {swap.info?.symbol}
|
|
81
|
+
* Price: {swap.price.price}
|
|
82
|
+
* Balance: {swap.balance.balance}
|
|
83
|
+
* </div>
|
|
84
|
+
* ))}
|
|
85
|
+
* </div>
|
|
86
|
+
* )
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
21
89
|
*/
|
|
22
90
|
export declare const useGetSwapPrices: (args: UseGetSwapPricesArgs, options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<SwapPricesWithCurrencyInfo[], Error>;
|
|
23
91
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSwapPrices.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapPrices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAoB,MAAM,sBAAsB,CAAA;AAKrE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM1C,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,SAAS,CAAA;IAChB,IAAI,EAAE,YAAY,GAAG,SAAS,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;
|
|
1
|
+
{"version":3,"file":"useGetSwapPrices.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapPrices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAoB,MAAM,sBAAsB,CAAA;AAKrE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM1C,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,SAAS,CAAA;IAChB,IAAI,EAAE,YAAY,GAAG,SAAS,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAmHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,oBAAoB,EAAE,UAAU,YAAY,wFAsBlF,CAAA"}
|