@0xsequence/hooks 5.0.9 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/contexts/ConfigContext.d.ts +3 -0
- package/dist/cjs/contexts/ConfigContext.d.ts.map +1 -1
- package/dist/cjs/contexts/ConfigContext.js +4 -1
- package/dist/cjs/contexts/ConfigContext.js.map +1 -1
- package/dist/cjs/hooks/API/useAPIClient.d.ts +37 -0
- package/dist/cjs/hooks/API/useAPIClient.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useAPIClient.js +40 -4
- package/dist/cjs/hooks/API/useAPIClient.js.map +1 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.d.ts +43 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.js +51 -1
- package/dist/cjs/hooks/API/useGetCoinPrices.js.map +1 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.d.ts +48 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.js +56 -1
- package/dist/cjs/hooks/API/useGetCollectiblePrices.js.map +1 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.d.ts +37 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.d.ts.map +1 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.js +37 -1
- package/dist/cjs/hooks/API/useGetExchangeRate.js.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapPrices.d.ts +69 -1
- package/dist/cjs/hooks/Combination/useGetSwapPrices.d.ts.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapPrices.js +70 -14
- package/dist/cjs/hooks/Combination/useGetSwapPrices.js.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapQuote.d.ts +74 -3
- package/dist/cjs/hooks/Combination/useGetSwapQuote.d.ts.map +1 -1
- package/dist/cjs/hooks/Combination/useGetSwapQuote.js +76 -5
- package/dist/cjs/hooks/Combination/useGetSwapQuote.js.map +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistory.d.ts +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistory.js +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.d.ts +66 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.d.ts.map +1 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.js +66 -1
- package/dist/cjs/hooks/Indexer/useGetTransactionHistorySummary.js.map +1 -1
- package/dist/cjs/hooks/Indexer/useIndexerClient.d.ts +98 -0
- package/dist/cjs/hooks/Indexer/useIndexerClient.d.ts.map +1 -1
- package/dist/cjs/hooks/Indexer/useIndexerClient.js +104 -6
- package/dist/cjs/hooks/Indexer/useIndexerClient.js.map +1 -1
- package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.d.ts.map +1 -1
- package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.js +3 -4
- package/dist/cjs/hooks/IndexerGateway/useIndexerGatewayClient.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.d.ts +61 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.js +61 -1
- package/dist/cjs/hooks/Metadata/useGetContractInfo.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.d.ts +89 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.js +89 -1
- package/dist/cjs/hooks/Metadata/useGetMultipleContractsInfo.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.d.ts +83 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.js +83 -1
- package/dist/cjs/hooks/Metadata/useGetTokenMetadata.js.map +1 -1
- package/dist/cjs/hooks/Metadata/useMetadataClient.d.ts +36 -0
- package/dist/cjs/hooks/Metadata/useMetadataClient.d.ts.map +1 -1
- package/dist/cjs/hooks/Metadata/useMetadataClient.js +39 -4
- package/dist/cjs/hooks/Metadata/useMetadataClient.js.map +1 -1
- package/dist/cjs/hooks/useConfig.d.ts +45 -0
- package/dist/cjs/hooks/useConfig.d.ts.map +1 -1
- package/dist/cjs/hooks/useConfig.js +45 -0
- package/dist/cjs/hooks/useConfig.js.map +1 -1
- package/dist/cjs/tests/Combination/useGetSwapQuote.test.js +3 -3
- package/dist/cjs/tests/Combination/useGetSwapQuote.test.js.map +1 -1
- package/dist/cjs/tests/handlers.d.ts.map +1 -1
- package/dist/cjs/tests/handlers.js +14 -0
- package/dist/cjs/tests/handlers.js.map +1 -1
- package/dist/esm/contexts/ConfigContext.d.ts +3 -0
- package/dist/esm/contexts/ConfigContext.d.ts.map +1 -1
- package/dist/esm/contexts/ConfigContext.js +5 -2
- package/dist/esm/contexts/ConfigContext.js.map +1 -1
- package/dist/esm/hooks/API/useAPIClient.d.ts +37 -0
- package/dist/esm/hooks/API/useAPIClient.d.ts.map +1 -1
- package/dist/esm/hooks/API/useAPIClient.js +40 -4
- package/dist/esm/hooks/API/useAPIClient.js.map +1 -1
- package/dist/esm/hooks/API/useGetCoinPrices.d.ts +43 -1
- package/dist/esm/hooks/API/useGetCoinPrices.d.ts.map +1 -1
- package/dist/esm/hooks/API/useGetCoinPrices.js +51 -1
- package/dist/esm/hooks/API/useGetCoinPrices.js.map +1 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.d.ts +48 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.d.ts.map +1 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.js +56 -1
- package/dist/esm/hooks/API/useGetCollectiblePrices.js.map +1 -1
- package/dist/esm/hooks/API/useGetExchangeRate.d.ts +37 -1
- package/dist/esm/hooks/API/useGetExchangeRate.d.ts.map +1 -1
- package/dist/esm/hooks/API/useGetExchangeRate.js +37 -1
- package/dist/esm/hooks/API/useGetExchangeRate.js.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapPrices.d.ts +69 -1
- package/dist/esm/hooks/Combination/useGetSwapPrices.d.ts.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapPrices.js +71 -15
- package/dist/esm/hooks/Combination/useGetSwapPrices.js.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapQuote.d.ts +74 -3
- package/dist/esm/hooks/Combination/useGetSwapQuote.d.ts.map +1 -1
- package/dist/esm/hooks/Combination/useGetSwapQuote.js +77 -6
- package/dist/esm/hooks/Combination/useGetSwapQuote.js.map +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistory.d.ts +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistory.js +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.d.ts +66 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.d.ts.map +1 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.js +66 -1
- package/dist/esm/hooks/Indexer/useGetTransactionHistorySummary.js.map +1 -1
- package/dist/esm/hooks/Indexer/useIndexerClient.d.ts +98 -0
- package/dist/esm/hooks/Indexer/useIndexerClient.d.ts.map +1 -1
- package/dist/esm/hooks/Indexer/useIndexerClient.js +104 -6
- package/dist/esm/hooks/Indexer/useIndexerClient.js.map +1 -1
- package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.d.ts.map +1 -1
- package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.js +3 -4
- package/dist/esm/hooks/IndexerGateway/useIndexerGatewayClient.js.map +1 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.d.ts +61 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.js +61 -1
- package/dist/esm/hooks/Metadata/useGetContractInfo.js.map +1 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.d.ts +89 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.js +89 -1
- package/dist/esm/hooks/Metadata/useGetMultipleContractsInfo.js.map +1 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.d.ts +83 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.js +83 -1
- package/dist/esm/hooks/Metadata/useGetTokenMetadata.js.map +1 -1
- package/dist/esm/hooks/Metadata/useMetadataClient.d.ts +36 -0
- package/dist/esm/hooks/Metadata/useMetadataClient.d.ts.map +1 -1
- package/dist/esm/hooks/Metadata/useMetadataClient.js +39 -4
- package/dist/esm/hooks/Metadata/useMetadataClient.js.map +1 -1
- package/dist/esm/hooks/useConfig.d.ts +45 -0
- package/dist/esm/hooks/useConfig.d.ts.map +1 -1
- package/dist/esm/hooks/useConfig.js +45 -0
- package/dist/esm/hooks/useConfig.js.map +1 -1
- package/dist/esm/tests/Combination/useGetSwapQuote.test.js +4 -4
- package/dist/esm/tests/Combination/useGetSwapQuote.test.js.map +1 -1
- package/dist/esm/tests/handlers.d.ts.map +1 -1
- package/dist/esm/tests/handlers.js +14 -0
- package/dist/esm/tests/handlers.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,27 +1,98 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
2
|
+
import { QUERY_KEYS, ZERO_ADDRESS, time } from '../../constants';
|
|
3
3
|
import { compareAddress } from '../../utils/helpers';
|
|
4
4
|
import { useAPIClient } from '../API/useAPIClient';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Hook to fetch a swap quote for exchanging between two currencies.
|
|
7
|
+
*
|
|
8
|
+
* This hook provides functionality to:
|
|
9
|
+
* - Get a quote for swapping between two currencies (native or ERC20)
|
|
10
|
+
* - Fetch necessary approval data for ERC20 tokens
|
|
11
|
+
* - Generate transaction data for executing the swap
|
|
12
|
+
*
|
|
13
|
+
* The hook automatically handles:
|
|
14
|
+
* - Native token address normalization (between 0x0 and 0xEEE...)
|
|
15
|
+
* - Approval data generation for ERC20 tokens when needed
|
|
16
|
+
* - Transaction data generation for the swap
|
|
17
|
+
* - Error handling for failed API calls
|
|
18
|
+
*
|
|
19
|
+
* Go to {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
|
|
20
|
+
*
|
|
21
|
+
* @param getSwapQuoteArgs - Configuration object for the swap quote query:
|
|
22
|
+
* - userAddress: The address of the user's wallet
|
|
23
|
+
* - buyCurrencyAddress: The address of the currency to buy
|
|
24
|
+
* - sellCurrencyAddress: The address of the currency to sell
|
|
25
|
+
* - buyAmount: The amount of currency to buy (in base units)
|
|
26
|
+
* - chainId: The chain ID where the swap will occur
|
|
27
|
+
* - includeApprove: Whether to include approval data for ERC20 tokens
|
|
28
|
+
*
|
|
29
|
+
* @param options - Optional configuration for the hook behavior:
|
|
30
|
+
* - disabled: Whether to disable the query
|
|
31
|
+
* - retry: Whether to retry failed queries
|
|
32
|
+
* - Other standard React Query options
|
|
33
|
+
*
|
|
34
|
+
* @returns A React Query result object containing:
|
|
35
|
+
* - data: The swap quote data including:
|
|
36
|
+
* - currencyAddress: The address of the currency being swapped
|
|
37
|
+
* - currencyBalance: The user's balance of the currency
|
|
38
|
+
* - price: The price for the swap
|
|
39
|
+
* - maxPrice: The maximum price (including slippage)
|
|
40
|
+
* - to: The target contract address for the swap
|
|
41
|
+
* - transactionData: The calldata for the swap transaction
|
|
42
|
+
* - transactionValue: The value to send with the transaction (for native tokens)
|
|
43
|
+
* - approveData: The approval transaction data (if needed)
|
|
44
|
+
* - isLoading: Whether the query is in progress
|
|
45
|
+
* - isError: Whether an error occurred
|
|
46
|
+
* - error: Any error that occurred
|
|
47
|
+
* - Other standard React Query properties
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import { useGetSwapQuote } from '@0xsequence/hooks'
|
|
54
|
+
*
|
|
55
|
+
* function SwapComponent() {
|
|
56
|
+
* const { data: swapQuote, isLoading } = useGetSwapQuote({
|
|
57
|
+
* userAddress: '0x123...',
|
|
58
|
+
* buyCurrencyAddress: '0x456...',
|
|
59
|
+
* sellCurrencyAddress: '0x789...',
|
|
60
|
+
* buyAmount: '1000000000000000000', // 1 token in base units
|
|
61
|
+
* chainId: 1,
|
|
62
|
+
* includeApprove: true
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* if (isLoading) return <div>Loading...</div>
|
|
66
|
+
*
|
|
67
|
+
* return (
|
|
68
|
+
* <div>
|
|
69
|
+
* <div>Price: {swapQuote?.price}</div>
|
|
70
|
+
* <div>Max Price: {swapQuote?.maxPrice}</div>
|
|
71
|
+
* <button onClick={() => executeSwap(swapQuote)}>
|
|
72
|
+
* Swap Tokens
|
|
73
|
+
* </button>
|
|
74
|
+
* </div>
|
|
75
|
+
* )
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
7
78
|
*/
|
|
8
79
|
export const useGetSwapQuote = (getSwapQuoteArgs, options) => {
|
|
9
80
|
const apiClient = useAPIClient();
|
|
10
81
|
return useQuery({
|
|
11
82
|
queryKey: [QUERY_KEYS.useGetSwapQuote, getSwapQuoteArgs, options],
|
|
12
83
|
queryFn: async () => {
|
|
13
|
-
const res = await apiClient.
|
|
84
|
+
const res = await apiClient.getSwapQuoteV2({
|
|
14
85
|
...getSwapQuoteArgs,
|
|
15
86
|
buyCurrencyAddress: compareAddress(getSwapQuoteArgs.buyCurrencyAddress, ZERO_ADDRESS)
|
|
16
|
-
?
|
|
87
|
+
? ZERO_ADDRESS
|
|
17
88
|
: getSwapQuoteArgs.buyCurrencyAddress,
|
|
18
89
|
sellCurrencyAddress: compareAddress(getSwapQuoteArgs.sellCurrencyAddress, ZERO_ADDRESS)
|
|
19
|
-
?
|
|
90
|
+
? ZERO_ADDRESS
|
|
20
91
|
: getSwapQuoteArgs.sellCurrencyAddress
|
|
21
92
|
});
|
|
22
93
|
return {
|
|
23
94
|
...res.swapQuote,
|
|
24
|
-
currencyAddress: compareAddress(res.swapQuote.currencyAddress,
|
|
95
|
+
currencyAddress: compareAddress(res.swapQuote.currencyAddress, ZERO_ADDRESS)
|
|
25
96
|
? ZERO_ADDRESS
|
|
26
97
|
: res.swapQuote.currencyAddress
|
|
27
98
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSwapQuote.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapQuote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useGetSwapQuote.js","sourceRoot":"","sources":["../../../../src/hooks/Combination/useGetSwapQuote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,gBAAoC,EAAE,OAAsB,EAAE,EAAE;IAC9F,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,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,cAAc,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,YAAY,CAAC;oBACnF,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,gBAAgB,CAAC,kBAAkB;gBACvC,mBAAmB,EAAE,cAAc,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC;oBACrF,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,gBAAgB,CAAC,mBAAmB;aACzC,CAAC,CAAA;YAEF,OAAO;gBACL,GAAG,GAAG,CAAC,SAAS;gBAChB,eAAe,EAAE,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,YAAY,CAAC;oBAC1E,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe;aAClC,CAAA;QACH,CAAC;QACD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,IAAI,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"}
|
|
@@ -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
|
*
|
|
@@ -34,7 +34,7 @@ const getTransactionHistory = async (indexerClient, { contractAddress, accountAd
|
|
|
34
34
|
* It can filter transactions by contract address and token ID, making it useful for both
|
|
35
35
|
* general account history and specific asset history views.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTransactionHistory} for more detailed documentation.
|
|
38
38
|
*
|
|
39
39
|
* @param args - Configuration object for the transaction history query {@link GetTransactionHistoryArgs}
|
|
40
40
|
*
|
|
@@ -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"}
|
|
@@ -26,7 +26,72 @@ const getTransactionHistorySummary = async (indexerClients, { accountAddress })
|
|
|
26
26
|
return transactions;
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* A hook that retrieves a comprehensive transaction history summary across multiple chains for a given account address.
|
|
30
|
+
* The transactions are ordered by timestamp (newest first) and include detailed transfer information.
|
|
31
|
+
*
|
|
32
|
+
* Implementation details:
|
|
33
|
+
* - Uses Promise.all with an array of indexer clients to fetch transactions from all specified chains in parallel
|
|
34
|
+
* - Flattens and sorts the combined results by timestamp
|
|
35
|
+
* - Normalizes all addresses in transfer objects using viem's getAddress
|
|
36
|
+
*
|
|
37
|
+
* @param getTransactionHistorySummaryArgs - Configuration object for the transaction history query
|
|
38
|
+
* @param getTransactionHistorySummaryArgs.accountAddress - The account address to fetch transactions for
|
|
39
|
+
* @param getTransactionHistorySummaryArgs.chainIds - Array of chain IDs to fetch transactions from. Each chain ID will be queried in parallel.
|
|
40
|
+
* @param options - Optional configuration for the hook behavior
|
|
41
|
+
* @param options.disabled - If true, disables the query
|
|
42
|
+
* @param options.retry - If true (default), retries failed requests
|
|
43
|
+
*
|
|
44
|
+
* @returns A React Query result object containing:
|
|
45
|
+
* - data: Array of Transaction objects combined from all specified chains, each containing:
|
|
46
|
+
* - txnHash: Transaction hash
|
|
47
|
+
* - chainId: Chain ID where transaction occurred
|
|
48
|
+
* - timestamp: Transaction timestamp
|
|
49
|
+
* - transfers: Array of transfer objects with normalized addresses
|
|
50
|
+
* - blockNumber: Block number where transaction was mined
|
|
51
|
+
* - blockHash: Hash of the block
|
|
52
|
+
* - metaTxnID: Optional meta transaction ID
|
|
53
|
+
* - Other standard React Query properties (isLoading, isError, etc.)
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTransactionHistorySummary} for more detailed documentation.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* import { useGetTransactionHistorySummary } from '@0xsequence/hooks'
|
|
60
|
+
* import { useAccount } from 'wagmi'
|
|
61
|
+
*
|
|
62
|
+
* // Basic usage in a component
|
|
63
|
+
* const TransactionHistory = () => {
|
|
64
|
+
* const { address: accountAddress } = useAccount()
|
|
65
|
+
* const {
|
|
66
|
+
* data: transactionHistory = [],
|
|
67
|
+
* isPending: isPendingTransactionHistory
|
|
68
|
+
* } = useGetTransactionHistorySummary({
|
|
69
|
+
* accountAddress: accountAddress || '',
|
|
70
|
+
* chainIds: [1, 137]
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* return (
|
|
74
|
+
* <div>
|
|
75
|
+
* {transactionHistory.map(tx => (
|
|
76
|
+
* <div key={tx.txnHash}>
|
|
77
|
+
* Transaction: {tx.txnHash}
|
|
78
|
+
* Chain: {tx.chainId}
|
|
79
|
+
* Time: {tx.timestamp}
|
|
80
|
+
* </div>
|
|
81
|
+
* ))}
|
|
82
|
+
* </div>
|
|
83
|
+
* )
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* - The hook uses the Sequence Indexer service to fetch transaction data
|
|
89
|
+
* - Creates a separate indexer client for each chain ID and fetches from all in parallel
|
|
90
|
+
* - Transactions from all chains are combined and sorted by timestamp (newest first)
|
|
91
|
+
* - All addresses in transfer objects are normalized using viem's getAddress
|
|
92
|
+
* - The query is enabled only when chainIds array is not empty and accountAddress is provided
|
|
93
|
+
* - The query result is cached for 30 seconds (staleTime)
|
|
94
|
+
* - The query automatically refetches when the component is mounted
|
|
30
95
|
*/
|
|
31
96
|
export const useGetTransactionHistorySummary = (getTransactionHistorySummaryArgs, options) => {
|
|
32
97
|
const indexerClients = useIndexerClients(getTransactionHistorySummaryArgs.chainIds);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTransactionHistorySummary.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useGetTransactionHistorySummary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AA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SAC5B,CAAC,CAAC;KACJ,CAAC,CAAC,CAAA;IAEH,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"useGetTransactionHistorySummary.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useGetTransactionHistorySummary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;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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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"}
|
|
@@ -4,15 +4,65 @@ import { useMemo } from 'react';
|
|
|
4
4
|
import { envString } from '../../utils/envstring';
|
|
5
5
|
import { useConfig } from '../useConfig';
|
|
6
6
|
import { useNetwork } from '../useNetwork';
|
|
7
|
+
/**
|
|
8
|
+
* Hook that creates and manages a Sequence Indexer client for a specific chain.
|
|
9
|
+
*
|
|
10
|
+
* This hook maintains a cached indexer client for the specified chain ID,
|
|
11
|
+
* initializing it with the appropriate indexer URL based on the network
|
|
12
|
+
* and environment configuration.
|
|
13
|
+
*
|
|
14
|
+
* Implementation details:
|
|
15
|
+
* - Creates a new SequenceIndexer instance for the specified chain ID if it doesn't exist
|
|
16
|
+
* - Caches the client in a Map to avoid recreating it unnecessarily
|
|
17
|
+
* - Uses projectAccessKey for authentication
|
|
18
|
+
* - Constructs appropriate indexer URL based on network and environment
|
|
19
|
+
*
|
|
20
|
+
* @param chainId - The chain ID to create an indexer client for
|
|
21
|
+
* @returns A SequenceIndexer instance for the specified chain
|
|
22
|
+
*
|
|
23
|
+
* @throws Error if an indexer client cannot be created for the specified chain ID
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const TokenBalanceChecker = () => {
|
|
28
|
+
* const chainId = useChainId()
|
|
29
|
+
* const indexerClient = useIndexerClient(chainId)
|
|
30
|
+
* const { address } = useAccount()
|
|
31
|
+
*
|
|
32
|
+
* const checkBalance = async () => {
|
|
33
|
+
* // Get native token balance
|
|
34
|
+
* const nativeBalance = await indexerClient.getNativeTokenBalance({
|
|
35
|
+
* accountAddress: address
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* // Get token balances
|
|
39
|
+
* const tokenBalances = await indexerClient.getTokenBalancesSummary({
|
|
40
|
+
* filter: {
|
|
41
|
+
* accountAddresses: [address],
|
|
42
|
+
* contractStatus: ContractVerificationStatus.ALL,
|
|
43
|
+
* omitNativeBalances: true
|
|
44
|
+
* }
|
|
45
|
+
* })
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* - The client is memoized based on projectAccessKey to prevent recreation
|
|
52
|
+
* - The client is initialized only once per chain ID
|
|
53
|
+
* - The environment configuration determines the indexer URL for the network
|
|
54
|
+
* - Throws an error if the chain ID is not supported or client creation fails
|
|
55
|
+
* - Used internally by useIndexerClients to manage multiple chain clients
|
|
56
|
+
*/
|
|
7
57
|
export const useIndexerClient = (chainId) => {
|
|
8
|
-
const { projectAccessKey,
|
|
58
|
+
const { env, projectAccessKey, jwt } = useConfig();
|
|
9
59
|
const indexerClients = useMemo(() => {
|
|
10
60
|
return new Map();
|
|
11
|
-
}, [projectAccessKey]);
|
|
61
|
+
}, [projectAccessKey, jwt]);
|
|
12
62
|
const network = useNetwork(chainId);
|
|
13
63
|
const indexerUrl = envString(env.indexerUrl, 'indexer', network.name);
|
|
14
64
|
if (!indexerClients.has(chainId)) {
|
|
15
|
-
indexerClients.set(chainId, new SequenceIndexer(indexerUrl, projectAccessKey));
|
|
65
|
+
indexerClients.set(chainId, new SequenceIndexer(indexerUrl, projectAccessKey, jwt));
|
|
16
66
|
}
|
|
17
67
|
const indexerClient = indexerClients.get(chainId);
|
|
18
68
|
if (!indexerClient) {
|
|
@@ -20,17 +70,65 @@ export const useIndexerClient = (chainId) => {
|
|
|
20
70
|
}
|
|
21
71
|
return indexerClient;
|
|
22
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* Hook that creates and manages Sequence Indexer clients for multiple chains.
|
|
75
|
+
*
|
|
76
|
+
* This hook maintains a map of indexer clients, one for each specified chain ID.
|
|
77
|
+
* Each client is initialized with the appropriate indexer URL based on the network
|
|
78
|
+
* and environment configuration.
|
|
79
|
+
*
|
|
80
|
+
* Implementation details:
|
|
81
|
+
* - Creates a new SequenceIndexer instance for each unique chain ID
|
|
82
|
+
* - Caches clients in a Map to avoid recreating them unnecessarily
|
|
83
|
+
* - Uses projectAccessKey for authentication
|
|
84
|
+
* - Constructs appropriate indexer URLs based on network and environment
|
|
85
|
+
*
|
|
86
|
+
* @param chainIds - Array of chain IDs to create indexer clients for
|
|
87
|
+
* @returns A Map where keys are chain IDs and values are the corresponding SequenceIndexer instances
|
|
88
|
+
*
|
|
89
|
+
* @throws Error if an indexer client cannot be created for any of the specified chain IDs
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useIndexerClients} for more detailed documentation.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const TransactionFetcher = () => {
|
|
96
|
+
* // Get indexer clients for Ethereum mainnet and Polygon
|
|
97
|
+
* const indexerClients = useIndexerClients([1, 137])
|
|
98
|
+
*
|
|
99
|
+
* // Use the clients to fetch data
|
|
100
|
+
* const fetchData = async () => {
|
|
101
|
+
* // Get Ethereum client
|
|
102
|
+
* const ethClient = indexerClients.get(1)
|
|
103
|
+
* // Get Polygon client
|
|
104
|
+
* const polygonClient = indexerClients.get(137)
|
|
105
|
+
*
|
|
106
|
+
* // Make parallel requests
|
|
107
|
+
* const [ethData, polygonData] = await Promise.all([
|
|
108
|
+
* ethClient.getTransactionHistory(...),
|
|
109
|
+
* polygonClient.getTransactionHistory(...)
|
|
110
|
+
* ])
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* - The clients are memoized based on projectAccessKey to prevent recreation
|
|
117
|
+
* - Each client is initialized only once per chain ID
|
|
118
|
+
* - The environment configuration determines the indexer URL for each network
|
|
119
|
+
* - Throws an error if a chain ID is not supported or client creation fails
|
|
120
|
+
*/
|
|
23
121
|
export const useIndexerClients = (chainIds) => {
|
|
24
|
-
const { projectAccessKey,
|
|
122
|
+
const { env, projectAccessKey, jwt } = useConfig();
|
|
25
123
|
const indexerClients = useMemo(() => {
|
|
26
124
|
return new Map();
|
|
27
|
-
}, [projectAccessKey]);
|
|
125
|
+
}, [projectAccessKey, jwt]);
|
|
28
126
|
const result = new Map();
|
|
29
127
|
for (const chainId of chainIds) {
|
|
30
128
|
const network = networks[chainId];
|
|
31
129
|
const indexerUrl = envString(env.indexerUrl, 'indexer', network.name);
|
|
32
130
|
if (!indexerClients.has(chainId)) {
|
|
33
|
-
indexerClients.set(chainId, new SequenceIndexer(indexerUrl, projectAccessKey));
|
|
131
|
+
indexerClients.set(chainId, new SequenceIndexer(indexerUrl, projectAccessKey, jwt));
|
|
34
132
|
}
|
|
35
133
|
const indexerClient = indexerClients.get(chainId);
|
|
36
134
|
if (!indexerClient) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndexerClient.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useIndexerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAW,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACnD,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"useIndexerClient.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useIndexerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAW,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,O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EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,CAAA;IAElD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,EAAE;QAClC,OAAO,IAAI,GAAG,EAA4B,CAAA;IAC5C,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;IAE3B,MAAM,MAAM,GAAG,IAAI,GAAG,EAA4B,CAAA;IAElD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAkB,CAAC,CAAA;QAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAErE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACjC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,eAAe,CAAC,UAAU,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;QACrF,CAAC;QAED,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAEjD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,qCAAqC,CAAC,CAAA;QACxG,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndexerGatewayClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/IndexerGateway/useIndexerGatewayClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAK5D,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"useIndexerGatewayClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/IndexerGateway/useIndexerGatewayClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAK5D,eAAO,MAAM,uBAAuB,8BAQnC,CAAA"}
|
|
@@ -2,11 +2,10 @@ import { SequenceIndexerGateway } from '@0xsequence/indexer';
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { useConfig } from '../useConfig';
|
|
4
4
|
export const useIndexerGatewayClient = () => {
|
|
5
|
-
const { projectAccessKey,
|
|
5
|
+
const { env, projectAccessKey, jwt } = useConfig();
|
|
6
6
|
const indexerGatewayClient = useMemo(() => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}, [projectAccessKey]);
|
|
7
|
+
return new SequenceIndexerGateway(env.indexerGatewayUrl, projectAccessKey, jwt);
|
|
8
|
+
}, [projectAccessKey, jwt]);
|
|
10
9
|
return indexerGatewayClient;
|
|
11
10
|
};
|
|
12
11
|
//# sourceMappingURL=useIndexerGatewayClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndexerGatewayClient.js","sourceRoot":"","sources":["../../../../src/hooks/IndexerGateway/useIndexerGatewayClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"useIndexerGatewayClient.js","sourceRoot":"","sources":["../../../../src/hooks/IndexerGateway/useIndexerGatewayClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,CAAA;IAElD,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,EAAE;QACxC,OAAO,IAAI,sBAAsB,CAAC,GAAG,CAAC,iBAAiB,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAA;IACjF,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;IAE3B,OAAO,oBAAoB,CAAA;AAC7B,CAAC,CAAA"}
|
|
@@ -2,7 +2,67 @@ import { ContractInfo, GetContractInfoArgs } from '@0xsequence/metadata';
|
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { HooksOptions } from '../../types';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Hook to fetch contract information.
|
|
6
|
+
* Handles ERC20/ERC721/ERC1155 contracts and native tokens (using ZERO_ADDRESS).
|
|
7
|
+
*
|
|
8
|
+
* For native tokens (like ETH, POL), it enriches the response with network-specific
|
|
9
|
+
* information like the native token symbol and network logo.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetContractInfo} for more detailed documentation.
|
|
12
|
+
*
|
|
13
|
+
* @param getContractInfoArgs - Arguments for fetching contract info
|
|
14
|
+
* @param getContractInfoArgs.chainID - Chain ID as string (e.g., "1" for Ethereum mainnet)
|
|
15
|
+
* @param getContractInfoArgs.contractAddress - Contract address or ZERO_ADDRESS for native token
|
|
16
|
+
* @param options - Optional configuration for the query behavior
|
|
17
|
+
* @param options.disabled - If true, disables the query from automatically running
|
|
18
|
+
* @param options.retry - If true (default), retries failed queries
|
|
19
|
+
*
|
|
20
|
+
* Query configuration:
|
|
21
|
+
* - Marks data as stale after 10 minutes
|
|
22
|
+
* - Retries failed requests by default
|
|
23
|
+
* - Only enabled when chainID and contractAddress are present and not explicitly disabled
|
|
24
|
+
*
|
|
25
|
+
* @returns Query result containing contract information:
|
|
26
|
+
* - `name`: Contract/token name
|
|
27
|
+
* - `symbol`: Token symbol
|
|
28
|
+
* - `decimals`: Token decimals (if applicable)
|
|
29
|
+
* - `logoURI`: URL of the contract/token logo
|
|
30
|
+
* - `type`: Contract type (e.g., "ERC721", "ERC20")
|
|
31
|
+
* - Additional metadata from the contract
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // Fetch NFT collection info
|
|
36
|
+
* function CollectionDetails() {
|
|
37
|
+
* const { data: contractInfo } = useGetContractInfo({
|
|
38
|
+
* chainID: "1",
|
|
39
|
+
* contractAddress: "0x123..."
|
|
40
|
+
* })
|
|
41
|
+
*
|
|
42
|
+
* return (
|
|
43
|
+
* <div>
|
|
44
|
+
* <img src={contractInfo?.logoURI} />
|
|
45
|
+
* <h1>{contractInfo?.name}</h1>
|
|
46
|
+
* <span>Type: {contractInfo?.type}</span>
|
|
47
|
+
* </div>
|
|
48
|
+
* )
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* // Used in checkout for displaying collection info
|
|
52
|
+
* function OrderSummaryItem() {
|
|
53
|
+
* const { data: contractInfo } = useGetContractInfo({
|
|
54
|
+
* chainID: String(chainId),
|
|
55
|
+
* contractAddress
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <div>
|
|
60
|
+
* <TokenImage src={contractInfo?.logoURI} />
|
|
61
|
+
* <Text>{contractInfo?.name || 'Unknown Collection'}</Text>
|
|
62
|
+
* </div>
|
|
63
|
+
* )
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
6
66
|
*/
|
|
7
67
|
export declare const useGetContractInfo: (getContractInfoArgs: GetContractInfoArgs, options?: HooksOptions) => UseQueryResult<ContractInfo>;
|
|
8
68
|
//# sourceMappingURL=useGetContractInfo.d.ts.map
|