@rango-dev/widget-embedded 0.37.1-next.0 → 0.37.1-next.2
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/containers/WidgetInfo/WidgetInfo.types.d.ts +2 -2
- package/dist/containers/WidgetInfo/WidgetInfo.types.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 +20 -0
- package/dist/store/slices/wallets.d.ts.map +1 -1
- package/dist/store/utils/wallets.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.tsx +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +2 -2
- package/src/store/slices/wallets.ts +89 -0
- package/src/store/utils/wallets.ts +4 -1
- package/src/utils/wallets.ts +4 -1
package/package.json
CHANGED
|
@@ -23,8 +23,8 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
23
23
|
const retrySwap = useQuoteStore.use.retry();
|
|
24
24
|
const {
|
|
25
25
|
findToken,
|
|
26
|
-
connectedWallets,
|
|
27
26
|
getBalances,
|
|
27
|
+
getConnectedWalletsDetails,
|
|
28
28
|
fetchBalances: refetch,
|
|
29
29
|
} = useAppStore();
|
|
30
30
|
|
|
@@ -49,7 +49,7 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
49
49
|
history,
|
|
50
50
|
wallets: {
|
|
51
51
|
isLoading,
|
|
52
|
-
details:
|
|
52
|
+
details: getConnectedWalletsDetails(),
|
|
53
53
|
totalBalance,
|
|
54
54
|
refetch: async (accounts) => refetch(accounts),
|
|
55
55
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WidgetHistory } from './WidgetInfo.helpers';
|
|
2
2
|
import type { FetchStatus, FindToken } from '../../store/slices/data';
|
|
3
|
-
import type {
|
|
3
|
+
import type { DeprecatedWalletDetail } from '../../store/slices/wallets';
|
|
4
4
|
import type { QuoteInputs, UpdateQuoteInputs, Wallet } from '../../types';
|
|
5
5
|
import type { Notification } from '../../types/notification';
|
|
6
6
|
import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
|
|
@@ -10,7 +10,7 @@ export interface WidgetInfoContextInterface {
|
|
|
10
10
|
setCurrentTabAsActive: () => void;
|
|
11
11
|
history: WidgetHistory;
|
|
12
12
|
wallets: {
|
|
13
|
-
details:
|
|
13
|
+
details: DeprecatedWalletDetail[];
|
|
14
14
|
totalBalance: string;
|
|
15
15
|
isLoading: boolean;
|
|
16
16
|
refetch: (accounts: Wallet[]) => void;
|
|
@@ -4,6 +4,7 @@ import type { StateCreator } from 'zustand';
|
|
|
4
4
|
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
|
|
7
|
+
import { ZERO } from '../../constants/numbers';
|
|
7
8
|
import { eventEmitter } from '../../services/eventEmitter';
|
|
8
9
|
import { httpService } from '../../services/httpService';
|
|
9
10
|
import {
|
|
@@ -46,6 +47,22 @@ export interface ConnectedWallet extends Wallet {
|
|
|
46
47
|
error: boolean;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
interface DeprecatedTokenBalance {
|
|
51
|
+
chain: string;
|
|
52
|
+
symbol: string;
|
|
53
|
+
ticker: string;
|
|
54
|
+
address: string | null;
|
|
55
|
+
rawAmount: string;
|
|
56
|
+
decimal: number | null;
|
|
57
|
+
amount: string;
|
|
58
|
+
logo: string | null;
|
|
59
|
+
usdPrice: number | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface DeprecatedWalletDetail extends ConnectedWallet {
|
|
63
|
+
balances: DeprecatedTokenBalance[] | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
49
66
|
export interface WalletsSlice {
|
|
50
67
|
_balances: BalanceState;
|
|
51
68
|
_aggregatedBalances: AggregatedBalanceState;
|
|
@@ -80,6 +97,13 @@ export interface WalletsSlice {
|
|
|
80
97
|
) => Promise<void>;
|
|
81
98
|
getBalanceFor: (token: Token) => Balance | null;
|
|
82
99
|
getBalances: () => BalanceState;
|
|
100
|
+
getBalancesForWalletAddress: (address: string) => BalanceState;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated
|
|
104
|
+
* This is been added for backward compatibilty for WidgetInfo
|
|
105
|
+
*/
|
|
106
|
+
getConnectedWalletsDetails: () => DeprecatedWalletDetail[];
|
|
83
107
|
}
|
|
84
108
|
|
|
85
109
|
export const createWalletsSlice: StateCreator<
|
|
@@ -485,4 +509,69 @@ export const createWalletsSlice: StateCreator<
|
|
|
485
509
|
});
|
|
486
510
|
return maxBalance;
|
|
487
511
|
},
|
|
512
|
+
getBalancesForWalletAddress: (address: string) => {
|
|
513
|
+
const balances = get().getBalances();
|
|
514
|
+
const balanceKeys = Object.keys(balances) as BalanceKey[];
|
|
515
|
+
|
|
516
|
+
const balancesForTargetWalletAddress = balanceKeys.reduce(
|
|
517
|
+
(output, balanceKey) => {
|
|
518
|
+
const balance = balances[balanceKey];
|
|
519
|
+
|
|
520
|
+
const [, , , balanceWalletAddreess] = balanceKey.split('-');
|
|
521
|
+
if (balanceWalletAddreess === address) {
|
|
522
|
+
output[balanceKey] = balance;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return output;
|
|
526
|
+
},
|
|
527
|
+
{} as BalanceState
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
return balancesForTargetWalletAddress;
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
getConnectedWalletsDetails: () => {
|
|
534
|
+
const connectedWallets = get().connectedWallets;
|
|
535
|
+
return connectedWallets.map((wallet) => {
|
|
536
|
+
const balances = get().getBalancesForWalletAddress(wallet.address);
|
|
537
|
+
const balancesKeys = Object.keys(balances) as BalanceKey[];
|
|
538
|
+
|
|
539
|
+
return {
|
|
540
|
+
...wallet,
|
|
541
|
+
balances: balancesKeys.reduce((output, balanceKey) => {
|
|
542
|
+
const balance = balances[balanceKey];
|
|
543
|
+
const asset = extractAssetFromBalanceKey(balanceKey);
|
|
544
|
+
|
|
545
|
+
if (asset.blockchain === wallet.chain) {
|
|
546
|
+
const token = get().findToken(asset);
|
|
547
|
+
|
|
548
|
+
if (!!token) {
|
|
549
|
+
const amount = balance.amount
|
|
550
|
+
? new BigNumber(balance.amount).shiftedBy(-balance.decimals)
|
|
551
|
+
: ZERO;
|
|
552
|
+
|
|
553
|
+
output.push({
|
|
554
|
+
chain: wallet.chain,
|
|
555
|
+
symbol: token.symbol,
|
|
556
|
+
ticker: token.symbol,
|
|
557
|
+
address: token.address,
|
|
558
|
+
rawAmount: balance.amount,
|
|
559
|
+
decimal: balance.decimals,
|
|
560
|
+
amount: amount.toString(),
|
|
561
|
+
logo: token.image,
|
|
562
|
+
usdPrice: token.usdPrice,
|
|
563
|
+
});
|
|
564
|
+
} else {
|
|
565
|
+
console.debug(
|
|
566
|
+
"Looking for asset but it couldn't be found in tokens store. May not be provided in meta.'",
|
|
567
|
+
asset
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return output;
|
|
573
|
+
}, [] as DeprecatedTokenBalance[]),
|
|
574
|
+
};
|
|
575
|
+
});
|
|
576
|
+
},
|
|
488
577
|
});
|
|
@@ -33,8 +33,11 @@ export function createBalanceKey(
|
|
|
33
33
|
|
|
34
34
|
export function extractAssetFromBalanceKey(key: BalanceKey): Asset {
|
|
35
35
|
const [assetChain, assetAddress, assetSymbol] = key.split('-');
|
|
36
|
+
|
|
37
|
+
// null will be serialized to 'null', we need to make it back to a null type
|
|
38
|
+
const address = assetAddress === 'null' ? null : assetAddress;
|
|
36
39
|
return {
|
|
37
|
-
address
|
|
40
|
+
address,
|
|
38
41
|
blockchain: assetChain,
|
|
39
42
|
symbol: assetSymbol,
|
|
40
43
|
};
|
package/src/utils/wallets.ts
CHANGED
|
@@ -280,7 +280,10 @@ export function resetConnectedWalletState(
|
|
|
280
280
|
|
|
281
281
|
export const calculateWalletUsdValue = (balances: BalanceState) => {
|
|
282
282
|
const total = Object.values(balances).reduce((prev, balance) => {
|
|
283
|
-
|
|
283
|
+
const formattedBalance = formatBalance(balance);
|
|
284
|
+
return formattedBalance?.usdValue
|
|
285
|
+
? prev.plus(formattedBalance.usdValue)
|
|
286
|
+
: prev;
|
|
284
287
|
}, new BigNumber(ZERO));
|
|
285
288
|
|
|
286
289
|
return numberWithThousandSeparator(total.toString());
|