@talismn/balances-react 0.0.0-pr660-20230328121248 → 0.0.0-pr664-20230330015052
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-
|
|
3
|
+
## 0.0.0-pr664-20230330015052
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -13,17 +13,16 @@
|
|
|
13
13
|
- 6643a4e4: fix: ported useDbCache related perf fixes to @talismn/balances-react
|
|
14
14
|
- Updated dependencies [3068bd60]
|
|
15
15
|
- Updated dependencies [6643a4e4]
|
|
16
|
-
- Updated dependencies [fa4d115f]
|
|
17
16
|
- Updated dependencies [79f6ccf6]
|
|
18
17
|
- Updated dependencies [6643a4e4]
|
|
19
18
|
- Updated dependencies [c24dc1fb]
|
|
20
|
-
- @talismn/chain-connector@0.0.0-
|
|
21
|
-
- @talismn/connection-meta@0.0.0-
|
|
22
|
-
- @talismn/balances@0.0.0-
|
|
23
|
-
- @talismn/token-rates@0.0.0-
|
|
24
|
-
- @talismn/chaindata-provider-extension@0.0.0-
|
|
25
|
-
- @talismn/chaindata-provider@0.0.0-
|
|
26
|
-
- @talismn/chain-connector-evm@0.0.0-
|
|
19
|
+
- @talismn/chain-connector@0.0.0-pr664-20230330015052
|
|
20
|
+
- @talismn/connection-meta@0.0.0-pr664-20230330015052
|
|
21
|
+
- @talismn/balances@0.0.0-pr664-20230330015052
|
|
22
|
+
- @talismn/token-rates@0.0.0-pr664-20230330015052
|
|
23
|
+
- @talismn/chaindata-provider-extension@0.0.0-pr664-20230330015052
|
|
24
|
+
- @talismn/chaindata-provider@0.0.0-pr664-20230330015052
|
|
25
|
+
- @talismn/chain-connector-evm@0.0.0-pr664-20230330015052
|
|
27
26
|
|
|
28
27
|
## 0.3.3
|
|
29
28
|
|
|
@@ -184,7 +184,7 @@ const useDbCacheProvider = () => {
|
|
|
184
184
|
// debounce every 500ms to prevent hammering UI with updates
|
|
185
185
|
reactUse.useDebounce(() => {
|
|
186
186
|
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
187
|
-
}, 500, [chainList, evmNetworkList, tokenList, tokenRates$1
|
|
187
|
+
}, 500, [chainList, evmNetworkList, tokenList, rawBalances, tokenRates$1]);
|
|
188
188
|
const refInitialized = react.useRef(false);
|
|
189
189
|
|
|
190
190
|
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
|
@@ -193,14 +193,14 @@ const useDbCacheProvider = () => {
|
|
|
193
193
|
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
194
194
|
refInitialized.current = true;
|
|
195
195
|
}
|
|
196
|
-
}, [chainList, evmNetworkList, tokenList, tokenRates$1
|
|
196
|
+
}, [chainList, evmNetworkList, rawBalances, tokenList, tokenRates$1]);
|
|
197
197
|
return dbData;
|
|
198
198
|
};
|
|
199
199
|
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
200
200
|
|
|
201
201
|
var packageJson = {
|
|
202
202
|
name: "@talismn/balances-react",
|
|
203
|
-
version: "0.0.0-
|
|
203
|
+
version: "0.0.0-pr664-20230330015052",
|
|
204
204
|
author: "Talisman",
|
|
205
205
|
homepage: "https://talisman.xyz",
|
|
206
206
|
license: "UNLICENSED",
|
|
@@ -503,25 +503,10 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
503
503
|
id
|
|
504
504
|
}) => id);
|
|
505
505
|
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
|
506
|
-
const subscriptionId = balances.createSubscriptionId();
|
|
507
|
-
|
|
508
|
-
// TODO: Create subscriptions in a service worker, where we can detect page closes
|
|
509
|
-
// and therefore reliably delete the subscriptionId when the user closes our dapp
|
|
510
|
-
//
|
|
511
|
-
// For more information, check out https://developer.chrome.com/blog/page-lifecycle-api/#faqs
|
|
512
|
-
// and scroll down to:
|
|
513
|
-
// - `What is the back/forward cache?`, and
|
|
514
|
-
// - `If I can't run asynchronous APIs in the frozen or terminated states, how can I save data to IndexedDB?
|
|
515
|
-
//
|
|
516
|
-
// For now, we'll just last-ditch remove the subscriptionId (it works surprisingly well!) in the beforeunload event
|
|
517
|
-
window.onbeforeunload = () => {
|
|
518
|
-
balances.deleteSubscriptionId();
|
|
519
|
-
};
|
|
520
506
|
const updateDb = balances$1 => {
|
|
521
507
|
const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
|
|
522
508
|
id,
|
|
523
|
-
...balance
|
|
524
|
-
status: balances.BalanceStatusLive(subscriptionId)
|
|
509
|
+
...balance
|
|
525
510
|
}));
|
|
526
511
|
balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.bulkPut(putBalances));
|
|
527
512
|
};
|
|
@@ -540,7 +525,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
540
525
|
const unsub = balances.balances(balanceModule, addressesByModuleToken, (error, balances$1) => {
|
|
541
526
|
// log errors
|
|
542
527
|
if (error) {
|
|
543
|
-
if (error?.type === "STALE_RPC_ERROR"
|
|
528
|
+
if (error?.type === "STALE_RPC_ERROR") return balances.db.balances.where({
|
|
544
529
|
source: balanceModule.type,
|
|
545
530
|
chainId: error.chainId
|
|
546
531
|
}).filter(balance => {
|
|
@@ -563,7 +548,15 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
563
548
|
unsub.then(unsubscribe => {
|
|
564
549
|
setTimeout(unsubscribe, 2_000);
|
|
565
550
|
});
|
|
566
|
-
balances.
|
|
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
|
+
});
|
|
567
560
|
};
|
|
568
561
|
});
|
|
569
562
|
const unsubscribeAll = () => {
|
|
@@ -652,7 +645,7 @@ function useBalances(addressesByToken) {
|
|
|
652
645
|
balances: balances$1
|
|
653
646
|
} = useDbCache();
|
|
654
647
|
const hydrate = useBalancesHydrate();
|
|
655
|
-
return react.useMemo(() => new balances.Balances(balances
|
|
648
|
+
return react.useMemo(() => new balances.Balances(balances$1.filter(balance => {
|
|
656
649
|
// check that this balance is included in our queried balance modules
|
|
657
650
|
if (!balanceModules.map(({
|
|
658
651
|
type
|
|
@@ -669,7 +662,7 @@ function useBalances(addressesByToken) {
|
|
|
669
662
|
|
|
670
663
|
// keep this balance
|
|
671
664
|
return true;
|
|
672
|
-
})
|
|
665
|
+
}),
|
|
673
666
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
|
674
667
|
hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
|
|
675
668
|
}
|
|
@@ -184,7 +184,7 @@ const useDbCacheProvider = () => {
|
|
|
184
184
|
// debounce every 500ms to prevent hammering UI with updates
|
|
185
185
|
reactUse.useDebounce(() => {
|
|
186
186
|
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
187
|
-
}, 500, [chainList, evmNetworkList, tokenList, tokenRates$1
|
|
187
|
+
}, 500, [chainList, evmNetworkList, tokenList, rawBalances, tokenRates$1]);
|
|
188
188
|
const refInitialized = react.useRef(false);
|
|
189
189
|
|
|
190
190
|
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
|
@@ -193,14 +193,14 @@ const useDbCacheProvider = () => {
|
|
|
193
193
|
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances));
|
|
194
194
|
refInitialized.current = true;
|
|
195
195
|
}
|
|
196
|
-
}, [chainList, evmNetworkList, tokenList, tokenRates$1
|
|
196
|
+
}, [chainList, evmNetworkList, rawBalances, tokenList, tokenRates$1]);
|
|
197
197
|
return dbData;
|
|
198
198
|
};
|
|
199
199
|
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
200
200
|
|
|
201
201
|
var packageJson = {
|
|
202
202
|
name: "@talismn/balances-react",
|
|
203
|
-
version: "0.0.0-
|
|
203
|
+
version: "0.0.0-pr664-20230330015052",
|
|
204
204
|
author: "Talisman",
|
|
205
205
|
homepage: "https://talisman.xyz",
|
|
206
206
|
license: "UNLICENSED",
|
|
@@ -503,25 +503,10 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
503
503
|
id
|
|
504
504
|
}) => id);
|
|
505
505
|
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
|
506
|
-
const subscriptionId = balances.createSubscriptionId();
|
|
507
|
-
|
|
508
|
-
// TODO: Create subscriptions in a service worker, where we can detect page closes
|
|
509
|
-
// and therefore reliably delete the subscriptionId when the user closes our dapp
|
|
510
|
-
//
|
|
511
|
-
// For more information, check out https://developer.chrome.com/blog/page-lifecycle-api/#faqs
|
|
512
|
-
// and scroll down to:
|
|
513
|
-
// - `What is the back/forward cache?`, and
|
|
514
|
-
// - `If I can't run asynchronous APIs in the frozen or terminated states, how can I save data to IndexedDB?
|
|
515
|
-
//
|
|
516
|
-
// For now, we'll just last-ditch remove the subscriptionId (it works surprisingly well!) in the beforeunload event
|
|
517
|
-
window.onbeforeunload = () => {
|
|
518
|
-
balances.deleteSubscriptionId();
|
|
519
|
-
};
|
|
520
506
|
const updateDb = balances$1 => {
|
|
521
507
|
const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
|
|
522
508
|
id,
|
|
523
|
-
...balance
|
|
524
|
-
status: balances.BalanceStatusLive(subscriptionId)
|
|
509
|
+
...balance
|
|
525
510
|
}));
|
|
526
511
|
balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.bulkPut(putBalances));
|
|
527
512
|
};
|
|
@@ -540,7 +525,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
540
525
|
const unsub = balances.balances(balanceModule, addressesByModuleToken, (error, balances$1) => {
|
|
541
526
|
// log errors
|
|
542
527
|
if (error) {
|
|
543
|
-
if (error?.type === "STALE_RPC_ERROR"
|
|
528
|
+
if (error?.type === "STALE_RPC_ERROR") return balances.db.balances.where({
|
|
544
529
|
source: balanceModule.type,
|
|
545
530
|
chainId: error.chainId
|
|
546
531
|
}).filter(balance => {
|
|
@@ -563,7 +548,15 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
563
548
|
unsub.then(unsubscribe => {
|
|
564
549
|
setTimeout(unsubscribe, 2_000);
|
|
565
550
|
});
|
|
566
|
-
balances.
|
|
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
|
+
});
|
|
567
560
|
};
|
|
568
561
|
});
|
|
569
562
|
const unsubscribeAll = () => {
|
|
@@ -652,7 +645,7 @@ function useBalances(addressesByToken) {
|
|
|
652
645
|
balances: balances$1
|
|
653
646
|
} = useDbCache();
|
|
654
647
|
const hydrate = useBalancesHydrate();
|
|
655
|
-
return react.useMemo(() => new balances.Balances(balances
|
|
648
|
+
return react.useMemo(() => new balances.Balances(balances$1.filter(balance => {
|
|
656
649
|
// check that this balance is included in our queried balance modules
|
|
657
650
|
if (!balanceModules.map(({
|
|
658
651
|
type
|
|
@@ -669,7 +662,7 @@ function useBalances(addressesByToken) {
|
|
|
669
662
|
|
|
670
663
|
// keep this balance
|
|
671
664
|
return true;
|
|
672
|
-
})
|
|
665
|
+
}),
|
|
673
666
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
|
674
667
|
hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
|
|
675
668
|
}
|
|
@@ -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,
|
|
7
|
+
import { db as db$1, balances, Balances } 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';
|
|
@@ -175,7 +175,7 @@ const useDbCacheProvider = () => {
|
|
|
175
175
|
// debounce every 500ms to prevent hammering UI with updates
|
|
176
176
|
useDebounce(() => {
|
|
177
177
|
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates, rawBalances));
|
|
178
|
-
}, 500, [chainList, evmNetworkList, tokenList,
|
|
178
|
+
}, 500, [chainList, evmNetworkList, tokenList, rawBalances, tokenRates]);
|
|
179
179
|
const refInitialized = useRef(false);
|
|
180
180
|
|
|
181
181
|
// force an update as soon as all datasources are fetched, so UI can display data ASAP
|
|
@@ -184,14 +184,14 @@ const useDbCacheProvider = () => {
|
|
|
184
184
|
setDbData(consolidateDbCache(chainList, evmNetworkList, tokenList, tokenRates, rawBalances));
|
|
185
185
|
refInitialized.current = true;
|
|
186
186
|
}
|
|
187
|
-
}, [chainList, evmNetworkList, tokenList, tokenRates
|
|
187
|
+
}, [chainList, evmNetworkList, rawBalances, tokenList, tokenRates]);
|
|
188
188
|
return dbData;
|
|
189
189
|
};
|
|
190
190
|
const [DbCacheProvider, useDbCache] = provideContext(useDbCacheProvider);
|
|
191
191
|
|
|
192
192
|
var packageJson = {
|
|
193
193
|
name: "@talismn/balances-react",
|
|
194
|
-
version: "0.0.0-
|
|
194
|
+
version: "0.0.0-pr664-20230330015052",
|
|
195
195
|
author: "Talisman",
|
|
196
196
|
homepage: "https://talisman.xyz",
|
|
197
197
|
license: "UNLICENSED",
|
|
@@ -494,25 +494,10 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
494
494
|
id
|
|
495
495
|
}) => id);
|
|
496
496
|
const addressesByToken = Object.fromEntries(tokenIds.map(tokenId => [tokenId, addresses]));
|
|
497
|
-
const subscriptionId = createSubscriptionId();
|
|
498
|
-
|
|
499
|
-
// TODO: Create subscriptions in a service worker, where we can detect page closes
|
|
500
|
-
// and therefore reliably delete the subscriptionId when the user closes our dapp
|
|
501
|
-
//
|
|
502
|
-
// For more information, check out https://developer.chrome.com/blog/page-lifecycle-api/#faqs
|
|
503
|
-
// and scroll down to:
|
|
504
|
-
// - `What is the back/forward cache?`, and
|
|
505
|
-
// - `If I can't run asynchronous APIs in the frozen or terminated states, how can I save data to IndexedDB?
|
|
506
|
-
//
|
|
507
|
-
// For now, we'll just last-ditch remove the subscriptionId (it works surprisingly well!) in the beforeunload event
|
|
508
|
-
window.onbeforeunload = () => {
|
|
509
|
-
deleteSubscriptionId();
|
|
510
|
-
};
|
|
511
497
|
const updateDb = balances => {
|
|
512
498
|
const putBalances = Object.entries(balances.toJSON()).map(([id, balance]) => ({
|
|
513
499
|
id,
|
|
514
|
-
...balance
|
|
515
|
-
status: BalanceStatusLive(subscriptionId)
|
|
500
|
+
...balance
|
|
516
501
|
}));
|
|
517
502
|
db$1.transaction("rw", db$1.balances, async () => await db$1.balances.bulkPut(putBalances));
|
|
518
503
|
};
|
|
@@ -531,7 +516,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
531
516
|
const unsub = balances(balanceModule, addressesByModuleToken, (error, balances) => {
|
|
532
517
|
// log errors
|
|
533
518
|
if (error) {
|
|
534
|
-
if (error?.type === "STALE_RPC_ERROR"
|
|
519
|
+
if (error?.type === "STALE_RPC_ERROR") return db$1.balances.where({
|
|
535
520
|
source: balanceModule.type,
|
|
536
521
|
chainId: error.chainId
|
|
537
522
|
}).filter(balance => {
|
|
@@ -554,7 +539,15 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
|
|
|
554
539
|
unsub.then(unsubscribe => {
|
|
555
540
|
setTimeout(unsubscribe, 2_000);
|
|
556
541
|
});
|
|
557
|
-
|
|
542
|
+
db$1.balances.where({
|
|
543
|
+
source: balanceModule.type
|
|
544
|
+
}).filter(balance => {
|
|
545
|
+
if (!Object.keys(addressesByModuleToken).includes(balance.tokenId)) return false;
|
|
546
|
+
if (!addressesByModuleToken[balance.tokenId].includes(balance.address)) return false;
|
|
547
|
+
return true;
|
|
548
|
+
}).modify({
|
|
549
|
+
status: "cache"
|
|
550
|
+
});
|
|
558
551
|
};
|
|
559
552
|
});
|
|
560
553
|
const unsubscribeAll = () => {
|
|
@@ -643,7 +636,7 @@ function useBalances(addressesByToken) {
|
|
|
643
636
|
balances
|
|
644
637
|
} = useDbCache();
|
|
645
638
|
const hydrate = useBalancesHydrate();
|
|
646
|
-
return useMemo(() => new Balances(
|
|
639
|
+
return useMemo(() => new Balances(balances.filter(balance => {
|
|
647
640
|
// check that this balance is included in our queried balance modules
|
|
648
641
|
if (!balanceModules.map(({
|
|
649
642
|
type
|
|
@@ -660,7 +653,7 @@ function useBalances(addressesByToken) {
|
|
|
660
653
|
|
|
661
654
|
// keep this balance
|
|
662
655
|
return true;
|
|
663
|
-
})
|
|
656
|
+
}),
|
|
664
657
|
// hydrate balance chains, evmNetworks, tokens and tokenRates
|
|
665
658
|
hydrate), [balances, hydrate, balanceModules, addressesByToken]);
|
|
666
659
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/balances-react",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-pr664-20230330015052",
|
|
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-
|
|
30
|
-
"@talismn/chain-connector": "^0.0.0-
|
|
31
|
-
"@talismn/chain-connector-evm": "^0.0.0-
|
|
32
|
-
"@talismn/chaindata-provider": "^0.0.0-
|
|
33
|
-
"@talismn/chaindata-provider-extension": "^0.0.0-
|
|
34
|
-
"@talismn/connection-meta": "^0.0.0-
|
|
35
|
-
"@talismn/token-rates": "^0.0.0-
|
|
29
|
+
"@talismn/balances": "^0.0.0-pr664-20230330015052",
|
|
30
|
+
"@talismn/chain-connector": "^0.0.0-pr664-20230330015052",
|
|
31
|
+
"@talismn/chain-connector-evm": "^0.0.0-pr664-20230330015052",
|
|
32
|
+
"@talismn/chaindata-provider": "^0.0.0-pr664-20230330015052",
|
|
33
|
+
"@talismn/chaindata-provider-extension": "^0.0.0-pr664-20230330015052",
|
|
34
|
+
"@talismn/connection-meta": "^0.0.0-pr664-20230330015052",
|
|
35
|
+
"@talismn/token-rates": "^0.0.0-pr664-20230330015052",
|
|
36
36
|
"anylogger": "^1.0.11",
|
|
37
37
|
"blueimp-md5": "2.19.0",
|
|
38
38
|
"dexie": "^3.2.3",
|