@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.
Files changed (133) hide show
  1. package/dist/cjs/contexts/ConfigContext.d.ts +3 -0
  2. package/dist/cjs/contexts/ConfigContext.d.ts.map +1 -1
  3. package/dist/cjs/contexts/ConfigContext.js +4 -1
  4. package/dist/cjs/contexts/ConfigContext.js.map +1 -1
  5. package/dist/cjs/hooks/API/useAPIClient.d.ts +37 -0
  6. package/dist/cjs/hooks/API/useAPIClient.d.ts.map +1 -1
  7. package/dist/cjs/hooks/API/useAPIClient.js +40 -4
  8. package/dist/cjs/hooks/API/useAPIClient.js.map +1 -1
  9. package/dist/cjs/hooks/API/useGetCoinPrices.d.ts +43 -1
  10. package/dist/cjs/hooks/API/useGetCoinPrices.d.ts.map +1 -1
  11. package/dist/cjs/hooks/API/useGetCoinPrices.js +51 -1
  12. package/dist/cjs/hooks/API/useGetCoinPrices.js.map +1 -1
  13. package/dist/cjs/hooks/API/useGetCollectiblePrices.d.ts +48 -1
  14. package/dist/cjs/hooks/API/useGetCollectiblePrices.d.ts.map +1 -1
  15. package/dist/cjs/hooks/API/useGetCollectiblePrices.js +56 -1
  16. package/dist/cjs/hooks/API/useGetCollectiblePrices.js.map +1 -1
  17. package/dist/cjs/hooks/API/useGetExchangeRate.d.ts +37 -1
  18. package/dist/cjs/hooks/API/useGetExchangeRate.d.ts.map +1 -1
  19. package/dist/cjs/hooks/API/useGetExchangeRate.js +37 -1
  20. package/dist/cjs/hooks/API/useGetExchangeRate.js.map +1 -1
  21. package/dist/cjs/hooks/Combination/useGetSwapPrices.d.ts +69 -1
  22. package/dist/cjs/hooks/Combination/useGetSwapPrices.d.ts.map +1 -1
  23. package/dist/cjs/hooks/Combination/useGetSwapPrices.js +70 -14
  24. package/dist/cjs/hooks/Combination/useGetSwapPrices.js.map +1 -1
  25. package/dist/cjs/hooks/Combination/useGetSwapQuote.d.ts +74 -3
  26. package/dist/cjs/hooks/Combination/useGetSwapQuote.d.ts.map +1 -1
  27. package/dist/cjs/hooks/Combination/useGetSwapQuote.js +76 -5
  28. package/dist/cjs/hooks/Combination/useGetSwapQuote.js.map +1 -1
  29. package/dist/cjs/hooks/Indexer/useGetTransactionHistory.d.ts +1 -1
  30. package/dist/cjs/hooks/Indexer/useGetTransactionHistory.js +1 -1
  31. package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.d.ts +66 -1
  32. package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.d.ts.map +1 -1
  33. package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.js +66 -1
  34. package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.js.map +1 -1
  35. package/dist/cjs/hooks/Indexer/useIndexerClient.d.ts +98 -0
  36. package/dist/cjs/hooks/Indexer/useIndexerClient.d.ts.map +1 -1
  37. package/dist/cjs/hooks/Indexer/useIndexerClient.js +104 -6
  38. package/dist/cjs/hooks/Indexer/useIndexerClient.js.map +1 -1
  39. package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.d.ts.map +1 -1
  40. package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.js +3 -4
  41. package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.js.map +1 -1
  42. package/dist/cjs/hooks/Metadata/useGetContractInfo.d.ts +61 -1
  43. package/dist/cjs/hooks/Metadata/useGetContractInfo.d.ts.map +1 -1
  44. package/dist/cjs/hooks/Metadata/useGetContractInfo.js +61 -1
  45. package/dist/cjs/hooks/Metadata/useGetContractInfo.js.map +1 -1
  46. package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.d.ts +89 -1
  47. package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.d.ts.map +1 -1
  48. package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.js +89 -1
  49. package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.js.map +1 -1
  50. package/dist/cjs/hooks/Metadata/useGetTokenMetadata.d.ts +83 -1
  51. package/dist/cjs/hooks/Metadata/useGetTokenMetadata.d.ts.map +1 -1
  52. package/dist/cjs/hooks/Metadata/useGetTokenMetadata.js +83 -1
  53. package/dist/cjs/hooks/Metadata/useGetTokenMetadata.js.map +1 -1
  54. package/dist/cjs/hooks/Metadata/useMetadataClient.d.ts +36 -0
  55. package/dist/cjs/hooks/Metadata/useMetadataClient.d.ts.map +1 -1
  56. package/dist/cjs/hooks/Metadata/useMetadataClient.js +39 -4
  57. package/dist/cjs/hooks/Metadata/useMetadataClient.js.map +1 -1
  58. package/dist/cjs/hooks/useConfig.d.ts +45 -0
  59. package/dist/cjs/hooks/useConfig.d.ts.map +1 -1
  60. package/dist/cjs/hooks/useConfig.js +45 -0
  61. package/dist/cjs/hooks/useConfig.js.map +1 -1
  62. package/dist/cjs/tests/Combination/useGetSwapQuote.test.js +3 -3
  63. package/dist/cjs/tests/Combination/useGetSwapQuote.test.js.map +1 -1
  64. package/dist/cjs/tests/handlers.d.ts.map +1 -1
  65. package/dist/cjs/tests/handlers.js +14 -0
  66. package/dist/cjs/tests/handlers.js.map +1 -1
  67. package/dist/esm/contexts/ConfigContext.d.ts +3 -0
  68. package/dist/esm/contexts/ConfigContext.d.ts.map +1 -1
  69. package/dist/esm/contexts/ConfigContext.js +5 -2
  70. package/dist/esm/contexts/ConfigContext.js.map +1 -1
  71. package/dist/esm/hooks/API/useAPIClient.d.ts +37 -0
  72. package/dist/esm/hooks/API/useAPIClient.d.ts.map +1 -1
  73. package/dist/esm/hooks/API/useAPIClient.js +40 -4
  74. package/dist/esm/hooks/API/useAPIClient.js.map +1 -1
  75. package/dist/esm/hooks/API/useGetCoinPrices.d.ts +43 -1
  76. package/dist/esm/hooks/API/useGetCoinPrices.d.ts.map +1 -1
  77. package/dist/esm/hooks/API/useGetCoinPrices.js +51 -1
  78. package/dist/esm/hooks/API/useGetCoinPrices.js.map +1 -1
  79. package/dist/esm/hooks/API/useGetCollectiblePrices.d.ts +48 -1
  80. package/dist/esm/hooks/API/useGetCollectiblePrices.d.ts.map +1 -1
  81. package/dist/esm/hooks/API/useGetCollectiblePrices.js +56 -1
  82. package/dist/esm/hooks/API/useGetCollectiblePrices.js.map +1 -1
  83. package/dist/esm/hooks/API/useGetExchangeRate.d.ts +37 -1
  84. package/dist/esm/hooks/API/useGetExchangeRate.d.ts.map +1 -1
  85. package/dist/esm/hooks/API/useGetExchangeRate.js +37 -1
  86. package/dist/esm/hooks/API/useGetExchangeRate.js.map +1 -1
  87. package/dist/esm/hooks/Combination/useGetSwapPrices.d.ts +69 -1
  88. package/dist/esm/hooks/Combination/useGetSwapPrices.d.ts.map +1 -1
  89. package/dist/esm/hooks/Combination/useGetSwapPrices.js +71 -15
  90. package/dist/esm/hooks/Combination/useGetSwapPrices.js.map +1 -1
  91. package/dist/esm/hooks/Combination/useGetSwapQuote.d.ts +74 -3
  92. package/dist/esm/hooks/Combination/useGetSwapQuote.d.ts.map +1 -1
  93. package/dist/esm/hooks/Combination/useGetSwapQuote.js +77 -6
  94. package/dist/esm/hooks/Combination/useGetSwapQuote.js.map +1 -1
  95. package/dist/esm/hooks/Indexer/useGetTransactionHistory.d.ts +1 -1
  96. package/dist/esm/hooks/Indexer/useGetTransactionHistory.js +1 -1
  97. package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.d.ts +66 -1
  98. package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.d.ts.map +1 -1
  99. package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.js +66 -1
  100. package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.js.map +1 -1
  101. package/dist/esm/hooks/Indexer/useIndexerClient.d.ts +98 -0
  102. package/dist/esm/hooks/Indexer/useIndexerClient.d.ts.map +1 -1
  103. package/dist/esm/hooks/Indexer/useIndexerClient.js +104 -6
  104. package/dist/esm/hooks/Indexer/useIndexerClient.js.map +1 -1
  105. package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.d.ts.map +1 -1
  106. package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.js +3 -4
  107. package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.js.map +1 -1
  108. package/dist/esm/hooks/Metadata/useGetContractInfo.d.ts +61 -1
  109. package/dist/esm/hooks/Metadata/useGetContractInfo.d.ts.map +1 -1
  110. package/dist/esm/hooks/Metadata/useGetContractInfo.js +61 -1
  111. package/dist/esm/hooks/Metadata/useGetContractInfo.js.map +1 -1
  112. package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.d.ts +89 -1
  113. package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.d.ts.map +1 -1
  114. package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.js +89 -1
  115. package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.js.map +1 -1
  116. package/dist/esm/hooks/Metadata/useGetTokenMetadata.d.ts +83 -1
  117. package/dist/esm/hooks/Metadata/useGetTokenMetadata.d.ts.map +1 -1
  118. package/dist/esm/hooks/Metadata/useGetTokenMetadata.js +83 -1
  119. package/dist/esm/hooks/Metadata/useGetTokenMetadata.js.map +1 -1
  120. package/dist/esm/hooks/Metadata/useMetadataClient.d.ts +36 -0
  121. package/dist/esm/hooks/Metadata/useMetadataClient.d.ts.map +1 -1
  122. package/dist/esm/hooks/Metadata/useMetadataClient.js +39 -4
  123. package/dist/esm/hooks/Metadata/useMetadataClient.js.map +1 -1
  124. package/dist/esm/hooks/useConfig.d.ts +45 -0
  125. package/dist/esm/hooks/useConfig.d.ts.map +1 -1
  126. package/dist/esm/hooks/useConfig.js +45 -0
  127. package/dist/esm/hooks/useConfig.js.map +1 -1
  128. package/dist/esm/tests/Combination/useGetSwapQuote.test.js +4 -4
  129. package/dist/esm/tests/Combination/useGetSwapQuote.test.js.map +1 -1
  130. package/dist/esm/tests/handlers.d.ts.map +1 -1
  131. package/dist/esm/tests/handlers.js +14 -0
  132. package/dist/esm/tests/handlers.js.map +1 -1
  133. 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
