@rango-dev/widget-embedded 0.39.0 → 0.39.1-next.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/CHANGELOG.md +4 -0
- 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 +2 -0
- 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 +1 -2
- 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 +2 -1
- 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 +10 -0
- package/dist/constants/quote.d.ts.map +1 -1
- 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 +6 -4
- 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/useStatefulConnect/useStatefulConnect.d.ts +2 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +3 -5
- 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 +2 -3
- 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 +2 -4
- 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 +4 -0
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/slices/types.d.ts +6 -0
- package/dist/store/slices/types.d.ts.map +1 -0
- package/dist/store/slices/wallets.d.ts +80 -0
- package/dist/store/slices/wallets.d.ts.map +1 -0
- package/dist/store/ui.d.ts +4 -0
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/utils/wallets.d.ts +17 -0
- package/dist/store/utils/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 +8 -17
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +3 -7
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +7 -9
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +5 -6
- 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 +12 -14
- 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 +17 -11
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -24
- package/src/components/ConfirmWalletsModal/WalletList.tsx +13 -13
- package/src/components/Layout/Layout.tsx +1 -3
- package/src/components/Quote/Quote.tsx +22 -3
- package/src/components/Quote/Quote.types.ts +2 -0
- package/src/components/Quote/QuoteCostDetails.styles.ts +0 -1
- package/src/components/Quote/QuoteCostDetails.tsx +23 -4
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
- package/src/components/Quotes/Quotes.tsx +2 -3
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +40 -37
- package/src/components/SwapDetails/SwapDetails.tsx +14 -6
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +26 -13
- package/src/components/TokenList/TokenList.tsx +4 -27
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +2 -1
- package/src/components/WalletStatefulConnect/Namespaces.tsx +31 -38
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
- package/src/constants/quote.ts +25 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +1 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
- package/src/containers/Inputs/Inputs.tsx +20 -7
- package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
- package/src/containers/Wallets/Wallets.tsx +76 -16
- package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
- package/src/hooks/useFetchApiConfig.ts +5 -1
- package/src/hooks/useFetchCustomToken.ts +5 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +50 -17
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +3 -5
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
- package/src/hooks/useSwapInput.ts +3 -11
- package/src/hooks/useWalletList.ts +4 -13
- package/src/hooks/useWalletProviders/useWalletProviders.ts +8 -12
- package/src/index.ts +1 -1
- package/src/pages/ConfirmSwapPage.tsx +7 -15
- package/src/pages/Home.tsx +5 -3
- package/src/pages/SelectSwapItemsPage.tsx +1 -2
- package/src/store/app.ts +4 -4
- package/src/store/quote.ts +3 -13
- package/src/store/slices/config.ts +72 -0
- package/src/store/slices/data.test.ts +20 -1
- package/src/store/slices/data.ts +3 -2
- package/src/store/slices/types.ts +9 -0
- package/src/store/slices/wallets.ts +577 -0
- package/src/store/ui.ts +6 -0
- package/src/store/utils/wallets.ts +111 -0
- package/src/types/config.ts +2 -2
- package/src/types/quote.ts +10 -24
- package/src/types/wallets.ts +3 -7
- package/src/utils/providers.ts +78 -37
- package/src/utils/quote.ts +57 -45
- package/src/utils/swap.ts +56 -37
- package/src/utils/wallets.ts +81 -141
- package/dist/constants/warnings.d.ts +0 -3
- package/dist/constants/warnings.d.ts.map +0 -1
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
- package/dist/store/wallets.d.ts +0 -66
- package/dist/store/wallets.d.ts.map +0 -1
- package/src/constants/warnings.ts +0 -26
- package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
- package/src/store/wallets.ts +0 -268
package/src/utils/wallets.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
1
|
+
import type { BalanceState, ConnectedWallet } from '../store/slices/wallets';
|
|
3
2
|
import type {
|
|
4
3
|
Balance,
|
|
5
4
|
SelectedQuote,
|
|
6
|
-
TokensBalance,
|
|
7
5
|
Wallet,
|
|
8
6
|
WalletInfoWithExtra,
|
|
9
7
|
} from '../types';
|
|
10
|
-
import type {
|
|
8
|
+
import type { ExtendedWalletInfo } from '@rango-dev/wallets-react';
|
|
11
9
|
import type {
|
|
12
10
|
Network,
|
|
13
|
-
WalletInfo,
|
|
14
11
|
WalletState,
|
|
15
12
|
WalletType,
|
|
16
13
|
WalletTypes,
|
|
17
14
|
} from '@rango-dev/wallets-shared';
|
|
18
|
-
import type {
|
|
19
|
-
BlockchainMeta,
|
|
20
|
-
Token,
|
|
21
|
-
TransactionType,
|
|
22
|
-
WalletDetail,
|
|
23
|
-
} from 'rango-sdk';
|
|
15
|
+
import type { BlockchainMeta, Token, TransactionType } from 'rango-sdk';
|
|
24
16
|
|
|
25
17
|
import {
|
|
26
18
|
BlockchainCategories,
|
|
@@ -47,9 +39,11 @@ import {
|
|
|
47
39
|
import { EXCLUDED_WALLETS } from '../constants/wallets';
|
|
48
40
|
|
|
49
41
|
import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
|
|
50
|
-
import { createTokenHash } from './meta';
|
|
51
42
|
import { numberToString } from './numbers';
|
|
52
43
|
|
|
44
|
+
export type ExtendedModalWalletInfo = WalletInfoWithExtra &
|
|
45
|
+
Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
|
|
46
|
+
|
|
53
47
|
export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
54
48
|
switch (true) {
|
|
55
49
|
case state.connected:
|
|
@@ -65,10 +59,10 @@ export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
|
65
59
|
|
|
66
60
|
export function mapWalletTypesToWalletInfo(
|
|
67
61
|
getState: (type: WalletType) => WalletState,
|
|
68
|
-
getWalletInfo: (type: WalletType) =>
|
|
62
|
+
getWalletInfo: (type: WalletType) => ExtendedWalletInfo,
|
|
69
63
|
list: WalletType[],
|
|
70
64
|
chain?: string
|
|
71
|
-
):
|
|
65
|
+
): ExtendedModalWalletInfo[] {
|
|
72
66
|
return list
|
|
73
67
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
74
68
|
.filter((wallet) => {
|
|
@@ -93,10 +87,11 @@ export function mapWalletTypesToWalletInfo(
|
|
|
93
87
|
img: image,
|
|
94
88
|
installLink,
|
|
95
89
|
showOnMobile,
|
|
96
|
-
|
|
97
|
-
singleNamespace,
|
|
90
|
+
needsNamespace,
|
|
98
91
|
supportedChains,
|
|
99
92
|
needsDerivationPath,
|
|
93
|
+
properties,
|
|
94
|
+
isHub,
|
|
100
95
|
} = getWalletInfo(type);
|
|
101
96
|
const blockchainTypes = removeDuplicateFrom(
|
|
102
97
|
supportedChains.map((item) => item.type)
|
|
@@ -110,10 +105,11 @@ export function mapWalletTypesToWalletInfo(
|
|
|
110
105
|
state,
|
|
111
106
|
type,
|
|
112
107
|
showOnMobile,
|
|
113
|
-
|
|
114
|
-
singleNamespace,
|
|
108
|
+
needsNamespace,
|
|
115
109
|
blockchainTypes,
|
|
116
110
|
needsDerivationPath,
|
|
111
|
+
properties,
|
|
112
|
+
isHub,
|
|
117
113
|
};
|
|
118
114
|
});
|
|
119
115
|
}
|
|
@@ -265,8 +261,6 @@ export function getQuoteWallets(params: {
|
|
|
265
261
|
return Array.from(wallets);
|
|
266
262
|
}
|
|
267
263
|
|
|
268
|
-
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
269
|
-
|
|
270
264
|
export function isAccountAndWalletMatched(
|
|
271
265
|
account: Wallet,
|
|
272
266
|
connectedWallet: ConnectedWallet
|
|
@@ -278,74 +272,21 @@ export function isAccountAndWalletMatched(
|
|
|
278
272
|
);
|
|
279
273
|
}
|
|
280
274
|
|
|
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
|
-
|
|
303
275
|
export function resetConnectedWalletState(
|
|
304
276
|
connectedWallet: ConnectedWallet
|
|
305
277
|
): ConnectedWallet {
|
|
306
278
|
return { ...connectedWallet, loading: false, error: true };
|
|
307
279
|
}
|
|
308
280
|
|
|
309
|
-
export const calculateWalletUsdValue = (
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
) === -1
|
|
317
|
-
? [...acc, current]
|
|
318
|
-
: acc;
|
|
319
|
-
},
|
|
320
|
-
[]
|
|
321
|
-
);
|
|
281
|
+
export const calculateWalletUsdValue = (balances: BalanceState) => {
|
|
282
|
+
const total = Object.values(balances).reduce((prev, balance) => {
|
|
283
|
+
const usdBalance = balance.usdValue
|
|
284
|
+
? representAmountInNumber(balance.usdValue, balance.decimals)
|
|
285
|
+
: ZERO.toFixed();
|
|
286
|
+
return prev.plus(usdBalance);
|
|
287
|
+
}, new BigNumber(ZERO));
|
|
322
288
|
|
|
323
|
-
|
|
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);
|
|
289
|
+
return numberWithThousandSeparator(total.toString());
|
|
349
290
|
};
|
|
350
291
|
|
|
351
292
|
function numberWithThousandSeparator(number: string | number): string {
|
|
@@ -383,20 +324,34 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
383
324
|
);
|
|
384
325
|
};
|
|
385
326
|
|
|
327
|
+
function representAmountInNumber(amount: string, decimals: number): string {
|
|
328
|
+
return new BigNumber(amount).shiftedBy(-decimals).toFixed();
|
|
329
|
+
}
|
|
330
|
+
|
|
386
331
|
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
|
+
|
|
387
350
|
const formattedBalance: Balance | null = balance
|
|
388
351
|
? {
|
|
389
352
|
...balance,
|
|
390
|
-
amount:
|
|
391
|
-
|
|
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
|
-
),
|
|
353
|
+
amount: formattedAmount,
|
|
354
|
+
usdValue: formattedUsdValue,
|
|
400
355
|
}
|
|
401
356
|
: null;
|
|
402
357
|
|
|
@@ -408,17 +363,39 @@ export function compareTokenBalance(
|
|
|
408
363
|
token2Balance: Balance | null
|
|
409
364
|
): number {
|
|
410
365
|
if (token1Balance?.usdValue || token2Balance?.usdValue) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
366
|
+
const token1UsdValue =
|
|
367
|
+
!!token1Balance && !!token1Balance.usdValue
|
|
368
|
+
? new BigNumber(token1Balance.usdValue).shiftedBy(
|
|
369
|
+
-token1Balance.decimals
|
|
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;
|
|
415
383
|
}
|
|
416
384
|
|
|
417
385
|
if (token1Balance?.amount || token2Balance?.amount) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
386
|
+
const token1Amount =
|
|
387
|
+
!!token1Balance && !!token1Balance.amount
|
|
388
|
+
? new BigNumber(token1Balance.amount).shiftedBy(-token1Balance.decimals)
|
|
389
|
+
: ZERO;
|
|
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;
|
|
422
399
|
}
|
|
423
400
|
|
|
424
401
|
return 0;
|
|
@@ -436,8 +413,8 @@ export function areTokensEqual(
|
|
|
436
413
|
}
|
|
437
414
|
|
|
438
415
|
export function sortWalletsBasedOnConnectionState(
|
|
439
|
-
wallets:
|
|
440
|
-
):
|
|
416
|
+
wallets: ExtendedModalWalletInfo[]
|
|
417
|
+
): ExtendedModalWalletInfo[] {
|
|
441
418
|
return wallets.sort(
|
|
442
419
|
(a, b) =>
|
|
443
420
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
@@ -484,43 +461,6 @@ export function getAddress({
|
|
|
484
461
|
)?.address;
|
|
485
462
|
}
|
|
486
463
|
|
|
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
|
-
|
|
524
464
|
export const isFetchingBalance = (
|
|
525
465
|
connectedWallets: ConnectedWallet[],
|
|
526
466
|
blockchain: string
|
|
@@ -529,12 +469,12 @@ export const isFetchingBalance = (
|
|
|
529
469
|
(wallet) => wallet.chain === blockchain && wallet.loading
|
|
530
470
|
);
|
|
531
471
|
|
|
532
|
-
export function hashWalletsState(walletsInfo:
|
|
472
|
+
export function hashWalletsState(walletsInfo: WalletInfoWithExtra[]) {
|
|
533
473
|
return walletsInfo.map((w) => w.state).join('-');
|
|
534
474
|
}
|
|
535
475
|
|
|
536
476
|
export function filterBlockchainsByWalletTypes(
|
|
537
|
-
wallets:
|
|
477
|
+
wallets: WalletInfoWithExtra[],
|
|
538
478
|
blockchains: BlockchainMeta[]
|
|
539
479
|
) {
|
|
540
480
|
const uniqueBlockchainTypes = new Set<TransactionType>();
|
|
@@ -551,7 +491,7 @@ export function filterBlockchainsByWalletTypes(
|
|
|
551
491
|
}
|
|
552
492
|
|
|
553
493
|
export function filterWalletsByCategory(
|
|
554
|
-
wallets:
|
|
494
|
+
wallets: ExtendedModalWalletInfo[],
|
|
555
495
|
category: string
|
|
556
496
|
) {
|
|
557
497
|
if (category === BlockchainCategories.ALL) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../src/constants/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,UAmBvE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useObserveBalanceChanges/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useObserveBalanceChanges.d.ts","sourceRoot":"","sources":["../../../src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts"],"names":[],"mappings":"AAUA,wBAAgB,wBAAwB,CAAC,kBAAkB,CAAC,EAAE,MAAM;;EAyDnE"}
|
package/dist/store/wallets.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { FindToken } from './slices/data';
|
|
2
|
-
import type { Balance, TokensBalance, Wallet } from '../types';
|
|
3
|
-
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
|
-
import type { Token } from 'rango-sdk';
|
|
5
|
-
export type TokenBalance = {
|
|
6
|
-
chain: string;
|
|
7
|
-
symbol: string;
|
|
8
|
-
ticker: string;
|
|
9
|
-
address: string | null;
|
|
10
|
-
rawAmount: string;
|
|
11
|
-
decimal: number | null;
|
|
12
|
-
amount: string;
|
|
13
|
-
logo: string | null;
|
|
14
|
-
usdPrice: number | null;
|
|
15
|
-
};
|
|
16
|
-
export interface ConnectedWallet extends Wallet {
|
|
17
|
-
balances: TokenBalance[] | null;
|
|
18
|
-
explorerUrl: string | null;
|
|
19
|
-
selected: boolean;
|
|
20
|
-
loading: boolean;
|
|
21
|
-
error: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface WalletsStore {
|
|
24
|
-
connectedWallets: ConnectedWallet[];
|
|
25
|
-
balances: TokensBalance;
|
|
26
|
-
loading: boolean;
|
|
27
|
-
connectWallet: (accounts: Wallet[], findToken: FindToken) => void;
|
|
28
|
-
disconnectWallet: (walletType: WalletType) => void;
|
|
29
|
-
selectWallets: (wallets: {
|
|
30
|
-
walletType: string;
|
|
31
|
-
chain: string;
|
|
32
|
-
}[]) => void;
|
|
33
|
-
clearConnectedWallet: () => void;
|
|
34
|
-
getWalletsDetails: (accounts: Wallet[], findToken: FindToken, shouldRetry?: boolean) => void;
|
|
35
|
-
getBalanceFor: (token: Token) => Balance | null;
|
|
36
|
-
}
|
|
37
|
-
export declare const useWalletsStore: {
|
|
38
|
-
(): WalletsStore;
|
|
39
|
-
<U>(selector: (state: WalletsStore) => U): U;
|
|
40
|
-
<U_1>(selector: (state: WalletsStore) => U_1, equalityFn: (a: U_1, b: U_1) => boolean): U_1;
|
|
41
|
-
} & Omit<import("zustand").StoreApi<WalletsStore>, "subscribe"> & {
|
|
42
|
-
subscribe: {
|
|
43
|
-
(listener: (selectedState: WalletsStore, previousSelectedState: WalletsStore) => void): () => void;
|
|
44
|
-
<U_2>(selector: (state: WalletsStore) => U_2, listener: (selectedState: U_2, previousSelectedState: U_2) => void, options?: {
|
|
45
|
-
equalityFn?: ((a: U_2, b: U_2) => boolean) | undefined;
|
|
46
|
-
fireImmediately?: boolean | undefined;
|
|
47
|
-
} | undefined): () => void;
|
|
48
|
-
};
|
|
49
|
-
} & {
|
|
50
|
-
use: {
|
|
51
|
-
connectedWallets: () => ConnectedWallet[];
|
|
52
|
-
balances: () => TokensBalance;
|
|
53
|
-
loading: () => boolean;
|
|
54
|
-
connectWallet: () => (accounts: Wallet[], findToken: FindToken) => void;
|
|
55
|
-
disconnectWallet: () => (walletType: WalletType) => void;
|
|
56
|
-
selectWallets: () => (wallets: {
|
|
57
|
-
walletType: string;
|
|
58
|
-
chain: string;
|
|
59
|
-
}[]) => void;
|
|
60
|
-
clearConnectedWallet: () => () => void;
|
|
61
|
-
getWalletsDetails: () => (accounts: Wallet[], findToken: FindToken, shouldRetry?: boolean) => void;
|
|
62
|
-
getBalanceFor: () => (token: Token) => Balance | null;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
export {};
|
|
66
|
-
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/store/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAkBvC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,eAAgB,SAAQ,MAAM;IAC7C,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AACD,UAAU,YAAY;IACpB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAClE,gBAAgB,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IACnD,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,IAAI,CAAC;IAC1E,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,EAAE,CACjB,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,KAClB,IAAI,CAAC;IACV,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAC;CACjD;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;wCAZA,MAAM,EAAE,aAAa,SAAS,KAAK,IAAI;6CAClC,UAAU,KAAK,IAAI;uCACzB;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,KAAK,IAAI;0CAC7C,IAAI;4CAEpB,MAAM,EAAE,aACP,SAAS,gBACN,OAAO,KAClB,IAAI;qCACc,KAAK,KAAK,OAAO,GAAG,IAAI;;CAsNhD,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { QuoteUpdateWarning } from '../types';
|
|
2
|
-
|
|
3
|
-
import { i18n } from '@lingui/core';
|
|
4
|
-
|
|
5
|
-
import { QuoteUpdateType } from '../types';
|
|
6
|
-
|
|
7
|
-
export function getQuoteUpdateWarningMessage(warning: QuoteUpdateWarning) {
|
|
8
|
-
switch (warning.type) {
|
|
9
|
-
case QuoteUpdateType.QUOTE_UPDATED:
|
|
10
|
-
return i18n.t('Route has been updated.');
|
|
11
|
-
case QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
12
|
-
return i18n.t(
|
|
13
|
-
'Output amount changed to {newOutputAmount} ({percentageChange}% change).',
|
|
14
|
-
{
|
|
15
|
-
newOutputAmount: warning.newOutputAmount,
|
|
16
|
-
percentageChange: warning.percentageChange,
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
case QuoteUpdateType.QUOTE_SWAPPERS_UPDATED:
|
|
20
|
-
return i18n.t('Route swappers has been updated.');
|
|
21
|
-
case QuoteUpdateType.QUOTE_COINS_UPDATED:
|
|
22
|
-
return i18n.t('Route internal coins has been updated.');
|
|
23
|
-
default:
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useObserveBalanceChanges } from './useObserveBalanceChanges';
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { WalletEventData } from '../../types';
|
|
2
|
-
|
|
3
|
-
import { useWallets } from '@rango-dev/wallets-react';
|
|
4
|
-
import { useEffect, useRef, useState } from 'react';
|
|
5
|
-
|
|
6
|
-
import { widgetEventEmitter } from '../../services/eventEmitter';
|
|
7
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
8
|
-
import { WalletEventTypes, WidgetEvents } from '../../types';
|
|
9
|
-
|
|
10
|
-
// A hook to listen for and detect changes in balances on a specific blockchain.
|
|
11
|
-
export function useObserveBalanceChanges(selectedBlockchain?: string) {
|
|
12
|
-
const { connectedWallets } = useWalletsStore();
|
|
13
|
-
const { getWalletInfo } = useWallets();
|
|
14
|
-
const prevFetchingBalanceWallets = useRef<string[]>([]);
|
|
15
|
-
// The "balanceKey" will be updated and incremented after each change in the balance for a blockchain.
|
|
16
|
-
const [balanceKey, setBalanceKey] = useState(0);
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
const handleWalletEvent = (event: WalletEventData) => {
|
|
20
|
-
if (event.type === WalletEventTypes.DISCONNECT) {
|
|
21
|
-
const walletInfo = getWalletInfo(event.payload.walletType);
|
|
22
|
-
const blockchainSupported = walletInfo.supportedChains.some(
|
|
23
|
-
(chain) => chain.name === selectedBlockchain
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
if (blockchainSupported) {
|
|
27
|
-
setBalanceKey((prev) => prev + 1);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
widgetEventEmitter.on(WidgetEvents.WalletEvent, handleWalletEvent);
|
|
33
|
-
|
|
34
|
-
if (!selectedBlockchain) {
|
|
35
|
-
return setBalanceKey((prev) => prev + 1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const supportedWallets = connectedWallets.filter(
|
|
39
|
-
(wallet) => wallet.chain === selectedBlockchain
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
supportedWallets.forEach((wallet) => {
|
|
43
|
-
const { walletType } = wallet;
|
|
44
|
-
const walletIsAlreadyFetching =
|
|
45
|
-
prevFetchingBalanceWallets.current.includes(walletType);
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Watching for changes in "wallet.balances.length" is not accurate.
|
|
49
|
-
* Additionally, checking the equality of previous and current balances for a specific blockchain is resource-intensive, so we avoid these methods.
|
|
50
|
-
*/
|
|
51
|
-
if (wallet.loading && !walletIsAlreadyFetching) {
|
|
52
|
-
prevFetchingBalanceWallets.current =
|
|
53
|
-
prevFetchingBalanceWallets.current.concat(walletType);
|
|
54
|
-
} else if (!wallet.loading && walletIsAlreadyFetching) {
|
|
55
|
-
prevFetchingBalanceWallets.current =
|
|
56
|
-
prevFetchingBalanceWallets.current.filter(
|
|
57
|
-
(prevWallet) => prevWallet !== walletType
|
|
58
|
-
);
|
|
59
|
-
setBalanceKey((prev) => prev + 1);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return () =>
|
|
64
|
-
widgetEventEmitter.off(WidgetEvents.WalletEvent, handleWalletEvent);
|
|
65
|
-
}, [connectedWallets, selectedBlockchain, getWalletInfo]);
|
|
66
|
-
|
|
67
|
-
return { balanceKey };
|
|
68
|
-
}
|