@rango-dev/widget-embedded 0.39.1-next.13 → 0.39.1-next.15
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/dist/constants/wallets.d.ts +1 -0
- package/dist/constants/wallets.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/store/slices/wallets.d.ts +5 -4
- package/dist/store/slices/wallets.d.ts.map +1 -1
- package/dist/store/utils/wallets.d.ts +3 -3
- package/dist/store/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +1 -1
- package/src/constants/wallets.ts +2 -0
- package/src/store/slices/wallets.ts +8 -5
- package/src/store/utils/wallets.ts +12 -11
package/package.json
CHANGED
package/src/constants/wallets.ts
CHANGED
|
@@ -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
|
|
32
|
-
export type AssetKey =
|
|
33
|
-
|
|
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}
|
|
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;
|
|
@@ -575,7 +577,8 @@ export const createWalletsSlice: StateCreator<
|
|
|
575
577
|
(output, balanceKey) => {
|
|
576
578
|
const balance = balances[balanceKey];
|
|
577
579
|
|
|
578
|
-
const [, , , balanceWalletAddreess] =
|
|
580
|
+
const [, , , balanceWalletAddreess] =
|
|
581
|
+
balanceKey.split(BALANCE_SEPARATOR);
|
|
579
582
|
if (balanceWalletAddreess === address) {
|
|
580
583
|
output[balanceKey] = balance;
|
|
581
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
|
|
18
|
+
* output format: BlockchainId${BALANCE_SEPARATOR}TokenAddress${BALANCE_SEPARATOR}TokenSymbol
|
|
18
19
|
*/
|
|
19
20
|
export function createAssetKey(asset: Asset): AssetKey {
|
|
20
|
-
return `${asset.blockchain}
|
|
21
|
+
return `${asset.blockchain}${BALANCE_SEPARATOR}${asset.address}${BALANCE_SEPARATOR}${asset.symbol}`;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* output format: BlockchainId
|
|
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}
|
|
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;
|