@talismn/balances-react 0.6.0 → 0.6.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/CHANGELOG.md +39 -0
- package/dist/declarations/src/hooks/index.d.ts +27 -1
- package/dist/declarations/src/hooks/useBalances.d.ts +2 -2
- package/dist/declarations/src/hooks/useBalancesHydrate.d.ts +0 -1
- package/dist/declarations/src/hooks/useBalancesStatus.d.ts +0 -1
- package/dist/declarations/src/hooks/useEnabledChains.d.ts +8 -0
- package/dist/talismn-balances-react.cjs.dev.js +55 -16
- package/dist/talismn-balances-react.cjs.prod.js +55 -16
- package/dist/talismn-balances-react.esm.js +55 -16
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# @talismn/balances-react
|
2
2
|
|
3
|
+
## 0.6.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 8f8de17: fix: typing
|
8
|
+
- 2439876: fix: remove old tokenRates for tokens which have no coingeckoId anymore
|
9
|
+
- 620b7eb: Dependency updates
|
10
|
+
- c0b25f2: feat: add enableChains prop to BalancesProvider
|
11
|
+
- Updated dependencies [771a5be]
|
12
|
+
- Updated dependencies [123647e]
|
13
|
+
- Updated dependencies [03939d5]
|
14
|
+
- Updated dependencies [d2ccdaf]
|
15
|
+
- Updated dependencies [123647e]
|
16
|
+
- Updated dependencies [be0d19e]
|
17
|
+
- Updated dependencies [e0eb84a]
|
18
|
+
- Updated dependencies [ade2908]
|
19
|
+
- Updated dependencies [372f995]
|
20
|
+
- Updated dependencies [c4d5967]
|
21
|
+
- Updated dependencies [a916db0]
|
22
|
+
- Updated dependencies [776432e]
|
23
|
+
- Updated dependencies [a3a1bd7]
|
24
|
+
- Updated dependencies [c36375f]
|
25
|
+
- Updated dependencies [23f0d3a]
|
26
|
+
- Updated dependencies [e0eb84a]
|
27
|
+
- Updated dependencies [620b7eb]
|
28
|
+
- Updated dependencies [850381a]
|
29
|
+
- Updated dependencies [5aadf99]
|
30
|
+
- Updated dependencies [5aadf99]
|
31
|
+
- Updated dependencies [4cace80]
|
32
|
+
- Updated dependencies [372f995]
|
33
|
+
- Updated dependencies [9ebcd93]
|
34
|
+
- @talismn/balances@0.6.1
|
35
|
+
- @talismn/token-rates@0.3.0
|
36
|
+
- @talismn/chaindata-provider@0.8.0
|
37
|
+
- @talismn/chaindata-provider-extension@0.8.0
|
38
|
+
- @talismn/chain-connector-evm@0.8.0
|
39
|
+
- @talismn/chain-connector@0.8.0
|
40
|
+
- @talismn/connection-meta@0.1.1
|
41
|
+
|
3
42
|
## 0.6.0
|
4
43
|
|
5
44
|
### Minor Changes
|
@@ -18,6 +18,32 @@ export type BalancesProviderProps = {
|
|
18
18
|
balanceModules: Array<(hydrate: Hydrate) => AnyBalanceModule>;
|
19
19
|
onfinalityApiKey?: string;
|
20
20
|
withTestnets?: boolean;
|
21
|
+
/**
|
22
|
+
* A list of chain genesisHashes to fetch balances for.
|
23
|
+
*
|
24
|
+
* If undefined, balances will be fetched for all chains.
|
25
|
+
*
|
26
|
+
* Only applies to built-in chains, custom chains will always fetch balances.
|
27
|
+
*
|
28
|
+
* NOTE: This is an allowlist to enable the dapp to disable balances for chains it does not care about.
|
29
|
+
* Adding a chain here which is not already supported by the library will not automagically begin to fetch balances.
|
30
|
+
* It will just be ignored.
|
31
|
+
*
|
32
|
+
* In a similar vein, if you add testnets here then make sure you've also set the `withTestnets` prop to `true`.
|
33
|
+
*
|
34
|
+
* @example
|
35
|
+
* enabledChains={[
|
36
|
+
* // polkadot
|
37
|
+
* "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
|
38
|
+
* // kusama
|
39
|
+
* "0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe",
|
40
|
+
* // rococo
|
41
|
+
* "0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e",
|
42
|
+
* // westend
|
43
|
+
* "0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e",
|
44
|
+
* ]}
|
45
|
+
*/
|
46
|
+
enabledChains?: string[];
|
21
47
|
children?: ReactNode;
|
22
48
|
};
|
23
|
-
export declare const BalancesProvider: ({ balanceModules, onfinalityApiKey, withTestnets, children, }: BalancesProviderProps) => JSX.Element;
|
49
|
+
export declare const BalancesProvider: ({ balanceModules, onfinalityApiKey, withTestnets, enabledChains, children, }: BalancesProviderProps) => JSX.Element;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { AddressesByToken
|
1
|
+
import { AddressesByToken } from "@talismn/balances";
|
2
2
|
import { Token } from "@talismn/chaindata-provider";
|
3
|
-
export declare function useBalances(addressesByToken: AddressesByToken<Token> | null):
|
3
|
+
export declare function useBalances(addressesByToken: AddressesByToken<Token> | null): any;
|
@@ -185,7 +185,7 @@ const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
185
185
|
|
186
186
|
var packageJson = {
|
187
187
|
name: "@talismn/balances-react",
|
188
|
-
version: "0.6.
|
188
|
+
version: "0.6.1",
|
189
189
|
author: "Talisman",
|
190
190
|
homepage: "https://talisman.xyz",
|
191
191
|
license: "GPL-3.0-or-later",
|
@@ -221,7 +221,7 @@ var packageJson = {
|
|
221
221
|
anylogger: "^1.0.11",
|
222
222
|
"blueimp-md5": "2.19.0",
|
223
223
|
dexie: "^3.2.4",
|
224
|
-
"dexie-react-hooks": "^1.1.
|
224
|
+
"dexie-react-hooks": "^1.1.7",
|
225
225
|
"react-use": "^17.4.0",
|
226
226
|
rxjs: "^7.8.1"
|
227
227
|
},
|
@@ -231,9 +231,9 @@ var packageJson = {
|
|
231
231
|
"@types/jest": "^27.5.1",
|
232
232
|
"@types/react": "^18.0.17",
|
233
233
|
eslint: "^8.4.0",
|
234
|
-
jest: "^
|
234
|
+
jest: "^29.7.0",
|
235
235
|
react: "^18.2.0",
|
236
|
-
"ts-jest": "^
|
236
|
+
"ts-jest": "^29.1.1",
|
237
237
|
typescript: "^4.6.4"
|
238
238
|
},
|
239
239
|
peerDependencies: {
|
@@ -341,6 +341,15 @@ const createMulticastSubscription = upstream => {
|
|
341
341
|
return subscribe;
|
342
342
|
};
|
343
343
|
|
344
|
+
const useEnabledChainsProvider = ({
|
345
|
+
enabledChains
|
346
|
+
}) => {
|
347
|
+
return {
|
348
|
+
enabledChains
|
349
|
+
};
|
350
|
+
};
|
351
|
+
const [EnabledChainsProvider, useEnabledChains] = provideContext(useEnabledChainsProvider);
|
352
|
+
|
344
353
|
const useWithTestnetsProvider = ({
|
345
354
|
withTestnets
|
346
355
|
}) => {
|
@@ -400,11 +409,21 @@ function useDbCacheBalancesSubscription() {
|
|
400
409
|
const {
|
401
410
|
withTestnets
|
402
411
|
} = useWithTestnets();
|
412
|
+
const {
|
413
|
+
enabledChains
|
414
|
+
} = useEnabledChains();
|
403
415
|
const balanceModules = useBalanceModules();
|
404
416
|
const chaindataProvider = useChaindata();
|
405
417
|
const chainConnectors = useChainConnectors();
|
406
418
|
const [allAddresses] = useAllAddresses();
|
407
|
-
const
|
419
|
+
const chains = useChains$1(withTestnets);
|
420
|
+
const allTokens = useTokens$1(withTestnets);
|
421
|
+
const tokens = react.useMemo(() => {
|
422
|
+
if (!enabledChains) return allTokens;
|
423
|
+
const chainsByGenesisHash = new Map(Object.values(chains).flatMap(chain => chain.genesisHash ? [[chain.genesisHash, chain.id]] : []));
|
424
|
+
const enabledChainIds = enabledChains.flatMap(genesisHash => chainsByGenesisHash.get(genesisHash) ?? []);
|
425
|
+
return Object.fromEntries(Object.entries(allTokens).flatMap(([id, token]) => token.chain && enabledChainIds.includes(token.chain.id) ? [[id, token]] : []));
|
426
|
+
}, [allTokens, chains, enabledChains]);
|
408
427
|
const subscriptionKey = react.useMemo(
|
409
428
|
// not super sexy but we need key to change based on this stuff
|
410
429
|
() => {
|
@@ -420,7 +439,14 @@ function useDbCacheBalancesSubscription() {
|
|
420
439
|
useSharedSubscription(subscriptionKey, subscription);
|
421
440
|
}
|
422
441
|
|
423
|
-
// subscriptionless version of useTokens, prevents circular dependency
|
442
|
+
// subscriptionless version of useChains and useTokens, prevents circular dependency
|
443
|
+
const useChains$1 = withTestnets => {
|
444
|
+
const {
|
445
|
+
chainsWithTestnetsMap,
|
446
|
+
chainsWithoutTestnetsMap
|
447
|
+
} = useDbCache();
|
448
|
+
return withTestnets ? chainsWithTestnetsMap : chainsWithoutTestnetsMap;
|
449
|
+
};
|
424
450
|
const useTokens$1 = withTestnets => {
|
425
451
|
const {
|
426
452
|
tokensWithTestnetsMap,
|
@@ -465,7 +491,16 @@ const subscribeTokenRates = tokens => {
|
|
465
491
|
tokenId,
|
466
492
|
rates
|
467
493
|
}));
|
468
|
-
tokenRates.db.transaction("rw", tokenRates.db.tokenRates, async () =>
|
494
|
+
await tokenRates.db.transaction("rw", tokenRates.db.tokenRates, async () => {
|
495
|
+
// override all tokenRates
|
496
|
+
await tokenRates.db.tokenRates.bulkPut(putTokenRates);
|
497
|
+
|
498
|
+
// delete tokenRates for tokens which no longer exist
|
499
|
+
const tokenIds = await tokenRates.db.tokenRates.toCollection().primaryKeys();
|
500
|
+
const validTokenIds = new Set(Object.keys(tokenRates$1));
|
501
|
+
const deleteTokenIds = tokenIds.filter(tokenId => !validTokenIds.has(tokenId));
|
502
|
+
if (deleteTokenIds.length > 0) await tokenRates.db.tokenRates.bulkDelete(deleteTokenIds);
|
503
|
+
});
|
469
504
|
timeout = setTimeout(() => {
|
470
505
|
refreshTokenRates();
|
471
506
|
}, REFRESH_INTERVAL);
|
@@ -637,7 +672,7 @@ function useBalances(addressesByToken) {
|
|
637
672
|
balances: balances$1
|
638
673
|
} = useDbCache();
|
639
674
|
const hydrate = useBalancesHydrate();
|
640
|
-
return react.useMemo(() => new balances.Balances(balances.deriveStatuses(
|
675
|
+
return react.useMemo(() => new balances.Balances(balances.deriveStatuses(balances.getValidSubscriptionIds(), balances$1.filter(balance => {
|
641
676
|
// check that this balance is included in our queried balance modules
|
642
677
|
if (!balanceModules.map(({
|
643
678
|
type
|
@@ -691,18 +726,22 @@ const BalancesProvider = ({
|
|
691
726
|
balanceModules,
|
692
727
|
onfinalityApiKey,
|
693
728
|
withTestnets,
|
729
|
+
enabledChains,
|
694
730
|
children
|
695
731
|
}) => /*#__PURE__*/jsxRuntime.jsx(WithTestnetsProvider, {
|
696
732
|
withTestnets: withTestnets,
|
697
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
698
|
-
|
699
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
733
|
+
children: /*#__PURE__*/jsxRuntime.jsx(EnabledChainsProvider, {
|
734
|
+
enabledChains: enabledChains,
|
735
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ChaindataProvider, {
|
700
736
|
onfinalityApiKey: onfinalityApiKey,
|
701
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
702
|
-
|
703
|
-
|
704
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
705
|
-
|
737
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ChainConnectorsProvider, {
|
738
|
+
onfinalityApiKey: onfinalityApiKey,
|
739
|
+
children: /*#__PURE__*/jsxRuntime.jsx(AllAddressesProvider, {
|
740
|
+
children: /*#__PURE__*/jsxRuntime.jsx(BalanceModulesProvider, {
|
741
|
+
balanceModules: balanceModules,
|
742
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DbCacheProvider, {
|
743
|
+
children: children
|
744
|
+
})
|
706
745
|
})
|
707
746
|
})
|
708
747
|
})
|
@@ -185,7 +185,7 @@ const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
185
185
|
|
186
186
|
var packageJson = {
|
187
187
|
name: "@talismn/balances-react",
|
188
|
-
version: "0.6.
|
188
|
+
version: "0.6.1",
|
189
189
|
author: "Talisman",
|
190
190
|
homepage: "https://talisman.xyz",
|
191
191
|
license: "GPL-3.0-or-later",
|
@@ -221,7 +221,7 @@ var packageJson = {
|
|
221
221
|
anylogger: "^1.0.11",
|
222
222
|
"blueimp-md5": "2.19.0",
|
223
223
|
dexie: "^3.2.4",
|
224
|
-
"dexie-react-hooks": "^1.1.
|
224
|
+
"dexie-react-hooks": "^1.1.7",
|
225
225
|
"react-use": "^17.4.0",
|
226
226
|
rxjs: "^7.8.1"
|
227
227
|
},
|
@@ -231,9 +231,9 @@ var packageJson = {
|
|
231
231
|
"@types/jest": "^27.5.1",
|
232
232
|
"@types/react": "^18.0.17",
|
233
233
|
eslint: "^8.4.0",
|
234
|
-
jest: "^
|
234
|
+
jest: "^29.7.0",
|
235
235
|
react: "^18.2.0",
|
236
|
-
"ts-jest": "^
|
236
|
+
"ts-jest": "^29.1.1",
|
237
237
|
typescript: "^4.6.4"
|
238
238
|
},
|
239
239
|
peerDependencies: {
|
@@ -341,6 +341,15 @@ const createMulticastSubscription = upstream => {
|
|
341
341
|
return subscribe;
|
342
342
|
};
|
343
343
|
|
344
|
+
const useEnabledChainsProvider = ({
|
345
|
+
enabledChains
|
346
|
+
}) => {
|
347
|
+
return {
|
348
|
+
enabledChains
|
349
|
+
};
|
350
|
+
};
|
351
|
+
const [EnabledChainsProvider, useEnabledChains] = provideContext(useEnabledChainsProvider);
|
352
|
+
|
344
353
|
const useWithTestnetsProvider = ({
|
345
354
|
withTestnets
|
346
355
|
}) => {
|
@@ -400,11 +409,21 @@ function useDbCacheBalancesSubscription() {
|
|
400
409
|
const {
|
401
410
|
withTestnets
|
402
411
|
} = useWithTestnets();
|
412
|
+
const {
|
413
|
+
enabledChains
|
414
|
+
} = useEnabledChains();
|
403
415
|
const balanceModules = useBalanceModules();
|
404
416
|
const chaindataProvider = useChaindata();
|
405
417
|
const chainConnectors = useChainConnectors();
|
406
418
|
const [allAddresses] = useAllAddresses();
|
407
|
-
const
|
419
|
+
const chains = useChains$1(withTestnets);
|
420
|
+
const allTokens = useTokens$1(withTestnets);
|
421
|
+
const tokens = react.useMemo(() => {
|
422
|
+
if (!enabledChains) return allTokens;
|
423
|
+
const chainsByGenesisHash = new Map(Object.values(chains).flatMap(chain => chain.genesisHash ? [[chain.genesisHash, chain.id]] : []));
|
424
|
+
const enabledChainIds = enabledChains.flatMap(genesisHash => chainsByGenesisHash.get(genesisHash) ?? []);
|
425
|
+
return Object.fromEntries(Object.entries(allTokens).flatMap(([id, token]) => token.chain && enabledChainIds.includes(token.chain.id) ? [[id, token]] : []));
|
426
|
+
}, [allTokens, chains, enabledChains]);
|
408
427
|
const subscriptionKey = react.useMemo(
|
409
428
|
// not super sexy but we need key to change based on this stuff
|
410
429
|
() => {
|
@@ -420,7 +439,14 @@ function useDbCacheBalancesSubscription() {
|
|
420
439
|
useSharedSubscription(subscriptionKey, subscription);
|
421
440
|
}
|
422
441
|
|
423
|
-
// subscriptionless version of useTokens, prevents circular dependency
|
442
|
+
// subscriptionless version of useChains and useTokens, prevents circular dependency
|
443
|
+
const useChains$1 = withTestnets => {
|
444
|
+
const {
|
445
|
+
chainsWithTestnetsMap,
|
446
|
+
chainsWithoutTestnetsMap
|
447
|
+
} = useDbCache();
|
448
|
+
return withTestnets ? chainsWithTestnetsMap : chainsWithoutTestnetsMap;
|
449
|
+
};
|
424
450
|
const useTokens$1 = withTestnets => {
|
425
451
|
const {
|
426
452
|
tokensWithTestnetsMap,
|
@@ -465,7 +491,16 @@ const subscribeTokenRates = tokens => {
|
|
465
491
|
tokenId,
|
466
492
|
rates
|
467
493
|
}));
|
468
|
-
tokenRates.db.transaction("rw", tokenRates.db.tokenRates, async () =>
|
494
|
+
await tokenRates.db.transaction("rw", tokenRates.db.tokenRates, async () => {
|
495
|
+
// override all tokenRates
|
496
|
+
await tokenRates.db.tokenRates.bulkPut(putTokenRates);
|
497
|
+
|
498
|
+
// delete tokenRates for tokens which no longer exist
|
499
|
+
const tokenIds = await tokenRates.db.tokenRates.toCollection().primaryKeys();
|
500
|
+
const validTokenIds = new Set(Object.keys(tokenRates$1));
|
501
|
+
const deleteTokenIds = tokenIds.filter(tokenId => !validTokenIds.has(tokenId));
|
502
|
+
if (deleteTokenIds.length > 0) await tokenRates.db.tokenRates.bulkDelete(deleteTokenIds);
|
503
|
+
});
|
469
504
|
timeout = setTimeout(() => {
|
470
505
|
refreshTokenRates();
|
471
506
|
}, REFRESH_INTERVAL);
|
@@ -637,7 +672,7 @@ function useBalances(addressesByToken) {
|
|
637
672
|
balances: balances$1
|
638
673
|
} = useDbCache();
|
639
674
|
const hydrate = useBalancesHydrate();
|
640
|
-
return react.useMemo(() => new balances.Balances(balances.deriveStatuses(
|
675
|
+
return react.useMemo(() => new balances.Balances(balances.deriveStatuses(balances.getValidSubscriptionIds(), balances$1.filter(balance => {
|
641
676
|
// check that this balance is included in our queried balance modules
|
642
677
|
if (!balanceModules.map(({
|
643
678
|
type
|
@@ -691,18 +726,22 @@ const BalancesProvider = ({
|
|
691
726
|
balanceModules,
|
692
727
|
onfinalityApiKey,
|
693
728
|
withTestnets,
|
729
|
+
enabledChains,
|
694
730
|
children
|
695
731
|
}) => /*#__PURE__*/jsxRuntime.jsx(WithTestnetsProvider, {
|
696
732
|
withTestnets: withTestnets,
|
697
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
698
|
-
|
699
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
733
|
+
children: /*#__PURE__*/jsxRuntime.jsx(EnabledChainsProvider, {
|
734
|
+
enabledChains: enabledChains,
|
735
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ChaindataProvider, {
|
700
736
|
onfinalityApiKey: onfinalityApiKey,
|
701
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
702
|
-
|
703
|
-
|
704
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
705
|
-
|
737
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ChainConnectorsProvider, {
|
738
|
+
onfinalityApiKey: onfinalityApiKey,
|
739
|
+
children: /*#__PURE__*/jsxRuntime.jsx(AllAddressesProvider, {
|
740
|
+
children: /*#__PURE__*/jsxRuntime.jsx(BalanceModulesProvider, {
|
741
|
+
balanceModules: balanceModules,
|
742
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DbCacheProvider, {
|
743
|
+
children: children
|
744
|
+
})
|
706
745
|
})
|
707
746
|
})
|
708
747
|
})
|
@@ -176,7 +176,7 @@ const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
176
176
|
|
177
177
|
var packageJson = {
|
178
178
|
name: "@talismn/balances-react",
|
179
|
-
version: "0.6.
|
179
|
+
version: "0.6.1",
|
180
180
|
author: "Talisman",
|
181
181
|
homepage: "https://talisman.xyz",
|
182
182
|
license: "GPL-3.0-or-later",
|
@@ -212,7 +212,7 @@ var packageJson = {
|
|
212
212
|
anylogger: "^1.0.11",
|
213
213
|
"blueimp-md5": "2.19.0",
|
214
214
|
dexie: "^3.2.4",
|
215
|
-
"dexie-react-hooks": "^1.1.
|
215
|
+
"dexie-react-hooks": "^1.1.7",
|
216
216
|
"react-use": "^17.4.0",
|
217
217
|
rxjs: "^7.8.1"
|
218
218
|
},
|
@@ -222,9 +222,9 @@ var packageJson = {
|
|
222
222
|
"@types/jest": "^27.5.1",
|
223
223
|
"@types/react": "^18.0.17",
|
224
224
|
eslint: "^8.4.0",
|
225
|
-
jest: "^
|
225
|
+
jest: "^29.7.0",
|
226
226
|
react: "^18.2.0",
|
227
|
-
"ts-jest": "^
|
227
|
+
"ts-jest": "^29.1.1",
|
228
228
|
typescript: "^4.6.4"
|
229
229
|
},
|
230
230
|
peerDependencies: {
|
@@ -332,6 +332,15 @@ const createMulticastSubscription = upstream => {
|
|
332
332
|
return subscribe;
|
333
333
|
};
|
334
334
|
|
335
|
+
const useEnabledChainsProvider = ({
|
336
|
+
enabledChains
|
337
|
+
}) => {
|
338
|
+
return {
|
339
|
+
enabledChains
|
340
|
+
};
|
341
|
+
};
|
342
|
+
const [EnabledChainsProvider, useEnabledChains] = provideContext(useEnabledChainsProvider);
|
343
|
+
|
335
344
|
const useWithTestnetsProvider = ({
|
336
345
|
withTestnets
|
337
346
|
}) => {
|
@@ -391,11 +400,21 @@ function useDbCacheBalancesSubscription() {
|
|
391
400
|
const {
|
392
401
|
withTestnets
|
393
402
|
} = useWithTestnets();
|
403
|
+
const {
|
404
|
+
enabledChains
|
405
|
+
} = useEnabledChains();
|
394
406
|
const balanceModules = useBalanceModules();
|
395
407
|
const chaindataProvider = useChaindata();
|
396
408
|
const chainConnectors = useChainConnectors();
|
397
409
|
const [allAddresses] = useAllAddresses();
|
398
|
-
const
|
410
|
+
const chains = useChains$1(withTestnets);
|
411
|
+
const allTokens = useTokens$1(withTestnets);
|
412
|
+
const tokens = useMemo(() => {
|
413
|
+
if (!enabledChains) return allTokens;
|
414
|
+
const chainsByGenesisHash = new Map(Object.values(chains).flatMap(chain => chain.genesisHash ? [[chain.genesisHash, chain.id]] : []));
|
415
|
+
const enabledChainIds = enabledChains.flatMap(genesisHash => chainsByGenesisHash.get(genesisHash) ?? []);
|
416
|
+
return Object.fromEntries(Object.entries(allTokens).flatMap(([id, token]) => token.chain && enabledChainIds.includes(token.chain.id) ? [[id, token]] : []));
|
417
|
+
}, [allTokens, chains, enabledChains]);
|
399
418
|
const subscriptionKey = useMemo(
|
400
419
|
// not super sexy but we need key to change based on this stuff
|
401
420
|
() => {
|
@@ -411,7 +430,14 @@ function useDbCacheBalancesSubscription() {
|
|
411
430
|
useSharedSubscription(subscriptionKey, subscription);
|
412
431
|
}
|
413
432
|
|
414
|
-
// subscriptionless version of useTokens, prevents circular dependency
|
433
|
+
// subscriptionless version of useChains and useTokens, prevents circular dependency
|
434
|
+
const useChains$1 = withTestnets => {
|
435
|
+
const {
|
436
|
+
chainsWithTestnetsMap,
|
437
|
+
chainsWithoutTestnetsMap
|
438
|
+
} = useDbCache();
|
439
|
+
return withTestnets ? chainsWithTestnetsMap : chainsWithoutTestnetsMap;
|
440
|
+
};
|
415
441
|
const useTokens$1 = withTestnets => {
|
416
442
|
const {
|
417
443
|
tokensWithTestnetsMap,
|
@@ -456,7 +482,16 @@ const subscribeTokenRates = tokens => {
|
|
456
482
|
tokenId,
|
457
483
|
rates
|
458
484
|
}));
|
459
|
-
db.transaction("rw", db.tokenRates, async () =>
|
485
|
+
await db.transaction("rw", db.tokenRates, async () => {
|
486
|
+
// override all tokenRates
|
487
|
+
await db.tokenRates.bulkPut(putTokenRates);
|
488
|
+
|
489
|
+
// delete tokenRates for tokens which no longer exist
|
490
|
+
const tokenIds = await db.tokenRates.toCollection().primaryKeys();
|
491
|
+
const validTokenIds = new Set(Object.keys(tokenRates));
|
492
|
+
const deleteTokenIds = tokenIds.filter(tokenId => !validTokenIds.has(tokenId));
|
493
|
+
if (deleteTokenIds.length > 0) await db.tokenRates.bulkDelete(deleteTokenIds);
|
494
|
+
});
|
460
495
|
timeout = setTimeout(() => {
|
461
496
|
refreshTokenRates();
|
462
497
|
}, REFRESH_INTERVAL);
|
@@ -628,7 +663,7 @@ function useBalances(addressesByToken) {
|
|
628
663
|
balances
|
629
664
|
} = useDbCache();
|
630
665
|
const hydrate = useBalancesHydrate();
|
631
|
-
return useMemo(() => new Balances(deriveStatuses(
|
666
|
+
return useMemo(() => new Balances(deriveStatuses(getValidSubscriptionIds(), balances.filter(balance => {
|
632
667
|
// check that this balance is included in our queried balance modules
|
633
668
|
if (!balanceModules.map(({
|
634
669
|
type
|
@@ -682,18 +717,22 @@ const BalancesProvider = ({
|
|
682
717
|
balanceModules,
|
683
718
|
onfinalityApiKey,
|
684
719
|
withTestnets,
|
720
|
+
enabledChains,
|
685
721
|
children
|
686
722
|
}) => /*#__PURE__*/jsx(WithTestnetsProvider, {
|
687
723
|
withTestnets: withTestnets,
|
688
|
-
children: /*#__PURE__*/jsx(
|
689
|
-
|
690
|
-
children: /*#__PURE__*/jsx(
|
724
|
+
children: /*#__PURE__*/jsx(EnabledChainsProvider, {
|
725
|
+
enabledChains: enabledChains,
|
726
|
+
children: /*#__PURE__*/jsx(ChaindataProvider, {
|
691
727
|
onfinalityApiKey: onfinalityApiKey,
|
692
|
-
children: /*#__PURE__*/jsx(
|
693
|
-
|
694
|
-
|
695
|
-
children: /*#__PURE__*/jsx(
|
696
|
-
|
728
|
+
children: /*#__PURE__*/jsx(ChainConnectorsProvider, {
|
729
|
+
onfinalityApiKey: onfinalityApiKey,
|
730
|
+
children: /*#__PURE__*/jsx(AllAddressesProvider, {
|
731
|
+
children: /*#__PURE__*/jsx(BalanceModulesProvider, {
|
732
|
+
balanceModules: balanceModules,
|
733
|
+
children: /*#__PURE__*/jsx(DbCacheProvider, {
|
734
|
+
children: children
|
735
|
+
})
|
697
736
|
})
|
698
737
|
})
|
699
738
|
})
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances-react",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.1",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "GPL-3.0-or-later",
|
@@ -26,29 +26,29 @@
|
|
26
26
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
27
27
|
},
|
28
28
|
"dependencies": {
|
29
|
-
"@talismn/balances": "0.6.
|
30
|
-
"@talismn/chain-connector": "0.
|
31
|
-
"@talismn/chain-connector-evm": "0.
|
32
|
-
"@talismn/chaindata-provider": "0.
|
33
|
-
"@talismn/chaindata-provider-extension": "0.
|
34
|
-
"@talismn/connection-meta": "0.1.
|
35
|
-
"@talismn/token-rates": "0.
|
29
|
+
"@talismn/balances": "0.6.1",
|
30
|
+
"@talismn/chain-connector": "0.8.0",
|
31
|
+
"@talismn/chain-connector-evm": "0.8.0",
|
32
|
+
"@talismn/chaindata-provider": "0.8.0",
|
33
|
+
"@talismn/chaindata-provider-extension": "0.8.0",
|
34
|
+
"@talismn/connection-meta": "0.1.1",
|
35
|
+
"@talismn/token-rates": "0.3.0",
|
36
36
|
"anylogger": "^1.0.11",
|
37
37
|
"blueimp-md5": "2.19.0",
|
38
38
|
"dexie": "^3.2.4",
|
39
|
-
"dexie-react-hooks": "^1.1.
|
39
|
+
"dexie-react-hooks": "^1.1.7",
|
40
40
|
"react-use": "^17.4.0",
|
41
41
|
"rxjs": "^7.8.1"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
|
-
"@talismn/eslint-config": "0.0.
|
44
|
+
"@talismn/eslint-config": "0.0.3",
|
45
45
|
"@talismn/tsconfig": "0.0.2",
|
46
46
|
"@types/jest": "^27.5.1",
|
47
47
|
"@types/react": "^18.0.17",
|
48
48
|
"eslint": "^8.4.0",
|
49
|
-
"jest": "^
|
49
|
+
"jest": "^29.7.0",
|
50
50
|
"react": "^18.2.0",
|
51
|
-
"ts-jest": "^
|
51
|
+
"ts-jest": "^29.1.1",
|
52
52
|
"typescript": "^4.6.4"
|
53
53
|
},
|
54
54
|
"peerDependencies": {
|