@rango-dev/widget-embedded 0.39.1-next.12 → 0.39.1-next.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.39.1-next.12",
3
+ "version": "0.39.1-next.14",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -1,3 +1,5 @@
1
1
  import { WalletTypes } from '@rango-dev/wallets-shared';
2
2
 
3
+ export const BALANCE_SEPARATOR = '$$';
4
+
3
5
  export const EXCLUDED_WALLETS = [WalletTypes.LEAP];
@@ -6,6 +6,7 @@ import type { StateCreator } from 'zustand';
6
6
  import BigNumber from 'bignumber.js';
7
7
 
8
8
  import { ZERO } from '../../constants/numbers';
9
+ import { BALANCE_SEPARATOR } from '../../constants/wallets';
9
10
  import { eventEmitter } from '../../services/eventEmitter';
10
11
  import { httpService } from '../../services/httpService';
11
12
  import {
@@ -28,11 +29,12 @@ type WalletAddress = string;
28
29
  type TokenAddress = string;
29
30
  type TokenSymbol = string;
30
31
  type BlockchainId = string;
31
- /** format: `BlockchainId-TokenAddress-TokenSymbol` */
32
- export type AssetKey = `${BlockchainId}-${TokenAddress}-${TokenSymbol}`;
33
- /** format: `BlockchainId-TokenAddress-TokenSymbol-WalletAddress` */
32
+ /** format: `BlockchainId${BALANCE_SEPARATOR}TokenAddress${BALANCE_SEPARATOR}TokenSymbol` */
33
+ export type AssetKey =
34
+ `${BlockchainId}${typeof BALANCE_SEPARATOR}${TokenAddress}${typeof BALANCE_SEPARATOR}${TokenSymbol}`;
35
+ /** format: `BlockchainId${BALANCE_SEPARATOR}TokenAddress${BALANCE_SEPARATOR}TokenSymbol${BALANCE_SEPARATOR}WalletAddress` */
34
36
  export type BalanceKey =
35
- `${BlockchainId}-${TokenAddress}-${TokenSymbol}-${WalletAddress}`;
37
+ `${BlockchainId}${typeof BALANCE_SEPARATOR}${TokenAddress}${typeof BALANCE_SEPARATOR}${TokenSymbol}${typeof BALANCE_SEPARATOR}${WalletAddress}`;
36
38
 
37
39
  export type BalanceState = {
38
40
  [key: BalanceKey]: Balance;
@@ -485,6 +487,21 @@ export const createWalletsSlice: StateCreator<
485
487
  chains: [wallet.blockChain],
486
488
  });
487
489
 
490
+ /*
491
+ * Check if after fetching balance for an account, the account still exists.
492
+ * (It might get disconnected while fetching balances is pending)
493
+ */
494
+ if (
495
+ !get().connectedWallets.find(
496
+ (connectedWallet) =>
497
+ connectedWallet.walletType === walletType &&
498
+ connectedWallet.address === wallet.address &&
499
+ connectedWallet.chain === wallet.blockChain
500
+ )
501
+ ) {
502
+ return;
503
+ }
504
+
488
505
  const balancesForWallet = createBalanceStateForNewAccount(wallet, get);
489
506
 
490
507
  nextAggregatedBalances = updateAggregatedBalanceStateForNewAccount(
@@ -560,7 +577,8 @@ export const createWalletsSlice: StateCreator<
560
577
  (output, balanceKey) => {
561
578
  const balance = balances[balanceKey];
562
579
 
563
- const [, , , balanceWalletAddreess] = balanceKey.split('-');
580
+ const [, , , balanceWalletAddreess] =
581
+ balanceKey.split(BALANCE_SEPARATOR);
564
582
  if (balanceWalletAddreess === address) {
565
583
  output[balanceKey] = balance;
566
584
  }
@@ -1,38 +1,39 @@
1
1
  import type { Balance } from '../../types';
2
2
  import type { AppStoreState } from '../app';
3
- import type {
4
- AggregatedBalanceState,
5
- AssetKey,
6
- BalanceKey,
7
- BalanceState,
8
- } from '../slices/wallets';
9
3
  import type { Asset, WalletDetail } from 'rango-types';
10
4
 
11
5
  import BigNumber from 'bignumber.js';
12
6
 
13
7
  import { ZERO } from '../../constants/numbers';
8
+ import { BALANCE_SEPARATOR } from '../../constants/wallets';
9
+ import {
10
+ type AggregatedBalanceState,
11
+ type AssetKey,
12
+ type BalanceKey,
13
+ type BalanceState,
14
+ } from '../slices/wallets';
14
15
 
15
16
  /**
16
17
  * Note: We need to use `symbol` as well since native coins and cosmos blockchains don't have `address`
17
- * output format: BlockchainId-TokenAddress-TokenSymbol
18
+ * output format: BlockchainId${BALANCE_SEPARATOR}TokenAddress${BALANCE_SEPARATOR}TokenSymbol
18
19
  */
19
20
  export function createAssetKey(asset: Asset): AssetKey {
20
- return `${asset.blockchain}-${asset.address}-${asset.symbol}`;
21
+ return `${asset.blockchain}${BALANCE_SEPARATOR}${asset.address}${BALANCE_SEPARATOR}${asset.symbol}`;
21
22
  }
22
23
 
23
24
  /**
24
- * output format: BlockchainId-TokenAddress-TokenSymbol-WalletAddress
25
+ * output format: BlockchainId${BALANCE_SEPARATOR}TokenAddress${BALANCE_SEPARATOR}TokenSymbol${BALANCE_SEPARATOR}WalletAddress
25
26
  */
26
27
  export function createBalanceKey(
27
28
  accountAddress: string,
28
29
  asset: Asset
29
30
  ): BalanceKey {
30
31
  const assetKey = createAssetKey(asset);
31
- return `${assetKey}-${accountAddress}`;
32
+ return `${assetKey}${BALANCE_SEPARATOR}${accountAddress}`;
32
33
  }
33
34
 
34
35
  export function extractAssetFromBalanceKey(key: BalanceKey): Asset {
35
- const [assetChain, assetAddress, assetSymbol] = key.split('-');
36
+ const [assetChain, assetAddress, assetSymbol] = key.split(BALANCE_SEPARATOR);
36
37
 
37
38
  // null will be serialized to 'null', we need to make it back to a null type
38
39
  const address = assetAddress === 'null' ? null : assetAddress;