@talismn/balances-react 0.0.0-pr669-20230403053044 → 0.0.0-pr675-20230413170259

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,21 @@
1
1
  # @talismn/balances-react
2
2
 
3
- ## 0.0.0-pr669-20230403053044
3
+ ## 0.0.0-pr675-20230413170259
4
+
5
+ ### Patch Changes
6
+
7
+ - fb8ee962: feat: proxy dapp websocket requests to talisman wallet backend when available
8
+ - Updated dependencies [fb8ee962]
9
+ - Updated dependencies [c898da98]
10
+ - @talismn/balances@0.0.0-pr675-20230413170259
11
+ - @talismn/chain-connector@0.0.0-pr675-20230413170259
12
+ - @talismn/chain-connector-evm@0.0.0-pr675-20230413170259
13
+ - @talismn/chaindata-provider@0.0.0-pr675-20230413170259
14
+ - @talismn/chaindata-provider-extension@0.0.0-pr675-20230413170259
15
+ - @talismn/connection-meta@0.0.0-pr675-20230413170259
16
+ - @talismn/token-rates@0.0.0-pr675-20230413170259
17
+
18
+ ## 0.4.0
4
19
 
5
20
  ### Minor Changes
6
21
 
@@ -16,13 +31,13 @@
16
31
  - Updated dependencies [79f6ccf6]
17
32
  - Updated dependencies [6643a4e4]
18
33
  - Updated dependencies [c24dc1fb]
19
- - @talismn/chain-connector@0.0.0-pr669-20230403053044
20
- - @talismn/connection-meta@0.0.0-pr669-20230403053044
21
- - @talismn/balances@0.0.0-pr669-20230403053044
22
- - @talismn/token-rates@0.0.0-pr669-20230403053044
23
- - @talismn/chaindata-provider-extension@0.0.0-pr669-20230403053044
24
- - @talismn/chaindata-provider@0.0.0-pr669-20230403053044
25
- - @talismn/chain-connector-evm@0.0.0-pr669-20230403053044
34
+ - @talismn/chain-connector@0.4.3
35
+ - @talismn/connection-meta@0.0.2
36
+ - @talismn/balances@0.4.0
37
+ - @talismn/token-rates@0.1.15
38
+ - @talismn/chaindata-provider-extension@0.4.3
39
+ - @talismn/chaindata-provider@0.4.3
40
+ - @talismn/chain-connector-evm@0.4.3
26
41
 
27
42
  ## 0.3.3
28
43
 
@@ -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, rawBalances, tokenRates$1]);
187
+ }, 500, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
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, rawBalances, tokenList, tokenRates$1]);
196
+ }, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
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-pr669-20230403053044",
203
+ version: "0.0.0-pr675-20230413170259",
204
204
  author: "Talisman",
205
205
  homepage: "https://talisman.xyz",
206
206
  license: "UNLICENSED",
@@ -503,10 +503,25 @@ 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
+ };
506
520
  const updateDb = balances$1 => {
507
521
  const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
508
522
  id,
509
- ...balance
523
+ ...balance,
524
+ status: balances.BalanceStatusLive(subscriptionId)
510
525
  }));
511
526
  balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.bulkPut(putBalances));
512
527
  };
