@rango-dev/widget-embedded 0.38.1-next.9 → 0.39.0
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/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/Quote/Quote.types.d.ts +0 -2
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts +2 -1
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +1 -2
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +0 -10
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/constants/warnings.d.ts +3 -0
- package/dist/constants/warnings.d.ts.map +1 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +4 -6
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
- package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +2 -0
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +1 -0
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +4 -0
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -2
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -3
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +3 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +4 -2
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +0 -4
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/ui.d.ts +0 -4
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +66 -0
- package/dist/store/wallets.d.ts.map +1 -0
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/quote.d.ts +17 -8
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +7 -3
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +9 -7
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +6 -5
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +5 -5
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +14 -12
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -7
- package/src/QueueManager.tsx +11 -17
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +24 -5
- package/src/components/ConfirmWalletsModal/WalletList.tsx +13 -13
- package/src/components/Layout/Layout.tsx +3 -1
- package/src/components/Quote/Quote.tsx +3 -22
- package/src/components/Quote/Quote.types.ts +0 -2
- package/src/components/Quote/QuoteCostDetails.styles.ts +1 -0
- package/src/components/Quote/QuoteCostDetails.tsx +4 -23
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +22 -42
- package/src/components/Quotes/Quotes.tsx +3 -2
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +37 -40
- package/src/components/SwapDetails/SwapDetails.tsx +6 -14
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +13 -26
- package/src/components/TokenList/TokenList.tsx +27 -4
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +1 -2
- package/src/components/WalletStatefulConnect/Namespaces.tsx +38 -31
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
- package/src/constants/quote.ts +0 -25
- package/src/constants/warnings.ts +26 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +0 -1
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
- package/src/containers/Inputs/Inputs.tsx +7 -20
- package/src/containers/QuoteInfo/QuoteInfo.tsx +9 -3
- package/src/containers/Wallets/Wallets.tsx +16 -76
- package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.tsx +8 -10
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +66 -29
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +15 -10
- package/src/hooks/useFetchApiConfig.ts +1 -5
- package/src/hooks/useFetchCustomToken.ts +0 -5
- package/src/hooks/useObserveBalanceChanges/index.ts +1 -0
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +68 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +17 -50
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +5 -3
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +6 -7
- package/src/hooks/useSwapInput.ts +11 -3
- package/src/hooks/useWalletList.ts +13 -4
- package/src/hooks/useWalletProviders/useWalletProviders.ts +12 -8
- package/src/index.ts +1 -1
- package/src/pages/ConfirmSwapPage.tsx +15 -7
- package/src/pages/Home.tsx +3 -5
- package/src/pages/SelectSwapItemsPage.tsx +2 -1
- package/src/store/app.ts +4 -4
- package/src/store/quote.ts +13 -3
- package/src/store/slices/config.ts +0 -72
- package/src/store/slices/data.test.ts +1 -20
- package/src/store/slices/data.ts +2 -3
- package/src/store/ui.ts +0 -6
- package/src/store/wallets.ts +268 -0
- package/src/types/config.ts +2 -2
- package/src/types/quote.ts +24 -10
- package/src/types/wallets.ts +7 -3
- package/src/utils/providers.ts +37 -78
- package/src/utils/quote.ts +45 -57
- package/src/utils/swap.ts +37 -56
- package/src/utils/wallets.ts +141 -81
- package/dist/store/slices/types.d.ts +0 -6
- package/dist/store/slices/types.d.ts.map +0 -1
- package/dist/store/slices/wallets.d.ts +0 -80
- package/dist/store/slices/wallets.d.ts.map +0 -1
- package/dist/store/utils/wallets.d.ts +0 -17
- package/dist/store/utils/wallets.d.ts.map +0 -1
- package/src/store/slices/types.ts +0 -9
- package/src/store/slices/wallets.ts +0 -577
- package/src/store/utils/wallets.ts +0 -111
package/src/utils/wallets.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FindToken } from '../store/slices/data';
|
|
2
|
+
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
2
3
|
import type {
|
|
3
4
|
Balance,
|
|
4
5
|
SelectedQuote,
|
|
6
|
+
TokensBalance,
|
|
5
7
|
Wallet,
|
|
6
8
|
WalletInfoWithExtra,
|
|
7
9
|
} from '../types';
|
|
8
|
-
import type {
|
|
10
|
+
import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
|
|
9
11
|
import type {
|
|
10
12
|
Network,
|
|
13
|
+
WalletInfo,
|
|
11
14
|
WalletState,
|
|
12
15
|
WalletType,
|
|
13
16
|
WalletTypes,
|
|
14
17
|
} from '@rango-dev/wallets-shared';
|
|
15
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
BlockchainMeta,
|
|
20
|
+
Token,
|
|
21
|
+
TransactionType,
|
|
22
|
+
WalletDetail,
|
|
23
|
+
} from 'rango-sdk';
|
|
16
24
|
|
|
17
25
|
import {
|
|
18
26
|
BlockchainCategories,
|
|
@@ -39,11 +47,9 @@ import {
|
|
|
39
47
|
import { EXCLUDED_WALLETS } from '../constants/wallets';
|
|
40
48
|
|
|
41
49
|
import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
|
|
50
|
+
import { createTokenHash } from './meta';
|
|
42
51
|
import { numberToString } from './numbers';
|
|
43
52
|
|
|
44
|
-
export type ExtendedModalWalletInfo = WalletInfoWithExtra &
|
|
45
|
-
Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
|
|
46
|
-
|
|
47
53
|
export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
48
54
|
switch (true) {
|
|
49
55
|
case state.connected:
|
|
@@ -59,10 +65,10 @@ export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
|
59
65
|
|
|
60
66
|
export function mapWalletTypesToWalletInfo(
|
|
61
67
|
getState: (type: WalletType) => WalletState,
|
|
62
|
-
getWalletInfo: (type: WalletType) =>
|
|
68
|
+
getWalletInfo: (type: WalletType) => WalletInfo,
|
|
63
69
|
list: WalletType[],
|
|
64
70
|
chain?: string
|
|
65
|
-
):
|
|
71
|
+
): WalletInfoWithExtra[] {
|
|
66
72
|
return list
|
|
67
73
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
68
74
|
.filter((wallet) => {
|
|
@@ -87,11 +93,10 @@ export function mapWalletTypesToWalletInfo(
|
|
|
87
93
|
img: image,
|
|
88
94
|
installLink,
|
|
89
95
|
showOnMobile,
|
|
90
|
-
|
|
96
|
+
namespaces,
|
|
97
|
+
singleNamespace,
|
|
91
98
|
supportedChains,
|
|
92
99
|
needsDerivationPath,
|
|
93
|
-
properties,
|
|
94
|
-
isHub,
|
|
95
100
|
} = getWalletInfo(type);
|
|
96
101
|
const blockchainTypes = removeDuplicateFrom(
|
|
97
102
|
supportedChains.map((item) => item.type)
|
|
@@ -105,11 +110,10 @@ export function mapWalletTypesToWalletInfo(
|
|
|
105
110
|
state,
|
|
106
111
|
type,
|
|
107
112
|
showOnMobile,
|
|
108
|
-
|
|
113
|
+
namespaces,
|
|
114
|
+
singleNamespace,
|
|
109
115
|
blockchainTypes,
|
|
110
116
|
needsDerivationPath,
|
|
111
|
-
properties,
|
|
112
|
-
isHub,
|
|
113
117
|
};
|
|
114
118
|
});
|
|
115
119
|
}
|
|
@@ -261,6 +265,8 @@ export function getQuoteWallets(params: {
|
|
|
261
265
|
return Array.from(wallets);
|
|
262
266
|
}
|
|
263
267
|
|
|
268
|
+
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
269
|
+
|
|
264
270
|
export function isAccountAndWalletMatched(
|
|
265
271
|
account: Wallet,
|
|
266
272
|
connectedWallet: ConnectedWallet
|
|
@@ -272,21 +278,74 @@ export function isAccountAndWalletMatched(
|
|
|
272
278
|
);
|
|
273
279
|
}
|
|
274
280
|
|
|
281
|
+
export function makeBalanceFor(
|
|
282
|
+
retrievedBalance: WalletDetail,
|
|
283
|
+
findToken: FindToken
|
|
284
|
+
): TokenBalance[] {
|
|
285
|
+
const { blockChain: chain, balances = [] } = retrievedBalance;
|
|
286
|
+
return (
|
|
287
|
+
balances?.map((tokenBalance) => ({
|
|
288
|
+
chain,
|
|
289
|
+
symbol: tokenBalance.asset.symbol,
|
|
290
|
+
ticker: tokenBalance.asset.symbol,
|
|
291
|
+
address: tokenBalance.asset.address || null,
|
|
292
|
+
rawAmount: tokenBalance.amount.amount,
|
|
293
|
+
decimal: tokenBalance.amount.decimals,
|
|
294
|
+
amount: new BigNumber(tokenBalance.amount.amount)
|
|
295
|
+
.shiftedBy(-tokenBalance.amount.decimals)
|
|
296
|
+
.toFixed(),
|
|
297
|
+
logo: '',
|
|
298
|
+
usdPrice: findToken(tokenBalance.asset)?.usdPrice || null,
|
|
299
|
+
})) || []
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
275
303
|
export function resetConnectedWalletState(
|
|
276
304
|
connectedWallet: ConnectedWallet
|
|
277
305
|
): ConnectedWallet {
|
|
278
306
|
return { ...connectedWallet, loading: false, error: true };
|
|
279
307
|
}
|
|
280
308
|
|
|
281
|
-
export const calculateWalletUsdValue = (
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
309
|
+
export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
|
|
310
|
+
const uniqueAccountAddresses = new Set<string | null>();
|
|
311
|
+
const uniqueBalance: ConnectedWallet[] = connectedWallet?.reduce(
|
|
312
|
+
(acc: ConnectedWallet[], current: ConnectedWallet) => {
|
|
313
|
+
return acc.findIndex(
|
|
314
|
+
(i) => i.address === current.address && i.chain === current.chain
|
|
315
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
316
|
+
) === -1
|
|
317
|
+
? [...acc, current]
|
|
318
|
+
: acc;
|
|
319
|
+
},
|
|
320
|
+
[]
|
|
321
|
+
);
|
|
288
322
|
|
|
289
|
-
|
|
323
|
+
const modifiedWalletBlockchains = uniqueBalance?.map((chain) => {
|
|
324
|
+
const modifiedWalletBlockchain: Blockchain = {
|
|
325
|
+
name: chain.chain,
|
|
326
|
+
accounts: [],
|
|
327
|
+
};
|
|
328
|
+
if (!uniqueAccountAddresses.has(chain.address)) {
|
|
329
|
+
uniqueAccountAddresses.add(chain.address);
|
|
330
|
+
}
|
|
331
|
+
uniqueAccountAddresses.forEach((accountAddress) => {
|
|
332
|
+
if (chain.address === accountAddress) {
|
|
333
|
+
modifiedWalletBlockchain.accounts.push(chain);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return modifiedWalletBlockchain;
|
|
337
|
+
});
|
|
338
|
+
const total = numberToString(
|
|
339
|
+
modifiedWalletBlockchains
|
|
340
|
+
?.flatMap((b) => b.accounts)
|
|
341
|
+
?.flatMap((a) => a?.balances)
|
|
342
|
+
?.map((b) =>
|
|
343
|
+
new BigNumber(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0)
|
|
344
|
+
)
|
|
345
|
+
?.reduce((a, b) => a.plus(b), ZERO) || ZERO
|
|
346
|
+
).toString();
|
|
347
|
+
|
|
348
|
+
return numberWithThousandSeparator(total);
|
|
290
349
|
};
|
|
291
350
|
|
|
292
351
|
function numberWithThousandSeparator(number: string | number): string {
|
|
@@ -324,34 +383,20 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
324
383
|
);
|
|
325
384
|
};
|
|
326
385
|
|
|
327
|
-
function representAmountInNumber(amount: string, decimals: number): string {
|
|
328
|
-
return new BigNumber(amount).shiftedBy(-decimals).toFixed();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
386
|
export function formatBalance(balance: Balance | null): Balance | null {
|
|
332
|
-
if (!balance) {
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const amount = representAmountInNumber(balance.amount, balance.decimals);
|
|
337
|
-
const usdValue = balance.usdValue
|
|
338
|
-
? representAmountInNumber(balance.usdValue, balance.decimals)
|
|
339
|
-
: null;
|
|
340
|
-
const formattedAmount = numberToString(
|
|
341
|
-
amount,
|
|
342
|
-
BALANCE_MIN_DECIMALS,
|
|
343
|
-
BALANCE_MAX_DECIMALS
|
|
344
|
-
);
|
|
345
|
-
// null is using for detecing uknown prices
|
|
346
|
-
const formattedUsdValue = usdValue
|
|
347
|
-
? numberToString(usdValue, USD_VALUE_MIN_DECIMALS, USD_VALUE_MAX_DECIMALS)
|
|
348
|
-
: null;
|
|
349
|
-
|
|
350
387
|
const formattedBalance: Balance | null = balance
|
|
351
388
|
? {
|
|
352
389
|
...balance,
|
|
353
|
-
amount:
|
|
354
|
-
|
|
390
|
+
amount: numberToString(
|
|
391
|
+
balance.amount,
|
|
392
|
+
BALANCE_MIN_DECIMALS,
|
|
393
|
+
BALANCE_MAX_DECIMALS
|
|
394
|
+
),
|
|
395
|
+
usdValue: numberToString(
|
|
396
|
+
balance.usdValue,
|
|
397
|
+
USD_VALUE_MIN_DECIMALS,
|
|
398
|
+
USD_VALUE_MAX_DECIMALS
|
|
399
|
+
),
|
|
355
400
|
}
|
|
356
401
|
: null;
|
|
357
402
|
|
|
@@ -363,39 +408,17 @@ export function compareTokenBalance(
|
|
|
363
408
|
token2Balance: Balance | null
|
|
364
409
|
): number {
|
|
365
410
|
if (token1Balance?.usdValue || token2Balance?.usdValue) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
)
|
|
371
|
-
: ZERO;
|
|
372
|
-
const token2UsdValue =
|
|
373
|
-
!!token2Balance && !!token2Balance.usdValue
|
|
374
|
-
? new BigNumber(token2Balance.usdValue).shiftedBy(
|
|
375
|
-
-token2Balance.decimals
|
|
376
|
-
)
|
|
377
|
-
: ZERO;
|
|
378
|
-
|
|
379
|
-
if (token1UsdValue.isEqualTo(token2UsdValue)) {
|
|
380
|
-
return 0;
|
|
381
|
-
}
|
|
382
|
-
return token1UsdValue.isGreaterThan(token2UsdValue) ? -1 : 1;
|
|
411
|
+
return (
|
|
412
|
+
parseFloat(token2Balance?.usdValue || '0') -
|
|
413
|
+
parseFloat(token1Balance?.usdValue || '0')
|
|
414
|
+
);
|
|
383
415
|
}
|
|
384
416
|
|
|
385
417
|
if (token1Balance?.amount || token2Balance?.amount) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const token2Amount =
|
|
391
|
-
!!token2Balance && !!token2Balance.amount
|
|
392
|
-
? new BigNumber(token2Balance.amount).shiftedBy(-token2Balance.decimals)
|
|
393
|
-
: ZERO;
|
|
394
|
-
|
|
395
|
-
if (token1Amount.isEqualTo(token2Amount)) {
|
|
396
|
-
return 0;
|
|
397
|
-
}
|
|
398
|
-
return token1Amount.isGreaterThan(token2Amount) ? -1 : 1;
|
|
418
|
+
return (
|
|
419
|
+
parseFloat(token2Balance?.amount || '0') -
|
|
420
|
+
parseFloat(token1Balance?.amount || '0')
|
|
421
|
+
);
|
|
399
422
|
}
|
|
400
423
|
|
|
401
424
|
return 0;
|
|
@@ -413,8 +436,8 @@ export function areTokensEqual(
|
|
|
413
436
|
}
|
|
414
437
|
|
|
415
438
|
export function sortWalletsBasedOnConnectionState(
|
|
416
|
-
wallets:
|
|
417
|
-
):
|
|
439
|
+
wallets: WalletInfoWithExtra[]
|
|
440
|
+
): WalletInfoWithExtra[] {
|
|
418
441
|
return wallets.sort(
|
|
419
442
|
(a, b) =>
|
|
420
443
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
@@ -461,6 +484,43 @@ export function getAddress({
|
|
|
461
484
|
)?.address;
|
|
462
485
|
}
|
|
463
486
|
|
|
487
|
+
export function makeTokensBalance(connectedWallets: ConnectedWallet[]) {
|
|
488
|
+
return connectedWallets
|
|
489
|
+
.flatMap((wallet) => wallet.balances)
|
|
490
|
+
.reduce((balances: TokensBalance, balance) => {
|
|
491
|
+
const currentBalance = {
|
|
492
|
+
amount: balance?.amount ?? '',
|
|
493
|
+
decimals: balance?.decimal ?? 0,
|
|
494
|
+
usdValue: balance?.usdPrice
|
|
495
|
+
? new BigNumber(balance?.usdPrice ?? ZERO)
|
|
496
|
+
.multipliedBy(balance?.amount)
|
|
497
|
+
.toString()
|
|
498
|
+
: '',
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
const tokenHash = balance
|
|
502
|
+
? createTokenHash({
|
|
503
|
+
symbol: balance.symbol,
|
|
504
|
+
blockchain: balance.chain,
|
|
505
|
+
address: balance.address,
|
|
506
|
+
})
|
|
507
|
+
: null;
|
|
508
|
+
|
|
509
|
+
const prevBalance = tokenHash ? balances[tokenHash] : null;
|
|
510
|
+
|
|
511
|
+
const shouldUpdateBalance =
|
|
512
|
+
tokenHash &&
|
|
513
|
+
(!prevBalance ||
|
|
514
|
+
(prevBalance && prevBalance.amount < currentBalance.amount));
|
|
515
|
+
|
|
516
|
+
if (shouldUpdateBalance) {
|
|
517
|
+
balances[tokenHash] = currentBalance;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return balances;
|
|
521
|
+
}, {});
|
|
522
|
+
}
|
|
523
|
+
|
|
464
524
|
export const isFetchingBalance = (
|
|
465
525
|
connectedWallets: ConnectedWallet[],
|
|
466
526
|
blockchain: string
|
|
@@ -469,12 +529,12 @@ export const isFetchingBalance = (
|
|
|
469
529
|
(wallet) => wallet.chain === blockchain && wallet.loading
|
|
470
530
|
);
|
|
471
531
|
|
|
472
|
-
export function hashWalletsState(walletsInfo:
|
|
532
|
+
export function hashWalletsState(walletsInfo: ModalWalletInfo[]) {
|
|
473
533
|
return walletsInfo.map((w) => w.state).join('-');
|
|
474
534
|
}
|
|
475
535
|
|
|
476
536
|
export function filterBlockchainsByWalletTypes(
|
|
477
|
-
wallets:
|
|
537
|
+
wallets: ModalWalletInfo[],
|
|
478
538
|
blockchains: BlockchainMeta[]
|
|
479
539
|
) {
|
|
480
540
|
const uniqueBlockchainTypes = new Set<TransactionType>();
|
|
@@ -491,7 +551,7 @@ export function filterBlockchainsByWalletTypes(
|
|
|
491
551
|
}
|
|
492
552
|
|
|
493
553
|
export function filterWalletsByCategory(
|
|
494
|
-
wallets:
|
|
554
|
+
wallets: WalletInfoWithExtra[],
|
|
495
555
|
category: string
|
|
496
556
|
) {
|
|
497
557
|
if (category === BlockchainCategories.ALL) {
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ConfigSlice } from './config';
|
|
2
|
-
import type { DataSlice } from './data';
|
|
3
|
-
import type { SettingsSlice } from './settings';
|
|
4
|
-
import type { WalletsSlice } from './wallets';
|
|
5
|
-
export type AppStoreState = DataSlice & ConfigSlice & SettingsSlice & WalletsSlice;
|
|
6
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/store/slices/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG,SAAS,GACnC,WAAW,GACX,aAAa,GACb,YAAY,CAAC"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { AppStoreState } from './types';
|
|
2
|
-
import type { Token } from 'rango-sdk';
|
|
3
|
-
import type { StateCreator } from 'zustand';
|
|
4
|
-
import { type Balance, type Wallet } from '../../types';
|
|
5
|
-
type WalletAddress = string;
|
|
6
|
-
type TokenAddress = string;
|
|
7
|
-
type TokenSymbol = string;
|
|
8
|
-
type BlockchainId = string;
|
|
9
|
-
/** format: `BlockchainId-TokenAddress-TokenSymbol` */
|
|
10
|
-
export type AssetKey = `${BlockchainId}-${TokenAddress}-${TokenSymbol}`;
|
|
11
|
-
/** format: `BlockchainId-TokenAddress-TokenSymbol-WalletAddress` */
|
|
12
|
-
export type BalanceKey = `${BlockchainId}-${TokenAddress}-${TokenSymbol}-${WalletAddress}`;
|
|
13
|
-
export type BalanceState = {
|
|
14
|
-
[key: BalanceKey]: Balance;
|
|
15
|
-
};
|
|
16
|
-
export type AggregatedBalanceState = {
|
|
17
|
-
[key: AssetKey]: BalanceKey[];
|
|
18
|
-
};
|
|
19
|
-
export interface ConnectedWallet extends Wallet {
|
|
20
|
-
explorerUrl: string | null;
|
|
21
|
-
selected: boolean;
|
|
22
|
-
loading: boolean;
|
|
23
|
-
error: boolean;
|
|
24
|
-
}
|
|
25
|
-
interface DeprecatedTokenBalance {
|
|
26
|
-
chain: string;
|
|
27
|
-
symbol: string;
|
|
28
|
-
ticker: string;
|
|
29
|
-
address: string | null;
|
|
30
|
-
rawAmount: string;
|
|
31
|
-
decimal: number | null;
|
|
32
|
-
amount: string;
|
|
33
|
-
logo: string | null;
|
|
34
|
-
usdPrice: number | null;
|
|
35
|
-
}
|
|
36
|
-
export interface DeprecatedWalletDetail extends ConnectedWallet {
|
|
37
|
-
balances: DeprecatedTokenBalance[] | null;
|
|
38
|
-
}
|
|
39
|
-
export interface WalletsSlice {
|
|
40
|
-
_balances: BalanceState;
|
|
41
|
-
_aggregatedBalances: AggregatedBalanceState;
|
|
42
|
-
connectedWallets: ConnectedWallet[];
|
|
43
|
-
fetchingWallets: boolean;
|
|
44
|
-
setConnectedWalletAsRefetching: (walletType: string) => void;
|
|
45
|
-
setConnectedWalletHasError: (walletType: string) => void;
|
|
46
|
-
setConnectedWalletRetrievedData: (walletType: string) => void;
|
|
47
|
-
removeBalancesForWallet: (walletType: string, options?: {
|
|
48
|
-
chains?: string[];
|
|
49
|
-
}) => void;
|
|
50
|
-
addConnectedWallet: (accounts: Wallet[]) => void;
|
|
51
|
-
setWalletsAsSelected: (wallets: {
|
|
52
|
-
walletType: string;
|
|
53
|
-
chain: string;
|
|
54
|
-
}[]) => void;
|
|
55
|
-
/**
|
|
56
|
-
* Add new accounts to store and fetch balances for them.
|
|
57
|
-
*/
|
|
58
|
-
newWalletConnected: (accounts: Wallet[]) => Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Disconnect a wallet and clean up balances after that.
|
|
61
|
-
*/
|
|
62
|
-
disconnectWallet: (walletType: string) => void;
|
|
63
|
-
clearConnectedWallet: () => void;
|
|
64
|
-
fetchBalances: (accounts: Wallet[], options?: {
|
|
65
|
-
retryOnFailedBalances?: boolean;
|
|
66
|
-
}) => Promise<void>;
|
|
67
|
-
getBalanceFor: (token: Token) => Balance | null;
|
|
68
|
-
getBalances: () => BalanceState;
|
|
69
|
-
getBalancesForWalletAddress: (address: string) => BalanceState;
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated
|
|
72
|
-
* This is been added for backward compatibilty for WidgetInfo
|
|
73
|
-
*/
|
|
74
|
-
getConnectedWalletsDetails: () => DeprecatedWalletDetail[];
|
|
75
|
-
}
|
|
76
|
-
export declare const createWalletsSlice: StateCreator<AppStoreState, [
|
|
77
|
-
], [
|
|
78
|
-
], WalletsSlice>;
|
|
79
|
-
export {};
|
|
80
|
-
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../../src/store/slices/wallets.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AppStoreState } from '../app';
|
|
2
|
-
import type { AggregatedBalanceState, AssetKey, BalanceKey, BalanceState } from '../slices/wallets';
|
|
3
|
-
import type { Asset, WalletDetail } from 'rango-types';
|
|
4
|
-
/**
|
|
5
|
-
* Note: We need to use `symbol` as well since native coins and cosmos blockchains don't have `address`
|
|
6
|
-
* output format: BlockchainId-TokenAddress-TokenSymbol
|
|
7
|
-
*/
|
|
8
|
-
export declare function createAssetKey(asset: Asset): AssetKey;
|
|
9
|
-
/**
|
|
10
|
-
* output format: BlockchainId-TokenAddress-TokenSymbol-WalletAddress
|
|
11
|
-
*/
|
|
12
|
-
export declare function createBalanceKey(accountAddress: string, asset: Asset): BalanceKey;
|
|
13
|
-
export declare function extractAssetFromBalanceKey(key: BalanceKey): Asset;
|
|
14
|
-
export declare function createBalanceStateForNewAccount(account: WalletDetail, store: () => AppStoreState): BalanceState;
|
|
15
|
-
export declare function updateAggregatedBalanceStateForNewAccount(aggregatedBalances: AggregatedBalanceState, balanceState: BalanceState): AggregatedBalanceState;
|
|
16
|
-
export declare function removeBalanceFromAggregatedBalance(aggregatedBalances: AggregatedBalanceState, balanceKey: BalanceKey): AggregatedBalanceState;
|
|
17
|
-
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../../src/store/utils/wallets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EACV,sBAAsB,EACtB,QAAQ,EACR,UAAU,EACV,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMvD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAErD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,KAAK,GACX,UAAU,CAGZ;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,UAAU,GAAG,KAAK,CAUjE;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,MAAM,aAAa,GACzB,YAAY,CAuBd;AAED,wBAAgB,yCAAyC,CACvD,kBAAkB,EAAE,sBAAsB,EAC1C,YAAY,EAAE,YAAY,0BAmB3B;AAED,wBAAgB,kCAAkC,CAChD,kBAAkB,EAAE,sBAAsB,EAC1C,UAAU,EAAE,UAAU,0BAYvB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ConfigSlice } from './config';
|
|
2
|
-
import type { DataSlice } from './data';
|
|
3
|
-
import type { SettingsSlice } from './settings';
|
|
4
|
-
import type { WalletsSlice } from './wallets';
|
|
5
|
-
|
|
6
|
-
export type AppStoreState = DataSlice &
|
|
7
|
-
ConfigSlice &
|
|
8
|
-
SettingsSlice &
|
|
9
|
-
WalletsSlice;
|