@rango-dev/widget-embedded 0.1.10-next.93 → 0.1.10-next.94
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/AppRoutes.d.ts +5 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/ConfirmSwapErrors.d.ts +3 -2
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +3 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/SwitchFromAndTo.d.ts +1 -1
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts +1 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts +11 -0
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/usePrevious.d.ts +1 -1
- package/dist/hooks/usePrevious.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +25 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +15 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/{store/confirmSwap.d.ts → types/routing.d.ts} +14 -5
- package/dist/types/routing.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +11 -5
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +4 -3
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +7 -2
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +574 -478
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +574 -478
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +575 -479
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/QueueManager.tsx +1 -0
- package/src/components/AppRoutes.tsx +54 -21
- package/src/components/ChangeSlippageButton.tsx +1 -1
- package/src/components/ConfirmSwapErrors.tsx +1 -1
- package/src/components/ConfirmSwapWarnings.tsx +1 -4
- package/src/components/Header.tsx +1 -1
- package/src/components/Layout.tsx +3 -3
- package/src/components/UpdateUrl.tsx +13 -22
- package/src/components/warnings/BalanceWarnings.tsx +27 -4
- package/src/components/warnings/ConfirmSwapExtraMessages.tsx +7 -1
- package/src/components/warnings/HighSlippageWarning.tsx +1 -1
- package/src/components/warnings/MinRequiredSlippage.tsx +2 -2
- package/src/hooks/useConfirmSwap.ts +260 -0
- package/src/pages/ConfirmSwapPage.tsx +17 -8
- package/src/pages/ConfirmWalletsPage.tsx +1 -1
- package/src/pages/Home.tsx +0 -1
- package/src/pages/SelectChainPage.tsx +2 -7
- package/src/pages/SelectTokenPage.tsx +22 -57
- package/src/pages/SettingsPage.tsx +8 -9
- package/src/pages/WalletsPage.tsx +16 -6
- package/src/store/bestRoute.ts +82 -37
- package/src/store/settings.ts +2 -2
- package/src/store/wallets.ts +26 -0
- package/src/types/index.ts +1 -0
- package/src/types/routing.ts +60 -0
- package/src/utils/numbers.ts +38 -17
- package/src/utils/routing.ts +115 -24
- package/src/utils/swap.ts +19 -11
- package/src/utils/wallets.ts +117 -73
- package/dist/store/confirmSwap.d.ts.map +0 -1
- package/src/store/confirmSwap.ts +0 -342
package/src/utils/routing.ts
CHANGED
|
@@ -3,57 +3,148 @@ import {
|
|
|
3
3
|
SimulationValidationStatus,
|
|
4
4
|
} from '@rango-dev/ui/dist/types/swaps';
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
|
-
import { BestRouteResponse } from 'rango-sdk';
|
|
6
|
+
import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
7
7
|
import { areEqual } from './common';
|
|
8
8
|
import { SelectedWallet } from './wallets';
|
|
9
|
+
import { BestRouteParams } from '../types';
|
|
10
|
+
import { TokenMeta } from '@rango-dev/ui/dist/types/meta';
|
|
11
|
+
import { numberToString } from './numbers';
|
|
12
|
+
import { getUsdFeeOfStep } from './swap';
|
|
13
|
+
import { BestRouteWithFee } from '@rango-dev/ui';
|
|
9
14
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
export function searchParamsToToken(
|
|
16
|
+
tokens: Token[],
|
|
17
|
+
searchParams: string | null,
|
|
18
|
+
chain: BlockchainMeta | null
|
|
19
|
+
): Token | null {
|
|
20
|
+
if (!chain) return null;
|
|
21
|
+
return (
|
|
22
|
+
tokens.find((token) => {
|
|
23
|
+
const symbolAndAddress = searchParams?.split('--');
|
|
24
|
+
if (symbolAndAddress?.length === 1)
|
|
25
|
+
return (
|
|
26
|
+
token.symbol === symbolAndAddress[0] &&
|
|
27
|
+
token.address === null &&
|
|
28
|
+
token.blockchain === chain.name
|
|
29
|
+
);
|
|
30
|
+
return (
|
|
31
|
+
token.symbol === symbolAndAddress?.[0] &&
|
|
32
|
+
token.address === symbolAndAddress?.[1] &&
|
|
33
|
+
token.blockchain === chain.name
|
|
34
|
+
);
|
|
35
|
+
}) || null
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getBestRouteToTokenUsdPrice(
|
|
40
|
+
bestRoute: BestRouteResponse | null
|
|
41
|
+
): number | null | undefined {
|
|
42
|
+
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to
|
|
43
|
+
.usdPrice;
|
|
44
|
+
}
|
|
14
45
|
|
|
15
|
-
export function isNumberOfSwapsChanged(
|
|
46
|
+
export function isNumberOfSwapsChanged(
|
|
47
|
+
route1: BestRouteResponse,
|
|
48
|
+
route2: BestRouteResponse
|
|
49
|
+
) {
|
|
16
50
|
const route1Swaps = route1.result?.swaps || [];
|
|
17
51
|
const route2Swaps = route2.result?.swaps || [];
|
|
18
52
|
return route1Swaps.length !== route2Swaps.length;
|
|
19
53
|
}
|
|
20
54
|
|
|
21
|
-
export function isRouteSwappersUpdated(
|
|
22
|
-
|
|
23
|
-
|
|
55
|
+
export function isRouteSwappersUpdated(
|
|
56
|
+
route1: BestRouteResponse,
|
|
57
|
+
route2: BestRouteResponse
|
|
58
|
+
) {
|
|
59
|
+
const route1Swappers =
|
|
60
|
+
route1.result?.swaps.map((swap) => swap.swapperId) || [];
|
|
61
|
+
const route2Swappers =
|
|
62
|
+
route2.result?.swaps.map((swap) => swap.swapperId) || [];
|
|
24
63
|
return !areEqual(route1Swappers, route2Swappers);
|
|
25
64
|
}
|
|
26
65
|
|
|
27
|
-
export function isRouteInternalCoinsUpdated(
|
|
28
|
-
|
|
29
|
-
|
|
66
|
+
export function isRouteInternalCoinsUpdated(
|
|
67
|
+
route1: BestRouteResponse,
|
|
68
|
+
route2: BestRouteResponse
|
|
69
|
+
) {
|
|
70
|
+
const route1InternalCoins =
|
|
71
|
+
route1.result?.swaps.map((swap) => swap.to.symbol) || [];
|
|
72
|
+
const route2InternalCoins =
|
|
73
|
+
route2.result?.swaps.map((swap) => swap.to.symbol) || [];
|
|
30
74
|
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
31
75
|
}
|
|
32
76
|
|
|
33
|
-
export
|
|
77
|
+
export function isRouteChanged(
|
|
78
|
+
route1: BestRouteResponse,
|
|
79
|
+
route2: BestRouteResponse
|
|
80
|
+
): boolean {
|
|
34
81
|
return (
|
|
35
82
|
isNumberOfSwapsChanged(route1, route2) ||
|
|
36
83
|
isRouteSwappersUpdated(route1, route2) ||
|
|
37
84
|
isRouteInternalCoinsUpdated(route1, route2)
|
|
38
85
|
);
|
|
39
|
-
}
|
|
86
|
+
}
|
|
40
87
|
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
88
|
+
export function outToRatioHasWarning(
|
|
89
|
+
fromUsdValue: BigNumber | null,
|
|
90
|
+
outToInRatio: BigNumber | 0
|
|
91
|
+
) {
|
|
92
|
+
return (
|
|
93
|
+
(parseInt(outToInRatio?.toFixed(2) || '0') <= -10 &&
|
|
94
|
+
(fromUsdValue === null || fromUsdValue.gte(new BigNumber(200)))) ||
|
|
95
|
+
(parseInt(outToInRatio?.toFixed(2) || '0') <= -5 &&
|
|
96
|
+
(fromUsdValue === null || fromUsdValue.gte(new BigNumber(1000))))
|
|
97
|
+
);
|
|
98
|
+
}
|
|
46
99
|
|
|
47
|
-
export
|
|
100
|
+
export function getRequiredBalanceOfWallet(
|
|
48
101
|
selectedWallet: SelectedWallet,
|
|
49
|
-
fee: SimulationValidationStatus[] | null
|
|
50
|
-
): SimulationAssetAndAmount[] | null
|
|
102
|
+
fee: SimulationValidationStatus[] | null
|
|
103
|
+
): SimulationAssetAndAmount[] | null {
|
|
51
104
|
if (fee === null) return null;
|
|
52
105
|
const relatedFeeStatus = fee
|
|
53
106
|
?.find((item) => item.blockchain === selectedWallet.chain)
|
|
54
107
|
?.wallets.find(
|
|
55
|
-
(wallet) =>
|
|
108
|
+
(wallet) =>
|
|
109
|
+
wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase()
|
|
56
110
|
);
|
|
57
111
|
if (!relatedFeeStatus) return null;
|
|
58
112
|
return relatedFeeStatus.requiredAssets;
|
|
59
|
-
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function isRouteParametersChanged(
|
|
116
|
+
prevParams: BestRouteParams,
|
|
117
|
+
currentParams: BestRouteParams
|
|
118
|
+
) {
|
|
119
|
+
return (
|
|
120
|
+
prevParams.fromChain?.name !== currentParams.fromChain?.name ||
|
|
121
|
+
prevParams.toChain?.name !== currentParams.toChain?.name ||
|
|
122
|
+
prevParams.fromToken?.symbol !== currentParams.fromToken?.symbol ||
|
|
123
|
+
prevParams.toToken?.symbol !== currentParams.toToken?.symbol ||
|
|
124
|
+
prevParams.fromToken?.blockchain !== currentParams.fromToken?.blockchain ||
|
|
125
|
+
prevParams.toToken?.blockchain !== currentParams.toToken?.blockchain ||
|
|
126
|
+
prevParams.fromToken?.address !== currentParams.fromToken?.address ||
|
|
127
|
+
prevParams.toToken?.address !== currentParams.toToken?.address ||
|
|
128
|
+
prevParams.inputAmount !== currentParams.inputAmount ||
|
|
129
|
+
prevParams.slippage !== currentParams.slippage ||
|
|
130
|
+
prevParams.customSlippage !== currentParams.customSlippage ||
|
|
131
|
+
prevParams.disabledLiquiditySources?.length !==
|
|
132
|
+
currentParams.disabledLiquiditySources?.length
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function getBestRouteWithCalculatedFees(
|
|
137
|
+
bestRoute: BestRouteResponse | null,
|
|
138
|
+
tokens: TokenMeta[]
|
|
139
|
+
): BestRouteWithFee | null {
|
|
140
|
+
if (!bestRoute || !bestRoute.result) return null;
|
|
141
|
+
const swapsWithFee = (bestRoute?.result?.swaps || []).map((swap) => ({
|
|
142
|
+
...swap,
|
|
143
|
+
feeInUsd: numberToString(getUsdFeeOfStep(swap, tokens), 0, 2),
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
...bestRoute,
|
|
148
|
+
result: { ...bestRoute.result, swaps: swapsWithFee },
|
|
149
|
+
};
|
|
150
|
+
}
|
package/src/utils/swap.ts
CHANGED
|
@@ -248,10 +248,10 @@ export function calculatePendingSwap(
|
|
|
248
248
|
transferTransaction: null,
|
|
249
249
|
diagnosisUrl: null,
|
|
250
250
|
internalSteps: null,
|
|
251
|
-
fromBlockchainLogo: fromBlockchain
|
|
252
|
-
toBlockchainLogo: toBlockchain
|
|
253
|
-
swapperLogo: swapper?.logo,
|
|
254
|
-
swapperType: swapperType,
|
|
251
|
+
fromBlockchainLogo: fromBlockchain?.logo || '',
|
|
252
|
+
toBlockchainLogo: toBlockchain?.logo || '',
|
|
253
|
+
swapperLogo: swapper?.logo || '',
|
|
254
|
+
swapperType: swapperType || '',
|
|
255
255
|
};
|
|
256
256
|
}) || [],
|
|
257
257
|
};
|
|
@@ -288,7 +288,10 @@ export const getUsdPrice = (
|
|
|
288
288
|
return token?.usdPrice || null;
|
|
289
289
|
};
|
|
290
290
|
|
|
291
|
-
function getUsdFeeOfStep(
|
|
291
|
+
export function getUsdFeeOfStep(
|
|
292
|
+
step: SwapResult,
|
|
293
|
+
allTokens: Token[]
|
|
294
|
+
): BigNumber {
|
|
292
295
|
let totalFeeInUsd = ZERO;
|
|
293
296
|
for (let i = 0; i < step.fee.length; i++) {
|
|
294
297
|
const fee = step.fee[i];
|
|
@@ -332,7 +335,9 @@ export function hasSlippageError(
|
|
|
332
335
|
return (slippages?.filter((s) => !!s?.error)?.length || 0) > 0;
|
|
333
336
|
}
|
|
334
337
|
|
|
335
|
-
export function getMinRequiredSlippage(
|
|
338
|
+
export function getMinRequiredSlippage(
|
|
339
|
+
route: BestRouteResponse
|
|
340
|
+
): number | null {
|
|
336
341
|
const slippages = route.result?.swaps.map(
|
|
337
342
|
(slippage) => slippage.recommendedSlippage
|
|
338
343
|
);
|
|
@@ -350,7 +355,8 @@ export function hasProperSlippage(
|
|
|
350
355
|
minRequiredSlippage: number | null
|
|
351
356
|
) {
|
|
352
357
|
if (!minRequiredSlippage) return true;
|
|
353
|
-
|
|
358
|
+
//@ts-ignore
|
|
359
|
+
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
354
360
|
}
|
|
355
361
|
|
|
356
362
|
export function hasEnoughBalance(
|
|
@@ -465,14 +471,15 @@ export function getWalletsForNewSwap(selectedWallets: SelectedWallet[]) {
|
|
|
465
471
|
return wallets;
|
|
466
472
|
}
|
|
467
473
|
|
|
468
|
-
export function getRouteOutputAmount(route: BestRouteResponse) {
|
|
469
|
-
return route
|
|
474
|
+
export function getRouteOutputAmount(route: BestRouteResponse | null) {
|
|
475
|
+
return route?.result?.outputAmount || null;
|
|
470
476
|
}
|
|
471
477
|
|
|
472
478
|
export function getPercentageChange(
|
|
473
|
-
oldValue: string | number,
|
|
474
|
-
newValue: string | number
|
|
479
|
+
oldValue: string | number | null,
|
|
480
|
+
newValue: string | number | null
|
|
475
481
|
) {
|
|
482
|
+
if (!oldValue || !newValue) return null;
|
|
476
483
|
return new BigNumber(newValue)
|
|
477
484
|
.div(new BigNumber(oldValue))
|
|
478
485
|
.minus(1)
|
|
@@ -490,6 +497,7 @@ export function isOutputAmountChangedALot(
|
|
|
490
497
|
oldOutputAmount,
|
|
491
498
|
newOutputAmount
|
|
492
499
|
);
|
|
500
|
+
if (!percentageChange) return true;
|
|
493
501
|
|
|
494
502
|
return percentageChange.toNumber() <= -1;
|
|
495
503
|
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -3,9 +3,10 @@ import {
|
|
|
3
3
|
isEvmAddress,
|
|
4
4
|
KEPLR_COMPATIBLE_WALLETS,
|
|
5
5
|
Network,
|
|
6
|
-
WalletInfo,
|
|
7
6
|
WalletState,
|
|
8
7
|
WalletType,
|
|
8
|
+
detectInstallLink,
|
|
9
|
+
WalletInfo,
|
|
9
10
|
} from '@rango-dev/wallets-shared';
|
|
10
11
|
|
|
11
12
|
import {
|
|
@@ -55,19 +56,25 @@ export function getlistWallet(
|
|
|
55
56
|
WalletType.UNKNOWN,
|
|
56
57
|
WalletType.TERRA_STATION,
|
|
57
58
|
WalletType.LEAP,
|
|
58
|
-
];
|
|
59
|
+
];
|
|
59
60
|
|
|
60
61
|
return list
|
|
61
62
|
.filter((wallet) => !excludedWallets.includes(wallet))
|
|
62
63
|
.map((type) => {
|
|
63
|
-
const {
|
|
64
|
+
const {
|
|
65
|
+
name,
|
|
66
|
+
img: image,
|
|
67
|
+
installLink,
|
|
68
|
+
showOnMobile,
|
|
69
|
+
} = getWalletInfo(type);
|
|
64
70
|
const state = getStateWallet(getState(type));
|
|
65
71
|
return {
|
|
66
72
|
name,
|
|
67
73
|
image,
|
|
68
|
-
installLink,
|
|
74
|
+
installLink: detectInstallLink(installLink),
|
|
69
75
|
state,
|
|
70
76
|
type,
|
|
77
|
+
showOnMobile: typeof showOnMobile === 'undefined' ? false : true,
|
|
71
78
|
};
|
|
72
79
|
});
|
|
73
80
|
}
|
|
@@ -320,76 +327,28 @@ function numberWithThousandSeperator(number: string | number): string {
|
|
|
320
327
|
return parts.join('.');
|
|
321
328
|
}
|
|
322
329
|
|
|
323
|
-
export const
|
|
324
|
-
tokens
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
.map((b) => `${b?.chain}.${b?.symbol}.${b?.address}`)
|
|
334
|
-
);
|
|
335
|
-
let sortedList = [
|
|
336
|
-
...tokens.filter(
|
|
337
|
-
(t) => !t.address && walletSymbols.size && position === 'to'
|
|
338
|
-
),
|
|
339
|
-
...tokens
|
|
340
|
-
.filter(
|
|
341
|
-
(t) =>
|
|
342
|
-
!(position === 'to' && !t.address) &&
|
|
343
|
-
walletSymbols.has(`${t.blockchain}.${t.symbol}.${t.address}`)
|
|
344
|
-
)
|
|
345
|
-
.sort((tokenA, tokenB) => compareBalance(tokenA, tokenB, balance)),
|
|
346
|
-
...tokens.filter(
|
|
347
|
-
(t) =>
|
|
348
|
-
!walletSymbols.has(`${t.blockchain}.${t.symbol}.${t.address}`) &&
|
|
349
|
-
!t.address &&
|
|
350
|
-
(!walletSymbols.size || position === 'from')
|
|
351
|
-
),
|
|
352
|
-
...tokens.filter(
|
|
353
|
-
(t) =>
|
|
354
|
-
!walletSymbols.has(`${t.blockchain}.${t.symbol}.${t.address}`) &&
|
|
355
|
-
t.address &&
|
|
356
|
-
!t.isSecondaryCoin
|
|
357
|
-
),
|
|
358
|
-
...tokens.filter(
|
|
359
|
-
(t) =>
|
|
360
|
-
!walletSymbols.has(`${t.blockchain}.${t.symbol}.${t.address}`) &&
|
|
361
|
-
t.isSecondaryCoin
|
|
362
|
-
),
|
|
363
|
-
];
|
|
364
|
-
|
|
365
|
-
return sortedList;
|
|
366
|
-
};
|
|
330
|
+
export const sortTokens = (tokens: TokenWithBalance[]): TokenWithBalance[] => {
|
|
331
|
+
let walletConnected = !!tokens.some((token) => token.balance);
|
|
332
|
+
if (!walletConnected) {
|
|
333
|
+
return tokens
|
|
334
|
+
.filter((token) => !token.address)
|
|
335
|
+
.concat(
|
|
336
|
+
tokens.filter((token) => token.address && !token.isSecondaryCoin),
|
|
337
|
+
tokens.filter((token) => token.isSecondaryCoin)
|
|
338
|
+
);
|
|
339
|
+
}
|
|
367
340
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
tokenA.symbol,
|
|
380
|
-
tokenA.address
|
|
381
|
-
)?.amount || ZERO
|
|
382
|
-
).multipliedBy(tokenA.usdPrice);
|
|
383
|
-
const tokenBUsdValue = new BigNumber(
|
|
384
|
-
getBalanceFromWallet(
|
|
385
|
-
wallet,
|
|
386
|
-
tokenB.blockchain,
|
|
387
|
-
tokenB.symbol,
|
|
388
|
-
tokenB.address
|
|
389
|
-
)?.amount || ZERO
|
|
390
|
-
).multipliedBy(tokenB.usdPrice);
|
|
391
|
-
if (tokenAUsdValue.gt(tokenBUsdValue)) return -1;
|
|
392
|
-
return 1;
|
|
341
|
+
return tokens
|
|
342
|
+
.filter((token) => !!token.balance)
|
|
343
|
+
.sort(
|
|
344
|
+
(tokenA, tokenB) =>
|
|
345
|
+
parseFloat(tokenB.balance?.usdValue || '0') -
|
|
346
|
+
parseFloat(tokenA.balance?.usdValue || '0')
|
|
347
|
+
)
|
|
348
|
+
.concat(
|
|
349
|
+
tokens.filter((token) => !token.balance && !token.isSecondaryCoin),
|
|
350
|
+
tokens.filter((token) => !token.balance && token.isSecondaryCoin)
|
|
351
|
+
);
|
|
393
352
|
};
|
|
394
353
|
|
|
395
354
|
export const getUsdPrice = (
|
|
@@ -429,3 +388,88 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
429
388
|
connectedWalletTypes.has(compatibleWallet)
|
|
430
389
|
);
|
|
431
390
|
};
|
|
391
|
+
|
|
392
|
+
export function getTokensWithBalance(
|
|
393
|
+
tokens: TokenWithBalance[],
|
|
394
|
+
balances: Balance[]
|
|
395
|
+
): TokenWithBalance[] {
|
|
396
|
+
return tokens.map(({ balance, ...otherProps }) => {
|
|
397
|
+
const tokenAmount = numberToString(
|
|
398
|
+
new BigNumber(
|
|
399
|
+
getBalanceFromWallet(
|
|
400
|
+
balances,
|
|
401
|
+
otherProps.blockchain,
|
|
402
|
+
otherProps.symbol,
|
|
403
|
+
otherProps.address
|
|
404
|
+
)?.amount || ZERO
|
|
405
|
+
)
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
let tokenUsdValue = '';
|
|
409
|
+
if (otherProps.usdPrice)
|
|
410
|
+
tokenUsdValue = numberToString(
|
|
411
|
+
new BigNumber(
|
|
412
|
+
getBalanceFromWallet(
|
|
413
|
+
balances,
|
|
414
|
+
otherProps.blockchain,
|
|
415
|
+
otherProps.symbol,
|
|
416
|
+
otherProps.address
|
|
417
|
+
)?.amount || ZERO
|
|
418
|
+
).multipliedBy(otherProps.usdPrice)
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
return {
|
|
422
|
+
...otherProps,
|
|
423
|
+
...(tokenAmount !== '0' && {
|
|
424
|
+
balance: { amount: tokenAmount, usdValue: tokenUsdValue },
|
|
425
|
+
}),
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function getSortedTokens(
|
|
431
|
+
chain: BlockchainMeta | null,
|
|
432
|
+
tokens: Token[],
|
|
433
|
+
balances: Balance[],
|
|
434
|
+
otherChainTokens: TokenWithBalance[]
|
|
435
|
+
): TokenWithBalance[] {
|
|
436
|
+
const fromChainEqueulsToToChain = chain?.name === otherChainTokens[0]?.name;
|
|
437
|
+
if (fromChainEqueulsToToChain) return otherChainTokens;
|
|
438
|
+
const filteredTokens = tokens.filter(
|
|
439
|
+
(token) => token.blockchain === chain?.name
|
|
440
|
+
);
|
|
441
|
+
return sortTokens(getTokensWithBalance(filteredTokens, balances));
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export function tokensAreEqual(tokenA: Token | null, tokenB: Token | null) {
|
|
445
|
+
return (
|
|
446
|
+
tokenA?.blockchain === tokenB?.blockchain &&
|
|
447
|
+
tokenA?.name === tokenB?.name &&
|
|
448
|
+
tokenA?.address === tokenB?.address
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function getDefaultToken(
|
|
453
|
+
sortedTokens: TokenWithBalance[],
|
|
454
|
+
otherToken: TokenWithBalance | null
|
|
455
|
+
): TokenWithBalance {
|
|
456
|
+
let selectedToken: TokenWithBalance;
|
|
457
|
+
const firstToken = sortedTokens[0];
|
|
458
|
+
const secondToken = sortedTokens[1];
|
|
459
|
+
if (sortedTokens.length === 1) selectedToken = firstToken;
|
|
460
|
+
else if (tokensAreEqual(firstToken, otherToken)) selectedToken = secondToken;
|
|
461
|
+
else selectedToken = firstToken;
|
|
462
|
+
return selectedToken;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export function sortWalletsBasedOnState(
|
|
466
|
+
wallets: ModalWalletInfo[]
|
|
467
|
+
): ModalWalletInfo[] {
|
|
468
|
+
return wallets.sort(
|
|
469
|
+
(a, b) =>
|
|
470
|
+
Number(b.state === WalletStatus.CONNECTED) -
|
|
471
|
+
Number(a.state === WalletStatus.CONNECTED) ||
|
|
472
|
+
Number(b.state === WalletStatus.DISCONNECTED) -
|
|
473
|
+
Number(a.state === WalletStatus.DISCONNECTED)
|
|
474
|
+
);
|
|
475
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"confirmSwap.d.ts","sourceRoot":"","sources":["../src/store/confirmSwap.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAS1E,eAAO,MAAM,mBAAmB,KAS/B,CAAC;AAEF,oBAAY,qBAAqB;IAC/B,QAAQ,IAAA;IACR,kCAAkC,IAAA;IAClC,cAAc,IAAA;IACd,qBAAqB,IAAA;CACtB;AAED,oBAAY,gBAAgB,GACxB;IACE,IAAI,EAAE,qBAAqB,CAAC,cAAc,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC,qBAAqB,CAAC;IAClD,mBAAmB,EAAE,MAAM,CAAC;CAC7B,GACD;IACE,IAAI,EAAE,OAAO,CACX,qBAAqB,EACnB,qBAAqB,CAAC,cAAc,GACpC,qBAAqB,CAAC,qBAAqB,CAC9C,CAAC;CACH,CAAC;AAEN,oBAAY,mBAAmB,GAC3B;IACE,IAAI,EAAE,uBAAuB,CAAC,+BAA+B,CAAC;IAC9D,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IAAE,IAAI,EAAE,uBAAuB,CAAC,oBAAoB,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GAC1E;IACE,IAAI,EAAE,OAAO,CACX,uBAAuB,EACrB,uBAAuB,CAAC,+BAA+B,GACvD,uBAAuB,CAAC,oBAAoB,CAC/C,CAAC;CACH,CAAC;AAEN,oBAAY,uBAAuB;IACjC,aAAa,IAAA;IACb,sBAAsB,IAAA;IACtB,mBAAmB,IAAA;IACnB,+BAA+B,IAAA;IAC/B,oBAAoB,IAAA;CACrB;AAED,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,WAAW,GAAG,SAAS,CAmPnE,CAAC"}
|