@rango-dev/widget-embedded 0.1.10-next.80 → 0.1.10-next.81
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/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/ChangeSlippageButton.d.ts +2 -0
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -0
- package/dist/components/ConfirmSwapErrors.d.ts +3 -0
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -0
- package/dist/components/ConfirmSwapWarnings.d.ts +3 -0
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -0
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceWarnings.d.ts +6 -0
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -0
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts +6 -0
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts.map +1 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts +6 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -0
- package/dist/components/warnings/MinRequiredSlippage.d.ts +6 -0
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -0
- package/dist/constants/swapSettings.d.ts +6 -0
- package/dist/constants/swapSettings.d.ts.map +1 -0
- package/dist/hooks/useNavigateBack.d.ts +4 -0
- package/dist/hooks/useNavigateBack.d.ts.map +1 -0
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/ConfirmWalletsPage.d.ts +0 -5
- package/dist/pages/ConfirmWalletsPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.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/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +1 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/confirmSwap.d.ts +35 -0
- package/dist/store/confirmSwap.d.ts.map +1 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/ui.d.ts +2 -0
- package/dist/store/ui.d.ts.map +1 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/swap.d.ts +11 -0
- package/dist/types/swap.d.ts.map +1 -0
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +5 -0
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +5 -7
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +31 -3
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -3
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +1809 -1326
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1809 -1326
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1813 -1330
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AppRouter.tsx +38 -3
- package/src/components/AppRoutes.tsx +8 -2
- package/src/components/ChangeSlippageButton.tsx +23 -0
- package/src/components/ConfirmSwapErrors.tsx +38 -0
- package/src/components/ConfirmSwapWarnings.tsx +38 -0
- package/src/components/Layout.tsx +22 -6
- package/src/components/UpdateUrl.tsx +100 -18
- package/src/components/warnings/BalanceWarnings.tsx +16 -0
- package/src/components/warnings/ConfirmSwapExtraMessages.tsx +14 -0
- package/src/components/warnings/HighSlippageWarning.tsx +21 -0
- package/src/components/warnings/MinRequiredSlippage.tsx +18 -0
- package/src/constants/navigationRoutes.ts +2 -2
- package/src/constants/swapSettings.ts +9 -0
- package/src/hooks/useNavigateBack.ts +37 -0
- package/src/pages/ConfirmSwapPage.tsx +30 -8
- package/src/pages/ConfirmWalletsPage.tsx +30 -17
- package/src/pages/HistoryPage.tsx +4 -4
- package/src/pages/Home.tsx +79 -36
- package/src/pages/LiquiditySourcesPage.tsx +11 -8
- package/src/pages/SelectChainPage.tsx +9 -28
- package/src/pages/SelectTokenPage.tsx +38 -27
- package/src/pages/SettingsPage.tsx +17 -6
- package/src/pages/SwapDetailsPage.tsx +9 -3
- package/src/pages/WalletsPage.tsx +37 -22
- package/src/store/bestRoute.ts +147 -28
- package/src/store/confirmSwap.ts +327 -0
- package/src/store/settings.ts +40 -28
- package/src/store/ui.ts +15 -0
- package/src/store/wallets.ts +93 -80
- package/src/swapBox.tsx +5 -5
- package/src/types/index.ts +1 -0
- package/src/types/swap.ts +13 -0
- package/src/utils/common.ts +4 -0
- package/src/utils/numbers.ts +17 -0
- package/src/utils/routing.ts +28 -77
- package/src/utils/swap.ts +445 -67
- package/src/utils/wallets.ts +4 -19
- package/dist/hooks/useBestRoute.d.ts +0 -8
- package/dist/hooks/useBestRoute.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap.d.ts +0 -2
- package/dist/hooks/useConfirmSwap.d.ts.map +0 -1
- package/src/hooks/useBestRoute.ts +0 -70
- package/src/hooks/useConfirmSwap.ts +0 -268
package/src/store/wallets.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { SelectableWallet } from '@rango-dev/ui';
|
|
1
2
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
2
3
|
import { create } from 'zustand';
|
|
3
|
-
import {
|
|
4
|
+
import { subscribeWithSelector } from 'zustand/middleware';
|
|
4
5
|
import { httpService } from '../services/httpService';
|
|
5
6
|
import {
|
|
6
7
|
getRequiredChains,
|
|
@@ -52,92 +53,104 @@ interface WalletsStore {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export const useWalletsStore = createSelectors(
|
|
55
|
-
create<WalletsStore>()(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
create<WalletsStore>()(
|
|
57
|
+
subscribeWithSelector((set) => ({
|
|
58
|
+
accounts: [],
|
|
59
|
+
balances: [],
|
|
60
|
+
selectedWallets: [],
|
|
61
|
+
connectWallet: (accounts) => {
|
|
62
|
+
const tokens = useMetaStore.getState().meta.tokens;
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
set((state) => ({
|
|
65
|
+
accounts: state.accounts.concat(accounts),
|
|
66
|
+
balances: state.balances.concat(
|
|
67
|
+
accounts.map((account) => ({
|
|
68
|
+
balances: [],
|
|
69
|
+
address: account.address,
|
|
70
|
+
chain: account.chain,
|
|
71
|
+
loading: true,
|
|
72
|
+
walletType: account.walletType,
|
|
73
|
+
error: false,
|
|
74
|
+
explorerUrl: null,
|
|
75
|
+
}))
|
|
76
|
+
),
|
|
77
|
+
}));
|
|
78
|
+
accounts.forEach(async (account) => {
|
|
79
|
+
try {
|
|
80
|
+
const response = await httpService.getWalletsDetails([
|
|
81
|
+
{ address: account.address, blockchain: account.chain },
|
|
82
|
+
]);
|
|
83
|
+
const retrivedBalance = response.wallets[0];
|
|
84
|
+
if (retrivedBalance) {
|
|
85
|
+
set((state) => ({
|
|
86
|
+
balances: state.balances.map((balance) => {
|
|
87
|
+
return isAccountAndBalanceMatched(account, balance)
|
|
88
|
+
? makeBalanceFor(account, retrivedBalance, tokens)
|
|
89
|
+
: balance;
|
|
90
|
+
}),
|
|
91
|
+
}));
|
|
92
|
+
} else throw new Error('Wallet not found');
|
|
93
|
+
} catch (error) {
|
|
83
94
|
set((state) => ({
|
|
84
95
|
balances: state.balances.map((balance) => {
|
|
85
96
|
return isAccountAndBalanceMatched(account, balance)
|
|
86
|
-
?
|
|
97
|
+
? resetBalanceState(balance)
|
|
87
98
|
: balance;
|
|
88
99
|
}),
|
|
89
100
|
}));
|
|
90
|
-
} else throw new Error('Wallet not found');
|
|
91
|
-
} catch (error) {
|
|
92
|
-
set((state) => ({
|
|
93
|
-
balances: state.balances.map((balance) => {
|
|
94
|
-
return isAccountAndBalanceMatched(account, balance)
|
|
95
|
-
? resetBalanceState(balance)
|
|
96
|
-
: balance;
|
|
97
|
-
}),
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
disconnectWallet: (walletType) => {
|
|
103
|
-
set((state) => ({
|
|
104
|
-
accounts: state.accounts.filter((account) => account.walletType !== walletType),
|
|
105
|
-
balances: state.balances.filter((balance) => balance.walletType !== walletType),
|
|
106
|
-
selectedWallets: state.selectedWallets.filter((wallet) => wallet.walletType != walletType),
|
|
107
|
-
}));
|
|
108
|
-
},
|
|
109
|
-
initSelectedWallets: () =>
|
|
110
|
-
set((state) => {
|
|
111
|
-
const requiredChains = getRequiredChains(useBestRouteStore.getState().bestRoute);
|
|
112
|
-
const connectedWallets = state.accounts;
|
|
113
|
-
const selectedWallets: SelectedWallet[] = [];
|
|
114
|
-
requiredChains.forEach((chain) => {
|
|
115
|
-
const anyWalletSelected = !!state.selectedWallets.find(
|
|
116
|
-
(wallet) => wallet.chain === chain,
|
|
117
|
-
);
|
|
118
|
-
if (!anyWalletSelected) {
|
|
119
|
-
const firstWalletWithMatchedChain = connectedWallets.find(
|
|
120
|
-
(wallet) => wallet.chain === chain,
|
|
121
|
-
);
|
|
122
|
-
if (!!firstWalletWithMatchedChain)
|
|
123
|
-
selectedWallets.push({
|
|
124
|
-
address: firstWalletWithMatchedChain.address,
|
|
125
|
-
chain: firstWalletWithMatchedChain.chain,
|
|
126
|
-
walletType: firstWalletWithMatchedChain.walletType,
|
|
127
|
-
});
|
|
128
101
|
}
|
|
129
102
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
103
|
+
},
|
|
104
|
+
disconnectWallet: (walletType) => {
|
|
105
|
+
set((state) => ({
|
|
106
|
+
accounts: state.accounts.filter(
|
|
107
|
+
(account) => account.walletType !== walletType
|
|
108
|
+
),
|
|
109
|
+
balances: state.balances.filter(
|
|
110
|
+
(balance) => balance.walletType !== walletType
|
|
111
|
+
),
|
|
112
|
+
selectedWallets: state.selectedWallets.filter(
|
|
113
|
+
(wallet) => wallet.walletType != walletType
|
|
114
|
+
),
|
|
115
|
+
}));
|
|
116
|
+
},
|
|
117
|
+
initSelectedWallets: () =>
|
|
118
|
+
set((state) => {
|
|
119
|
+
const requiredChains = getRequiredChains(
|
|
120
|
+
useBestRouteStore.getState().bestRoute
|
|
121
|
+
);
|
|
122
|
+
const connectedWallets = state.accounts;
|
|
123
|
+
const selectedWallets: SelectedWallet[] = [];
|
|
124
|
+
requiredChains.forEach((chain) => {
|
|
125
|
+
const anyWalletSelected = !!state.selectedWallets.find(
|
|
126
|
+
(wallet) => wallet.chain === chain
|
|
127
|
+
);
|
|
128
|
+
if (!anyWalletSelected) {
|
|
129
|
+
const firstWalletWithMatchedChain = connectedWallets.find(
|
|
130
|
+
(wallet) => wallet.chain === chain
|
|
131
|
+
);
|
|
132
|
+
if (!!firstWalletWithMatchedChain)
|
|
133
|
+
selectedWallets.push({
|
|
134
|
+
address: firstWalletWithMatchedChain.address,
|
|
135
|
+
chain: firstWalletWithMatchedChain.chain,
|
|
136
|
+
walletType: firstWalletWithMatchedChain.walletType,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
selectedWallets: state.selectedWallets.concat(selectedWallets),
|
|
142
|
+
};
|
|
143
|
+
}),
|
|
144
|
+
setSelectedWallet: (wallet) =>
|
|
145
|
+
set((state) => ({
|
|
146
|
+
selectedWallets: state.selectedWallets
|
|
147
|
+
.filter((selectedWallet) => selectedWallet.chain !== wallet.chain)
|
|
148
|
+
.concat({
|
|
149
|
+
chain: wallet.chain,
|
|
150
|
+
address: wallet.address,
|
|
151
|
+
walletType: wallet.walletType,
|
|
152
|
+
}),
|
|
153
|
+
})),
|
|
154
|
+
}))
|
|
155
|
+
)
|
|
143
156
|
);
|
package/src/swapBox.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { SwapContainer } from '@
|
|
1
|
+
import { SwapContainer } from '@rango-dev/ui';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { AppRouter } from './components/AppRouter';
|
|
4
4
|
import { useMetaStore } from './store/meta';
|
|
5
|
-
import { Events, Provider } from '@
|
|
6
|
-
import { allProviders } from '@
|
|
7
|
-
import { EventHandler } from '@
|
|
8
|
-
import { isEvmBlockchain, Network } from '@
|
|
5
|
+
import { Events, Provider } from '@rango-dev/wallets-core';
|
|
6
|
+
import { allProviders } from '@rango-dev/provider-all';
|
|
7
|
+
import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
|
|
8
|
+
import { isEvmBlockchain, Network } from '@rango-dev/wallets-shared';
|
|
9
9
|
import {
|
|
10
10
|
prepareAccountsForWalletStore,
|
|
11
11
|
walletAndSupportedChainsNames,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './swap';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SwapSavedSettings } from '@rango-dev/ui/dist/types/swaps';
|
|
2
|
+
|
|
3
|
+
export type PendingSwapSettings = Omit<
|
|
4
|
+
SwapSavedSettings,
|
|
5
|
+
'disabledSwappersIds'
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
export type SwapButtonState = (
|
|
9
|
+
| { disabled: true }
|
|
10
|
+
| { disabled: false; hasWarning?: boolean }
|
|
11
|
+
) & {
|
|
12
|
+
title: string;
|
|
13
|
+
};
|
package/src/utils/common.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export function removeDuplicateFrom<T>(array: T[]): T[] {
|
|
2
2
|
return Array.from(new Set(array));
|
|
3
3
|
}
|
|
4
|
+
|
|
5
|
+
export function areEqual(array1: (number | string)[], array2: (number | string)[]) {
|
|
6
|
+
return array1.length === array2.length && array1.every((v, i) => v === array2[i]);
|
|
7
|
+
}
|
package/src/utils/numbers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BigNumber } from 'bignumber.js';
|
|
2
|
+
import { BestRouteResponse } from 'rango-sdk';
|
|
2
3
|
|
|
3
4
|
export const percentToString = (p: number, fractions = 0): string => (p * 100).toFixed(fractions);
|
|
4
5
|
export const secondsToString = (s: number): string => {
|
|
@@ -92,3 +93,19 @@ export function removeExtraDecimals(num: string, maxDecimals: number): string {
|
|
|
92
93
|
return num;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
96
|
+
|
|
97
|
+
export const totalArrivalTime = (data: BestRouteResponse | null) =>
|
|
98
|
+
data?.result?.swaps?.reduce((a, b) => a + b.estimatedTimeInSeconds, 0) || 0;
|
|
99
|
+
|
|
100
|
+
export const rawFees = (data: BestRouteResponse): string =>
|
|
101
|
+
(
|
|
102
|
+
data?.result?.swaps?.flatMap((s) => s.fee.map((f) => ({ swapperId: s.swapperId, fee: f }))) ||
|
|
103
|
+
[]
|
|
104
|
+
)
|
|
105
|
+
.reduce((partialSum, a) => partialSum + parseFloat(a.fee.amount), 0)
|
|
106
|
+
.toFixed(3);
|
|
107
|
+
|
|
108
|
+
export const decimalNumber = (number = '0', toFixed: number) => parseFloat(number).toFixed(toFixed);
|
|
109
|
+
|
|
110
|
+
export const containsText = (text: string, searchText: string) =>
|
|
111
|
+
text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
|
package/src/utils/routing.ts
CHANGED
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
} from '@rango-dev/ui/dist/types/swaps';
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
import { BestRouteResponse } from 'rango-sdk';
|
|
7
|
-
import {
|
|
8
|
-
import { numberToString } from './numbers';
|
|
7
|
+
import { areEqual } from './common';
|
|
9
8
|
import { SelectedWallet } from './wallets';
|
|
10
9
|
|
|
11
10
|
export const getBestRouteToTokenUsdPrice = (
|
|
@@ -13,82 +12,32 @@ export const getBestRouteToTokenUsdPrice = (
|
|
|
13
12
|
): number | null | undefined =>
|
|
14
13
|
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
15
14
|
|
|
16
|
-
export
|
|
17
|
-
isChanged: boolean;
|
|
18
|
-
warningMessage?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const compareRoutes = (
|
|
22
|
-
route1: BestRouteResponse,
|
|
23
|
-
route2: BestRouteResponse,
|
|
24
|
-
inputAmount: string,
|
|
25
|
-
fromTokenUsdPrice: number | null,
|
|
26
|
-
toTokenUsdPrice: number | null,
|
|
27
|
-
): RouteChangeStatus => {
|
|
28
|
-
let outUsdValue: BigNumber = (
|
|
29
|
-
new BigNumber(route2.result?.outputAmount || '0') || ZERO
|
|
30
|
-
).multipliedBy(toTokenUsdPrice || 0);
|
|
31
|
-
if (outUsdValue.isNaN()) outUsdValue = ZERO;
|
|
32
|
-
let inUsdValue: BigNumber = new BigNumber(inputAmount || '0').multipliedBy(
|
|
33
|
-
fromTokenUsdPrice || 0,
|
|
34
|
-
);
|
|
35
|
-
if (inUsdValue.isNaN()) inUsdValue = ZERO;
|
|
36
|
-
const outToInRatio =
|
|
37
|
-
inUsdValue === null || inUsdValue.lte(ZERO)
|
|
38
|
-
? 0
|
|
39
|
-
: outUsdValue === null || outUsdValue.lte(ZERO)
|
|
40
|
-
? 0
|
|
41
|
-
: outUsdValue.div(inUsdValue).minus(1).multipliedBy(100);
|
|
42
|
-
const disableSwapButton =
|
|
43
|
-
(parseInt(outToInRatio?.toFixed(2) || '0') <= -10 &&
|
|
44
|
-
(inUsdValue === null || inUsdValue.gte(new BigNumber(400)))) ||
|
|
45
|
-
(parseInt(outToInRatio?.toFixed(2) || '0') <= -5 &&
|
|
46
|
-
(inUsdValue === null || inUsdValue.gte(new BigNumber(1000))));
|
|
47
|
-
|
|
48
|
-
if (disableSwapButton) {
|
|
49
|
-
return {
|
|
50
|
-
isChanged: true,
|
|
51
|
-
warningMessage: 'Route updated and price impact is too high, try again later!',
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const out1 = route1.result?.outputAmount || null;
|
|
56
|
-
const out2 = route2.result?.outputAmount || null;
|
|
57
|
-
if (!!out1 && !!out2) {
|
|
58
|
-
const changePercent = new BigNumber(out2).div(new BigNumber(out1)).minus(1).multipliedBy(100);
|
|
59
|
-
if (changePercent.toNumber() <= -1) {
|
|
60
|
-
return {
|
|
61
|
-
isChanged: true,
|
|
62
|
-
warningMessage: `Output amount changed to ${numberToString(out2)}
|
|
63
|
-
(${numberToString(changePercent, null, 2)}% change).`,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
15
|
+
export function isNumberOfSwapsChanged(route1: BestRouteResponse, route2: BestRouteResponse) {
|
|
67
16
|
const route1Swaps = route1.result?.swaps || [];
|
|
68
17
|
const route2Swaps = route2.result?.swaps || [];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
18
|
+
return route1Swaps.length !== route2Swaps.length;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isRouteSwappersUpdated(route1: BestRouteResponse, route2: BestRouteResponse) {
|
|
22
|
+
const route1Swappers = route1.result?.swaps.map((swap) => swap.swapperId) || [];
|
|
23
|
+
const route2Swappers = route2.result?.swaps.map((swap) => swap.swapperId) || [];
|
|
24
|
+
return !areEqual(route1Swappers, route2Swappers);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isRouteInternalCoinsUpdated(route1: BestRouteResponse, route2: BestRouteResponse) {
|
|
28
|
+
const route1InternalCoins = route1.result?.swaps.map((swap) => swap.to.symbol) || [];
|
|
29
|
+
const route2InternalCoins = route2.result?.swaps.map((swap) => swap.to.symbol) || [];
|
|
30
|
+
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const isRouteChanged = (route1: BestRouteResponse, route2: BestRouteResponse): boolean => {
|
|
34
|
+
return (
|
|
35
|
+
isNumberOfSwapsChanged(route1, route2) ||
|
|
36
|
+
isRouteSwappersUpdated(route1, route2) ||
|
|
37
|
+
isRouteInternalCoinsUpdated(route1, route2)
|
|
38
|
+
);
|
|
83
39
|
};
|
|
84
40
|
|
|
85
|
-
export const getOutToInRatio = (fromUsdValue: BigNumber | null, toUsdValue: BigNumber | null) =>
|
|
86
|
-
fromUsdValue === null || fromUsdValue.lte(ZERO)
|
|
87
|
-
? 0
|
|
88
|
-
: toUsdValue === null || toUsdValue.lte(ZERO)
|
|
89
|
-
? 0
|
|
90
|
-
: toUsdValue.div(fromUsdValue).minus(1).multipliedBy(100);
|
|
91
|
-
|
|
92
41
|
export const outToRatioHasWarning = (fromUsdValue: BigNumber | null, outToInRatio: BigNumber | 0) =>
|
|
93
42
|
(parseInt(outToInRatio?.toFixed(2) || '0') <= -10 &&
|
|
94
43
|
(fromUsdValue === null || fromUsdValue.gte(new BigNumber(200)))) ||
|
|
@@ -96,13 +45,15 @@ export const outToRatioHasWarning = (fromUsdValue: BigNumber | null, outToInRati
|
|
|
96
45
|
(fromUsdValue === null || fromUsdValue.gte(new BigNumber(1000))));
|
|
97
46
|
|
|
98
47
|
export const getRequiredBalanceOfWallet = (
|
|
99
|
-
|
|
48
|
+
selectedWallet: SelectedWallet,
|
|
100
49
|
fee: SimulationValidationStatus[] | null,
|
|
101
50
|
): SimulationAssetAndAmount[] | null => {
|
|
102
51
|
if (fee === null) return null;
|
|
103
52
|
const relatedFeeStatus = fee
|
|
104
|
-
?.find((item) => item.blockchain ===
|
|
105
|
-
?.wallets.find(
|
|
53
|
+
?.find((item) => item.blockchain === selectedWallet.chain)
|
|
54
|
+
?.wallets.find(
|
|
55
|
+
(wallet) => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase(),
|
|
56
|
+
);
|
|
106
57
|
if (!relatedFeeStatus) return null;
|
|
107
58
|
return relatedFeeStatus.requiredAssets;
|
|
108
59
|
};
|