- * @description Gets the prices of a list of tokens
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;;GAEG;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
+ {"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
- * @description Gets the prices of a list of collectibles
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;AAc1C;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,KAAK,EAAE,EAAE,UAAU,YAAY,kGAU9E,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
- * @description Gets the prices of a list of collectibles
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,EA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C,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
- * @description Gets the exchange rate from USD to another currency
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;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,EAAE,UAAU,YAAY,kEAkB5E,CAAA"}
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
- * @description Gets the exchange rate from USD to another currency
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;;GAEG;AACH,MAAM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,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
- * @description Gets the Swap Prices for a given currency
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;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,oBAAoB,EAAE,UAAU,YAAY,wFAsBlF,CAAA"}
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"}
@@ -1,6 +1,6 @@
1
1
  import { findSupportedNetwork } from '@0xsequence/network';
2
2
  import { useQuery } from '@tanstack/react-query';
3
- import { NATIVE_TOKEN_ADDRESS_0X_SWAP, QUERY_KEYS, ZERO_ADDRESS, time } from '../../constants';
3
+ import { NATIVE_TOKEN_ADDRESS_0X_SWAP, QUERY_KEYS, time, ZERO_ADDRESS } from '../../constants';
4
4
  import { compareAddress } from '../../utils/helpers';
5
5
  import { useAPIClient } from '../API/useAPIClient';
6
6
  import { useIndexerGatewayClient } from '../IndexerGateway/useIndexerGatewayClient';
@@ -11,22 +11,25 @@ const getSwapPrices = async (apiClient, metadataClient, indexerGatewayClient, ar
11
11
  }
12
12
  const network = findSupportedNetwork(args.chainId);
13
13
  const { withContractInfo, ...swapPricesArgs } = args;
14
- const res = await apiClient.getSwapPrices(swapPricesArgs);
15
- if (res.swapPrices === null) {
14
+ const isNativeTokenInArgs = compareAddress(args.buyCurrencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP) || compareAddress(args.buyCurrencyAddress, ZERO_ADDRESS);
15
+ const res = await apiClient.getSwapPermit2Prices({
16
+ ...swapPricesArgs,
17
+ buyCurrencyAddress: isNativeTokenInArgs ? NATIVE_TOKEN_ADDRESS_0X_SWAP : args.buyCurrencyAddress
18
+ });
19
+ if (res.swapPermit2Prices === null) {
16
20
  return [];
17
21
  }
18
22
  const currencyInfoMap = new Map();
19
23
  if (withContractInfo) {
20
- res?.swapPrices.forEach(price => {
21
- const { currencyAddress: rawCurrencyAddress } = price;
22
- const currencyAddress = compareAddress(rawCurrencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP) ? ZERO_ADDRESS : rawCurrencyAddress;
23
- const isNativeToken = compareAddress(currencyAddress, ZERO_ADDRESS);
24
+ res?.swapPermit2Prices.forEach(price => {
25
+ const { currencyAddress } = price;
26
+ const isNativeToken = compareAddress(currencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP || ZERO_ADDRESS);
24
27
  if (currencyAddress && !currencyInfoMap.has(currencyAddress)) {
25
28
  const getNativeTokenInfo = () => new Promise(resolve => {
26
29
  resolve({
27
30
  ...network?.nativeToken,
28
31
  logoURI: network?.logoURI || '',
29
- address: ZERO_ADDRESS
32
+ address: NATIVE_TOKEN_ADDRESS_0X_SWAP
30
33
  });
31
34
  });
32
35
  currencyInfoMap.set(currencyAddress, isNativeToken
@@ -45,10 +48,9 @@ const getSwapPrices = async (apiClient, metadataClient, indexerGatewayClient, ar
45
48
  });
46
49
  }
47
50
  const currencyBalanceInfoMap = new Map();
48
- res?.swapPrices.forEach(price => {
49
- const { currencyAddress: rawCurrencyAddress } = price;
50
- const currencyAddress = compareAddress(rawCurrencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP) ? ZERO_ADDRESS : rawCurrencyAddress;
51
- const isNativeToken = compareAddress(currencyAddress, ZERO_ADDRESS);
51
+ res?.swapPermit2Prices.forEach(price => {
52
+ const { currencyAddress } = price;
53
+ const isNativeToken = compareAddress(currencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP || ZERO_ADDRESS);
52
54
  if (currencyAddress && !currencyBalanceInfoMap.has(currencyAddress)) {
53
55
  const tokenBalance = indexerGatewayClient
54
56
  .getTokenBalancesSummary({
@@ -78,9 +80,11 @@ const getSwapPrices = async (apiClient, metadataClient, indexerGatewayClient, ar
78
80
  currencyBalanceInfoMap.set(currencyAddress, tokenBalance);
79
81
  }
80
82
  });
81
- return Promise.all(res?.swapPrices.map(async (price) => {
83
+ return Promise.all(res?.swapPermit2Prices.map(async (price) => {
82
84
  const { currencyAddress: rawCurrencyAddress } = price;
83
- const currencyAddress = compareAddress(rawCurrencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP) ? ZERO_ADDRESS : rawCurrencyAddress;
85
+ const currencyAddress = compareAddress(rawCurrencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP)
86
+ ? NATIVE_TOKEN_ADDRESS_0X_SWAP
87
+ : rawCurrencyAddress;
84
88
  return {
85
89
  price: {
86
90
  ...price,
@@ -92,7 +96,59 @@ const getSwapPrices = async (apiClient, metadataClient, indexerGatewayClient, ar
92
96
  }) || []);
93
97
  };
94
98
  /**
95
- * @description Gets the Swap Prices for a given currency
99
+ * Hook to fetch available swap prices for a given currency pair.
100
+ *
101
+ * This hook provides functionality to:
102
+ * - Get swap prices for a specified currency and amount
103
+ * - Fetch token information and balances for available swap options
104
+ * - Support both native tokens and ERC20 tokens
105
+ * - Handle currency conversions and price formatting
106
+ *
107
+ * The hook automatically handles:
108
+ * - Native token address normalization (between 0x0 and 0xEEE...)
109
+ * - Contract information fetching (name, symbol, decimals, etc.)
110
+ * - Error handling for failed API calls or balance fetches
111
+ *
112
+ * @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapPrices} for more detailed documentation.
113
+ *
114
+ * @param args - Configuration object for the swap prices query {@link UseGetSwapPricesArgs}
115
+ * @param options - Optional configuration for the hook behavior {@link HooksOptions}
116
+ *
117
+ * @returns A React Query result object containing:
118
+ * - data: Array of {@link SwapPricesWithCurrencyInfo} objects
119
+ * - isLoading: Whether the query is in progress
120
+ * - isError: Whether an error occurred
121
+ * - error: Any error that occurred
122
+ * - Other standard React Query properties
123
+ *
124
+ * @example
125
+ * ```tsx
126
+ * import { useGetSwapPrices } from '@0xsequence/hooks'
127
+ *
128
+ * function SwapComponent() {
129
+ * const { data: swapPrices, isLoading } = useGetSwapPrices({
130
+ * userAddress: '0x123...',
131
+ * buyCurrencyAddress: '0x456...',
132
+ * buyAmount: '1000000000000000000', // 1 token in base units
133
+ * chainId: 1,
134
+ * withContractInfo: true
135
+ * })
136
+ *
137
+ * if (isLoading) return <div>Loading...</div>
138
+ *
139
+ * return (
140
+ * <div>
141
+ * {swapPrices?.map(swap => (
142
+ * <div key={swap.info?.address}>
143
+ * Token: {swap.info?.symbol}
144
+ * Price: {swap.price.price}
145
+ * Balance: {swap.balance.balance}
146
+ * </div>
147
+ * ))}
148
+ * </div>
149
+ * )
150
+ * }
151
+ * ```
96
152
  */
97
153
  export const useGetSwapPrices = (args, options) => {
98
154
  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,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,4BAA4B,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE9F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAA;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAoBjE,MAAM,aAAa,GAAG,KAAK,EACzB,SAA4B,EAC5B,cAAgC,EAChC,oBAA4C,EAC5C,IAA0B,EACa,EAAE;IACzC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,GAAG,EAAE,CAAC;QAChH,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAElD,MAA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;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAA0B,EAAE,OAAsB,EAAE,EAAE;IACrF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAA;IAC1C,MAAM,oBAAoB,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 { GetSwapQuoteArgs } from '@0xsequence/api';
1
+ import { GetSwapQuoteV2Args } from '@0xsequence/api';
2
2
  import { HooksOptions } from '../../types';
3
3
  /**
4
- * @description Gets the swap quote for a given currency pair
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: GetSwapQuoteArgs, options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<{
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,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,kBAAkB,gBAAgB,EAAE,UAAU,YAAY;;;;;;;;;SA4BzF,CAAA"}
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"}