@0xsequence/hooks 5.0.9 → 5.1.0
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 +53 -1
- 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 +53 -1
- 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
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { QUERY_KEYS, time } from '../../constants';
|
|
3
3
|
import { useAPIClient } from './useAPIClient';
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to fetch coin prices from the Sequence API.
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The Sequence API client instance
|
|
8
|
+
* @param tokens - Array of tokens to get prices for, each containing chainId and contractAddress
|
|
9
|
+
* @returns Array of token prices, or empty array if no tokens provided
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
4
12
|
const getCoinPrices = async (apiClient, tokens) => {
|
|
5
13
|
if (tokens.length === 0) {
|
|
6
14
|
return [];
|
|
@@ -9,7 +17,49 @@ const getCoinPrices = async (apiClient, tokens) => {
|
|
|
9
17
|
return res?.tokenPrices || [];
|
|
10
18
|
};
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
20
|
+
* Hook to fetch current prices for a list of tokens.
|
|
21
|
+
*
|
|
22
|
+
* This hook uses React Query to fetch and cache token prices from the Sequence API.
|
|
23
|
+
* Prices are automatically refreshed every minute to ensure they stay current.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetCoinPrices} for more detailed documentation.
|
|
26
|
+
*
|
|
27
|
+
* @param tokens - Array of tokens to get prices for. Each token must include:
|
|
28
|
+
* - chainId: The chain ID where the token exists
|
|
29
|
+
* - contractAddress: The token's contract address (use ZERO_ADDRESS for native tokens)
|
|
30
|
+
*
|
|
31
|
+
* @param options - Optional configuration options:
|
|
32
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
33
|
+
* - disabled: Whether to disable the query
|
|
34
|
+
*
|
|
35
|
+
* @returns React Query result object containing:
|
|
36
|
+
* - data: Array of token prices when available
|
|
37
|
+
* - isLoading: Whether the initial request is in progress
|
|
38
|
+
* - error: Any error that occurred
|
|
39
|
+
* - isError: Whether an error occurred
|
|
40
|
+
* - isSuccess: Whether the request was successful
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const { data: prices, isLoading, error } = useGetCoinPrices([
|
|
45
|
+
* {
|
|
46
|
+
* chainId: 1,
|
|
47
|
+
* contractAddress: ZERO_ADDRESS // ETH
|
|
48
|
+
* },
|
|
49
|
+
* {
|
|
50
|
+
* chainId: 137,
|
|
51
|
+
* contractAddress: '0x...' // USDC on Polygon
|
|
52
|
+
* }
|
|
53
|
+
* ])
|
|
54
|
+
*
|
|
55
|
+
* if (isLoading) {
|
|
56
|
+
* return <div>Loading prices...</div>
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* if (prices) {
|
|
60
|
+
* console.log('ETH price:', prices[0].price.value)
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
13
63
|
*/
|
|
14
64
|
export const useGetCoinPrices = (tokens, options) => {
|
|
15
65
|
const apiClient = useAPIClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCoinPrices.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCoinPrices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;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,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;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;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAe,EAAE,OAAsB,EAAE,EAAE;IAC1E,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,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,IAAI,CAAC,SAAS;QACzB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ;KACjD,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -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"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { QUERY_KEYS, time } from '../../constants';
|
|
3
3
|
import { useAPIClient } from './useAPIClient';
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to fetch collectible prices from the Sequence API.
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The Sequence API client instance
|
|
8
|
+
* @param tokens - Array of tokens to get prices for. Each token should include chainId, contractAddress, and tokenId
|
|
9
|
+
* @returns Array of token prices with floor, buy, and sell prices, or empty array if no tokens provided
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
4
12
|
const getCollectiblePrices = async (apiClient, tokens) => {
|
|
5
13
|
if (tokens.length === 0) {
|
|
6
14
|
return [];
|
|
@@ -9,7 +17,54 @@ const getCollectiblePrices = async (apiClient, tokens) => {
|
|
|
9
17
|
return res?.tokenPrices || [];
|
|
10
18
|
};
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
20
|
+
* Hook to fetch current market prices for NFTs/collectibles.
|
|
21
|
+
*
|
|
22
|
+
* This hook uses React Query to fetch and cache collectible prices from the Sequence API.
|
|
23
|
+
* Prices are automatically refreshed every minute to ensure they stay current.
|
|
24
|
+
* Used in various UI components to display NFT valuations, particularly in collection views
|
|
25
|
+
* and transaction details.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetCollectiblePrices} for more detailed documentation.
|
|
28
|
+
*
|
|
29
|
+
* @param tokens - Array of tokens to get prices for. Each token must include:
|
|
30
|
+
* - chainId: The chain ID where the NFT exists
|
|
31
|
+
* - contractAddress: The NFT collection's contract address
|
|
32
|
+
* - tokenId: The specific token ID within the collection
|
|
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, each containing:
|
|
40
|
+
* - price: The price for the collection
|
|
41
|
+
* - price24hChange: The price change for the collection in the last 24 hours (if available)
|
|
42
|
+
* - floorPrice: The floor price for the collection (if available)
|
|
43
|
+
* - buyPrice: Current market buy price (if available)
|
|
44
|
+
* - sellPrice: Current market sell price (if available)
|
|
45
|
+
* - isLoading: Whether the initial request is in progress
|
|
46
|
+
* - error: Any error that occurred
|
|
47
|
+
* - isError: Whether an error occurred
|
|
48
|
+
* - isSuccess: Whether the request was successful
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* const { data: prices, isLoading } = useGetCollectiblePrices([
|
|
53
|
+
* {
|
|
54
|
+
* chainId: 1,
|
|
55
|
+
* contractAddress: '0x...', // NFT collection address
|
|
56
|
+
* tokenId: '123' // Specific NFT ID
|
|
57
|
+
* }
|
|
58
|
+
* ])
|
|
59
|
+
*
|
|
60
|
+
* if (isLoading) {
|
|
61
|
+
* return <div>Loading prices...</div>
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* if (prices?.[0]) {
|
|
65
|
+
* console.log('Price:', prices[0].price.value)
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
13
68
|
*/
|
|
14
69
|
export const useGetCollectiblePrices = (tokens, options) => {
|
|
15
70
|
const apiClient = useAPIClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCollectiblePrices.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetCollectiblePrices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;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,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;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;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAe,EAAE,OAAsB,EAAE,EAAE;IACjF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,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,IAAI,CAAC,SAAS;QACzB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ;KACjD,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -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"}
|
|
@@ -2,7 +2,43 @@ import { useQuery } from '@tanstack/react-query';
|
|
|
2
2
|
import { QUERY_KEYS, time } from '../../constants';
|
|
3
3
|
import { useAPIClient } from './useAPIClient';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Hook to fetch current exchange rates from USD to other currencies.
|
|
6
|
+
*
|
|
7
|
+
* This hook uses React Query to fetch and cache exchange rates from the Sequence API.
|
|
8
|
+
* Rates are automatically refreshed every 10 minutes to ensure they stay current.
|
|
9
|
+
* Used throughout the wallet widget and checkout components to display fiat values
|
|
10
|
+
* for tokens and NFTs.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetExchangeRate} for more detailed documentation.
|
|
13
|
+
*
|
|
14
|
+
* @param toCurrency - The target currency code (e.g., 'EUR', 'GBP', 'JPY').
|
|
15
|
+
* If 'USD' is provided, returns 1 as the conversion rate.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Optional configuration options:
|
|
18
|
+
* - retry: Whether to retry failed requests (defaults to true)
|
|
19
|
+
* - disabled: Whether to disable the query
|
|
20
|
+
*
|
|
21
|
+
* @returns React Query result object containing:
|
|
22
|
+
* - data: The exchange rate value from USD to the target currency
|
|
23
|
+
* - isLoading: Whether the initial request is in progress
|
|
24
|
+
* - error: Any error that occurred
|
|
25
|
+
* - isError: Whether an error occurred
|
|
26
|
+
* - isSuccess: Whether the request was successful
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const { data: rate = 1, isLoading } = useGetExchangeRate('EUR')
|
|
31
|
+
*
|
|
32
|
+
* // Convert USD amount to EUR
|
|
33
|
+
* const usdAmount = 100
|
|
34
|
+
* const eurAmount = usdAmount * rate
|
|
35
|
+
*
|
|
36
|
+
* if (isLoading) {
|
|
37
|
+
* return <div>Loading rates...</div>
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* console.log(`${usdAmount} USD = ${eurAmount} EUR`)
|
|
41
|
+
* ```
|
|
6
42
|
*/
|
|
7
43
|
export const useGetExchangeRate = (toCurrency, options) => {
|
|
8
44
|
const apiClient = useAPIClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetExchangeRate.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetExchangeRate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C
|
|
1
|
+
{"version":3,"file":"useGetExchangeRate.js","sourceRoot":"","sources":["../../../../src/hooks/API/useGetExchangeRate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAE,OAAsB,EAAE,EAAE;IAC/E,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,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,IAAI,CAAC,SAAS,GAAG,EAAE;QAC9B,OAAO,EAAE,CAAC,CAAC,UAAU,IAAI,CAAC,OAAO,EAAE,QAAQ;KAC5C,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -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;AA8GD
|
|
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;AA8GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,oBAAoB,EAAE,UAAU,YAAY,wFAsBlF,CAAA"}
|
|
@@ -92,7 +92,59 @@ const getSwapPrices = async (apiClient, metadataClient, indexerGatewayClient, ar
|
|
|
92
92
|
}) || []);
|
|
93
93
|
};
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* Hook to fetch available swap prices for a given currency pair.
|
|
96
|
+
*
|
|
97
|
+
* This hook provides functionality to:
|
|
98
|
+
* - Get swap prices for a specified currency and amount
|
|
99
|
+
* - Fetch token information and balances for available swap options
|
|
100
|
+
* - Support both native tokens and ERC20 tokens
|
|
101
|
+
* - Handle currency conversions and price formatting
|
|
102
|
+
*
|
|
103
|
+
* The hook automatically handles:
|
|
104
|
+
* - Native token address normalization (between 0x0 and 0xEEE...)
|
|
105
|
+
* - Contract information fetching (name, symbol, decimals, etc.)
|
|
106
|
+
* - Error handling for failed API calls or balance fetches
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapPrices} for more detailed documentation.
|
|
109
|
+
*
|
|
110
|
+
* @param args - Configuration object for the swap prices query {@link UseGetSwapPricesArgs}
|
|
111
|
+
* @param options - Optional configuration for the hook behavior {@link HooksOptions}
|
|
112
|
+
*
|
|
113
|
+
* @returns A React Query result object containing:
|
|
114
|
+
* - data: Array of {@link SwapPricesWithCurrencyInfo} objects
|
|
115
|
+
* - isLoading: Whether the query is in progress
|
|
116
|
+
* - isError: Whether an error occurred
|
|
117
|
+
* - error: Any error that occurred
|
|
118
|
+
* - Other standard React Query properties
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```tsx
|
|
122
|
+
* import { useGetSwapPrices } from '@0xsequence/hooks'
|
|
123
|
+
*
|
|
124
|
+
* function SwapComponent() {
|
|
125
|
+
* const { data: swapPrices, isLoading } = useGetSwapPrices({
|
|
126
|
+
* userAddress: '0x123...',
|
|
127
|
+
* buyCurrencyAddress: '0x456...',
|
|
128
|
+
* buyAmount: '1000000000000000000', // 1 token in base units
|
|
129
|
+
* chainId: 1,
|
|
130
|
+
* withContractInfo: true
|
|
131
|
+
* })
|
|
132
|
+
*
|
|
133
|
+
* if (isLoading) return <div>Loading...</div>
|
|
134
|
+
*
|
|
135
|
+
* return (
|
|
136
|
+
* <div>
|
|
137
|
+
* {swapPrices?.map(swap => (
|
|
138
|
+
* <div key={swap.info?.address}>
|
|
139
|
+
* Token: {swap.info?.symbol}
|
|
140
|
+
* Price: {swap.price.price}
|
|
141
|
+
* Balance: {swap.balance.balance}
|
|
142
|
+
* </div>
|
|
143
|
+
* ))}
|
|
144
|
+
* </div>
|
|
145
|
+
* )
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
96
148
|
*/
|
|
97
149
|
export const useGetSwapPrices = (args, options) => {
|
|
98
150
|
const apiClient = useAPIClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSwapPrices.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapPrices.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAA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BAAoB,GAAG,uBAAuB,EAAE,CAAA;IAEtD,MAAM,OAAO,GACX,CAAC,CAAC,IAAI,CAAC,OAAO;QACd,CAAC,CAAC,IAAI,CAAC,WAAW;QAClB,CAAC,CAAC,IAAI,CAAC,kBAAkB;QACzB,CAAC,CAAC,IAAI,CAAC,SAAS;QAChB,IAAI,CAAC,SAAS,KAAK,GAAG;QACtB,CAAC,OAAO,EAAE,QAAQ,CAAA;IAEpB,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,gBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC;QACtD,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,cAAc,EAAE,oBAAoB,EAAE,IAAI,CAAC;QACnF,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,qHAAqH;QACrH,iDAAiD;QACjD,SAAS,EAAE,IAAI,CAAC,OAAO;QACvB,OAAO;KACR,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,9 +1,80 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetSwapQuoteV2Args } from '@0xsequence/api';
|
|
2
2
|
import { HooksOptions } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook to fetch a swap quote for exchanging between two currencies.
|
|
5
|
+
*
|
|
6
|
+
* This hook provides functionality to:
|
|
7
|
+
* - Get a quote for swapping between two currencies (native or ERC20)
|
|
8
|
+
* - Fetch necessary approval data for ERC20 tokens
|
|
9
|
+
* - Generate transaction data for executing the swap
|
|
10
|
+
*
|
|
11
|
+
* The hook automatically handles:
|
|
12
|
+
* - Native token address normalization (between 0x0 and 0xEEE...)
|
|
13
|
+
* - Approval data generation for ERC20 tokens when needed
|
|
14
|
+
* - Transaction data generation for the swap
|
|
15
|
+
* - Error handling for failed API calls
|
|
16
|
+
*
|
|
17
|
+
* Go to {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
|
|
18
|
+
*
|
|
19
|
+
* @param getSwapQuoteArgs - Configuration object for the swap quote query:
|
|
20
|
+
* - userAddress: The address of the user's wallet
|
|
21
|
+
* - buyCurrencyAddress: The address of the currency to buy
|
|
22
|
+
* - sellCurrencyAddress: The address of the currency to sell
|
|
23
|
+
* - buyAmount: The amount of currency to buy (in base units)
|
|
24
|
+
* - chainId: The chain ID where the swap will occur
|
|
25
|
+
* - includeApprove: Whether to include approval data for ERC20 tokens
|
|
26
|
+
*
|
|
27
|
+
* @param options - Optional configuration for the hook behavior:
|
|
28
|
+
* - disabled: Whether to disable the query
|
|
29
|
+
* - retry: Whether to retry failed queries
|
|
30
|
+
* - Other standard React Query options
|
|
31
|
+
*
|
|
32
|
+
* @returns A React Query result object containing:
|
|
33
|
+
* - data: The swap quote data including:
|
|
34
|
+
* - currencyAddress: The address of the currency being swapped
|
|
35
|
+
* - currencyBalance: The user's balance of the currency
|
|
36
|
+
* - price: The price for the swap
|
|
37
|
+
* - maxPrice: The maximum price (including slippage)
|
|
38
|
+
* - to: The target contract address for the swap
|
|
39
|
+
* - transactionData: The calldata for the swap transaction
|
|
40
|
+
* - transactionValue: The value to send with the transaction (for native tokens)
|
|
41
|
+
* - approveData: The approval transaction data (if needed)
|
|
42
|
+
* - isLoading: Whether the query is in progress
|
|
43
|
+
* - isError: Whether an error occurred
|
|
44
|
+
* - error: Any error that occurred
|
|
45
|
+
* - Other standard React Query properties
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* import { useGetSwapQuote } from '@0xsequence/hooks'
|
|
52
|
+
*
|
|
53
|
+
* function SwapComponent() {
|
|
54
|
+
* const { data: swapQuote, isLoading } = useGetSwapQuote({
|
|
55
|
+
* userAddress: '0x123...',
|
|
56
|
+
* buyCurrencyAddress: '0x456...',
|
|
57
|
+
* sellCurrencyAddress: '0x789...',
|
|
58
|
+
* buyAmount: '1000000000000000000', // 1 token in base units
|
|
59
|
+
* chainId: 1,
|
|
60
|
+
* includeApprove: true
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* if (isLoading) return <div>Loading...</div>
|
|
64
|
+
*
|
|
65
|
+
* return (
|
|
66
|
+
* <div>
|
|
67
|
+
* <div>Price: {swapQuote?.price}</div>
|
|
68
|
+
* <div>Max Price: {swapQuote?.maxPrice}</div>
|
|
69
|
+
* <button onClick={() => executeSwap(swapQuote)}>
|
|
70
|
+
* Swap Tokens
|
|
71
|
+
* </button>
|
|
72
|
+
* </div>
|
|
73
|
+
* )
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
5
76
|
*/
|
|
6
|
-
export declare const useGetSwapQuote: (getSwapQuoteArgs:
|
|
77
|
+
export declare const useGetSwapQuote: (getSwapQuoteArgs: GetSwapQuoteV2Args, options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<{
|
|
7
78
|
currencyAddress: string;
|
|
8
79
|
currencyBalance: string;
|
|
9
80
|
price: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSwapQuote.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapQuote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useGetSwapQuote.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapQuote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,eAAO,MAAM,eAAe,GAAI,kBAAkB,kBAAkB,EAAE,UAAU,YAAY;;;;;;;;;SA4B3F,CAAA"}
|