@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
|
@@ -95,7 +95,59 @@ const getSwapPrices = async (apiClient, metadataClient, indexerGatewayClient, ar
|
|
|
95
95
|
}) || []);
|
|
96
96
|
};
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
98
|
+
* Hook to fetch available swap prices for a given currency pair.
|
|
99
|
+
*
|
|
100
|
+
* This hook provides functionality to:
|
|
101
|
+
* - Get swap prices for a specified currency and amount
|
|
102
|
+
* - Fetch token information and balances for available swap options
|
|
103
|
+
* - Support both native tokens and ERC20 tokens
|
|
104
|
+
* - Handle currency conversions and price formatting
|
|
105
|
+
*
|
|
106
|
+
* The hook automatically handles:
|
|
107
|
+
* - Native token address normalization (between 0x0 and 0xEEE...)
|
|
108
|
+
* - Contract information fetching (name, symbol, decimals, etc.)
|
|
109
|
+
* - Error handling for failed API calls or balance fetches
|
|
110
|
+
*
|
|
111
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapPrices} for more detailed documentation.
|
|
112
|
+
*
|
|
113
|
+
* @param args - Configuration object for the swap prices query {@link UseGetSwapPricesArgs}
|
|
114
|
+
* @param options - Optional configuration for the hook behavior {@link HooksOptions}
|
|
115
|
+
*
|
|
116
|
+
* @returns A React Query result object containing:
|
|
117
|
+
* - data: Array of {@link SwapPricesWithCurrencyInfo} objects
|
|
118
|
+
* - isLoading: Whether the query is in progress
|
|
119
|
+
* - isError: Whether an error occurred
|
|
120
|
+
* - error: Any error that occurred
|
|
121
|
+
* - Other standard React Query properties
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* import { useGetSwapPrices } from '@0xsequence/hooks'
|
|
126
|
+
*
|
|
127
|
+
* function SwapComponent() {
|
|
128
|
+
* const { data: swapPrices, isLoading } = useGetSwapPrices({
|
|
129
|
+
* userAddress: '0x123...',
|
|
130
|
+
* buyCurrencyAddress: '0x456...',
|
|
131
|
+
* buyAmount: '1000000000000000000', // 1 token in base units
|
|
132
|
+
* chainId: 1,
|
|
133
|
+
* withContractInfo: true
|
|
134
|
+
* })
|
|
135
|
+
*
|
|
136
|
+
* if (isLoading) return <div>Loading...</div>
|
|
137
|
+
*
|
|
138
|
+
* return (
|
|
139
|
+
* <div>
|
|
140
|
+
* {swapPrices?.map(swap => (
|
|
141
|
+
* <div key={swap.info?.address}>
|
|
142
|
+
* Token: {swap.info?.symbol}
|
|
143
|
+
* Price: {swap.price.price}
|
|
144
|
+
* Balance: {swap.balance.balance}
|
|
145
|
+
* </div>
|
|
146
|
+
* ))}
|
|
147
|
+
* </div>
|
|
148
|
+
* )
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
99
151
|
*/
|
|
100
152
|
const useGetSwapPrices = (args, options) => {
|
|
101
153
|
const apiClient = (0, useAPIClient_1.useAPIClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSwapPrices.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapPrices.ts"],"names":[],"mappings":";;;AAGA,iDAA0D;AAC1D,uDAAgD;AAEhD,+CAA8F;AAE9F,iDAAoD;AACpD,sDAAkD;AAClD,uFAAmF;AACnF,qEAAiE;
|
|
1
|
+
{"version":3,"file":"useGetSwapPrices.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapPrices.ts"],"names":[],"mappings":";;;AAGA,iDAA0D;AAC1D,uDAAgD;AAEhD,+CAA8F;AAE9F,iDAAoD;AACpD,sDAAkD;AAClD,uFAAmF;AACnF,qEAAiE;AAoCjE,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,IAAA,8BAAoB,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAElD,MAAM,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,GAAG,IAAI,CAAA;IAEpD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;IAEzD,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,eAAe,GAAG,IAAI,GAAG,EA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GAAG;QACtB,CAAC,OAAO,EAAE,QAAQ,CAAA;IAEpB,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,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,gBAAI,CAAC,OAAO;QACvB,OAAO;KACR,CAAC,CAAA;AACJ,CAAC,CAAA;AAtBY,QAAA,gBAAgB,oBAsB5B"}
|
|
@@ -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"}
|
|
@@ -6,25 +6,96 @@ const constants_1 = require("../../constants");
|
|
|
6
6
|
const helpers_1 = require("../../utils/helpers");
|
|
7
7
|
const useAPIClient_1 = require("../API/useAPIClient");
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Hook to fetch a swap quote for exchanging between two currencies.
|
|
10
|
+
*
|
|
11
|
+
* This hook provides functionality to:
|
|
12
|
+
* - Get a quote for swapping between two currencies (native or ERC20)
|
|
13
|
+
* - Fetch necessary approval data for ERC20 tokens
|
|
14
|
+
* - Generate transaction data for executing the swap
|
|
15
|
+
*
|
|
16
|
+
* The hook automatically handles:
|
|
17
|
+
* - Native token address normalization (between 0x0 and 0xEEE...)
|
|
18
|
+
* - Approval data generation for ERC20 tokens when needed
|
|
19
|
+
* - Transaction data generation for the swap
|
|
20
|
+
* - Error handling for failed API calls
|
|
21
|
+
*
|
|
22
|
+
* Go to {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
|
|
23
|
+
*
|
|
24
|
+
* @param getSwapQuoteArgs - Configuration object for the swap quote query:
|
|
25
|
+
* - userAddress: The address of the user's wallet
|
|
26
|
+
* - buyCurrencyAddress: The address of the currency to buy
|
|
27
|
+
* - sellCurrencyAddress: The address of the currency to sell
|
|
28
|
+
* - buyAmount: The amount of currency to buy (in base units)
|
|
29
|
+
* - chainId: The chain ID where the swap will occur
|
|
30
|
+
* - includeApprove: Whether to include approval data for ERC20 tokens
|
|
31
|
+
*
|
|
32
|
+
* @param options - Optional configuration for the hook behavior:
|
|
33
|
+
* - disabled: Whether to disable the query
|
|
34
|
+
* - retry: Whether to retry failed queries
|
|
35
|
+
* - Other standard React Query options
|
|
36
|
+
*
|
|
37
|
+
* @returns A React Query result object containing:
|
|
38
|
+
* - data: The swap quote data including:
|
|
39
|
+
* - currencyAddress: The address of the currency being swapped
|
|
40
|
+
* - currencyBalance: The user's balance of the currency
|
|
41
|
+
* - price: The price for the swap
|
|
42
|
+
* - maxPrice: The maximum price (including slippage)
|
|
43
|
+
* - to: The target contract address for the swap
|
|
44
|
+
* - transactionData: The calldata for the swap transaction
|
|
45
|
+
* - transactionValue: The value to send with the transaction (for native tokens)
|
|
46
|
+
* - approveData: The approval transaction data (if needed)
|
|
47
|
+
* - isLoading: Whether the query is in progress
|
|
48
|
+
* - isError: Whether an error occurred
|
|
49
|
+
* - error: Any error that occurred
|
|
50
|
+
* - Other standard React Query properties
|
|
51
|
+
*
|
|
52
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* import { useGetSwapQuote } from '@0xsequence/hooks'
|
|
57
|
+
*
|
|
58
|
+
* function SwapComponent() {
|
|
59
|
+
* const { data: swapQuote, isLoading } = useGetSwapQuote({
|
|
60
|
+
* userAddress: '0x123...',
|
|
61
|
+
* buyCurrencyAddress: '0x456...',
|
|
62
|
+
* sellCurrencyAddress: '0x789...',
|
|
63
|
+
* buyAmount: '1000000000000000000', // 1 token in base units
|
|
64
|
+
* chainId: 1,
|
|
65
|
+
* includeApprove: true
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* if (isLoading) return <div>Loading...</div>
|
|
69
|
+
*
|
|
70
|
+
* return (
|
|
71
|
+
* <div>
|
|
72
|
+
* <div>Price: {swapQuote?.price}</div>
|
|
73
|
+
* <div>Max Price: {swapQuote?.maxPrice}</div>
|
|
74
|
+
* <button onClick={() => executeSwap(swapQuote)}>
|
|
75
|
+
* Swap Tokens
|
|
76
|
+
* </button>
|
|
77
|
+
* </div>
|
|
78
|
+
* )
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
10
81
|
*/
|
|
11
82
|
const useGetSwapQuote = (getSwapQuoteArgs, options) => {
|
|
12
83
|
const apiClient = (0, useAPIClient_1.useAPIClient)();
|
|
13
84
|
return (0, react_query_1.useQuery)({
|
|
14
85
|
queryKey: [constants_1.QUERY_KEYS.useGetSwapQuote, getSwapQuoteArgs, options],
|
|
15
86
|
queryFn: async () => {
|
|
16
|
-
const res = await apiClient.
|
|
87
|
+
const res = await apiClient.getSwapQuoteV2({
|
|
17
88
|
...getSwapQuoteArgs,
|
|
18
89
|
buyCurrencyAddress: (0, helpers_1.compareAddress)(getSwapQuoteArgs.buyCurrencyAddress, constants_1.ZERO_ADDRESS)
|
|
19
|
-
? constants_1.
|
|
90
|
+
? constants_1.ZERO_ADDRESS
|
|
20
91
|
: getSwapQuoteArgs.buyCurrencyAddress,
|
|
21
92
|
sellCurrencyAddress: (0, helpers_1.compareAddress)(getSwapQuoteArgs.sellCurrencyAddress, constants_1.ZERO_ADDRESS)
|
|
22
|
-
? constants_1.
|
|
93
|
+
? constants_1.ZERO_ADDRESS
|
|
23
94
|
: getSwapQuoteArgs.sellCurrencyAddress
|
|
24
95
|
});
|
|
25
96
|
return {
|
|
26
97
|
...res.swapQuote,
|
|
27
|
-
currencyAddress: (0, helpers_1.compareAddress)(res.swapQuote.currencyAddress, constants_1.
|
|
98
|
+
currencyAddress: (0, helpers_1.compareAddress)(res.swapQuote.currencyAddress, constants_1.ZERO_ADDRESS)
|
|
28
99
|
? constants_1.ZERO_ADDRESS
|
|
29
100
|
: res.swapQuote.currencyAddress
|
|
30
101
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSwapQuote.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapQuote.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+
|
|
1
|
+
{"version":3,"file":"useGetSwapQuote.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapQuote.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAgE;AAEhE,iDAAoD;AACpD,sDAAkD;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACI,MAAM,eAAe,GAAG,CAAC,gBAAoC,EAAE,OAAsB,EAAE,EAAE;IAC9F,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAA;IAEhC,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,eAAe,EAAE,gBAAgB,EAAE,OAAO,CAAC;QACjE,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC;gBACzC,GAAG,gBAAgB;gBACnB,kBAAkB,EAAE,IAAA,wBAAc,EAAC,gBAAgB,CAAC,kBAAkB,EAAE,wBAAY,CAAC;oBACnF,CAAC,CAAC,wBAAY;oBACd,CAAC,CAAC,gBAAgB,CAAC,kBAAkB;gBACvC,mBAAmB,EAAE,IAAA,wBAAc,EAAC,gBAAgB,CAAC,mBAAmB,EAAE,wBAAY,CAAC;oBACrF,CAAC,CAAC,wBAAY;oBACd,CAAC,CAAC,gBAAgB,CAAC,mBAAmB;aACzC,CAAC,CAAA;YAEF,OAAO;gBACL,GAAG,GAAG,CAAC,SAAS;gBAChB,eAAe,EAAE,IAAA,wBAAc,EAAC,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,wBAAY,CAAC;oBAC1E,CAAC,CAAC,wBAAY;oBACd,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe;aAClC,CAAA;QACH,CAAC;QACD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,SAAS,GAAG,CAAC;QAC7B,OAAO,EACL,CAAC,OAAO,EAAE,QAAQ,IAAI,CAAC,gBAAgB,CAAC,WAAW,IAAI,CAAC,gBAAgB,CAAC,OAAO,IAAI,CAAC,gBAAgB,CAAC,kBAAkB;KAC3H,CAAC,CAAA;AACJ,CAAC,CAAA;AA5BY,QAAA,eAAe,mBA4B3B"}
|
|
@@ -39,7 +39,7 @@ export interface UseGetTransactionHistoryArgs extends GetTransactionHistoryArgs
|
|
|
39
39
|
* It can filter transactions by contract address and token ID, making it useful for both
|
|
40
40
|
* general account history and specific asset history views.
|
|
41
41
|
*
|
|
42
|
-
*
|
|
42
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTransactionHistory} for more detailed documentation.
|
|
43
43
|
*
|
|
44
44
|
* @param args - Configuration object for the transaction history query {@link GetTransactionHistoryArgs}
|
|
45
45
|
*
|
|
@@ -37,7 +37,7 @@ const getTransactionHistory = async (indexerClient, { contractAddress, accountAd
|
|
|
37
37
|
* It can filter transactions by contract address and token ID, making it useful for both
|
|
38
38
|
* general account history and specific asset history views.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
40
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTransactionHistory} for more detailed documentation.
|
|
41
41
|
*
|
|
42
42
|
* @param args - Configuration object for the transaction history query {@link GetTransactionHistoryArgs}
|
|
43
43
|
*
|
|
@@ -5,7 +5,72 @@ export interface GetTransactionHistorySummaryArgs {
|
|
|
5
5
|
chainIds: number[];
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* A hook that retrieves a comprehensive transaction history summary across multiple chains for a given account address.
|
|
9
|
+
* The transactions are ordered by timestamp (newest first) and include detailed transfer information.
|
|
10
|
+
*
|
|
11
|
+
* Implementation details:
|
|
12
|
+
* - Uses Promise.all with an array of indexer clients to fetch transactions from all specified chains in parallel
|
|
13
|
+
* - Flattens and sorts the combined results by timestamp
|
|
14
|
+
* - Normalizes all addresses in transfer objects using viem's getAddress
|
|
15
|
+
*
|
|
16
|
+
* @param getTransactionHistorySummaryArgs - Configuration object for the transaction history query
|
|
17
|
+
* @param getTransactionHistorySummaryArgs.accountAddress - The account address to fetch transactions for
|
|
18
|
+
* @param getTransactionHistorySummaryArgs.chainIds - Array of chain IDs to fetch transactions from. Each chain ID will be queried in parallel.
|
|
19
|
+
* @param options - Optional configuration for the hook behavior
|
|
20
|
+
* @param options.disabled - If true, disables the query
|
|
21
|
+
* @param options.retry - If true (default), retries failed requests
|
|
22
|
+
*
|
|
23
|
+
* @returns A React Query result object containing:
|
|
24
|
+
* - data: Array of Transaction objects combined from all specified chains, each containing:
|
|
25
|
+
* - txnHash: Transaction hash
|
|
26
|
+
* - chainId: Chain ID where transaction occurred
|
|
27
|
+
* - timestamp: Transaction timestamp
|
|
28
|
+
* - transfers: Array of transfer objects with normalized addresses
|
|
29
|
+
* - blockNumber: Block number where transaction was mined
|
|
30
|
+
* - blockHash: Hash of the block
|
|
31
|
+
* - metaTxnID: Optional meta transaction ID
|
|
32
|
+
* - Other standard React Query properties (isLoading, isError, etc.)
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTransactionHistorySummary} for more detailed documentation.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* import { useGetTransactionHistorySummary } from '@0xsequence/hooks'
|
|
39
|
+
* import { useAccount } from 'wagmi'
|
|
40
|
+
*
|
|
41
|
+
* // Basic usage in a component
|
|
42
|
+
* const TransactionHistory = () => {
|
|
43
|
+
* const { address: accountAddress } = useAccount()
|
|
44
|
+
* const {
|
|
45
|
+
* data: transactionHistory = [],
|
|
46
|
+
* isPending: isPendingTransactionHistory
|
|
47
|
+
* } = useGetTransactionHistorySummary({
|
|
48
|
+
* accountAddress: accountAddress || '',
|
|
49
|
+
* chainIds: [1, 137]
|
|
50
|
+
* })
|
|
51
|
+
*
|
|
52
|
+
* return (
|
|
53
|
+
* <div>
|
|
54
|
+
* {transactionHistory.map(tx => (
|
|
55
|
+
* <div key={tx.txnHash}>
|
|
56
|
+
* Transaction: {tx.txnHash}
|
|
57
|
+
* Chain: {tx.chainId}
|
|
58
|
+
* Time: {tx.timestamp}
|
|
59
|
+
* </div>
|
|
60
|
+
* ))}
|
|
61
|
+
* </div>
|
|
62
|
+
* )
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* - The hook uses the Sequence Indexer service to fetch transaction data
|
|
68
|
+
* - Creates a separate indexer client for each chain ID and fetches from all in parallel
|
|
69
|
+
* - Transactions from all chains are combined and sorted by timestamp (newest first)
|
|
70
|
+
* - All addresses in transfer objects are normalized using viem's getAddress
|
|
71
|
+
* - The query is enabled only when chainIds array is not empty and accountAddress is provided
|
|
72
|
+
* - The query result is cached for 30 seconds (staleTime)
|
|
73
|
+
* - The query automatically refetches when the component is mounted
|
|
9
74
|
*/
|
|
10
75
|
export declare const useGetTransactionHistorySummary: (getTransactionHistorySummaryArgs: GetTransactionHistorySummaryArgs, options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<Transaction[], Error>;
|
|
11
76
|
//# sourceMappingURL=useGetTransactionHistorySummary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTransactionHistorySummary.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useGetTransactionHistorySummary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKlE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,MAAM,WAAW,gCAAgC;IAC/C,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAoCD
|
|
1
|
+
{"version":3,"file":"useGetTransactionHistorySummary.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useGetTransactionHistorySummary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKlE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,MAAM,WAAW,gCAAgC;IAC/C,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAoCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,eAAO,MAAM,+BAA+B,GAC1C,kCAAkC,gCAAgC,EAClE,UAAU,YAAY,yEAiBvB,CAAA"}
|
|
@@ -29,7 +29,72 @@ const getTransactionHistorySummary = async (indexerClients, { accountAddress })
|
|
|
29
29
|
return transactions;
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* A hook that retrieves a comprehensive transaction history summary across multiple chains for a given account address.
|
|
33
|
+
* The transactions are ordered by timestamp (newest first) and include detailed transfer information.
|
|
34
|
+
*
|
|
35
|
+
* Implementation details:
|
|
36
|
+
* - Uses Promise.all with an array of indexer clients to fetch transactions from all specified chains in parallel
|
|
37
|
+
* - Flattens and sorts the combined results by timestamp
|
|
38
|
+
* - Normalizes all addresses in transfer objects using viem's getAddress
|
|
39
|
+
*
|
|
40
|
+
* @param getTransactionHistorySummaryArgs - Configuration object for the transaction history query
|
|
41
|
+
* @param getTransactionHistorySummaryArgs.accountAddress - The account address to fetch transactions for
|
|
42
|
+
* @param getTransactionHistorySummaryArgs.chainIds - Array of chain IDs to fetch transactions from. Each chain ID will be queried in parallel.
|
|
43
|
+
* @param options - Optional configuration for the hook behavior
|
|
44
|
+
* @param options.disabled - If true, disables the query
|
|
45
|
+
* @param options.retry - If true (default), retries failed requests
|
|
46
|
+
*
|
|
47
|
+
* @returns A React Query result object containing:
|
|
48
|
+
* - data: Array of Transaction objects combined from all specified chains, each containing:
|
|
49
|
+
* - txnHash: Transaction hash
|
|
50
|
+
* - chainId: Chain ID where transaction occurred
|
|
51
|
+
* - timestamp: Transaction timestamp
|
|
52
|
+
* - transfers: Array of transfer objects with normalized addresses
|
|
53
|
+
* - blockNumber: Block number where transaction was mined
|
|
54
|
+
* - blockHash: Hash of the block
|
|
55
|
+
* - metaTxnID: Optional meta transaction ID
|
|
56
|
+
* - Other standard React Query properties (isLoading, isError, etc.)
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTransactionHistorySummary} for more detailed documentation.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* import { useGetTransactionHistorySummary } from '@0xsequence/hooks'
|
|
63
|
+
* import { useAccount } from 'wagmi'
|
|
64
|
+
*
|
|
65
|
+
* // Basic usage in a component
|
|
66
|
+
* const TransactionHistory = () => {
|
|
67
|
+
* const { address: accountAddress } = useAccount()
|
|
68
|
+
* const {
|
|
69
|
+
* data: transactionHistory = [],
|
|
70
|
+
* isPending: isPendingTransactionHistory
|
|
71
|
+
* } = useGetTransactionHistorySummary({
|
|
72
|
+
* accountAddress: accountAddress || '',
|
|
73
|
+
* chainIds: [1, 137]
|
|
74
|
+
* })
|
|
75
|
+
*
|
|
76
|
+
* return (
|
|
77
|
+
* <div>
|
|
78
|
+
* {transactionHistory.map(tx => (
|
|
79
|
+
* <div key={tx.txnHash}>
|
|
80
|
+
* Transaction: {tx.txnHash}
|
|
81
|
+
* Chain: {tx.chainId}
|
|
82
|
+
* Time: {tx.timestamp}
|
|
83
|
+
* </div>
|
|
84
|
+
* ))}
|
|
85
|
+
* </div>
|
|
86
|
+
* )
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* - The hook uses the Sequence Indexer service to fetch transaction data
|
|
92
|
+
* - Creates a separate indexer client for each chain ID and fetches from all in parallel
|
|
93
|
+
* - Transactions from all chains are combined and sorted by timestamp (newest first)
|
|
94
|
+
* - All addresses in transfer objects are normalized using viem's getAddress
|
|
95
|
+
* - The query is enabled only when chainIds array is not empty and accountAddress is provided
|
|
96
|
+
* - The query result is cached for 30 seconds (staleTime)
|
|
97
|
+
* - The query automatically refetches when the component is mounted
|
|
33
98
|
*/
|
|
34
99
|
const useGetTransactionHistorySummary = (getTransactionHistorySummaryArgs, options) => {
|
|
35
100
|
const indexerClients = (0, useIndexerClient_1.useIndexerClients)(getTransactionHistorySummaryArgs.chainIds);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTransactionHistorySummary.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useGetTransactionHistorySummary.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAChD,+BAAiC;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rB,CAAC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"useGetTransactionHistorySummary.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useGetTransactionHistorySummary.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAChD,+BAAiC;AAEjC,+CAAkD;AAGlD,yDAAsD;AAOtD,MAAM,4BAA4B,GAAG,KAAK,EACxC,cAA4C,EAC5C,EAAE,cAAc,EAAoC,EAC5B,EAAE;IAC1B,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CACtD,aAAa,CAAC,qBAAqB,CAAC;QAClC,MAAM,EAAE;YACN,cAAc;SACf;QACD,eAAe,EAAE,IAAI;KACtB,CAAC,CACH,CACF,CAAA;IAED,MAAM,qBAAqB,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAA;IACnF,MAAM,mBAAmB,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC9D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAA;QACjD,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAA;QAClD,OAAO,UAAU,GAAG,SAAS,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,MAAM,YAAY,GAAG,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC3D,GAAG,WAAW;QACd,SAAS,EAAE,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACjD,GAAG,QAAQ;YACX,IAAI,EAAE,IAAA,iBAAU,EAAC,QAAQ,CAAC,IAAI,CAAC;YAC/B,EAAE,EAAE,IAAA,iBAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;SAC5B,CAAC,CAAC;KACJ,CAAC,CAAC,CAAA;IAEH,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACI,MAAM,+BAA+B,GAAG,CAC7C,gCAAkE,EAClE,OAAsB,EACtB,EAAE;IACF,MAAM,cAAc,GAAG,IAAA,oCAAiB,EAAC,gCAAgC,CAAC,QAAQ,CAAC,CAAA;IAEnF,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,+BAA+B,EAAE,gCAAgC,EAAE,OAAO,CAAC;QACjG,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,MAAM,4BAA4B,CAAC,cAAc,EAAE,gCAAgC,CAAC,CAAA;QAC7F,CAAC;QACD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,SAAS,GAAG,EAAE;QAC9B,cAAc,EAAE,IAAI;QACpB,OAAO,EACL,gCAAgC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACpD,CAAC,CAAC,gCAAgC,CAAC,cAAc;YACjD,CAAC,OAAO,EAAE,QAAQ;KACrB,CAAC,CAAA;AACJ,CAAC,CAAA;AAnBY,QAAA,+BAA+B,mCAmB3C"}
|
|
@@ -1,5 +1,103 @@
|
|
|
1
1
|
import { SequenceIndexer } from '@0xsequence/indexer';
|
|
2
2
|
import { ChainId } from '@0xsequence/network';
|
|
3
|
+
/**
|
|
4
|
+
* Hook that creates and manages a Sequence Indexer client for a specific chain.
|
|
5
|
+
*
|
|
6
|
+
* This hook maintains a cached indexer client for the specified chain ID,
|
|
7
|
+
* initializing it with the appropriate indexer URL based on the network
|
|
8
|
+
* and environment configuration.
|
|
9
|
+
*
|
|
10
|
+
* Implementation details:
|
|
11
|
+
* - Creates a new SequenceIndexer instance for the specified chain ID if it doesn't exist
|
|
12
|
+
* - Caches the client in a Map to avoid recreating it unnecessarily
|
|
13
|
+
* - Uses projectAccessKey for authentication
|
|
14
|
+
* - Constructs appropriate indexer URL based on network and environment
|
|
15
|
+
*
|
|
16
|
+
* @param chainId - The chain ID to create an indexer client for
|
|
17
|
+
* @returns A SequenceIndexer instance for the specified chain
|
|
18
|
+
*
|
|
19
|
+
* @throws Error if an indexer client cannot be created for the specified chain ID
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const TokenBalanceChecker = () => {
|
|
24
|
+
* const chainId = useChainId()
|
|
25
|
+
* const indexerClient = useIndexerClient(chainId)
|
|
26
|
+
* const { address } = useAccount()
|
|
27
|
+
*
|
|
28
|
+
* const checkBalance = async () => {
|
|
29
|
+
* // Get native token balance
|
|
30
|
+
* const nativeBalance = await indexerClient.getNativeTokenBalance({
|
|
31
|
+
* accountAddress: address
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* // Get token balances
|
|
35
|
+
* const tokenBalances = await indexerClient.getTokenBalancesSummary({
|
|
36
|
+
* filter: {
|
|
37
|
+
* accountAddresses: [address],
|
|
38
|
+
* contractStatus: ContractVerificationStatus.ALL,
|
|
39
|
+
* omitNativeBalances: true
|
|
40
|
+
* }
|
|
41
|
+
* })
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* - The client is memoized based on projectAccessKey to prevent recreation
|
|
48
|
+
* - The client is initialized only once per chain ID
|
|
49
|
+
* - The environment configuration determines the indexer URL for the network
|
|
50
|
+
* - Throws an error if the chain ID is not supported or client creation fails
|
|
51
|
+
* - Used internally by useIndexerClients to manage multiple chain clients
|
|
52
|
+
*/
|
|
3
53
|
export declare const useIndexerClient: (chainId: ChainId) => SequenceIndexer;
|
|
54
|
+
/**
|
|
55
|
+
* Hook that creates and manages Sequence Indexer clients for multiple chains.
|
|
56
|
+
*
|
|
57
|
+
* This hook maintains a map of indexer clients, one for each specified chain ID.
|
|
58
|
+
* Each client is initialized with the appropriate indexer URL based on the network
|
|
59
|
+
* and environment configuration.
|
|
60
|
+
*
|
|
61
|
+
* Implementation details:
|
|
62
|
+
* - Creates a new SequenceIndexer instance for each unique chain ID
|
|
63
|
+
* - Caches clients in a Map to avoid recreating them unnecessarily
|
|
64
|
+
* - Uses projectAccessKey for authentication
|
|
65
|
+
* - Constructs appropriate indexer URLs based on network and environment
|
|
66
|
+
*
|
|
67
|
+
* @param chainIds - Array of chain IDs to create indexer clients for
|
|
68
|
+
* @returns A Map where keys are chain IDs and values are the corresponding SequenceIndexer instances
|
|
69
|
+
*
|
|
70
|
+
* @throws Error if an indexer client cannot be created for any of the specified chain IDs
|
|
71
|
+
*
|
|
72
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useIndexerClients} for more detailed documentation.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const TransactionFetcher = () => {
|
|
77
|
+
* // Get indexer clients for Ethereum mainnet and Polygon
|
|
78
|
+
* const indexerClients = useIndexerClients([1, 137])
|
|
79
|
+
*
|
|
80
|
+
* // Use the clients to fetch data
|
|
81
|
+
* const fetchData = async () => {
|
|
82
|
+
* // Get Ethereum client
|
|
83
|
+
* const ethClient = indexerClients.get(1)
|
|
84
|
+
* // Get Polygon client
|
|
85
|
+
* const polygonClient = indexerClients.get(137)
|
|
86
|
+
*
|
|
87
|
+
* // Make parallel requests
|
|
88
|
+
* const [ethData, polygonData] = await Promise.all([
|
|
89
|
+
* ethClient.getTransactionHistory(...),
|
|
90
|
+
* polygonClient.getTransactionHistory(...)
|
|
91
|
+
* ])
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* - The clients are memoized based on projectAccessKey to prevent recreation
|
|
98
|
+
* - Each client is initialized only once per chain ID
|
|
99
|
+
* - The environment configuration determines the indexer URL for each network
|
|
100
|
+
* - Throws an error if a chain ID is not supported or client creation fails
|
|
101
|
+
*/
|
|
4
102
|
export declare const useIndexerClients: (chainIds: number[]) => Map<ChainId, SequenceIndexer>;
|
|
5
103
|
//# sourceMappingURL=useIndexerClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndexerClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useIndexerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAY,MAAM,qBAAqB,CAAA;AAOvD,eAAO,MAAM,gBAAgB,GAAI,SAAS,OAAO,oBAqBhD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,EAAE,kCA2BnD,CAAA"}
|
|
1
|
+
{"version":3,"file":"useIndexerClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useIndexerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAY,MAAM,qBAAqB,CAAA;AAOvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,OAAO,oBAqBhD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,EAAE,kCA2BnD,CAAA"}
|