@talismn/balances-react 0.0.0-pr660-20230328111733 → 0.0.0-pr660-20230329012844
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @talismn/balances-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-pr660-
|
|
3
|
+
## 0.0.0-pr660-20230329012844
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
- Updated dependencies [79f6ccf6]
|
|
18
18
|
- Updated dependencies [6643a4e4]
|
|
19
19
|
- Updated dependencies [c24dc1fb]
|
|
20
|
-
- @talismn/chain-connector@0.0.0-pr660-
|
|
21
|
-
- @talismn/connection-meta@0.0.0-pr660-
|
|
22
|
-
- @talismn/balances@0.0.0-pr660-
|
|
23
|
-
- @talismn/token-rates@0.0.0-pr660-
|
|
24
|
-
- @talismn/chaindata-provider-extension@0.0.0-pr660-
|
|
25
|
-
- @talismn/chaindata-provider@0.0.0-pr660-
|
|
26
|
-
- @talismn/chain-connector-evm@0.0.0-pr660-
|
|
20
|
+
- @talismn/chain-connector@0.0.0-pr660-20230329012844
|
|
21
|
+
- @talismn/connection-meta@0.0.0-pr660-20230329012844
|
|
22
|
+
- @talismn/balances@0.0.0-pr660-20230329012844
|
|
23
|
+
- @talismn/token-rates@0.0.0-pr660-20230329012844
|
|
24
|
+
- @talismn/chaindata-provider-extension@0.0.0-pr660-20230329012844
|
|
25
|
+
- @talismn/chaindata-provider@0.0.0-pr660-20230329012844
|
|
26
|
+
- @talismn/chain-connector-evm@0.0.0-pr660-20230329012844
|
|
27
27
|
|
|
28
28
|
## 0.3.3
|
|
29
29
|
|
|
@@ -17,9 +17,6 @@ type DbCache = {
|
|
|
17
17
|
tokensWithoutTestnetsMap: Record<TokenId, Token>;
|
|
18
18
|
tokenRatesMap: Record<TokenId, TokenRates>;
|
|
19
19
|
balances: BalanceJson[];
|
|
20
|
-
balancesMeta: {
|
|
21
|
-
subscriptionId: string | undefined;
|
|
22
|
-
};
|
|
23
20
|
};
|
|
24
21
|
export declare const DbCacheProvider: import("react").FC<{
|
|
25
22
|
children?: import("react").ReactNode;
|
|
@@ -117,12 +117,9 @@ const DEFAULT_VALUE = {
|
|
|
117
117
|
tokensWithTestnetsMap: {},
|
|
118
118
|
tokensWithoutTestnetsMap: {},
|
|
119
119
|
tokenRatesMap: {},
|
|
120
|
-
balances: []
|
|
121
|
-
balancesMeta: {
|
|
122
|
-
subscriptionId: undefined
|
|
123
|
-
}
|
|
120
|
+
balances: []
|
|
124
121
|
};
|
|
125
|
-
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances
|
|
122
|
+
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances) => {
|
|
126
123
|
if (!chainsMap || !evmNetworksMap || !tokensMap || !tokenRates || !allBalances) return DEFAULT_VALUE;
|
|
127
124
|
|
|
128
125
|
// BEGIN: temp hack to indicate that
|
|
@@ -158,11 +155,6 @@ const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, al
|
|
|
158
155
|
|
|
159
156
|
// return only balances for which we have a token
|
|
160
157
|
const balances = allBalances.filter(b => tokensWithTestnetsMap[b.tokenId]);
|
|
161
|
-
const balancesMeta = {
|
|
162
|
-
subscriptionId: meta?.find(({
|
|
163
|
-
id
|
|
164
|
-
}) => id === "subscriptionId")?.value
|
|
165
|
-
};
|
|
166
158
|
return {
|
|
167
159
|
chainsWithTestnets,
|
|
168
160
|
chainsWithoutTestnets,
|
|
@@ -177,8 +169,7 @@ const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, al
|
|
|
177
169
|
tokensWithTestnetsMap,
|
|
178
170
|
tokensWithoutTestnetsMap,
|
|
179
171
|
tokenRatesMap,
|
|
180
|
-
balances
|
|
181
|
-
balancesMeta
|
|
172
|
+
balances
|
|
182
173
|
};
|
|
183
174
|
};
|
|
184
175
|
const useDbCacheProvider = () => {
|
|
@@ -188,29 +179,28 @@ const useDbCacheProvider = () => {
|
|
|
188
179
|
const tokenList = dexieReactHooks.useLiveQuery(() => chaindataProvider?.tokens(), [chaindataProvider]);
|
|
189
180
|
const tokenRates$1 = dexieReactHooks.useLiveQuery(() => tokenRates.db.tokenRates.toArray(), []);
|
|
190
181
|
const rawBalances = dexieReactHooks.useLiveQuery(() => balances.db.balances.toArray(), []);
|
|
191
|
-
const meta = dexieReactHooks.useLiveQuery(() => balances.db.meta.toArray(), []);
|
|
192
182
|
const [dbData, setDbData] = react.useState(DEFAULT_VALUE);
|
|
193
183
|
|
|
194
184
|
// debounce every 500ms to prevent hammering UI with updates
|
|
195
185
|
reactUse.useDebounce(() => {
|
|
196
|
-
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
197
|
-
}, 500, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
186
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
187
|
+
}, 500, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
|
|
198
188
|
const refInitialized = react.useRef(false);
|
|
199
189
|
|
|
200
190
|
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
|
201
191
|
react.useEffect(() => {
|
|
202
|
-
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates$1 && rawBalances
|
|
203
|
-
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
192
|
+
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates$1 && rawBalances) {
|
|
193
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
204
194
|
refInitialized.current = true;
|
|
205
195
|
}
|
|
206
|
-
}, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
196
|
+
}, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
|
|
207
197
|
return dbData;
|
|
208
198
|
};
|
|
209
199
|
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
210
200
|
|
|
211
201
|
var packageJson = {
|
|
212
202
|
name: "@talismn/balances-react",
|
|
213
|
-
version: "0.0.0-pr660-
|
|
203
|
+
version: "0.0.0-pr660-20230329012844",
|
|
214
204
|
author: "Talisman",
|
|
215
205
|
homepage: "https://talisman.xyz",
|
|
216
206
|
license: "UNLICENSED",
|
|
@@ -513,11 +503,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
513
503
|
id
|
|
514
504
|
}) => id);
|
|
515
505
|
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
|
516
|
-
const subscriptionId =
|
|
517
|
-
balances.db.meta.put({
|
|
518
|
-
id: "subscriptionId",
|
|
519
|
-
value: subscriptionId
|
|
520
|
-
});
|
|
506
|
+
const subscriptionId = balances.createSubscriptionId();
|
|
521
507
|
|
|
522
508
|
// TODO: Create subscriptions in a service worker, where we can detect page closes
|
|
523
509
|
// and therefore reliably delete the subscriptionId when the user closes our dapp
|
|
@@ -529,7 +515,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
529
515
|
//
|
|
530
516
|
// For now, we'll just last-ditch remove the subscriptionId (it works surprisingly well!) in the beforeunload event
|
|
531
517
|
window.onbeforeunload = () => {
|
|
532
|
-
balances.
|
|
518
|
+
balances.deleteSubscriptionId();
|
|
533
519
|
};
|
|
534
520
|
const updateDb = balances$1 => {
|
|
535
521
|
const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
|
|
@@ -577,7 +563,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
577
563
|
unsub.then(unsubscribe => {
|
|
578
564
|
setTimeout(unsubscribe, 2_000);
|
|
579
565
|
});
|
|
580
|
-
balances.
|
|
566
|
+
balances.deleteSubscriptionId();
|
|
581
567
|
};
|
|
582
568
|
});
|
|
583
569
|
const unsubscribeAll = () => {
|
|
@@ -663,11 +649,10 @@ function useBalances(addressesByToken) {
|
|
|
663
649
|
useDbCacheBalancesSubscription();
|
|
664
650
|
const balanceModules = useBalanceModules();
|
|
665
651
|
const {
|
|
666
|
-
balances: balances$1
|
|
667
|
-
balancesMeta
|
|
652
|
+
balances: balances$1
|
|
668
653
|
} = useDbCache();
|
|
669
654
|
const hydrate = useBalancesHydrate();
|
|
670
|
-
return react.useMemo(() => new balances.Balances(balances.deriveStatuses(
|
|
655
|
+
return react.useMemo(() => new balances.Balances(balances.deriveStatuses([...balances.getValidSubscriptionIds()], balances$1.filter(balance => {
|
|
671
656
|
// check that this balance is included in our queried balance modules
|
|
672
657
|
if (!balanceModules.map(({
|
|
673
658
|
type
|
|
@@ -686,7 +671,7 @@ function useBalances(addressesByToken) {
|
|
|
686
671
|
return true;
|
|
687
672
|
})),
|
|
688
673
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
|
689
|
-
hydrate), [
|
|
674
|
+
hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
|
|
690
675
|
}
|
|
691
676
|
|
|
692
677
|
/**
|
|
@@ -117,12 +117,9 @@ const DEFAULT_VALUE = {
|
|
|
117
117
|
tokensWithTestnetsMap: {},
|
|
118
118
|
tokensWithoutTestnetsMap: {},
|
|
119
119
|
tokenRatesMap: {},
|
|
120
|
-
balances: []
|
|
121
|
-
balancesMeta: {
|
|
122
|
-
subscriptionId: undefined
|
|
123
|
-
}
|
|
120
|
+
balances: []
|
|
124
121
|
};
|
|
125
|
-
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances
|
|
122
|
+
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances) => {
|
|
126
123
|
if (!chainsMap || !evmNetworksMap || !tokensMap || !tokenRates || !allBalances) return DEFAULT_VALUE;
|
|
127
124
|
|
|
128
125
|
// BEGIN: temp hack to indicate that
|
|
@@ -158,11 +155,6 @@ const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, al
|
|
|
158
155
|
|
|
159
156
|
// return only balances for which we have a token
|
|
160
157
|
const balances = allBalances.filter(b => tokensWithTestnetsMap[b.tokenId]);
|
|
161
|
-
const balancesMeta = {
|
|
162
|
-
subscriptionId: meta?.find(({
|
|
163
|
-
id
|
|
164
|
-
}) => id === "subscriptionId")?.value
|
|
165
|
-
};
|
|
166
158
|
return {
|
|
167
159
|
chainsWithTestnets,
|
|
168
160
|
chainsWithoutTestnets,
|
|
@@ -177,8 +169,7 @@ const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, al
|
|
|
177
169
|
tokensWithTestnetsMap,
|
|
178
170
|
tokensWithoutTestnetsMap,
|
|
179
171
|
tokenRatesMap,
|
|
180
|
-
balances
|
|
181
|
-
balancesMeta
|
|
172
|
+
balances
|
|
182
173
|
};
|
|
183
174
|
};
|
|
184
175
|
const useDbCacheProvider = () => {
|
|
@@ -188,29 +179,28 @@ const useDbCacheProvider = () => {
|
|
|
188
179
|
const tokenList = dexieReactHooks.useLiveQuery(() => chaindataProvider?.tokens(), [chaindataProvider]);
|
|
189
180
|
const tokenRates$1 = dexieReactHooks.useLiveQuery(() => tokenRates.db.tokenRates.toArray(), []);
|
|
190
181
|
const rawBalances = dexieReactHooks.useLiveQuery(() => balances.db.balances.toArray(), []);
|
|
191
|
-
const meta = dexieReactHooks.useLiveQuery(() => balances.db.meta.toArray(), []);
|
|
192
182
|
const [dbData, setDbData] = react.useState(DEFAULT_VALUE);
|
|
193
183
|
|
|
194
184
|
// debounce every 500ms to prevent hammering UI with updates
|
|
195
185
|
reactUse.useDebounce(() => {
|
|
196
|
-
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
197
|
-
}, 500, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
186
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
187
|
+
}, 500, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
|
|
198
188
|
const refInitialized = react.useRef(false);
|
|
199
189
|
|
|
200
190
|
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
|
201
191
|
react.useEffect(() => {
|
|
202
|
-
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates$1 && rawBalances
|
|
203
|
-
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
192
|
+
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates$1 && rawBalances) {
|
|
193
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
204
194
|
refInitialized.current = true;
|
|
205
195
|
}
|
|
206
|
-
}, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances
|
|
196
|
+
}, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
|
|
207
197
|
return dbData;
|
|
208
198
|
};
|
|
209
199
|
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
210
200
|
|
|
211
201
|
var packageJson = {
|
|
212
202
|
name: "@talismn/balances-react",
|
|
213
|
-
version: "0.0.0-pr660-
|
|
203
|
+
version: "0.0.0-pr660-20230329012844",
|
|
214
204
|
author: "Talisman",
|
|
215
205
|
homepage: "https://talisman.xyz",
|
|
216
206
|
license: "UNLICENSED",
|
|
@@ -513,11 +503,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
513
503
|
id
|
|
514
504
|
}) => id);
|
|
515
505
|
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
|
516
|
-
const subscriptionId =
|
|
517
|
-
balances.db.meta.put({
|
|
518
|
-
id: "subscriptionId",
|
|
519
|
-
value: subscriptionId
|
|
520
|
-
});
|
|
506
|
+
const subscriptionId = balances.createSubscriptionId();
|
|
521
507
|
|
|
522
508
|
// TODO: Create subscriptions in a service worker, where we can detect page closes
|
|
523
509
|
// and therefore reliably delete the subscriptionId when the user closes our dapp
|
|
@@ -529,7 +515,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
529
515
|
//
|
|
530
516
|
// For now, we'll just last-ditch remove the subscriptionId (it works surprisingly well!) in the beforeunload event
|
|
531
517
|
window.onbeforeunload = () => {
|
|
532
|
-
balances.
|
|
518
|
+
balances.deleteSubscriptionId();
|
|
533
519
|
};
|
|
534
520
|
const updateDb = balances$1 => {
|
|
535
521
|
const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
|
|
@@ -577,7 +563,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
577
563
|
unsub.then(unsubscribe => {
|
|
578
564
|
setTimeout(unsubscribe, 2_000);
|
|
579
565
|
});
|
|
580
|
-
balances.
|
|
566
|
+
balances.deleteSubscriptionId();
|
|
581
567
|
};
|
|
582
568
|
});
|
|
583
569
|
const unsubscribeAll = () => {
|
|
@@ -663,11 +649,10 @@ function useBalances(addressesByToken) {
|
|
|
663
649
|
useDbCacheBalancesSubscription();
|
|
664
650
|
const balanceModules = useBalanceModules();
|
|
665
651
|
const {
|
|
666
|
-
balances: balances$1
|
|
667
|
-
balancesMeta
|
|
652
|
+
balances: balances$1
|
|
668
653
|
} = useDbCache();
|
|
669
654
|
const hydrate = useBalancesHydrate();
|
|
670
|
-
return react.useMemo(() => new balances.Balances(balances.deriveStatuses(
|
|
655
|
+
return react.useMemo(() => new balances.Balances(balances.deriveStatuses([...balances.getValidSubscriptionIds()], balances$1.filter(balance => {
|
|
671
656
|
// check that this balance is included in our queried balance modules
|
|
672
657
|
if (!balanceModules.map(({
|
|
673
658
|
type
|
|
@@ -686,7 +671,7 @@ function useBalances(addressesByToken) {
|
|
|
686
671
|
return true;
|
|
687
672
|
})),
|
|
688
673
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
|
689
|
-
hydrate), [
|
|
674
|
+
hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
|
|
690
675
|
}
|
|
691
676
|
|
|
692
677
|
/**
|
|
@@ -4,7 +4,7 @@ import { ChainConnector } from '@talismn/chain-connector';
|
|
|
4
4
|
import { ChainConnectorEvm } from '@talismn/chain-connector-evm';
|
|
5
5
|
import { connectionMetaDb } from '@talismn/connection-meta';
|
|
6
6
|
import { ChaindataProviderExtension } from '@talismn/chaindata-provider-extension';
|
|
7
|
-
import { db as db$1, balances, BalanceStatusLive, Balances, deriveStatuses } from '@talismn/balances';
|
|
7
|
+
import { db as db$1, createSubscriptionId, deleteSubscriptionId, balances, BalanceStatusLive, Balances, deriveStatuses, getValidSubscriptionIds } from '@talismn/balances';
|
|
8
8
|
import { db, fetchTokenRates } from '@talismn/token-rates';
|
|
9
9
|
import { useLiveQuery } from 'dexie-react-hooks';
|
|
10
10
|
import { useDebounce } from 'react-use';
|
|
@@ -108,12 +108,9 @@ const DEFAULT_VALUE = {
|
|
|
108
108
|
tokensWithTestnetsMap: {},
|
|
109
109
|
tokensWithoutTestnetsMap: {},
|
|
110
110
|
tokenRatesMap: {},
|
|
111
|
-
balances: []
|
|
112
|
-
balancesMeta: {
|
|
113
|
-
subscriptionId: undefined
|
|
114
|
-
}
|
|
111
|
+
balances: []
|
|
115
112
|
};
|
|
116
|
-
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances
|
|
113
|
+
const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, allBalances) => {
|
|
117
114
|
if (!chainsMap || !evmNetworksMap || !tokensMap || !tokenRates || !allBalances) return DEFAULT_VALUE;
|
|
118
115
|
|
|
119
116
|
// BEGIN: temp hack to indicate that
|
|
@@ -149,11 +146,6 @@ const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, al
|
|
|
149
146
|
|
|
150
147
|
// return only balances for which we have a token
|
|
151
148
|
const balances = allBalances.filter(b => tokensWithTestnetsMap[b.tokenId]);
|
|
152
|
-
const balancesMeta = {
|
|
153
|
-
subscriptionId: meta?.find(({
|
|
154
|
-
id
|
|
155
|
-
}) => id === "subscriptionId")?.value
|
|
156
|
-
};
|
|
157
149
|
return {
|
|
158
150
|
chainsWithTestnets,
|
|
159
151
|
chainsWithoutTestnets,
|
|
@@ -168,8 +160,7 @@ const consolidateDbCache = (chainsMap, evmNetworksMap, tokensMap, tokenRates, al
|
|
|
168
160
|
tokensWithTestnetsMap,
|
|
169
161
|
tokensWithoutTestnetsMap,
|
|
170
162
|
tokenRatesMap,
|
|
171
|
-
balances
|
|
172
|
-
balancesMeta
|
|
163
|
+
balances
|
|
173
164
|
};
|
|
174
165
|
};
|
|
175
166
|
const useDbCacheProvider = () => {
|
|
@@ -179,29 +170,28 @@ const useDbCacheProvider = () => {
|
|
|
179
170
|
const tokenList = useLiveQuery(() => chaindataProvider?.tokens(), [chaindataProvider]);
|
|
180
171
|
const tokenRates = useLiveQuery(() => db.tokenRates.toArray(), []);
|
|
181
172
|
const rawBalances = useLiveQuery(() => db$1.balances.toArray(), []);
|
|
182
|
-
const meta = useLiveQuery(() => db$1.meta.toArray(), []);
|
|
183
173
|
const [dbData, setDbData] = useState(DEFAULT_VALUE);
|
|
184
174
|
|
|
185
175
|
// debounce every 500ms to prevent hammering UI with updates
|
|
186
176
|
useDebounce(() => {
|
|
187
|
-
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates, rawBalances
|
|
188
|
-
}, 500, [chainList, evmNetworkList, tokenList, tokenRates, rawBalances
|
|
177
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates, rawBalances));
|
|
178
|
+
}, 500, [chainList, evmNetworkList, tokenList, tokenRates, rawBalances]);
|
|
189
179
|
const refInitialized = useRef(false);
|
|
190
180
|
|
|
191
181
|
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
|
192
182
|
useEffect(() => {
|
|
193
|
-
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates && rawBalances
|
|
194
|
-
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates, rawBalances
|
|
183
|
+
if (!refInitialized.current && chainList && evmNetworkList && tokenList && tokenRates && rawBalances) {
|
|
184
|
+
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates, rawBalances));
|
|
195
185
|
refInitialized.current = true;
|
|
196
186
|
}
|
|
197
|
-
}, [chainList, evmNetworkList, tokenList, tokenRates, rawBalances
|
|
187
|
+
}, [chainList, evmNetworkList, tokenList, tokenRates, rawBalances]);
|
|
198
188
|
return dbData;
|
|
199
189
|
};
|
|
200
190
|
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
201
191
|
|
|
202
192
|
var packageJson = {
|
|
203
193
|
name: "@talismn/balances-react",
|
|
204
|
-
version: "0.0.0-pr660-
|
|
194
|
+
version: "0.0.0-pr660-20230329012844",
|
|
205
195
|
author: "Talisman",
|
|
206
196
|
homepage: "https://talisman.xyz",
|
|
207
197
|
license: "UNLICENSED",
|
|
@@ -504,11 +494,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
504
494
|
id
|
|
505
495
|
}) => id);
|
|
506
496
|
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
|
507
|
-
const subscriptionId =
|
|
508
|
-
db$1.meta.put({
|
|
509
|
-
id: "subscriptionId",
|
|
510
|
-
value: subscriptionId
|
|
511
|
-
});
|
|
497
|
+
const subscriptionId = createSubscriptionId();
|
|
512
498
|
|
|
513
499
|
// TODO: Create subscriptions in a service worker, where we can detect page closes
|
|
514
500
|
// and therefore reliably delete the subscriptionId when the user closes our dapp
|
|
@@ -520,7 +506,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
520
506
|
//
|
|
521
507
|
// For now, we'll just last-ditch remove the subscriptionId (it works surprisingly well!) in the beforeunload event
|
|
522
508
|
window.onbeforeunload = () => {
|
|
523
|
-
|
|
509
|
+
deleteSubscriptionId();
|
|
524
510
|
};
|
|
525
511
|
const updateDb = balances => {
|
|
526
512
|
const putBalances = Object.entries(balances.toJSON()).map(([id, balance]) => ({
|
|
@@ -568,7 +554,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
568
554
|
unsub.then(unsubscribe => {
|
|
569
555
|
setTimeout(unsubscribe, 2_000);
|
|
570
556
|
});
|
|
571
|
-
|
|
557
|
+
deleteSubscriptionId();
|
|
572
558
|
};
|
|
573
559
|
});
|
|
574
560
|
const unsubscribeAll = () => {
|
|
@@ -654,11 +640,10 @@ function useBalances(addressesByToken) {
|
|
|
654
640
|
useDbCacheBalancesSubscription();
|
|
655
641
|
const balanceModules = useBalanceModules();
|
|
656
642
|
const {
|
|
657
|
-
balances
|
|
658
|
-
balancesMeta
|
|
643
|
+
balances
|
|
659
644
|
} = useDbCache();
|
|
660
645
|
const hydrate = useBalancesHydrate();
|
|
661
|
-
return useMemo(() => new Balances(deriveStatuses(
|
|
646
|
+
return useMemo(() => new Balances(deriveStatuses([...getValidSubscriptionIds()], balances.filter(balance => {
|
|
662
647
|
// check that this balance is included in our queried balance modules
|
|
663
648
|
if (!balanceModules.map(({
|
|
664
649
|
type
|
|
@@ -677,7 +662,7 @@ function useBalances(addressesByToken) {
|
|
|
677
662
|
return true;
|
|
678
663
|
})),
|
|
679
664
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
|
680
|
-
hydrate), [
|
|
665
|
+
hydrate), [balances, hydrate, balanceModules, addressesByToken]);
|
|
681
666
|
}
|
|
682
667
|
|
|
683
668
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/balances-react",
|
|
3
|
-
"version": "0.0.0-pr660-
|
|
3
|
+
"version": "0.0.0-pr660-20230329012844",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@talismn/balances": "^0.0.0-pr660-
|
|
30
|
-
"@talismn/chain-connector": "^0.0.0-pr660-
|
|
31
|
-
"@talismn/chain-connector-evm": "^0.0.0-pr660-
|
|
32
|
-
"@talismn/chaindata-provider": "^0.0.0-pr660-
|
|
33
|
-
"@talismn/chaindata-provider-extension": "^0.0.0-pr660-
|
|
34
|
-
"@talismn/connection-meta": "^0.0.0-pr660-
|
|
35
|
-
"@talismn/token-rates": "^0.0.0-pr660-
|
|
29
|
+
"@talismn/balances": "^0.0.0-pr660-20230329012844",
|
|
30
|
+
"@talismn/chain-connector": "^0.0.0-pr660-20230329012844",
|
|
31
|
+
"@talismn/chain-connector-evm": "^0.0.0-pr660-20230329012844",
|
|
32
|
+
"@talismn/chaindata-provider": "^0.0.0-pr660-20230329012844",
|
|
33
|
+
"@talismn/chaindata-provider-extension": "^0.0.0-pr660-20230329012844",
|
|
34
|
+
"@talismn/connection-meta": "^0.0.0-pr660-20230329012844",
|
|
35
|
+
"@talismn/token-rates": "^0.0.0-pr660-20230329012844",
|
|
36
36
|
"anylogger": "^1.0.11",
|
|
37
37
|
"blueimp-md5": "2.19.0",
|
|
38
38
|
"dexie": "^3.2.3",
|