@@ -525,7 +540,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
525
540
  const unsub = balances.balances(balanceModule, addressesByModuleToken, (error, balances$1) => {
526
541
  // log errors
527
542
  if (error) {
528
- if (error?.type === "STALE_RPC_ERROR") return balances.db.balances.where({
543
+ if (error?.type === "STALE_RPC_ERROR" || error?.type === "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR") return balances.db.balances.where({
529
544
  source: balanceModule.type,
530
545
  chainId: error.chainId
531
546
  }).filter(balance => {
@@ -548,15 +563,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
548
563
  unsub.then(unsubscribe => {
549
564
  setTimeout(unsubscribe, 2_000);
550
565
  });
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
- });
566
+ balances.deleteSubscriptionId();
560
567
  };
561
568
  });
562
569
  const unsubscribeAll = () => {
@@ -645,7 +652,7 @@ function useBalances(addressesByToken) {
645
652
  balances: balances$1
646
653
  } = useDbCache();
647
654
  const hydrate = useBalancesHydrate();
648
- return react.useMemo(() => new balances.Balances(balances$1.filter(balance => {
655
+ return react.useMemo(() => new balances.Balances(balances.deriveStatuses([...balances.getValidSubscriptionIds()], balances$1.filter(balance => {
649
656
  // check that this balance is included in our queried balance modules
650
657
  if (!balanceModules.map(({
651
658
  type
@@ -662,7 +669,7 @@ function useBalances(addressesByToken) {
662
669
 
663
670
  // keep this balance
664
671
  return true;
665
- }),
672
+ })),
666
673
  // hydrate balance chains, evmNetworks, tokens and tokenRates
667
674
  hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
668
675
  }
@@ -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, rawBalances, tokenRates$1]);
187
+ }, 500, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
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, rawBalances, tokenList, tokenRates$1]);
196
+ }, [chainList, evmNetworkList, tokenList, tokenRates$1, rawBalances]);
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-pr669-20230403053044",
203
+ version: "0.0.0-pr675-20230413170259",
204
204
  author: "Talisman",
205
205
  homepage: "https://talisman.xyz",
206
206
  license: "UNLICENSED",
@@ -503,10 +503,25 @@ 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
+ };
506
520
  const updateDb = balances$1 => {
507
521
  const putBalances = Object.entries(balances$1.toJSON()).map(([id, balance]) => ({
508
522
  id,
509
- ...balance
523
+ ...balance,
524
+ status: balances.BalanceStatusLive(subscriptionId)
510
525
  }));
511
526
  balances.db.transaction("rw", balances.db.balances, async () => await balances.db.balances.bulkPut(putBalances));
512
527
  };
@@ -525,7 +540,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
525
540
  const unsub = balances.balances(balanceModule, addressesByModuleToken, (error, balances$1) => {
526
541
  // log errors
527
542
  if (error) {
528
- if (error?.type === "STALE_RPC_ERROR") return balances.db.balances.where({
543
+ if (error?.type === "STALE_RPC_ERROR" || error?.type === "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR") return balances.db.balances.where({
529
544
  source: balanceModule.type,
530
545
  chainId: error.chainId
531
546
  }).filter(balance => {
@@ -548,15 +563,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
548
563
  unsub.then(unsubscribe => {
549
564
  setTimeout(unsubscribe, 2_000);
550
565
  });
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
- });
566
+ balances.deleteSubscriptionId();
560
567
  };
561
568
  });
562
569
  const unsubscribeAll = () => {
@@ -645,7 +652,7 @@ function useBalances(addressesByToken) {
645
652
  balances: balances$1
646
653
  } = useDbCache();
647
654
  const hydrate = useBalancesHydrate();
648
- return react.useMemo(() => new balances.Balances(balances$1.filter(balance => {
655
+ return react.useMemo(() => new balances.Balances(balances.deriveStatuses([...balances.getValidSubscriptionIds()], balances$1.filter(balance => {
649
656
  // check that this balance is included in our queried balance modules
650
657
  if (!balanceModules.map(({
651
658
  type
@@ -662,7 +669,7 @@ function useBalances(addressesByToken) {
662
669
 
663
670
  // keep this balance
664
671
  return true;
665
- }),
672
+ })),
666
673
  // hydrate balance chains, evmNetworks, tokens and tokenRates
667
674
  hydrate), [balances$1, hydrate, balanceModules, addressesByToken]);
668
675
  }
@@ -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, Balances } 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';
@@ -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, rawBalances, tokenRates]);
178
+ }, 500, [chainList, evmNetworkList, tokenList, tokenRates, rawBalances]);
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, rawBalances, tokenList, tokenRates]);
187
+ }, [chainList, evmNetworkList, tokenList, tokenRates, rawBalances]);
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-pr669-20230403053044",
194
+ version: "0.0.0-pr675-20230413170259",
195
195
  author: "Talisman",
196
196
  homepage: "https://talisman.xyz",
197
197
  license: "UNLICENSED",
@@ -494,10 +494,25 @@ 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
+ };
497
511
  const updateDb = balances => {
498
512
  const putBalances = Object.entries(balances.toJSON()).map(([id, balance]) => ({
499
513
  id,
500
- ...balance
514
+ ...balance,
515
+ status: BalanceStatusLive(subscriptionId)
501
516
  }));
502
517
  db$1.transaction("rw", db$1.balances, async () => await db$1.balances.bulkPut(putBalances));
503
518
  };
@@ -516,7 +531,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
516
531
  const unsub = balances(balanceModule, addressesByModuleToken, (error, balances) => {
517
532
  // log errors
518
533
  if (error) {
519
- if (error?.type === "STALE_RPC_ERROR") return db$1.balances.where({
534
+ if (error?.type === "STALE_RPC_ERROR" || error?.type === "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR") return db$1.balances.where({
520
535
  source: balanceModule.type,
521
536
  chainId: error.chainId
522
537
  }).filter(balance => {
@@ -539,15 +554,7 @@ const subscribeBalances = (tokens, addresses, balanceModules) => {
539
554
  unsub.then(unsubscribe => {
540
555
  setTimeout(unsubscribe, 2_000);
541
556
  });
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
- });
557
+ deleteSubscriptionId();
551
558
  };
552
559
  });
553
560
  const unsubscribeAll = () => {
@@ -636,7 +643,7 @@ function useBalances(addressesByToken) {
636
643
  balances
637
644
  } = useDbCache();
638
645
  const hydrate = useBalancesHydrate();
639
- return useMemo(() => new Balances(balances.filter(balance => {
646
+ return useMemo(() => new Balances(deriveStatuses([...getValidSubscriptionIds()], balances.filter(balance => {
640
647
  // check that this balance is included in our queried balance modules
641
648
  if (!balanceModules.map(({
642
649
  type
@@ -653,7 +660,7 @@ function useBalances(addressesByToken) {
653
660
 
654
661
  // keep this balance
655
662
  return true;
656
- }),
663
+ })),
657
664
  // hydrate balance chains, evmNetworks, tokens and tokenRates
658
665
  hydrate), [balances, hydrate, balanceModules, addressesByToken]);
659
666
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances-react",
3
- "version": "0.0.0-pr669-20230403053044",
3
+ "version": "0.0.0-pr675-20230413170259",
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-pr669-20230403053044",
30
- "@talismn/chain-connector": "^0.0.0-pr669-20230403053044",
31
- "@talismn/chain-connector-evm": "^0.0.0-pr669-20230403053044",
32
- "@talismn/chaindata-provider": "^0.0.0-pr669-20230403053044",
33
- "@talismn/chaindata-provider-extension": "^0.0.0-pr669-20230403053044",
34
- "@talismn/connection-meta": "^0.0.0-pr669-20230403053044",
35
- "@talismn/token-rates": "^0.0.0-pr669-20230403053044",
29
+ "@talismn/balances": "^0.0.0-pr675-20230413170259",
30
+ "@talismn/chain-connector": "^0.0.0-pr675-20230413170259",
31
+ "@talismn/chain-connector-evm": "^0.0.0-pr675-20230413170259",
32
+ "@talismn/chaindata-provider": "^0.0.0-pr675-20230413170259",
33
+ "@talismn/chaindata-provider-extension": "^0.0.0-pr675-20230413170259",
34
+ "@talismn/connection-meta": "^0.0.0-pr675-20230413170259",
35
+ "@talismn/token-rates": "^0.0.0-pr675-20230413170259",
36
36
  "anylogger": "^1.0.11",
37
37
  "blueimp-md5": "2.19.0",
38
38
  "dexie": "^3.2.3",