@talismn/balances-react 0.3.3 → 0.4.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/CHANGELOG.md +24 -0
- package/dist/declarations/src/hooks/index.d.ts +20 -0
- package/dist/declarations/src/hooks/useAllAddresses.d.ts +4 -0
- package/dist/declarations/src/hooks/useBalanceModules.d.ts +8 -0
- package/dist/declarations/src/hooks/useBalances.d.ts +3 -6
- package/dist/declarations/src/hooks/useBalancesHydrate.d.ts +2 -0
- package/dist/declarations/src/hooks/useBalancesStatus.d.ts +19 -0
- package/dist/declarations/src/hooks/useChainConnectors.d.ts +12 -0
- package/dist/declarations/src/hooks/useChaindata.d.ts +6 -23
- package/dist/declarations/src/hooks/useChains.d.ts +3 -0
- package/dist/declarations/src/hooks/useDbCache.d.ts +24 -0
- package/dist/declarations/src/hooks/useDbCacheSubscription.d.ts +13 -0
- package/dist/declarations/src/hooks/useEvmNetworks.d.ts +3 -0
- package/dist/declarations/src/hooks/useTokenRates.d.ts +3 -3
- package/dist/declarations/src/hooks/useTokens.d.ts +3 -0
- package/dist/declarations/src/hooks/useWithTestnets.d.ts +8 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/util/index.d.ts +2 -0
- package/dist/declarations/src/util/provideContext.d.ts +9 -0
- package/dist/declarations/src/util/useMulticastSubscription.d.ts +16 -0
- package/dist/declarations/src/util/useSharedSubscription.d.ts +9 -0
- package/dist/talismn-balances-react.cjs.dev.js +628 -248
- package/dist/talismn-balances-react.cjs.prod.js +628 -248
- package/dist/talismn-balances-react.esm.js +606 -249
- package/package.json +14 -11
@@ -2,23 +2,205 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var
|
5
|
+
var react = require('react');
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
6
7
|
var chainConnector = require('@talismn/chain-connector');
|
7
8
|
var chainConnectorEvm = require('@talismn/chain-connector-evm');
|
9
|
+
var connectionMeta = require('@talismn/connection-meta');
|
10
|
+
var chaindataProviderExtension = require('@talismn/chaindata-provider-extension');
|
11
|
+
var balances = require('@talismn/balances');
|
12
|
+
var tokenRates = require('@talismn/token-rates');
|
8
13
|
var dexieReactHooks = require('dexie-react-hooks');
|
9
|
-
var react = require('react');
|
10
14
|
var reactUse = require('react-use');
|
15
|
+
var md5 = require('blueimp-md5');
|
11
16
|
var anylogger = require('anylogger');
|
12
|
-
var
|
13
|
-
var tokenRates = require('@talismn/token-rates');
|
17
|
+
var rxjs = require('rxjs');
|
14
18
|
|
15
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
16
20
|
|
21
|
+
var md5__default = /*#__PURE__*/_interopDefault(md5);
|
17
22
|
var anylogger__default = /*#__PURE__*/_interopDefault(anylogger);
|
18
23
|
|
24
|
+
const provideContext = useProviderContext => {
|
25
|
+
// automatic typing based on our hook's return type
|
26
|
+
|
27
|
+
const Context = /*#__PURE__*/react.createContext({
|
28
|
+
__provideContextInternalDefaultValue: true
|
29
|
+
});
|
30
|
+
const Provider = ({
|
31
|
+
children,
|
32
|
+
...props
|
33
|
+
}) => {
|
34
|
+
const ctx = useProviderContext(props);
|
35
|
+
return /*#__PURE__*/jsxRuntime.jsx(Context.Provider, {
|
36
|
+
value: ctx,
|
37
|
+
children: children
|
38
|
+
});
|
39
|
+
};
|
40
|
+
const useProvidedContext = () => {
|
41
|
+
const context = react.useContext(Context);
|
42
|
+
if (typeof context === "object" && context && "__provideContextInternalDefaultValue" in context) throw new Error("This hook requires a provider to be present above it in the tree");
|
43
|
+
return context;
|
44
|
+
};
|
45
|
+
const result = [Provider, useProvidedContext];
|
46
|
+
return result;
|
47
|
+
};
|
48
|
+
|
49
|
+
const useAllAddressesProvider = () => react.useState([]);
|
50
|
+
const [AllAddressesProvider, useAllAddresses] = provideContext(useAllAddressesProvider);
|
51
|
+
|
52
|
+
function useChaindataProvider(options = {}) {
|
53
|
+
const [onfinalityApiKey, setOnfinalityApiKey] = react.useState(options.onfinalityApiKey);
|
54
|
+
|
55
|
+
// make sure we recreate provider only when the onfinalityApiKey changes
|
56
|
+
react.useEffect(() => {
|
57
|
+
if (options.onfinalityApiKey !== onfinalityApiKey) setOnfinalityApiKey(options.onfinalityApiKey);
|
58
|
+
}, [options.onfinalityApiKey, onfinalityApiKey]);
|
59
|
+
return react.useMemo(() => new chaindataProviderExtension.ChaindataProviderExtension({
|
60
|
+
onfinalityApiKey
|
61
|
+
}), [onfinalityApiKey]);
|
62
|
+
}
|
63
|
+
const [ChaindataProvider, useChaindata] = provideContext(useChaindataProvider);
|
64
|
+
|
65
|
+
function useChainConnectorsProvider(options) {
|
66
|
+
const [onfinalityApiKey, setOnfinalityApiKey] = react.useState(options.onfinalityApiKey);
|
67
|
+
|
68
|
+
// make sure we recreate provider only when the onfinalityApiKey changes
|
69
|
+
react.useEffect(() => {
|
70
|
+
if (options.onfinalityApiKey !== onfinalityApiKey) setOnfinalityApiKey(options.onfinalityApiKey);
|
71
|
+
}, [options.onfinalityApiKey, onfinalityApiKey]);
|
72
|
+
|
73
|
+
// chaindata dependency
|
74
|
+
const chaindata = useChaindata();
|
75
|
+
|
76
|
+
// substrate connector
|
77
|
+
const substrate = react.useMemo(() => new chainConnector.ChainConnector(chaindata, connectionMeta.connectionMetaDb), [chaindata]);
|
78
|
+
|
79
|
+
// evm connector
|
80
|
+
const evm = react.useMemo(() => new chainConnectorEvm.ChainConnectorEvm(chaindata, {
|
81
|
+
onfinalityApiKey
|
82
|
+
}), [chaindata, onfinalityApiKey]);
|
83
|
+
return react.useMemo(() => ({
|
84
|
+
substrate,
|
85
|
+
evm
|
86
|
+
}), [substrate, evm]);
|
87
|
+
}
|
88
|
+
const [ChainConnectorsProvider, useChainConnectors] = provideContext(useChainConnectorsProvider);
|
89
|
+
|
90
|
+
const useBalanceModulesProvider = ({
|
91
|
+
balanceModules
|
92
|
+
}) => {
|
93
|
+
const chainConnectors = useChainConnectors();
|
94
|
+
const chaindataProvider = useChaindata();
|
95
|
+
const hydrated = react.useMemo(() => chainConnectors.substrate && chainConnectors.evm && chaindataProvider ? balanceModules.map(mod => mod({
|
96
|
+
chainConnectors,
|
97
|
+
chaindataProvider
|
98
|
+
})) : [], [balanceModules, chainConnectors, chaindataProvider]);
|
99
|
+
return hydrated;
|
100
|
+
};
|
101
|
+
const [BalanceModulesProvider, useBalanceModules] = provideContext(useBalanceModulesProvider);
|
102
|
+
|
103
|
+
const filterNoTestnet = ({
|
104
|
+
isTestnet
|
105
|
+
}) => isTestnet === false;
|
106
|
+
const DEFAULT_VALUE = {
|
107
|
+
chainsWithTestnets: [],
|
108
|
+
chainsWithoutTestnets: [],
|
109
|
+
evmNetworksWithTestnets: [],
|
110
|
+
evmNetworksWithoutTestnets: [],
|
111
|
+
tokensWithTestnets: [],
|
112
|
+
tokensWithoutTestnets: [],
|
113
|
+
chainsWithTestnetsMap: {},
|
114
|
+
chainsWithoutTestnetsMap: {},
|
115
|
+
evmNetworksWithTestnetsMap: {},
|
116
|
+
evmNetworksWithoutTestnetsMap: {},
|
117
|
+
tokensWithTestnetsMap: {},
|
118
|
+
tokensWithoutTestnetsMap: {},
|
119
|
+
tokenRatesMap: {},
|
120
|
+
balances: []
|
121
|
+
};
|
122
|
+
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances) => {
|
123
|
+
if (!chainsMap || !evmNetworksMap || !tokensMap || !tokenRates || !allBalances) return DEFAULT_VALUE;
|
124
|
+
|
125
|
+
// BEGIN: temp hack to indicate that
|
126
|
+
// - EVM GLMR is a mirror of substrate GLMR
|
127
|
+
// - EVM MOVR is a mirror of substrate MOVR
|
128
|
+
// - EVM DEV is a mirror of substrate DEV
|
129
|
+
// - EVM ACA is a mirror of substrate ACA
|
130
|
+
const mirrorTokenIds = {
|
131
|
+
"1284-evm-native-glmr": "moonbeam-substrate-native-glmr",
|
132
|
+
"1285-evm-native-movr": "moonriver-substrate-native-movr",
|
133
|
+
"1287-evm-native-dev": "moonbase-alpha-testnet-substrate-native-dev",
|
134
|
+
"787-evm-native-aca": "acala-substrate-native-aca"
|
135
|
+
};
|
136
|
+
Object.entries(mirrorTokenIds).filter(([mirrorToken]) => tokensMap[mirrorToken]).forEach(([mirrorToken, mirrorOf]) => tokensMap[mirrorToken].mirrorOf = mirrorOf);
|
137
|
+
// END: temp hack
|
138
|
+
|
139
|
+
const chainsWithTestnets = Object.values(chainsMap);
|
140
|
+
const chainsWithoutTestnets = chainsWithTestnets.filter(filterNoTestnet);
|
141
|
+
const chainsWithoutTestnetsMap = Object.fromEntries(chainsWithoutTestnets.map(network => [network.id, network]));
|
142
|
+
const evmNetworksWithTestnets = Object.values(evmNetworksMap);
|
143
|
+
const evmNetworksWithoutTestnets = evmNetworksWithTestnets.filter(filterNoTestnet);
|
144
|
+
const evmNetworksWithoutTestnetsMap = Object.fromEntries(evmNetworksWithoutTestnets.map(network => [network.id, network]));
|
145
|
+
|
146
|
+
// ensure that we have corresponding network for each token
|
147
|
+
const tokensWithTestnets = Object.values(tokensMap).filter(token => token.chain && chainsMap[token.chain.id] || token.evmNetwork && evmNetworksMap[token.evmNetwork.id]);
|
148
|
+
const tokensWithoutTestnets = tokensWithTestnets.filter(filterNoTestnet).filter(token => token.chain && chainsWithoutTestnetsMap[token.chain.id] || token.evmNetwork && evmNetworksWithoutTestnetsMap[token.evmNetwork.id]);
|
149
|
+
const tokensWithTestnetsMap = Object.fromEntries(tokensWithTestnets.map(token => [token.id, token]));
|
150
|
+
const tokensWithoutTestnetsMap = Object.fromEntries(tokensWithoutTestnets.map(token => [token.id, token]));
|
151
|
+
const tokenRatesMap = Object.fromEntries(tokenRates.map(({
|
152
|
+
tokenId,
|
153
|
+
rates
|
154
|
+
}) => [tokenId, rates]));
|
155
|
+
|
156
|
+
// return only balances for which we have a token
|
157
|
+
const balances = allBalances.filter(b => tokensWithTestnetsMap[b.tokenId]);
|
158
|
+
return {
|
159
|
+
chainsWithTestnets,
|
160
|
+
chainsWithoutTestnets,
|
161
|
+
evmNetworksWithTestnets,
|
162
|
+
evmNetworksWithoutTestnets,
|
163
|
+
tokensWithTestnets,
|
164
|
+
tokensWithoutTestnets,
|
165
|
+
chainsWithTestnetsMap: chainsMap,
|
166
|
+
chainsWithoutTestnetsMap,
|
167
|
+
evmNetworksWithTestnetsMap: evmNetworksMap,
|
168
|
+
evmNetworksWithoutTestnetsMap,
|
169
|
+
tokensWithTestnetsMap,
|
170
|
+
tokensWithoutTestnetsMap,
|
171
|
+
tokenRatesMap,
|
172
|
+
balances
|
173
|
+
};
|
174
|
+
};
|
175
|
+
const useDbCacheProvider = () => {
|
176
|
+
const chaindataProvider = useChaindata();
|
177
|
+
const chainList = dexieReactHooks.useLiveQuery(() => chaindataProvider?.chains(), [chaindataProvider]);
|
178
|
+
const evmNetworkList = dexieReactHooks.useLiveQuery(() => chaindataProvider?.evmNetworks(), [chaindataProvider]);
|
179
|
+
const tokenList = dexieReactHooks.useLiveQuery(() => chaindataProvider?.tokens(), [chaindataProvider]);
|
180
|
+
const tokenRates$1 = dexieReactHooks.useLiveQuery(() => tokenRates.db.tokenRates.toArray(), []);
|
181
|
+
const rawBalances = dexieReactHooks.useLiveQuery(() => balances.db.balances.toArray(), []);
|
182
|
+
const [dbData, setDbData] = react.useState(DEFAULT_VALUE);
|
183
|
+
|
184
|
+
// debounce every 500ms to prevent hammering UI with updates
|
185
|
+
reactUse.useDebounce(() => {
|
186
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
187
|
+
}, 500, [chainList, evmNetworkList, tokenList, rawBalances, tokenRates$1]);
|
188
|
+
const refInitialized = react.useRef(false);
|
189
|
+
|
190
|
+
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
191
|
+
react.useEffect(() => {
|
192
|
+
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates$1 && rawBalances) {
|
193
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
194
|
+
refInitialized.current = true;
|
195
|
+
}
|
196
|
+
}, [chainList, evmNetworkList, rawBalances, tokenList, tokenRates$1]);
|
197
|
+
return dbData;
|
198
|
+
};
|
199
|
+
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
200
|
+
|
19
201
|
var packageJson = {
|
20
202
|
name: "@talismn/balances-react",
|
21
|
-
version: "0.
|
203
|
+
version: "0.4.0",
|
22
204
|
author: "Talisman",
|
23
205
|
homepage: "https://talisman.xyz",
|
24
206
|
license: "UNLICENSED",
|
@@ -36,7 +218,7 @@ var packageJson = {
|
|
36
218
|
"/dist"
|
37
219
|
],
|
38
220
|
engines: {
|
39
|
-
node: ">=
|
221
|
+
node: ">=18"
|
40
222
|
},
|
41
223
|
scripts: {
|
42
224
|
test: "jest",
|
@@ -49,11 +231,14 @@ var packageJson = {
|
|
49
231
|
"@talismn/chain-connector-evm": "workspace:^",
|
50
232
|
"@talismn/chaindata-provider": "workspace:^",
|
51
233
|
"@talismn/chaindata-provider-extension": "workspace:^",
|
234
|
+
"@talismn/connection-meta": "workspace:^",
|
52
235
|
"@talismn/token-rates": "workspace:^",
|
53
236
|
anylogger: "^1.0.11",
|
54
|
-
|
55
|
-
|
56
|
-
"react-
|
237
|
+
"blueimp-md5": "2.19.0",
|
238
|
+
dexie: "^3.2.3",
|
239
|
+
"dexie-react-hooks": "^1.1.3",
|
240
|
+
"react-use": "^17.4.0",
|
241
|
+
rxjs: "^7.8.0"
|
57
242
|
},
|
58
243
|
devDependencies: {
|
59
244
|
"@talismn/eslint-config": "workspace:^",
|
@@ -80,139 +265,387 @@ var packageJson = {
|
|
80
265
|
|
81
266
|
var log = anylogger__default["default"](packageJson.name);
|
82
267
|
|
83
|
-
//
|
84
|
-
|
85
|
-
const [chaindataProvider, setChaindataProvider] = react.useState(null);
|
268
|
+
// global data store containing all subscriptions
|
269
|
+
const subscriptions = {};
|
86
270
|
|
87
|
-
|
88
|
-
|
271
|
+
/**
|
272
|
+
* This hook ensures a subscription is created only once, and unsubscribe automatically as soon as there is no consumer to the hook
|
273
|
+
* @param key key that is unique to the subscription's parameters
|
274
|
+
* @param subscribe // subscribe function that will be shared by all consumers of the key
|
275
|
+
*/
|
276
|
+
const useSharedSubscription = (key, subscribe) => {
|
277
|
+
// create the rxJS subject if it doesn't exist
|
278
|
+
if (!subscriptions[key]) subscriptions[key] = {
|
279
|
+
subject: new rxjs.Subject()
|
280
|
+
};
|
89
281
|
react.useEffect(() => {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
282
|
+
// subscribe to subject.
|
283
|
+
// it won't change but we need to count subscribers, to unsubscribe main subscription when no more observers
|
284
|
+
const s = subscriptions[key].subject.subscribe();
|
285
|
+
return () => {
|
286
|
+
// unsubscribe from our local observable updates to prevent memory leaks
|
287
|
+
s.unsubscribe();
|
288
|
+
const {
|
289
|
+
subject,
|
290
|
+
unsubscribe
|
291
|
+
} = subscriptions[key];
|
292
|
+
if (!subject.observed && unsubscribe) {
|
293
|
+
log.debug(`[useSharedSubscription] unsubscribing ${key}`);
|
294
|
+
|
295
|
+
// unsubscribe from backend updates to prevent unnecessary network connections
|
296
|
+
unsubscribe();
|
297
|
+
delete subscriptions[key].unsubscribe;
|
105
298
|
}
|
106
299
|
};
|
107
|
-
|
108
|
-
|
300
|
+
}, [key]);
|
301
|
+
|
302
|
+
// Initialize subscription
|
303
|
+
react.useEffect(() => {
|
304
|
+
const {
|
305
|
+
unsubscribe
|
306
|
+
} = subscriptions[key];
|
307
|
+
// launch the subscription if it's a new key
|
308
|
+
if (!unsubscribe) {
|
309
|
+
const cb = subscribe();
|
310
|
+
log.debug(`[useSharedSubscription] subscribing ${key}`);
|
311
|
+
if (cb) subscriptions[key].unsubscribe = cb;
|
312
|
+
// this error should only happen when developping a new hook, let it bubble up
|
313
|
+
else throw new Error(`${key} subscribe did not return an unsubscribe callback`);
|
314
|
+
}
|
315
|
+
}, [key, subscribe]);
|
316
|
+
};
|
317
|
+
|
318
|
+
/**
|
319
|
+
* Creates a subscription function that can be used to subscribe to a multicast observable created from an upstream source.
|
320
|
+
*
|
321
|
+
* An example of when this is useful is when we want to subscribe to some data from multiple components, but we only want
|
322
|
+
* to actively keep that data hydrated when at least one component is subscribed to it.
|
323
|
+
*
|
324
|
+
* When the first component subscribes, the `upstream` function will be called. It should then set up a subscription and return a teardown function.
|
325
|
+
* When subsequent components subscribe, they will be added to the existing subscription.
|
326
|
+
* When the last component unsubscribes, the teardown function returned from the `upstream` function will be called.
|
327
|
+
*
|
328
|
+
* @param upstream A function that takes a "next" callback function as an argument, and returns either an unsubscribe function or void.
|
329
|
+
* @returns A subscription function that can be used to subscribe to the multicast observable.
|
330
|
+
*/
|
331
|
+
const useMulticastSubscription = upstream => {
|
332
|
+
const subscribe = react.useMemo(() => createMulticastSubscription(upstream), [upstream]);
|
333
|
+
return subscribe;
|
334
|
+
};
|
335
|
+
const createMulticastSubscription = upstream => {
|
336
|
+
// Create an upstream observable using the provided function.
|
337
|
+
const upstreamObservable = new rxjs.Observable(subscriber => {
|
338
|
+
const unsubscribe = upstream(val => subscriber.next(val));
|
109
339
|
return () => {
|
110
|
-
|
340
|
+
typeof unsubscribe === "function" && unsubscribe();
|
111
341
|
};
|
112
|
-
}
|
113
|
-
|
114
|
-
|
342
|
+
});
|
343
|
+
|
344
|
+
// Create a multicast observable from the upstream observable, using the shareReplay operator.
|
345
|
+
const multicastObservable = rxjs.defer(() => upstreamObservable).pipe(rxjs.shareReplay({
|
346
|
+
bufferSize: 1,
|
347
|
+
refCount: true
|
348
|
+
}));
|
349
|
+
|
350
|
+
// Create a subscription function that subscribes to the multicast observable and returns an unsubscribe function.
|
351
|
+
const subscribe = callback => {
|
352
|
+
const subscription = multicastObservable.subscribe(callback);
|
353
|
+
const unsubscribe = () => subscription.unsubscribe();
|
354
|
+
return unsubscribe;
|
355
|
+
};
|
356
|
+
return subscribe;
|
357
|
+
};
|
358
|
+
|
359
|
+
const useWithTestnetsProvider = ({
|
360
|
+
withTestnets
|
361
|
+
}) => {
|
362
|
+
return {
|
363
|
+
withTestnets
|
364
|
+
};
|
365
|
+
};
|
366
|
+
const [WithTestnetsProvider, useWithTestnets] = provideContext(useWithTestnetsProvider);
|
367
|
+
|
368
|
+
/**
|
369
|
+
* This hook is responsible for fetching the data used for balances and inserting it into the db.
|
370
|
+
*/
|
371
|
+
const useDbCacheSubscription = subscribeTo => {
|
372
|
+
const provider = useChaindata();
|
373
|
+
|
374
|
+
// can't handle balances & tokenRates here as they have other dependencies, it would trigger to many subscriptions
|
375
|
+
const subscribe = react.useCallback(() => {
|
376
|
+
switch (subscribeTo) {
|
377
|
+
case "chains":
|
378
|
+
return subscribeChainDataHydrate(provider, "chains");
|
379
|
+
case "evmNetworks":
|
380
|
+
return subscribeChainDataHydrate(provider, "evmNetworks");
|
381
|
+
case "tokens":
|
382
|
+
return subscribeChainDataHydrate(provider, "tokens");
|
383
|
+
}
|
384
|
+
}, [provider, subscribeTo]);
|
385
|
+
useSharedSubscription(subscribeTo, subscribe);
|
386
|
+
};
|
387
|
+
|
388
|
+
/**
|
389
|
+
* This hook is responsible for fetching the data used for token rates and inserting it into the db.
|
390
|
+
*/
|
391
|
+
function useDbCacheTokenRatesSubscription() {
|
392
|
+
const {
|
393
|
+
withTestnets
|
394
|
+
} = useWithTestnets();
|
395
|
+
const tokens = useTokens$1(withTestnets);
|
396
|
+
const subscriptionKey = react.useMemo(
|
397
|
+
// not super sexy but we need key to change based on this stuff
|
398
|
+
() => {
|
399
|
+
const key = Object.values(tokens ?? {}).map(({
|
400
|
+
id
|
401
|
+
}) => id).sort().join();
|
402
|
+
return `tokenRates-${md5__default["default"](key)}`;
|
403
|
+
}, [tokens]);
|
404
|
+
const subscription = react.useCallback(() => {
|
405
|
+
if (!Object.values(tokens ?? {}).length) return () => {};
|
406
|
+
return subscribeTokenRates(tokens);
|
407
|
+
}, [tokens]);
|
408
|
+
useSharedSubscription(subscriptionKey, subscription);
|
115
409
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
410
|
+
|
411
|
+
/**
|
412
|
+
* This hook is responsible for fetching the data used for balances and inserting it into the db.
|
413
|
+
*/
|
414
|
+
function useDbCacheBalancesSubscription() {
|
415
|
+
const {
|
416
|
+
withTestnets
|
417
|
+
} = useWithTestnets();
|
418
|
+
const balanceModules = useBalanceModules();
|
419
|
+
const chaindataProvider = useChaindata();
|
420
|
+
const chainConnectors = useChainConnectors();
|
421
|
+
const [allAddresses] = useAllAddresses();
|
422
|
+
const tokens = useTokens$1(withTestnets);
|
423
|
+
const subscriptionKey = react.useMemo(
|
424
|
+
// not super sexy but we need key to change based on this stuff
|
425
|
+
() => {
|
426
|
+
const key = allAddresses.sort().join().concat(...Object.values(tokens ?? {}).map(({
|
427
|
+
id
|
428
|
+
}) => id).sort()).concat(`evm:${!!chainConnectors.evm}`, `sub:${!!chainConnectors.substrate}`, ...balanceModules.map(m => m.type).sort(), `cd:${!!chaindataProvider}`);
|
429
|
+
return `balances-${md5__default["default"](key)}`;
|
430
|
+
}, [allAddresses, balanceModules, chainConnectors, chaindataProvider, tokens]);
|
431
|
+
const subscription = react.useCallback(() => {
|
432
|
+
if (!Object.values(tokens ?? {}).length || !allAddresses.length) return () => {};
|
433
|
+
return subscribeBalances(tokens ?? {}, allAddresses, balanceModules);
|
434
|
+
}, [allAddresses, balanceModules, tokens]);
|
435
|
+
useSharedSubscription(subscriptionKey, subscription);
|
436
|
+
}
|
437
|
+
|
438
|
+
// subscriptionless version of useTokens, prevents circular dependency
|
439
|
+
const useTokens$1 = withTestnets => {
|
440
|
+
const {
|
441
|
+
tokensWithTestnetsMap,
|
442
|
+
tokensWithoutTestnetsMap
|
443
|
+
} = useDbCache();
|
444
|
+
return withTestnets ? tokensWithTestnetsMap : tokensWithoutTestnetsMap;
|
445
|
+
};
|
446
|
+
const subscribeChainDataHydrate = (provider, type) => {
|
447
|
+
const chaindata = provider;
|
448
|
+
const delay = 300_000; // 300_000ms = 300s = 5 minutes
|
449
|
+
|
450
|
+
let timeout = null;
|
451
|
+
const hydrate = async () => {
|
452
|
+
try {
|
453
|
+
if (type === "chains") await chaindata.hydrateChains();
|
454
|
+
if (type === "evmNetworks") await chaindata.hydrateEvmNetworks();
|
455
|
+
if (type === "tokens") await chaindata.hydrateTokens();
|
456
|
+
timeout = setTimeout(hydrate, delay);
|
457
|
+
} catch (error) {
|
458
|
+
const retryTimeout = 5_000; // 5_000ms = 5 seconds
|
459
|
+
log.error(`Failed to fetch chaindata, retrying in ${Math.round(retryTimeout / 1000)} seconds`, error);
|
460
|
+
timeout = setTimeout(hydrate, retryTimeout);
|
461
|
+
}
|
462
|
+
};
|
463
|
+
|
464
|
+
// launch the loop
|
465
|
+
hydrate();
|
466
|
+
return () => {
|
467
|
+
if (timeout) clearTimeout(timeout);
|
468
|
+
};
|
469
|
+
};
|
470
|
+
const subscribeTokenRates = tokens => {
|
471
|
+
const REFRESH_INTERVAL = 300_000; // 6 minutes
|
472
|
+
const RETRY_INTERVAL = 5_000; // 5 sec
|
473
|
+
|
474
|
+
let timeout = null;
|
475
|
+
const refreshTokenRates = async () => {
|
476
|
+
try {
|
477
|
+
if (timeout) clearTimeout(timeout);
|
478
|
+
const tokenRates$1 = await tokenRates.fetchTokenRates(tokens);
|
479
|
+
const putTokenRates = Object.entries(tokenRates$1).map(([tokenId, rates]) => ({
|
480
|
+
tokenId,
|
481
|
+
rates
|
482
|
+
}));
|
483
|
+
tokenRates.db.transaction("rw", tokenRates.db.tokenRates, async () => await tokenRates.db.tokenRates.bulkPut(putTokenRates));
|
484
|
+
timeout = setTimeout(() => {
|
485
|
+
refreshTokenRates();
|
486
|
+
}, REFRESH_INTERVAL);
|
487
|
+
} catch (error) {
|
488
|
+
log.error(`Failed to fetch tokenRates, retrying in ${Math.round(RETRY_INTERVAL / 1000)} seconds`, error);
|
489
|
+
setTimeout(async () => {
|
490
|
+
refreshTokenRates();
|
491
|
+
}, RETRY_INTERVAL);
|
492
|
+
}
|
493
|
+
};
|
494
|
+
|
495
|
+
// launch the loop
|
496
|
+
refreshTokenRates();
|
497
|
+
return () => {
|
498
|
+
if (timeout) clearTimeout(timeout);
|
499
|
+
};
|
500
|
+
};
|
501
|
+
const subscribeBalances = (tokens, addresses, balanceModules) => {
|
502
|
+
const tokenIds = Object.values(tokens).map(({
|
503
|
+
id
|
504
|
+
}) => id);
|
505
|
+
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
506
|
+
const updateDb = balances$1 => {
|
507
|
+
const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
|
508
|
+
id,
|
509
|
+
...balance
|
510
|
+
}));
|
511
|
+
balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.bulkPut(putBalances));
|
512
|
+
};
|
513
|
+
let unsubscribed = false;
|
514
|
+
|
515
|
+
// eslint-disable-next-line no-console
|
516
|
+
log.log("subscribing to balance changes for %d tokens and %d addresses", tokenIds.length, addresses.length);
|
517
|
+
const unsubs = balanceModules.map(async balanceModule => {
|
518
|
+
// filter out tokens to only include those which this module knows how to fetch balances for
|
519
|
+
const moduleTokenIds = Object.values(tokens ?? {}).filter(({
|
520
|
+
type
|
521
|
+
}) => type === balanceModule.type).map(({
|
522
|
+
id
|
523
|
+
}) => id);
|
524
|
+
const addressesByModuleToken = Object.fromEntries(Object.entries(addressesByToken).filter(([tokenId]) => moduleTokenIds.includes(tokenId)));
|
525
|
+
const unsub = balances.balances(balanceModule, addressesByModuleToken, (error, balances$1) => {
|
526
|
+
// log errors
|
527
|
+
if (error) {
|
528
|
+
if (error?.type === "STALE_RPC_ERROR") return balances.db.balances.where({
|
529
|
+
source: balanceModule.type,
|
530
|
+
chainId: error.chainId
|
531
|
+
}).filter(balance => {
|
532
|
+
if (!Object.keys(addressesByModuleToken).includes(balance.tokenId)) return false;
|
533
|
+
if (!addressesByModuleToken[balance.tokenId].includes(balance.address)) return false;
|
534
|
+
return true;
|
535
|
+
}).modify({
|
536
|
+
status: "stale"
|
537
|
+
});
|
538
|
+
return log.error(`Failed to fetch ${balanceModule.type} balances`, error);
|
539
|
+
}
|
540
|
+
// ignore empty balance responses
|
541
|
+
if (!balances$1) return;
|
542
|
+
// ignore balances from old subscriptions which are still in the process of unsubscribing
|
543
|
+
if (unsubscribed) return;
|
544
|
+
updateDb(balances$1);
|
124
545
|
});
|
125
|
-
|
126
|
-
|
546
|
+
return () => {
|
547
|
+
// wait 2 seconds before actually unsubscribing, allowing for websocket to be reused
|
548
|
+
unsub.then(unsubscribe => {
|
549
|
+
setTimeout(unsubscribe, 2_000);
|
550
|
+
});
|
551
|
+
balances.db.balances.where({
|
552
|
+
source: balanceModule.type
|
553
|
+
}).filter(balance => {
|
554
|
+
if (!Object.keys(addressesByModuleToken).includes(balance.tokenId)) return false;
|
555
|
+
if (!addressesByModuleToken[balance.tokenId].includes(balance.address)) return false;
|
556
|
+
return true;
|
557
|
+
}).modify({
|
558
|
+
status: "cache"
|
559
|
+
});
|
560
|
+
};
|
561
|
+
});
|
562
|
+
const unsubscribeAll = () => {
|
563
|
+
unsubscribed = true;
|
564
|
+
unsubs.forEach(unsub => unsub.then(unsubscribe => unsubscribe()));
|
565
|
+
};
|
566
|
+
return unsubscribeAll;
|
567
|
+
};
|
568
|
+
|
569
|
+
function useChains(withTestnets) {
|
570
|
+
// keep db data up to date
|
571
|
+
useDbCacheSubscription("chains");
|
572
|
+
const {
|
573
|
+
chainsWithTestnetsMap,
|
574
|
+
chainsWithoutTestnetsMap
|
575
|
+
} = useDbCache();
|
576
|
+
return withTestnets ? chainsWithTestnetsMap : chainsWithoutTestnetsMap;
|
127
577
|
}
|
128
|
-
function useChain(
|
129
|
-
const
|
130
|
-
|
131
|
-
if (chaindata === null) return;
|
132
|
-
if (!chainId) return;
|
133
|
-
chaindata.getChain(chainId).then(setChain);
|
134
|
-
}, [chainId, chaindata, chaindata?.generation]);
|
135
|
-
return chain;
|
578
|
+
function useChain(chainId, withTestnets) {
|
579
|
+
const chains = useChains(withTestnets);
|
580
|
+
return chainId ? chains[chainId] : undefined;
|
136
581
|
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
}, [chaindata, chaindata?.generation]);
|
147
|
-
return evmNetworks || {};
|
582
|
+
|
583
|
+
function useEvmNetworks(withTestnets) {
|
584
|
+
// keep db data up to date
|
585
|
+
useDbCacheSubscription("evmNetworks");
|
586
|
+
const {
|
587
|
+
evmNetworksWithTestnetsMap,
|
588
|
+
evmNetworksWithoutTestnetsMap
|
589
|
+
} = useDbCache();
|
590
|
+
return withTestnets ? evmNetworksWithTestnetsMap : evmNetworksWithoutTestnetsMap;
|
148
591
|
}
|
149
|
-
function useEvmNetwork(
|
150
|
-
const
|
151
|
-
|
152
|
-
if (chaindata === null) return;
|
153
|
-
if (!evmNetworkId) return;
|
154
|
-
chaindata.getEvmNetwork(evmNetworkId).then(setEvmNetwork);
|
155
|
-
}, [chaindata, chaindata?.generation, evmNetworkId]);
|
156
|
-
return evmNetwork;
|
592
|
+
function useEvmNetwork(evmNetworkId, withTestnets) {
|
593
|
+
const evmNetworks = useEvmNetworks(withTestnets);
|
594
|
+
return evmNetworkId ? evmNetworks[evmNetworkId] : undefined;
|
157
595
|
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
});
|
167
|
-
}, [chaindata, chaindata?.generation]);
|
168
|
-
return tokens || {};
|
596
|
+
|
597
|
+
function useTokenRates() {
|
598
|
+
// keep db data up to date
|
599
|
+
useDbCacheTokenRatesSubscription();
|
600
|
+
const {
|
601
|
+
tokenRatesMap
|
602
|
+
} = useDbCache();
|
603
|
+
return tokenRatesMap;
|
169
604
|
}
|
170
|
-
function
|
171
|
-
const
|
172
|
-
|
173
|
-
if (chaindata === null) return;
|
174
|
-
if (!tokenId) return;
|
175
|
-
chaindata.getToken(tokenId).then(setToken);
|
176
|
-
}, [chaindata, chaindata?.generation, tokenId]);
|
177
|
-
return token;
|
605
|
+
function useTokenRate(tokenId) {
|
606
|
+
const tokenRates = useTokenRates();
|
607
|
+
return tokenId ? tokenRates[tokenId] : undefined;
|
178
608
|
}
|
179
609
|
|
180
|
-
function
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
// otherwise we risk replacing the most recent data with older data
|
189
|
-
generation.current = (generation.current + 1) % Number.MAX_SAFE_INTEGER;
|
190
|
-
const thisGeneration = generation.current;
|
191
|
-
tokenRates.fetchTokenRates(tokens).then(tokenRates => {
|
192
|
-
if (thisGeneration !== generation.current) return;
|
193
|
-
setTokenRates(tokenRates);
|
194
|
-
});
|
195
|
-
}, [tokens]);
|
196
|
-
return tokenRates$1 || {};
|
610
|
+
function useTokens(withTestnets) {
|
611
|
+
// keep db data up to date
|
612
|
+
useDbCacheSubscription("tokens");
|
613
|
+
const {
|
614
|
+
tokensWithTestnetsMap,
|
615
|
+
tokensWithoutTestnetsMap
|
616
|
+
} = useDbCache();
|
617
|
+
return withTestnets ? tokensWithTestnetsMap : tokensWithoutTestnetsMap;
|
197
618
|
}
|
619
|
+
function useToken(tokenId, withTestnets) {
|
620
|
+
const tokens = useTokens(withTestnets);
|
621
|
+
return tokenId ? tokens[tokenId] : undefined;
|
622
|
+
}
|
623
|
+
|
624
|
+
const useBalancesHydrate = () => {
|
625
|
+
const {
|
626
|
+
withTestnets
|
627
|
+
} = useWithTestnets();
|
628
|
+
const chains = useChains(withTestnets);
|
629
|
+
const evmNetworks = useEvmNetworks(withTestnets);
|
630
|
+
const tokens = useTokens(withTestnets);
|
631
|
+
const tokenRates = useTokenRates();
|
632
|
+
return react.useMemo(() => ({
|
633
|
+
chains,
|
634
|
+
evmNetworks,
|
635
|
+
tokens,
|
636
|
+
tokenRates
|
637
|
+
}), [chains, evmNetworks, tokens, tokenRates]);
|
638
|
+
};
|
198
639
|
|
199
|
-
|
200
|
-
//
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
// TODO: Make this array of BalanceModules more type-safe
|
209
|
-
balanceModules, chaindataProvider, addressesByToken, options = {}) {
|
210
|
-
useBalancesSubscriptions(balanceModules, chaindataProvider, addressesByToken, options);
|
211
|
-
const chains = useChains(chaindataProvider);
|
212
|
-
const evmNetworks = useEvmNetworks(chaindataProvider);
|
213
|
-
const tokens = useTokens(chaindataProvider);
|
214
|
-
const tokenRates = useTokenRates(tokens);
|
215
|
-
const balances$1 = dexieReactHooks.useLiveQuery(async () => new balances.Balances(await balances.db.balances.filter(balance => {
|
640
|
+
function useBalances(addressesByToken) {
|
641
|
+
// keep db data up to date
|
642
|
+
useDbCacheBalancesSubscription();
|
643
|
+
const balanceModules = useBalanceModules();
|
644
|
+
const {
|
645
|
+
balances: balances$1
|
646
|
+
} = useDbCache();
|
647
|
+
const hydrate = useBalancesHydrate();
|
648
|
+
return react.useMemo(() => new balances.Balances(balances$1.filter(balance => {
|
216
649
|
// check that this balance is included in our queried balance modules
|
217
650
|
if (!balanceModules.map(({
|
218
651
|
type
|
@@ -229,144 +662,91 @@ balanceModules, chaindataProvider, addressesByToken, options = {}) {
|
|
229
662
|
|
230
663
|
// keep this balance
|
231
664
|
return true;
|
232
|
-
})
|
665
|
+
}),
|
233
666
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
234
|
-
|
235
|
-
chains,
|
236
|
-
evmNetworks,
|
237
|
-
tokens,
|
238
|
-
tokenRates
|
239
|
-
}), [balanceModules, addressesByToken, chains, evmNetworks, tokens, tokenRates]);
|
240
|
-
|
241
|
-
// debounce every 100ms to prevent hammering UI with updates
|
242
|
-
const [debouncedBalances, setDebouncedBalances] = react.useState(balances$1);
|
243
|
-
reactUse.useDebounce(() => balances$1 && setDebouncedBalances(balances$1), 100, [balances$1]);
|
244
|
-
return debouncedBalances;
|
667
|
+
hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
|
245
668
|
}
|
246
669
|
|
247
|
-
|
248
|
-
|
670
|
+
/**
|
671
|
+
* Given a collection of `Balances`, this hook returns a `BalancesStatus` summary for the collection.
|
672
|
+
*
|
673
|
+
* @param balances The collection of balances to get the status from.
|
674
|
+
* @param isLoadingLocks Because the wallet currently fetches locks outside of the balances api, this param can be used to indicate that the locks are still loading, even if the `Balances` collection is not.
|
675
|
+
* @returns An instance of `BalancesStatus` which represents the status of the balances collection.
|
249
676
|
|
250
|
-
|
251
|
-
|
252
|
-
//
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
// >({})
|
259
|
-
|
260
|
-
const addSubscription = (key, balanceModule, chainConnectors, chaindataProvider, addressesByToken) => {
|
261
|
-
// create subscription if it doesn't already exist
|
262
|
-
if (!subscriptions[key] || subscriptions[key].refcount === 0) {
|
263
|
-
const generation = ((subscriptions[key]?.generation || 0) + 1) % Number.MAX_SAFE_INTEGER;
|
264
|
-
const unsub = balances.balances(balanceModule, chainConnectors, chaindataProvider, addressesByToken, (error, balances$1) => {
|
265
|
-
if (error) return log.error(`Failed to fetch ${balanceModule.type} balances`, error);
|
266
|
-
if (!balances$1) return;
|
267
|
-
|
268
|
-
// ignore balances from old subscriptions which are still in the process of unsubscribing
|
269
|
-
if (subscriptions[key].generation !== generation) return;
|
270
|
-
const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
|
271
|
-
id,
|
272
|
-
...balance
|
273
|
-
}));
|
274
|
-
balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.bulkPut(putBalances));
|
275
|
-
});
|
276
|
-
subscriptions[key] = {
|
277
|
-
unsub,
|
278
|
-
refcount: 0,
|
279
|
-
generation
|
280
|
-
};
|
281
|
-
}
|
677
|
+
*/
|
678
|
+
const useBalancesStatus = (balances, isLoadingLocks) => react.useMemo(() => {
|
679
|
+
// stale
|
680
|
+
const staleChains = getStaleChains(balances);
|
681
|
+
if (staleChains.length > 0) return {
|
682
|
+
status: "stale",
|
683
|
+
staleChains
|
684
|
+
};
|
282
685
|
|
283
|
-
|
284
|
-
|
686
|
+
// fetching
|
687
|
+
const hasCachedBalances = balances.each.some(b => b.status === "cache");
|
688
|
+
if (hasCachedBalances || isLoadingLocks) return {
|
689
|
+
status: "fetching"
|
285
690
|
};
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
// drop the refcount by one
|
291
|
-
subscriptions[key].refcount -= 1;
|
292
|
-
|
293
|
-
// unsubscribe if refcount is now 0 (nobody wants this subcription anymore)
|
294
|
-
if (subscriptions[key].refcount < 1) {
|
295
|
-
// remove subscription
|
296
|
-
subscriptions[key].unsub.then(unsub => unsub());
|
297
|
-
delete subscriptions[key];
|
298
|
-
|
299
|
-
// set this subscription's balances in the store to status: cache
|
300
|
-
balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.filter(balance => {
|
301
|
-
if (balance.source !== balanceModule.type) return false;
|
302
|
-
if (!Object.keys(addressesByToken).includes(balance.tokenId)) return false;
|
303
|
-
if (!addressesByToken[balance.tokenId].includes(balance.address)) return false;
|
304
|
-
return true;
|
305
|
-
}).modify({
|
306
|
-
status: "cache"
|
307
|
-
}));
|
308
|
-
}
|
691
|
+
|
692
|
+
// live
|
693
|
+
return {
|
694
|
+
status: "live"
|
309
695
|
};
|
310
|
-
|
311
|
-
|
312
|
-
const tokens = useTokens(chaindataProvider);
|
313
|
-
react.useEffect(() => {
|
314
|
-
if (chainConnector === null) return;
|
315
|
-
if (chainConnectorEvm === null) return;
|
316
|
-
if (chaindataProvider === null) return;
|
317
|
-
if (addressesByToken === null) return;
|
318
|
-
const unsubs = balanceModules.map(balanceModule => {
|
319
|
-
const subscriptionKey = `${balanceModule.type}-${JSON.stringify(addressesByToken)}`;
|
320
|
-
|
321
|
-
// filter out tokens to only include those which this module knows how to fetch balances for
|
322
|
-
const moduleTokenIds = Object.values(tokens).filter(({
|
323
|
-
type
|
324
|
-
}) => type === balanceModule.type).map(({
|
325
|
-
id
|
326
|
-
}) => id);
|
327
|
-
const addressesByModuleToken = Object.fromEntries(Object.entries(addressesByToken).filter(([tokenId]) => moduleTokenIds.includes(tokenId)));
|
328
|
-
|
329
|
-
// add balance subscription for this module
|
330
|
-
addSubscription(subscriptionKey, balanceModule, {
|
331
|
-
substrate: chainConnector,
|
332
|
-
evm: chainConnectorEvm
|
333
|
-
}, chaindataProvider, addressesByModuleToken);
|
334
|
-
|
335
|
-
// return an unsub method, to be called when this effect unmounts
|
336
|
-
return () => removeSubscription(subscriptionKey, balanceModule, addressesByToken);
|
337
|
-
});
|
338
|
-
const unsubAll = () => unsubs.forEach(unsub => unsub());
|
339
|
-
return unsubAll;
|
340
|
-
}, [addressesByToken, balanceModules, chainConnector, chainConnectorEvm, chaindataProvider, tokens]);
|
341
|
-
}
|
696
|
+
}, [balances, isLoadingLocks]);
|
697
|
+
const getStaleChains = balances => [...new Set(balances.sorted.filter(b => b.status === "stale").map(b => b.chain?.name ?? b.chainId ?? "Unknown"))];
|
342
698
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
}
|
699
|
+
const BalancesProvider = ({
|
700
|
+
balanceModules,
|
701
|
+
onfinalityApiKey,
|
702
|
+
withTestnets,
|
703
|
+
children
|
704
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(WithTestnetsProvider, {
|
705
|
+
withTestnets: withTestnets,
|
706
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ChaindataProvider, {
|
707
|
+
onfinalityApiKey: onfinalityApiKey,
|
708
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ChainConnectorsProvider, {
|
709
|
+
onfinalityApiKey: onfinalityApiKey,
|
710
|
+
children: /*#__PURE__*/jsxRuntime.jsx(AllAddressesProvider, {
|
711
|
+
children: /*#__PURE__*/jsxRuntime.jsx(BalanceModulesProvider, {
|
712
|
+
balanceModules: balanceModules,
|
713
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DbCacheProvider, {
|
714
|
+
children: children
|
715
|
+
})
|
716
|
+
})
|
717
|
+
})
|
718
|
+
})
|
719
|
+
})
|
720
|
+
});
|
363
721
|
|
722
|
+
exports.AllAddressesProvider = AllAddressesProvider;
|
723
|
+
exports.BalanceModulesProvider = BalanceModulesProvider;
|
724
|
+
exports.BalancesProvider = BalancesProvider;
|
725
|
+
exports.ChainConnectorsProvider = ChainConnectorsProvider;
|
726
|
+
exports.ChaindataProvider = ChaindataProvider;
|
727
|
+
exports.DbCacheProvider = DbCacheProvider;
|
728
|
+
exports.WithTestnetsProvider = WithTestnetsProvider;
|
729
|
+
exports.createMulticastSubscription = createMulticastSubscription;
|
730
|
+
exports.getStaleChains = getStaleChains;
|
731
|
+
exports.provideContext = provideContext;
|
732
|
+
exports.useAllAddresses = useAllAddresses;
|
733
|
+
exports.useBalanceModules = useBalanceModules;
|
364
734
|
exports.useBalances = useBalances;
|
735
|
+
exports.useBalancesHydrate = useBalancesHydrate;
|
736
|
+
exports.useBalancesStatus = useBalancesStatus;
|
365
737
|
exports.useChain = useChain;
|
738
|
+
exports.useChainConnectors = useChainConnectors;
|
366
739
|
exports.useChaindata = useChaindata;
|
367
740
|
exports.useChains = useChains;
|
741
|
+
exports.useDbCache = useDbCache;
|
742
|
+
exports.useDbCacheBalancesSubscription = useDbCacheBalancesSubscription;
|
743
|
+
exports.useDbCacheSubscription = useDbCacheSubscription;
|
744
|
+
exports.useDbCacheTokenRatesSubscription = useDbCacheTokenRatesSubscription;
|
368
745
|
exports.useEvmNetwork = useEvmNetwork;
|
369
746
|
exports.useEvmNetworks = useEvmNetworks;
|
747
|
+
exports.useMulticastSubscription = useMulticastSubscription;
|
370
748
|
exports.useToken = useToken;
|
749
|
+
exports.useTokenRate = useTokenRate;
|
371
750
|
exports.useTokenRates = useTokenRates;
|
372
751
|
exports.useTokens = useTokens;
|
752
|
+
exports.useWithTestnets = useWithTestnets;
|