@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
|
@@ -7,15 +7,65 @@ const react_1 = require("react");
|
|
|
7
7
|
const envstring_1 = require("../../utils/envstring");
|
|
8
8
|
const useConfig_1 = require("../useConfig");
|
|
9
9
|
const useNetwork_1 = require("../useNetwork");
|
|
10
|
+
/**
|
|
11
|
+
* Hook that creates and manages a Sequence Indexer client for a specific chain.
|
|
12
|
+
*
|
|
13
|
+
* This hook maintains a cached indexer client for the specified chain ID,
|
|
14
|
+
* initializing it with the appropriate indexer URL based on the network
|
|
15
|
+
* and environment configuration.
|
|
16
|
+
*
|
|
17
|
+
* Implementation details:
|
|
18
|
+
* - Creates a new SequenceIndexer instance for the specified chain ID if it doesn't exist
|
|
19
|
+
* - Caches the client in a Map to avoid recreating it unnecessarily
|
|
20
|
+
* - Uses projectAccessKey for authentication
|
|
21
|
+
* - Constructs appropriate indexer URL based on network and environment
|
|
22
|
+
*
|
|
23
|
+
* @param chainId - The chain ID to create an indexer client for
|
|
24
|
+
* @returns A SequenceIndexer instance for the specified chain
|
|
25
|
+
*
|
|
26
|
+
* @throws Error if an indexer client cannot be created for the specified chain ID
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const TokenBalanceChecker = () => {
|
|
31
|
+
* const chainId = useChainId()
|
|
32
|
+
* const indexerClient = useIndexerClient(chainId)
|
|
33
|
+
* const { address } = useAccount()
|
|
34
|
+
*
|
|
35
|
+
* const checkBalance = async () => {
|
|
36
|
+
* // Get native token balance
|
|
37
|
+
* const nativeBalance = await indexerClient.getNativeTokenBalance({
|
|
38
|
+
* accountAddress: address
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* // Get token balances
|
|
42
|
+
* const tokenBalances = await indexerClient.getTokenBalancesSummary({
|
|
43
|
+
* filter: {
|
|
44
|
+
* accountAddresses: [address],
|
|
45
|
+
* contractStatus: ContractVerificationStatus.ALL,
|
|
46
|
+
* omitNativeBalances: true
|
|
47
|
+
* }
|
|
48
|
+
* })
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* - The client is memoized based on projectAccessKey to prevent recreation
|
|
55
|
+
* - The client is initialized only once per chain ID
|
|
56
|
+
* - The environment configuration determines the indexer URL for the network
|
|
57
|
+
* - Throws an error if the chain ID is not supported or client creation fails
|
|
58
|
+
* - Used internally by useIndexerClients to manage multiple chain clients
|
|
59
|
+
*/
|
|
10
60
|
const useIndexerClient = (chainId) => {
|
|
11
|
-
const { projectAccessKey,
|
|
61
|
+
const { env, projectAccessKey, jwt } = (0, useConfig_1.useConfig)();
|
|
12
62
|
const indexerClients = (0, react_1.useMemo)(() => {
|
|
13
63
|
return new Map();
|
|
14
|
-
}, [projectAccessKey]);
|
|
64
|
+
}, [projectAccessKey, jwt]);
|
|
15
65
|
const network = (0, useNetwork_1.useNetwork)(chainId);
|
|
16
66
|
const indexerUrl = (0, envstring_1.envString)(env.indexerUrl, 'indexer', network.name);
|
|
17
67
|
if (!indexerClients.has(chainId)) {
|
|
18
|
-
indexerClients.set(chainId, new indexer_1.SequenceIndexer(indexerUrl, projectAccessKey));
|
|
68
|
+
indexerClients.set(chainId, new indexer_1.SequenceIndexer(indexerUrl, projectAccessKey, jwt));
|
|
19
69
|
}
|
|
20
70
|
const indexerClient = indexerClients.get(chainId);
|
|
21
71
|
if (!indexerClient) {
|
|
@@ -24,17 +74,65 @@ const useIndexerClient = (chainId) => {
|
|
|
24
74
|
return indexerClient;
|
|
25
75
|
};
|
|
26
76
|
exports.useIndexerClient = useIndexerClient;
|
|
77
|
+
/**
|
|
78
|
+
* Hook that creates and manages Sequence Indexer clients for multiple chains.
|
|
79
|
+
*
|
|
80
|
+
* This hook maintains a map of indexer clients, one for each specified chain ID.
|
|
81
|
+
* Each client is initialized with the appropriate indexer URL based on the network
|
|
82
|
+
* and environment configuration.
|
|
83
|
+
*
|
|
84
|
+
* Implementation details:
|
|
85
|
+
* - Creates a new SequenceIndexer instance for each unique chain ID
|
|
86
|
+
* - Caches clients in a Map to avoid recreating them unnecessarily
|
|
87
|
+
* - Uses projectAccessKey for authentication
|
|
88
|
+
* - Constructs appropriate indexer URLs based on network and environment
|
|
89
|
+
*
|
|
90
|
+
* @param chainIds - Array of chain IDs to create indexer clients for
|
|
91
|
+
* @returns A Map where keys are chain IDs and values are the corresponding SequenceIndexer instances
|
|
92
|
+
*
|
|
93
|
+
* @throws Error if an indexer client cannot be created for any of the specified chain IDs
|
|
94
|
+
*
|
|
95
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useIndexerClients} for more detailed documentation.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const TransactionFetcher = () => {
|
|
100
|
+
* // Get indexer clients for Ethereum mainnet and Polygon
|
|
101
|
+
* const indexerClients = useIndexerClients([1, 137])
|
|
102
|
+
*
|
|
103
|
+
* // Use the clients to fetch data
|
|
104
|
+
* const fetchData = async () => {
|
|
105
|
+
* // Get Ethereum client
|
|
106
|
+
* const ethClient = indexerClients.get(1)
|
|
107
|
+
* // Get Polygon client
|
|
108
|
+
* const polygonClient = indexerClients.get(137)
|
|
109
|
+
*
|
|
110
|
+
* // Make parallel requests
|
|
111
|
+
* const [ethData, polygonData] = await Promise.all([
|
|
112
|
+
* ethClient.getTransactionHistory(...),
|
|
113
|
+
* polygonClient.getTransactionHistory(...)
|
|
114
|
+
* ])
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* - The clients are memoized based on projectAccessKey to prevent recreation
|
|
121
|
+
* - Each client is initialized only once per chain ID
|
|
122
|
+
* - The environment configuration determines the indexer URL for each network
|
|
123
|
+
* - Throws an error if a chain ID is not supported or client creation fails
|
|
124
|
+
*/
|
|
27
125
|
const useIndexerClients = (chainIds) => {
|
|
28
|
-
const { projectAccessKey,
|
|
126
|
+
const { env, projectAccessKey, jwt } = (0, useConfig_1.useConfig)();
|
|
29
127
|
const indexerClients = (0, react_1.useMemo)(() => {
|
|
30
128
|
return new Map();
|
|
31
|
-
}, [projectAccessKey]);
|
|
129
|
+
}, [projectAccessKey, jwt]);
|
|
32
130
|
const result = new Map();
|
|
33
131
|
for (const chainId of chainIds) {
|
|
34
132
|
const network = network_1.networks[chainId];
|
|
35
133
|
const indexerUrl = (0, envstring_1.envString)(env.indexerUrl, 'indexer', network.name);
|
|
36
134
|
if (!indexerClients.has(chainId)) {
|
|
37
|
-
indexerClients.set(chainId, new indexer_1.SequenceIndexer(indexerUrl, projectAccessKey));
|
|
135
|
+
indexerClients.set(chainId, new indexer_1.SequenceIndexer(indexerUrl, projectAccessKey, jwt));
|
|
38
136
|
}
|
|
39
137
|
const indexerClient = indexerClients.get(chainId);
|
|
40
138
|
if (!indexerClient) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndexerClient.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useIndexerClient.ts"],"names":[],"mappings":";;;AAAA,iDAAqD;AACrD,iDAAuD;AACvD,iCAA+B;AAE/B,qDAAiD;AACjD,4CAAwC;AACxC,8CAA0C;
|
|
1
|
+
{"version":3,"file":"useIndexerClient.js","sourceRoot":"","sources":["../../../../src/hooks/Indexer/useIndexerClient.ts"],"names":[],"mappings":";;;AAAA,iDAAqD;AACrD,iDAAuD;AACvD,iCAA+B;AAE/B,qDAAiD;AACjD,4CAAwC;AACxC,8CAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACI,MAAM,gBAAgB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACnD,MAAM,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,IAAA,qBAAS,GAAE,CAAA;IAElD,MAAM,cAAc,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAClC,OAAO,IAAI,GAAG,EAA4B,CAAA;IAC5C,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;IAE3B,MAAM,OAAO,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAA;IACnC,MAAM,UAAU,GAAG,IAAA,qBAAS,EAAC,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAErE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,yBAAe,CAAC,UAAU,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;IACrF,CAAC;IAED,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEjD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,qCAAqC,CAAC,CAAA;IACxG,CAAC;IAED,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AArBY,QAAA,gBAAgB,oBAqB5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACI,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAAE,EAAE;IACtD,MAAM,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,IAAA,qBAAS,GAAE,CAAA;IAElD,MAAM,cAAc,GAAG,IAAA,eAAO,EAAC,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,kBAAQ,CAAC,OAAkB,CAAC,CAAA;QAC5C,MAAM,UAAU,GAAG,IAAA,qBAAS,EAAC,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,yBAAe,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;AA3BY,QAAA,iBAAiB,qBA2B7B"}
|
|
@@ -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"}
|
|
@@ -5,11 +5,10 @@ const indexer_1 = require("@0xsequence/indexer");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const useConfig_1 = require("../useConfig");
|
|
7
7
|
const useIndexerGatewayClient = () => {
|
|
8
|
-
const { projectAccessKey,
|
|
8
|
+
const { env, projectAccessKey, jwt } = (0, useConfig_1.useConfig)();
|
|
9
9
|
const indexerGatewayClient = (0, react_1.useMemo)(() => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}, [projectAccessKey]);
|
|
10
|
+
return new indexer_1.SequenceIndexerGateway(env.indexerGatewayUrl, projectAccessKey, jwt);
|
|
11
|
+
}, [projectAccessKey, jwt]);
|
|
13
12
|
return indexerGatewayClient;
|
|
14
13
|
};
|
|
15
14
|
exports.useIndexerGatewayClient = useIndexerGatewayClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndexerGatewayClient.js","sourceRoot":"","sources":["../../../../src/hooks/IndexerGateway/useIndexerGatewayClient.ts"],"names":[],"mappings":";;;AAAA,iDAA4D;AAC5D,iCAA+B;AAE/B,4CAAwC;AAEjC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,IAAA,qBAAS,GAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"useIndexerGatewayClient.js","sourceRoot":"","sources":["../../../../src/hooks/IndexerGateway/useIndexerGatewayClient.ts"],"names":[],"mappings":";;;AAAA,iDAA4D;AAC5D,iCAA+B;AAE/B,4CAAwC;AAEjC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,IAAA,qBAAS,GAAE,CAAA;IAElD,MAAM,oBAAoB,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACxC,OAAO,IAAI,gCAAsB,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;AARY,QAAA,uBAAuB,2BAQnC"}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetContractInfo.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetContractInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAExE,OAAO,EAAE,cAAc,EAAY,MAAM,uBAAuB,CAAA;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK1C
|
|
1
|
+
{"version":3,"file":"useGetContractInfo.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetContractInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAExE,OAAO,EAAE,cAAc,EAAY,MAAM,uBAAuB,CAAA;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,eAAO,MAAM,kBAAkB,GAC7B,qBAAqB,mBAAmB,EACxC,UAAU,YAAY,KACrB,cAAc,CAAC,YAAY,CAyB7B,CAAA"}
|
|
@@ -7,7 +7,67 @@ const constants_1 = require("../../constants");
|
|
|
7
7
|
const helpers_1 = require("../../utils/helpers");
|
|
8
8
|
const useMetadataClient_1 = require("./useMetadataClient");
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Hook to fetch contract information.
|
|
11
|
+
* Handles ERC20/ERC721/ERC1155 contracts and native tokens (using ZERO_ADDRESS).
|
|
12
|
+
*
|
|
13
|
+
* For native tokens (like ETH, POL), it enriches the response with network-specific
|
|
14
|
+
* information like the native token symbol and network logo.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetContractInfo} for more detailed documentation.
|
|
17
|
+
*
|
|
18
|
+
* @param getContractInfoArgs - Arguments for fetching contract info
|
|
19
|
+
* @param getContractInfoArgs.chainID - Chain ID as string (e.g., "1" for Ethereum mainnet)
|
|
20
|
+
* @param getContractInfoArgs.contractAddress - Contract address or ZERO_ADDRESS for native token
|
|
21
|
+
* @param options - Optional configuration for the query behavior
|
|
22
|
+
* @param options.disabled - If true, disables the query from automatically running
|
|
23
|
+
* @param options.retry - If true (default), retries failed queries
|
|
24
|
+
*
|
|
25
|
+
* Query configuration:
|
|
26
|
+
* - Marks data as stale after 10 minutes
|
|
27
|
+
* - Retries failed requests by default
|
|
28
|
+
* - Only enabled when chainID and contractAddress are present and not explicitly disabled
|
|
29
|
+
*
|
|
30
|
+
* @returns Query result containing contract information:
|
|
31
|
+
* - `name`: Contract/token name
|
|
32
|
+
* - `symbol`: Token symbol
|
|
33
|
+
* - `decimals`: Token decimals (if applicable)
|
|
34
|
+
* - `logoURI`: URL of the contract/token logo
|
|
35
|
+
* - `type`: Contract type (e.g., "ERC721", "ERC20")
|
|
36
|
+
* - Additional metadata from the contract
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* // Fetch NFT collection info
|
|
41
|
+
* function CollectionDetails() {
|
|
42
|
+
* const { data: contractInfo } = useGetContractInfo({
|
|
43
|
+
* chainID: "1",
|
|
44
|
+
* contractAddress: "0x123..."
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* return (
|
|
48
|
+
* <div>
|
|
49
|
+
* <img src={contractInfo?.logoURI} />
|
|
50
|
+
* <h1>{contractInfo?.name}</h1>
|
|
51
|
+
* <span>Type: {contractInfo?.type}</span>
|
|
52
|
+
* </div>
|
|
53
|
+
* )
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* // Used in checkout for displaying collection info
|
|
57
|
+
* function OrderSummaryItem() {
|
|
58
|
+
* const { data: contractInfo } = useGetContractInfo({
|
|
59
|
+
* chainID: String(chainId),
|
|
60
|
+
* contractAddress
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* return (
|
|
64
|
+
* <div>
|
|
65
|
+
* <TokenImage src={contractInfo?.logoURI} />
|
|
66
|
+
* <Text>{contractInfo?.name || 'Unknown Collection'}</Text>
|
|
67
|
+
* </div>
|
|
68
|
+
* )
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
11
71
|
*/
|
|
12
72
|
const useGetContractInfo = (getContractInfoArgs, options) => {
|
|
13
73
|
const metadataClient = (0, useMetadataClient_1.useMetadataClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetContractInfo.js","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetContractInfo.ts"],"names":[],"mappings":";;;AACA,iDAA0D;AAC1D,uDAAgE;AAEhE,+CAAgE;AAEhE,iDAAoD;AAEpD,2DAAuD;AAEvD
|
|
1
|
+
{"version":3,"file":"useGetContractInfo.js","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetContractInfo.ts"],"names":[],"mappings":";;;AACA,iDAA0D;AAC1D,uDAAgE;AAEhE,+CAAgE;AAEhE,iDAAoD;AAEpD,2DAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACI,MAAM,kBAAkB,GAAG,CAChC,mBAAwC,EACxC,OAAsB,EACQ,EAAE;IAChC,MAAM,cAAc,GAAG,IAAA,qCAAiB,GAAE,CAAA;IAE1C,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,OAAO,CAAC;QACvE,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,aAAa,GAAG,IAAA,wBAAc,EAAC,wBAAY,EAAE,mBAAmB,CAAC,eAAe,CAAC,CAAA;YAEvF,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAA;YACrE,MAAM,OAAO,GAAG,IAAA,8BAAoB,EAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;YAEjE,OAAO;gBACL,GAAG,GAAG,CAAC,YAAY;gBACnB,GAAG,CAAC,aAAa,IAAI,OAAO;oBAC1B,CAAC,CAAC;wBACE,GAAG,OAAO,CAAC,WAAW;wBACtB,OAAO,EAAE,OAAO,CAAC,OAAO;qBACzB;oBACH,CAAC,CAAC,EAAE,CAAC;aACR,CAAA;QACH,CAAC;QACD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,SAAS,GAAG,EAAE;QAC9B,OAAO,EAAE,CAAC,CAAC,mBAAmB,CAAC,OAAO,IAAI,CAAC,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,OAAO,EAAE,QAAQ;KACtG,CAAC,CAAA;AACJ,CAAC,CAAA;AA5BY,QAAA,kBAAkB,sBA4B9B"}
|
|
@@ -1,7 +1,95 @@
|
|
|
1
1
|
import { ContractInfo, GetContractInfoArgs } from '@0xsequence/metadata';
|
|
2
2
|
import { HooksOptions } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook to fetch contract information for multiple contracts in parallel.
|
|
5
|
+
* This is a batch version of {@link useGetContractInfo} that optimizes fetching metadata
|
|
6
|
+
* for multiple contracts in a single hook.
|
|
7
|
+
*
|
|
8
|
+
* Supports fetching contracts from different chains in a single query, making it ideal
|
|
9
|
+
* for cross-chain applications. Can fetch any combination of NFTs (ERC721/ERC1155) and
|
|
10
|
+
* tokens (ERC20) across different chains simultaneously.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetMultipleContractsInfo} for more detailed documentation.
|
|
13
|
+
*
|
|
14
|
+
* @param useGetMultipleContractsInfoArgs - Array of contract info arguments
|
|
15
|
+
* @param useGetMultipleContractsInfoArgs[].chainID - Chain ID as string (e.g., "1" for Ethereum mainnet)
|
|
16
|
+
* @param useGetMultipleContractsInfoArgs[].contractAddress - Contract address to fetch info for
|
|
17
|
+
* @param options - Optional configuration for the query behavior
|
|
18
|
+
* @param options.disabled - If true, disables the query from automatically running
|
|
19
|
+
* @param options.retry - If true (default), retries failed queries
|
|
20
|
+
*
|
|
21
|
+
* Query configuration:
|
|
22
|
+
* - Uses a 1 hour stale time (compared to 10 minutes for single contract info)
|
|
23
|
+
* - Retries failed requests by default
|
|
24
|
+
* - Enabled by default unless explicitly disabled
|
|
25
|
+
* - Fetches all contracts in parallel regardless of chain
|
|
26
|
+
*
|
|
27
|
+
* @returns Query result containing an array of contract information objects, each containing:
|
|
28
|
+
* - `name`: Contract/token name
|
|
29
|
+
* - `symbol`: Token symbol
|
|
30
|
+
* - `decimals`: Token decimals (if applicable)
|
|
31
|
+
* - `logoURI`: URL of the contract/token logo
|
|
32
|
+
* - `type`: Contract type (e.g., "ERC721", "ERC20", "ERC1155")
|
|
33
|
+
* - Additional metadata from each contract
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* // Cross-chain NFT and Token Portfolio
|
|
38
|
+
* function CrossChainPortfolio() {
|
|
39
|
+
* const { data: contractsInfo, isLoading } = useGetMultipleContractsInfo([
|
|
40
|
+
* // NFTs
|
|
41
|
+
* { chainID: "1", contractAddress: "0xbc4ca0..." },
|
|
42
|
+
* { chainID: "1", contractAddress: "0x60e4d7..." },
|
|
43
|
+
* { chainID: "137", contractAddress: "0x631998..." },
|
|
44
|
+
* // Tokens
|
|
45
|
+
* { chainID: "1", contractAddress: "0xa0b86991..." },
|
|
46
|
+
* { chainID: "137", contractAddress: "0x2791bca..." }
|
|
47
|
+
* ])
|
|
48
|
+
*
|
|
49
|
+
* if (isLoading) return <div>Loading portfolio...</div>
|
|
50
|
+
*
|
|
51
|
+
* const nfts = contractsInfo?.filter(info =>
|
|
52
|
+
* info.type === 'ERC721' || info.type === 'ERC1155'
|
|
53
|
+
* ) || []
|
|
54
|
+
*
|
|
55
|
+
* const tokens = contractsInfo?.filter(info =>
|
|
56
|
+
* info.type === 'ERC20'
|
|
57
|
+
* ) || []
|
|
58
|
+
*
|
|
59
|
+
* return (
|
|
60
|
+
* <div className="portfolio">
|
|
61
|
+
* <div className="nft-section">
|
|
62
|
+
* <h2>NFT Collections</h2>
|
|
63
|
+
* {nfts.map((nft, index) => (
|
|
64
|
+
* <div key={index} className="nft-card">
|
|
65
|
+
* <img src={nft.logoURI} alt={nft.name} />
|
|
66
|
+
* <div className="nft-info">
|
|
67
|
+
* <Text variant="title">{nft.name}</Text>
|
|
68
|
+
* <Text>Collection Type: {nft.type}</Text>
|
|
69
|
+
* <Text>Chain: {nft.chainID}</Text>
|
|
70
|
+
* </div>
|
|
71
|
+
* </div>
|
|
72
|
+
* ))}
|
|
73
|
+
* </div>
|
|
74
|
+
*
|
|
75
|
+
* <div className="token-section">
|
|
76
|
+
* <h2>Tokens</h2>
|
|
77
|
+
* {tokens.map((token, index) => (
|
|
78
|
+
* <div key={index} className="token-card">
|
|
79
|
+
* <TokenImage src={token.logoURI} />
|
|
80
|
+
* <div className="token-info">
|
|
81
|
+
* <Text>{token.name}</Text>
|
|
82
|
+
* <Text>Symbol: {token.symbol}</Text>
|
|
83
|
+
* <Text>Chain: {token.chainID}</Text>
|
|
84
|
+
* <Text>Decimals: {token.decimals}</Text>
|
|
85
|
+
* </div>
|
|
86
|
+
* </div>
|
|
87
|
+
* ))}
|
|
88
|
+
* </div>
|
|
89
|
+
* </div>
|
|
90
|
+
* )
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
5
93
|
*/
|
|
6
94
|
export declare const useGetMultipleContractsInfo: (useGetMultipleContractsInfoArgs: GetContractInfoArgs[], options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<ContractInfo[], Error>;
|
|
7
95
|
//# sourceMappingURL=useGetMultipleContractsInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetMultipleContractsInfo.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetMultipleContractsInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAI1F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAiB1C
|
|
1
|
+
{"version":3,"file":"useGetMultipleContractsInfo.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetMultipleContractsInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAI1F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAiB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0FG;AACH,eAAO,MAAM,2BAA2B,GAAI,iCAAiC,mBAAmB,EAAE,EAAE,UAAU,YAAY,0EAUzH,CAAA"}
|
|
@@ -14,7 +14,95 @@ const getMultipleContractsInfo = async (metadataClient, arg) => {
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Hook to fetch contract information for multiple contracts in parallel.
|
|
18
|
+
* This is a batch version of {@link useGetContractInfo} that optimizes fetching metadata
|
|
19
|
+
* for multiple contracts in a single hook.
|
|
20
|
+
*
|
|
21
|
+
* Supports fetching contracts from different chains in a single query, making it ideal
|
|
22
|
+
* for cross-chain applications. Can fetch any combination of NFTs (ERC721/ERC1155) and
|
|
23
|
+
* tokens (ERC20) across different chains simultaneously.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetMultipleContractsInfo} for more detailed documentation.
|
|
26
|
+
*
|
|
27
|
+
* @param useGetMultipleContractsInfoArgs - Array of contract info arguments
|
|
28
|
+
* @param useGetMultipleContractsInfoArgs[].chainID - Chain ID as string (e.g., "1" for Ethereum mainnet)
|
|
29
|
+
* @param useGetMultipleContractsInfoArgs[].contractAddress - Contract address to fetch info for
|
|
30
|
+
* @param options - Optional configuration for the query behavior
|
|
31
|
+
* @param options.disabled - If true, disables the query from automatically running
|
|
32
|
+
* @param options.retry - If true (default), retries failed queries
|
|
33
|
+
*
|
|
34
|
+
* Query configuration:
|
|
35
|
+
* - Uses a 1 hour stale time (compared to 10 minutes for single contract info)
|
|
36
|
+
* - Retries failed requests by default
|
|
37
|
+
* - Enabled by default unless explicitly disabled
|
|
38
|
+
* - Fetches all contracts in parallel regardless of chain
|
|
39
|
+
*
|
|
40
|
+
* @returns Query result containing an array of contract information objects, each containing:
|
|
41
|
+
* - `name`: Contract/token name
|
|
42
|
+
* - `symbol`: Token symbol
|
|
43
|
+
* - `decimals`: Token decimals (if applicable)
|
|
44
|
+
* - `logoURI`: URL of the contract/token logo
|
|
45
|
+
* - `type`: Contract type (e.g., "ERC721", "ERC20", "ERC1155")
|
|
46
|
+
* - Additional metadata from each contract
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* // Cross-chain NFT and Token Portfolio
|
|
51
|
+
* function CrossChainPortfolio() {
|
|
52
|
+
* const { data: contractsInfo, isLoading } = useGetMultipleContractsInfo([
|
|
53
|
+
* // NFTs
|
|
54
|
+
* { chainID: "1", contractAddress: "0xbc4ca0..." },
|
|
55
|
+
* { chainID: "1", contractAddress: "0x60e4d7..." },
|
|
56
|
+
* { chainID: "137", contractAddress: "0x631998..." },
|
|
57
|
+
* // Tokens
|
|
58
|
+
* { chainID: "1", contractAddress: "0xa0b86991..." },
|
|
59
|
+
* { chainID: "137", contractAddress: "0x2791bca..." }
|
|
60
|
+
* ])
|
|
61
|
+
*
|
|
62
|
+
* if (isLoading) return <div>Loading portfolio...</div>
|
|
63
|
+
*
|
|
64
|
+
* const nfts = contractsInfo?.filter(info =>
|
|
65
|
+
* info.type === 'ERC721' || info.type === 'ERC1155'
|
|
66
|
+
* ) || []
|
|
67
|
+
*
|
|
68
|
+
* const tokens = contractsInfo?.filter(info =>
|
|
69
|
+
* info.type === 'ERC20'
|
|
70
|
+
* ) || []
|
|
71
|
+
*
|
|
72
|
+
* return (
|
|
73
|
+
* <div className="portfolio">
|
|
74
|
+
* <div className="nft-section">
|
|
75
|
+
* <h2>NFT Collections</h2>
|
|
76
|
+
* {nfts.map((nft, index) => (
|
|
77
|
+
* <div key={index} className="nft-card">
|
|
78
|
+
* <img src={nft.logoURI} alt={nft.name} />
|
|
79
|
+
* <div className="nft-info">
|
|
80
|
+
* <Text variant="title">{nft.name}</Text>
|
|
81
|
+
* <Text>Collection Type: {nft.type}</Text>
|
|
82
|
+
* <Text>Chain: {nft.chainID}</Text>
|
|
83
|
+
* </div>
|
|
84
|
+
* </div>
|
|
85
|
+
* ))}
|
|
86
|
+
* </div>
|
|
87
|
+
*
|
|
88
|
+
* <div className="token-section">
|
|
89
|
+
* <h2>Tokens</h2>
|
|
90
|
+
* {tokens.map((token, index) => (
|
|
91
|
+
* <div key={index} className="token-card">
|
|
92
|
+
* <TokenImage src={token.logoURI} />
|
|
93
|
+
* <div className="token-info">
|
|
94
|
+
* <Text>{token.name}</Text>
|
|
95
|
+
* <Text>Symbol: {token.symbol}</Text>
|
|
96
|
+
* <Text>Chain: {token.chainID}</Text>
|
|
97
|
+
* <Text>Decimals: {token.decimals}</Text>
|
|
98
|
+
* </div>
|
|
99
|
+
* </div>
|
|
100
|
+
* ))}
|
|
101
|
+
* </div>
|
|
102
|
+
* </div>
|
|
103
|
+
* )
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
18
106
|
*/
|
|
19
107
|
const useGetMultipleContractsInfo = (useGetMultipleContractsInfoArgs, options) => {
|
|
20
108
|
const metadataClient = (0, useMetadataClient_1.useMetadataClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetMultipleContractsInfo.js","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetMultipleContractsInfo.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAkD;AAGlD,2DAAuD;AAEvD,MAAM,wBAAwB,GAAG,KAAK,EACpC,cAAgC,EAChC,GAA0B,EACD,EAAE;IAC3B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAE9E,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,CAAA;IACT,CAAC;AACH,CAAC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"useGetMultipleContractsInfo.js","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetMultipleContractsInfo.ts"],"names":[],"mappings":";;;AACA,uDAAgD;AAEhD,+CAAkD;AAGlD,2DAAuD;AAEvD,MAAM,wBAAwB,GAAG,KAAK,EACpC,cAAgC,EAChC,GAA0B,EACD,EAAE;IAC3B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAE9E,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,CAAA;IACT,CAAC;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0FG;AACI,MAAM,2BAA2B,GAAG,CAAC,+BAAsD,EAAE,OAAsB,EAAE,EAAE;IAC5H,MAAM,cAAc,GAAG,IAAA,qCAAiB,GAAE,CAAA;IAE1C,OAAO,IAAA,sBAAQ,EAAC;QACd,QAAQ,EAAE,CAAC,sBAAU,CAAC,0BAA0B,EAAE,+BAA+B,EAAE,OAAO,CAAC;QAC3F,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,wBAAwB,CAAC,cAAc,EAAE,+BAA+B,CAAC;QACpG,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;QAC7B,SAAS,EAAE,gBAAI,CAAC,OAAO;QACvB,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ;KAC5B,CAAC,CAAA;AACJ,CAAC,CAAA;AAVY,QAAA,2BAA2B,+BAUvC"}
|
|
@@ -1,7 +1,89 @@
|
|
|
1
1
|
import { GetTokenMetadataArgs } from '@0xsequence/metadata';
|
|
2
2
|
import { HooksOptions } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook to fetch token-specific metadata for individual tokens within a contract.
|
|
5
|
+
* This differs from {@link useGetContractInfo} which returns contract-level information.
|
|
6
|
+
* This hook is specifically for getting metadata about individual token IDs (like NFT attributes,
|
|
7
|
+
* images, etc).
|
|
8
|
+
*
|
|
9
|
+
* Optimized for batch fetching with automatic chunking of token IDs to respect
|
|
10
|
+
* rate limits (50 tokens per request).
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetTokenMetadata} for more detailed documentation.
|
|
13
|
+
*
|
|
14
|
+
* @param getTokenMetadataArgs - Arguments for fetching token metadata
|
|
15
|
+
* @param getTokenMetadataArgs.chainID - Chain ID as string (e.g., "1" for Ethereum mainnet)
|
|
16
|
+
* @param getTokenMetadataArgs.contractAddress - Contract address of the token/NFT
|
|
17
|
+
* @param getTokenMetadataArgs.tokenIDs - Array of token IDs to fetch metadata for. Each ID represents a specific token
|
|
18
|
+
* @param options - Optional configuration for the query behavior
|
|
19
|
+
* @param options.disabled - If true, disables the query from automatically running
|
|
20
|
+
* @param options.retry - If true (default), retries failed queries
|
|
21
|
+
*
|
|
22
|
+
* Query configuration:
|
|
23
|
+
* - Marks data as stale after 1 hour
|
|
24
|
+
* - Retries failed requests by default
|
|
25
|
+
* - Only enabled when chainID and contractAddress are present and not explicitly disabled
|
|
26
|
+
* - Automatically chunks requests into batches of 50 tokens to respect API limits
|
|
27
|
+
*
|
|
28
|
+
* @returns Query result containing an array of token metadata objects, each containing:
|
|
29
|
+
* - `name`: Name of the specific token (e.g., "Bored Ape #1234")
|
|
30
|
+
* - `description`: Description of the specific token
|
|
31
|
+
* - `image`: Token-specific image URL (proxied through image service)
|
|
32
|
+
* - `attributes`: Token-specific attributes/traits (for NFTs)
|
|
33
|
+
* - `decimals`: Token decimals (for ERC1155 tokens)
|
|
34
|
+
* - Additional token-specific metadata
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* // Fetch metadata for a specific NFT
|
|
39
|
+
* function NFTDetails() {
|
|
40
|
+
* const { data: tokensMetadata } = useGetTokenMetadata({
|
|
41
|
+
* chainID: "1",
|
|
42
|
+
* contractAddress: "0xbc4ca0...",
|
|
43
|
+
* tokenIDs: ["1234"]
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* const nft = tokensMetadata?.[0]
|
|
47
|
+
*
|
|
48
|
+
* return (
|
|
49
|
+
* <div>
|
|
50
|
+
* <img src={nft?.image} alt={nft?.name} />
|
|
51
|
+
* <h2>{nft?.name}</h2>
|
|
52
|
+
* <p>{nft?.description}</p>
|
|
53
|
+
* {nft?.attributes?.map(attr => (
|
|
54
|
+
* <div key={attr.trait_type}>
|
|
55
|
+
* {attr.trait_type}: {attr.value}
|
|
56
|
+
* </div>
|
|
57
|
+
* ))}
|
|
58
|
+
* </div>
|
|
59
|
+
* )
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* // Fetch metadata for multiple tokens in a transaction
|
|
63
|
+
* function TransactionDetails() {
|
|
64
|
+
* const { data: tokenMetadata } = useGetTokenMetadata({
|
|
65
|
+
* chainID: String(chainId),
|
|
66
|
+
* contractAddress,
|
|
67
|
+
* tokenIDs: transferProps.tokenIds // Array of transferred token IDs
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* return (
|
|
71
|
+
* <div>
|
|
72
|
+
* {tokenMetadata?.map(token => (
|
|
73
|
+
* <div key={token.id} className="token-transfer">
|
|
74
|
+
* <CollectibleTileImage imageUrl={token.image} />
|
|
75
|
+
* <Text>{token.name}</Text>
|
|
76
|
+
* {token.attributes && (
|
|
77
|
+
* <div className="attributes">
|
|
78
|
+
* Token attributes here
|
|
79
|
+
* </div>
|
|
80
|
+
* )}
|
|
81
|
+
* </div>
|
|
82
|
+
* ))}
|
|
83
|
+
* </div>
|
|
84
|
+
* )
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
5
87
|
*/
|
|
6
88
|
export declare const useGetTokenMetadata: (getTokenMetadataArgs: GetTokenMetadataArgs, options?: HooksOptions) => import("@tanstack/react-query").UseQueryResult<import("@0xsequence/metadata").TokenMetadata[], Error>;
|
|
7
89
|
//# sourceMappingURL=useGetTokenMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTokenMetadata.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetTokenMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAiC1C
|
|
1
|
+
{"version":3,"file":"useGetTokenMetadata.d.ts","sourceRoot":"","sources":["../../../../src/hooks/Metadata/useGetTokenMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAiC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AACH,eAAO,MAAM,mBAAmB,GAAI,sBAAsB,oBAAoB,EAAE,UAAU,YAAY,0GAWrG,CAAA"}
|