@rango-dev/widget-embedded 0.1.19 → 0.1.20-next.1
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 +3 -3
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/Widget.d.ts +8 -0
- package/dist/Widget.d.ts.map +1 -0
- package/dist/components/AppRouter.d.ts +7 -7
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +7 -7
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/BottomLogo.d.ts +2 -2
- package/dist/components/BottomLogo.d.ts.map +1 -1
- package/dist/components/ChangeSlippageButton.d.ts +2 -2
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -1
- package/dist/components/ConfirmSwapErrors.d.ts +3 -3
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +2 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/Footer.d.ts +111 -1
- package/dist/components/Footer.d.ts.map +1 -1
- package/dist/components/HeaderButtons.d.ts +6 -6
- package/dist/components/HeaderButtons.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +6 -6
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/PercentageChange.d.ts +8 -8
- package/dist/components/PercentageChange.d.ts.map +1 -1
- package/dist/components/RoutesOverview.d.ts +119 -9
- package/dist/components/RoutesOverview.d.ts.map +1 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts +119 -9
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
- package/dist/components/SwitchFromAndTo.d.ts +3 -3
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts +17 -17
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +20 -20
- package/dist/components/TokenPreview.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/BalanceErrors.d.ts +6 -6
- package/dist/components/warnings/BalanceErrors.d.ts.map +1 -1
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts +6 -6
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts.map +1 -1
- package/dist/components/warnings/HighSlippageWarning.d.ts +6 -6
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts +6 -6
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +3 -3
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/constants/navigationRoutes.d.ts +13 -13
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/constants/numbers.d.ts +2 -2
- package/dist/constants/numbers.d.ts.map +1 -1
- package/dist/constants/searchParams.d.ts +7 -7
- package/dist/constants/searchParams.d.ts.map +1 -1
- package/dist/constants/swapSettings.d.ts +5 -5
- package/dist/constants/swapSettings.d.ts.map +1 -1
- package/dist/globalStyles.d.ts +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts +10 -10
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useNavigateBack.d.ts +3 -3
- package/dist/hooks/useNavigateBack.d.ts.map +1 -1
- package/dist/hooks/usePrevious.d.ts +1 -1
- package/dist/hooks/usePrevious.d.ts.map +1 -1
- package/dist/hooks/useSelectLanguage.d.ts +4 -4
- package/dist/hooks/useSelectLanguage.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +30 -4
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/i18n.d.ts +2 -2
- package/dist/i18n.d.ts.map +1 -1
- package/dist/index.d.ts +5 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +7 -0
- package/dist/mockData/pendingSwap.d.ts +1 -1
- package/dist/mockData/pendingSwap.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts +2 -2
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts +2 -2
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts +2 -2
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts +6 -6
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts +7 -7
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts +14 -14
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +7 -7
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts +2 -2
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +8 -8
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/httpService.d.ts +3 -3
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +67 -31
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/meta.d.ts +17 -8
- package/dist/store/meta.d.ts.map +1 -1
- package/dist/store/selectors.d.ts +10 -10
- package/dist/store/selectors.d.ts.map +1 -1
- package/dist/store/settings.d.ts +55 -18
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/ui.d.ts +22 -1
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +55 -33
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +114 -114
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/routing.d.ts +57 -57
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/types/swap.d.ts +16 -16
- package/dist/types/swap.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +6 -6
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/common.d.ts +3 -3
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +6 -6
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/date.d.ts +2 -2
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +13 -13
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/queue.d.ts +3 -3
- package/dist/utils/queue.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +17 -17
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +50 -50
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts +3 -3
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +27 -27
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +15 -11
- package/src/QueueManager.tsx +5 -1
- package/src/{index.tsx → Widget.tsx} +1 -14
- package/src/components/Layout.tsx +23 -17
- package/src/components/RoutesOverview.tsx +2 -2
- package/src/components/TokenInfo.tsx +4 -4
- package/src/components/TokenPreview.tsx +3 -3
- package/src/components/warnings/BalanceErrors.tsx +2 -2
- package/src/components/warnings/MinRequiredSlippage.tsx +2 -2
- package/src/index.ts +18 -0
- package/src/pages/ConfirmSwapPage.tsx +14 -12
- package/src/pages/SwapDetailsPage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +6 -2
- package/src/utils/wallets.ts +6 -3
- package/dist/widget-embedded.cjs.development.js +0 -3398
- package/dist/widget-embedded.cjs.development.js.map +0 -1
- package/dist/widget-embedded.cjs.production.min.js +0 -3398
- package/dist/widget-embedded.cjs.production.min.js.map +0 -1
- package/dist/widget-embedded.esm.js +0 -3384
- package/dist/widget-embedded.esm.js.map +0 -1
|
@@ -1,3398 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var ui = require('@rango-dev/ui');
|
|
8
|
-
var React = require('react');
|
|
9
|
-
var React__default = _interopDefault(React);
|
|
10
|
-
var reactRouter = require('react-router');
|
|
11
|
-
var queueManagerRangoPreset = require('@rango-dev/queue-manager-rango-preset');
|
|
12
|
-
var rangoTypes = require('rango-types');
|
|
13
|
-
var reactRouterDom = require('react-router-dom');
|
|
14
|
-
var zustand = require('zustand');
|
|
15
|
-
var BigNumber = require('bignumber.js');
|
|
16
|
-
var BigNumber__default = _interopDefault(BigNumber);
|
|
17
|
-
var middleware = require('zustand/middleware');
|
|
18
|
-
var rangoSdk = require('rango-sdk');
|
|
19
|
-
var walletsShared = require('@rango-dev/wallets-shared');
|
|
20
|
-
var walletsCore = require('@rango-dev/wallets-core');
|
|
21
|
-
var shallow = require('zustand/shallow');
|
|
22
|
-
var providerAll = require('@rango-dev/provider-all');
|
|
23
|
-
var reactI18next = require('react-i18next');
|
|
24
|
-
var i18n = require('i18next');
|
|
25
|
-
var i18n__default = _interopDefault(i18n);
|
|
26
|
-
var queueManagerReact = require('@rango-dev/queue-manager-react');
|
|
27
|
-
var dayjs = _interopDefault(require('dayjs'));
|
|
28
|
-
var _ = require('@rango-dev/ui/');
|
|
29
|
-
var Backend = _interopDefault(require('i18next-http-backend'));
|
|
30
|
-
var LanguageDetector = _interopDefault(require('i18next-browser-languagedetector'));
|
|
31
|
-
|
|
32
|
-
const ZERO = /*#__PURE__*/new BigNumber__default(0);
|
|
33
|
-
|
|
34
|
-
function removeDuplicateFrom(array) {
|
|
35
|
-
return Array.from(new Set(array));
|
|
36
|
-
}
|
|
37
|
-
function areEqual(array1, array2) {
|
|
38
|
-
return array1.length === array2.length && array1.every((v, i) => v === array2[i]);
|
|
39
|
-
}
|
|
40
|
-
function debounce(fn, time) {
|
|
41
|
-
let timeoutId;
|
|
42
|
-
return wrapper;
|
|
43
|
-
function wrapper() {
|
|
44
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
|
-
args[_key] = arguments[_key];
|
|
46
|
-
}
|
|
47
|
-
if (timeoutId) {
|
|
48
|
-
clearTimeout(timeoutId);
|
|
49
|
-
}
|
|
50
|
-
timeoutId = setTimeout(() => {
|
|
51
|
-
timeoutId = null;
|
|
52
|
-
fn(...args);
|
|
53
|
-
}, time);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const secondsToString = s => {
|
|
58
|
-
const seconds = (s % 60).toString().padStart(2, '0');
|
|
59
|
-
const minutes = parseInt((s / 60).toString()).toString().padStart(2, '0');
|
|
60
|
-
return `${minutes}:${seconds}`;
|
|
61
|
-
};
|
|
62
|
-
const numberToString = function (number, minDecimals, maxDecimals) {
|
|
63
|
-
if (minDecimals === void 0) {
|
|
64
|
-
minDecimals = null;
|
|
65
|
-
}
|
|
66
|
-
if (maxDecimals === void 0) {
|
|
67
|
-
maxDecimals = null;
|
|
68
|
-
}
|
|
69
|
-
if (number === null || number === undefined) return '';
|
|
70
|
-
if (number === '') return '';
|
|
71
|
-
const n = new BigNumber.BigNumber(number);
|
|
72
|
-
const roundingMode = 1;
|
|
73
|
-
let maxI = 1000;
|
|
74
|
-
for (let i = 0; i < 60; i++) {
|
|
75
|
-
if (new BigNumber.BigNumber(n.toFixed(i, roundingMode)).eq(n)) {
|
|
76
|
-
maxI = i;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (n.gte(10000)) return n.toFormat(0, roundingMode);
|
|
81
|
-
if (n.gte(1000)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 1))), roundingMode);
|
|
82
|
-
if (n.gte(100)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 1))), roundingMode);
|
|
83
|
-
if (n.gte(1)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 2))), roundingMode);
|
|
84
|
-
if (n.gte(0.01)) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 4))), roundingMode);
|
|
85
|
-
for (let i = minDecimals || 4; i < 17; i++) if (n.gte(Math.pow(10, -i))) return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, i))), roundingMode);
|
|
86
|
-
if (n.isEqualTo(0)) return '0';
|
|
87
|
-
return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 8))), roundingMode);
|
|
88
|
-
};
|
|
89
|
-
const totalArrivalTime = data => data?.result?.swaps?.reduce((a, b) => a + b.estimatedTimeInSeconds, 0) || 0;
|
|
90
|
-
const isPositiveNumber = text => !!text && parseFloat(text) > 0;
|
|
91
|
-
|
|
92
|
-
function searchParamsToToken(tokens, searchParams, chain) {
|
|
93
|
-
if (!chain) return null;
|
|
94
|
-
return tokens.find(token => {
|
|
95
|
-
const symbolAndAddress = searchParams?.split('--');
|
|
96
|
-
if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
|
|
97
|
-
return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
|
|
98
|
-
}) || null;
|
|
99
|
-
}
|
|
100
|
-
function getBestRouteToTokenUsdPrice(bestRoute) {
|
|
101
|
-
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
102
|
-
}
|
|
103
|
-
function isNumberOfSwapsChanged(route1, route2) {
|
|
104
|
-
const route1Swaps = route1.result?.swaps || [];
|
|
105
|
-
const route2Swaps = route2.result?.swaps || [];
|
|
106
|
-
return route1Swaps.length !== route2Swaps.length;
|
|
107
|
-
}
|
|
108
|
-
function isRouteSwappersUpdated(route1, route2) {
|
|
109
|
-
const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
|
|
110
|
-
const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
|
|
111
|
-
return !areEqual(route1Swappers, route2Swappers);
|
|
112
|
-
}
|
|
113
|
-
function isRouteInternalCoinsUpdated(route1, route2) {
|
|
114
|
-
const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
115
|
-
const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
116
|
-
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
117
|
-
}
|
|
118
|
-
function isRouteChanged(route1, route2) {
|
|
119
|
-
return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
|
|
120
|
-
}
|
|
121
|
-
function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
122
|
-
if (fee === null) return null;
|
|
123
|
-
const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
|
|
124
|
-
if (!relatedFeeStatus) return null;
|
|
125
|
-
return relatedFeeStatus.requiredAssets;
|
|
126
|
-
}
|
|
127
|
-
function isRouteParametersChanged(params) {
|
|
128
|
-
if (params.store === 'bestRoute') {
|
|
129
|
-
const {
|
|
130
|
-
prevState,
|
|
131
|
-
currentState
|
|
132
|
-
} = params;
|
|
133
|
-
return !!currentState.fromToken && !!currentState.toToken && (prevState.fromChain?.name !== currentState.fromChain?.name || prevState.toChain?.name !== currentState.toChain?.name || prevState.fromToken?.symbol !== currentState.fromToken?.symbol || prevState.toToken?.symbol !== currentState.toToken?.symbol || prevState.fromToken?.blockchain !== prevState.fromToken?.blockchain || prevState.toToken?.blockchain !== currentState.toToken?.blockchain || prevState.fromToken?.address !== currentState.fromToken?.address || prevState.toToken?.address !== currentState.toToken?.address || prevState.inputAmount !== currentState.inputAmount);
|
|
134
|
-
} else if (params.store === 'settings') {
|
|
135
|
-
const {
|
|
136
|
-
prevState,
|
|
137
|
-
currentState
|
|
138
|
-
} = params;
|
|
139
|
-
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
140
|
-
}
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
function getFormatedBestRoute(bestRoute) {
|
|
144
|
-
if (!bestRoute) return null;
|
|
145
|
-
const formatedSwaps = (bestRoute.result?.swaps || []).map(swap => ({
|
|
146
|
-
...swap,
|
|
147
|
-
fromAmount: numberToString(swap.fromAmount, 6, 6),
|
|
148
|
-
toAmount: numberToString(swap.toAmount, 6, 6)
|
|
149
|
-
}));
|
|
150
|
-
return {
|
|
151
|
-
...bestRoute,
|
|
152
|
-
...(bestRoute.result && {
|
|
153
|
-
result: {
|
|
154
|
-
...bestRoute.result,
|
|
155
|
-
swaps: formatedSwaps
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function getFormatedPendingSwap(pendingSwap) {
|
|
161
|
-
const formatedSteps = pendingSwap.steps.map(step => ({
|
|
162
|
-
...step,
|
|
163
|
-
feeInUsd: numberToString(step.feeInUsd, 4, 4),
|
|
164
|
-
outputAmount: numberToString(step.outputAmount, 6, 6),
|
|
165
|
-
expectedOutputAmountHumanReadable: numberToString(step.expectedOutputAmountHumanReadable, 6, 6)
|
|
166
|
-
}));
|
|
167
|
-
return {
|
|
168
|
-
...pendingSwap,
|
|
169
|
-
inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
|
|
170
|
-
steps: formatedSteps
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
//todo: refactor bestRoute store and add loadingStatus
|
|
174
|
-
const getBestRouteStatus = (loading, error) => {
|
|
175
|
-
if (loading) return 'loading';
|
|
176
|
-
if (error) return 'failed';else return 'success';
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const createSelectors = _store => {
|
|
180
|
-
let store = _store;
|
|
181
|
-
store.use = {};
|
|
182
|
-
for (let k of Object.keys(store.getState())) {
|
|
183
|
-
store.use[k] = () => store(s => s[k]);
|
|
184
|
-
}
|
|
185
|
-
return store;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
189
|
-
let configs = {
|
|
190
|
-
API_KEY: RANGO_PUBLIC_API_KEY
|
|
191
|
-
};
|
|
192
|
-
function getConfig(name) {
|
|
193
|
-
return configs[name];
|
|
194
|
-
}
|
|
195
|
-
function initConfig(nextConfigs) {
|
|
196
|
-
let clonedConfigs;
|
|
197
|
-
if (typeof structuredClone === 'function') {
|
|
198
|
-
clonedConfigs = structuredClone(nextConfigs);
|
|
199
|
-
} else {
|
|
200
|
-
clonedConfigs = JSON.parse(JSON.stringify(nextConfigs));
|
|
201
|
-
}
|
|
202
|
-
configs = clonedConfigs;
|
|
203
|
-
return configs;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let rango = undefined;
|
|
207
|
-
const httpService = () => {
|
|
208
|
-
if (rango) return rango;
|
|
209
|
-
rango = new rangoSdk.RangoClient(getConfig('API_KEY'));
|
|
210
|
-
return rango;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
214
|
-
const DEFAULT_SLIPPAGE = 1;
|
|
215
|
-
const HIGH_SLIPPAGE = 5;
|
|
216
|
-
const MAX_SLIPPAGE = 100;
|
|
217
|
-
const MIN_SLIPPGAE = 0;
|
|
218
|
-
|
|
219
|
-
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
|
|
220
|
-
meta: {
|
|
221
|
-
blockchains: [],
|
|
222
|
-
popularTokens: [],
|
|
223
|
-
swappers: [],
|
|
224
|
-
tokens: []
|
|
225
|
-
},
|
|
226
|
-
loadingStatus: 'loading',
|
|
227
|
-
fetchMeta: async () => {
|
|
228
|
-
try {
|
|
229
|
-
const response = await httpService().getAllMetadata();
|
|
230
|
-
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
231
|
-
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
232
|
-
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
233
|
-
set({
|
|
234
|
-
meta: response,
|
|
235
|
-
loadingStatus: 'success'
|
|
236
|
-
});
|
|
237
|
-
} catch (error) {
|
|
238
|
-
set({
|
|
239
|
-
loadingStatus: 'failed'
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
})));
|
|
244
|
-
|
|
245
|
-
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.persist( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
246
|
-
slippage: DEFAULT_SLIPPAGE,
|
|
247
|
-
customSlippage: null,
|
|
248
|
-
infiniteApprove: false,
|
|
249
|
-
affiliateRef: null,
|
|
250
|
-
disabledLiquiditySources: [],
|
|
251
|
-
theme: 'auto',
|
|
252
|
-
setSlippage: slippage => set(() => ({
|
|
253
|
-
slippage: slippage
|
|
254
|
-
})),
|
|
255
|
-
setCustomSlippage: customSlippage => set(() => ({
|
|
256
|
-
customSlippage: customSlippage
|
|
257
|
-
})),
|
|
258
|
-
setAffiliateRef: affiliateRef => set(() => ({
|
|
259
|
-
affiliateRef
|
|
260
|
-
})),
|
|
261
|
-
toggleAllLiquiditySources: () => set(state => {
|
|
262
|
-
const {
|
|
263
|
-
swappers
|
|
264
|
-
} = useMetaStore.getState().meta;
|
|
265
|
-
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
266
|
-
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
267
|
-
disabledLiquiditySources: []
|
|
268
|
-
};else {
|
|
269
|
-
return {
|
|
270
|
-
disabledLiquiditySources: swappersGroup
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}),
|
|
274
|
-
toggleInfiniteApprove: () => set(state => ({
|
|
275
|
-
infiniteApprove: !state.infiniteApprove
|
|
276
|
-
})),
|
|
277
|
-
toggleLiquiditySource: name => set(state => {
|
|
278
|
-
if (state.disabledLiquiditySources.includes(name)) return {
|
|
279
|
-
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
280
|
-
};else return {
|
|
281
|
-
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
282
|
-
};
|
|
283
|
-
}),
|
|
284
|
-
setTheme: theme => set(() => ({
|
|
285
|
-
theme
|
|
286
|
-
}))
|
|
287
|
-
})), {
|
|
288
|
-
name: 'user-settings'
|
|
289
|
-
})));
|
|
290
|
-
|
|
291
|
-
function getStateWallet(state) {
|
|
292
|
-
switch (true) {
|
|
293
|
-
case state.connected:
|
|
294
|
-
return ui.WalletState.CONNECTED;
|
|
295
|
-
case state.connecting:
|
|
296
|
-
return ui.WalletState.CONNECTING;
|
|
297
|
-
case !state.installed:
|
|
298
|
-
return ui.WalletState.NOT_INSTALLED;
|
|
299
|
-
default:
|
|
300
|
-
return ui.WalletState.DISCONNECTED;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
const excludedWallets = [walletsShared.WalletType.UNKNOWN, walletsShared.WalletType.LEAP];
|
|
304
|
-
function getlistWallet(getState, getWalletInfo, list) {
|
|
305
|
-
return list.filter(wallet => !excludedWallets.includes(wallet)).map(type => {
|
|
306
|
-
const {
|
|
307
|
-
name,
|
|
308
|
-
img: image,
|
|
309
|
-
installLink,
|
|
310
|
-
showOnMobile
|
|
311
|
-
} = getWalletInfo(type);
|
|
312
|
-
const state = getStateWallet(getState(type));
|
|
313
|
-
return {
|
|
314
|
-
name,
|
|
315
|
-
image,
|
|
316
|
-
installLink: walletsShared.detectInstallLink(installLink),
|
|
317
|
-
state,
|
|
318
|
-
type,
|
|
319
|
-
showOnMobile: typeof showOnMobile === 'undefined' ? false : true
|
|
320
|
-
};
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
function walletAndSupportedChainsNames(supportedChains) {
|
|
324
|
-
if (!supportedChains) return null;
|
|
325
|
-
let walletAndSupportedChainsNames = [];
|
|
326
|
-
walletAndSupportedChainsNames = supportedChains.map(blockchainMeta => blockchainMeta.name);
|
|
327
|
-
return walletAndSupportedChainsNames;
|
|
328
|
-
}
|
|
329
|
-
function prepareAccountsForWalletStore(wallet, accounts, evmBasedChains, supportedChainNames) {
|
|
330
|
-
const result = [];
|
|
331
|
-
function addAccount(network, address) {
|
|
332
|
-
const newAccount = {
|
|
333
|
-
address,
|
|
334
|
-
chain: network,
|
|
335
|
-
walletType: wallet
|
|
336
|
-
};
|
|
337
|
-
result.push(newAccount);
|
|
338
|
-
}
|
|
339
|
-
const supportedChains = supportedChainNames || [];
|
|
340
|
-
accounts.forEach(account => {
|
|
341
|
-
const {
|
|
342
|
-
address,
|
|
343
|
-
network
|
|
344
|
-
} = walletsCore.readAccountAddress(account);
|
|
345
|
-
const hasLimitation = supportedChains.length > 0;
|
|
346
|
-
const isSupported = supportedChains.includes(network);
|
|
347
|
-
const isUnknown = network === walletsShared.Network.Unknown;
|
|
348
|
-
const notSupportedNetworkByWallet = hasLimitation && !isSupported && !isUnknown;
|
|
349
|
-
// Here we check given `network` is not supported by wallet
|
|
350
|
-
// And also the network is known.
|
|
351
|
-
if (notSupportedNetworkByWallet) return;
|
|
352
|
-
// In some cases we can handle unknown network by checking its address
|
|
353
|
-
// pattern and act on it.
|
|
354
|
-
// Example: showing our evm compatible netwrok when the uknown network is evem.
|
|
355
|
-
// Otherwise, we stop executing this function.
|
|
356
|
-
const isUknownAndEvmBased = network === walletsShared.Network.Unknown && walletsShared.isEvmAddress(address);
|
|
357
|
-
if (isUnknown && !isUknownAndEvmBased) return;
|
|
358
|
-
const isEvmBasedChain = evmBasedChains.includes(network);
|
|
359
|
-
// If it's an evm network, we will add the address to all the evm chains.
|
|
360
|
-
if (isEvmBasedChain || isUknownAndEvmBased) {
|
|
361
|
-
// all evm chains are not supported in wallets, so we are adding
|
|
362
|
-
// only to those that are supported by wallet.
|
|
363
|
-
const evmChainsSupportedByWallet = supportedChains.filter(chain => evmBasedChains.includes(chain));
|
|
364
|
-
evmChainsSupportedByWallet.forEach(network => {
|
|
365
|
-
// EVM addresses are not case sensetive.
|
|
366
|
-
// Some wallets like Binance-chain return some letters in uppercase which produces bugs in our wallet state.
|
|
367
|
-
addAccount(network, address.toLowerCase());
|
|
368
|
-
});
|
|
369
|
-
} else {
|
|
370
|
-
addAccount(network, address);
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
return result;
|
|
374
|
-
}
|
|
375
|
-
function getRequiredChains(route) {
|
|
376
|
-
const wallets = [];
|
|
377
|
-
route?.result?.swaps.forEach(swap => {
|
|
378
|
-
const currentStepFromBlockchain = swap.from.blockchain;
|
|
379
|
-
const currentStepToBlockchain = swap.to.blockchain;
|
|
380
|
-
let lastAddedWallet = wallets[wallets.length - 1];
|
|
381
|
-
if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
|
|
382
|
-
lastAddedWallet = wallets[wallets.length - 1];
|
|
383
|
-
if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
|
|
384
|
-
});
|
|
385
|
-
return wallets;
|
|
386
|
-
}
|
|
387
|
-
function getSelectableWallets(connectedWallets, selectedWallets, getWalletInfo) {
|
|
388
|
-
const selectableWallets = connectedWallets.map(connectedWallet => ({
|
|
389
|
-
address: connectedWallet.address,
|
|
390
|
-
walletType: connectedWallet.walletType,
|
|
391
|
-
chain: connectedWallet.chain,
|
|
392
|
-
image: getWalletInfo(connectedWallet.walletType).img,
|
|
393
|
-
name: getWalletInfo(connectedWallet.walletType).name,
|
|
394
|
-
selected: !!selectedWallets.find(selectedWallet => selectedWallet.chain === connectedWallet.chain && selectedWallet.walletType === connectedWallet.walletType)
|
|
395
|
-
}));
|
|
396
|
-
return selectableWallets;
|
|
397
|
-
}
|
|
398
|
-
function getBalanceFromWallet(connectedWallets, chain, symbol, address) {
|
|
399
|
-
if (connectedWallets.length === 0) return null;
|
|
400
|
-
const selectedChainWallets = connectedWallets.filter(wallet => wallet.chain === chain);
|
|
401
|
-
if (selectedChainWallets.length === 0) return null;
|
|
402
|
-
return selectedChainWallets.map(wallet => wallet.balances?.find(balance => address !== null && balance.address === address || address === null && balance.address === address && balance.symbol === symbol) || null).filter(balance => balance !== null).sort((a, b) => parseFloat(b?.amount || '0') - parseFloat(a?.amount || '1')).find(() => true) || null;
|
|
403
|
-
}
|
|
404
|
-
function isAccountAndWalletMatched(account, connectedWallet) {
|
|
405
|
-
return account.address === connectedWallet.address && account.chain === connectedWallet.chain;
|
|
406
|
-
}
|
|
407
|
-
function makeBalanceFor(wallet, retrivedBalance, tokens) {
|
|
408
|
-
const {
|
|
409
|
-
address,
|
|
410
|
-
blockChain: chain,
|
|
411
|
-
explorerUrl,
|
|
412
|
-
balances = []
|
|
413
|
-
} = retrivedBalance;
|
|
414
|
-
return {
|
|
415
|
-
address,
|
|
416
|
-
chain,
|
|
417
|
-
loading: false,
|
|
418
|
-
error: false,
|
|
419
|
-
explorerUrl,
|
|
420
|
-
walletType: wallet.walletType,
|
|
421
|
-
balances: balances?.map(tokenBalance => ({
|
|
422
|
-
chain,
|
|
423
|
-
symbol: tokenBalance.asset.symbol,
|
|
424
|
-
ticker: tokenBalance.asset.symbol,
|
|
425
|
-
address: tokenBalance.asset.address || null,
|
|
426
|
-
rawAmount: tokenBalance.amount.amount,
|
|
427
|
-
decimal: tokenBalance.amount.decimals,
|
|
428
|
-
amount: new BigNumber__default(tokenBalance.amount.amount).shiftedBy(-tokenBalance.amount.decimals).toFixed(),
|
|
429
|
-
logo: '',
|
|
430
|
-
usdPrice: getUsdPrice(chain, tokenBalance.asset.symbol, tokenBalance.asset.address, tokens) || null
|
|
431
|
-
})) || []
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
function resetConnectedWalletState(connectedWallet) {
|
|
435
|
-
return {
|
|
436
|
-
...connectedWallet,
|
|
437
|
-
loading: false,
|
|
438
|
-
error: true
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
const calculateWalletUsdValue = connectedWallet => {
|
|
442
|
-
const uniqueAccountAddresses = new Set();
|
|
443
|
-
const uniqueBalane = connectedWallet?.reduce((acc, current) => {
|
|
444
|
-
return acc.findIndex(i => i.address === current.address && i.chain === current.chain) === -1 ? [...acc, current] : acc;
|
|
445
|
-
}, []);
|
|
446
|
-
const modifiedWalletBlockchains = uniqueBalane?.map(chain => {
|
|
447
|
-
const modifiedWalletBlockchain = {
|
|
448
|
-
name: chain.chain,
|
|
449
|
-
accounts: []
|
|
450
|
-
};
|
|
451
|
-
if (!uniqueAccountAddresses.has(chain.address)) {
|
|
452
|
-
uniqueAccountAddresses.add(chain.address);
|
|
453
|
-
}
|
|
454
|
-
uniqueAccountAddresses.forEach(accountAddress => {
|
|
455
|
-
if (chain.address === accountAddress) modifiedWalletBlockchain.accounts.push(chain);
|
|
456
|
-
});
|
|
457
|
-
return modifiedWalletBlockchain;
|
|
458
|
-
});
|
|
459
|
-
const total = numberToString(modifiedWalletBlockchains?.flatMap(b => b.accounts)?.flatMap(a => a?.balances)?.map(b => new BigNumber__default(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0))?.reduce((a, b) => a.plus(b), ZERO) || ZERO).toString();
|
|
460
|
-
return numberWithThousandSeperator(total);
|
|
461
|
-
};
|
|
462
|
-
function numberWithThousandSeperator(number) {
|
|
463
|
-
var parts = number.toString().split('.');
|
|
464
|
-
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
465
|
-
return parts.join('.');
|
|
466
|
-
}
|
|
467
|
-
const sortTokens = tokens => {
|
|
468
|
-
let walletConnected = !!tokens.some(token => token.balance);
|
|
469
|
-
if (!walletConnected) {
|
|
470
|
-
return tokens.filter(token => !token.address).concat(tokens.filter(token => token.address && !token.isSecondaryCoin), tokens.filter(token => token.isSecondaryCoin));
|
|
471
|
-
}
|
|
472
|
-
return tokens.filter(token => !!token.balance).sort((tokenA, tokenB) => parseFloat(tokenB.balance?.usdValue || '0') - parseFloat(tokenA.balance?.usdValue || '0')).concat(tokens.filter(token => !token.balance && !token.isSecondaryCoin), tokens.filter(token => !token.balance && token.isSecondaryCoin));
|
|
473
|
-
};
|
|
474
|
-
const getUsdPrice = (blockchain, symbol, address, allTokens) => {
|
|
475
|
-
const token = allTokens?.find(t => t.blockchain === blockchain && t.symbol?.toUpperCase() === symbol?.toUpperCase() && t.address === address);
|
|
476
|
-
return token?.usdPrice || null;
|
|
477
|
-
};
|
|
478
|
-
const isExperimentalChain = (blockchains, wallet) => {
|
|
479
|
-
const cosmosExperimentalChainInfo = walletsShared.getCosmosExperimentalChainInfo(Object.entries(blockchains).map(_ref => {
|
|
480
|
-
let [, blockchainMeta] = _ref;
|
|
481
|
-
return blockchainMeta;
|
|
482
|
-
}).filter(rangoTypes.isCosmosBlockchain));
|
|
483
|
-
return cosmosExperimentalChainInfo && !!cosmosExperimentalChainInfo[wallet];
|
|
484
|
-
};
|
|
485
|
-
const getKeplrCompatibleConnectedWallets = selectableWallets => {
|
|
486
|
-
const connectedWalletTypes = new Set(selectableWallets.map(a => a.walletType.toString()));
|
|
487
|
-
return walletsShared.KEPLR_COMPATIBLE_WALLETS.filter(compatibleWallet => connectedWalletTypes.has(compatibleWallet));
|
|
488
|
-
};
|
|
489
|
-
function getTokensWithBalance(tokens, connectedWallets) {
|
|
490
|
-
return tokens.map(_ref2 => {
|
|
491
|
-
let {
|
|
492
|
-
balance,
|
|
493
|
-
...otherProps
|
|
494
|
-
} = _ref2;
|
|
495
|
-
const tokenAmount = numberToString(new BigNumber__default(getBalanceFromWallet(connectedWallets, otherProps.blockchain, otherProps.symbol, otherProps.address)?.amount || ZERO));
|
|
496
|
-
let tokenUsdValue = '';
|
|
497
|
-
if (otherProps.usdPrice) tokenUsdValue = numberToString(new BigNumber__default(getBalanceFromWallet(connectedWallets, otherProps.blockchain, otherProps.symbol, otherProps.address)?.amount || ZERO).multipliedBy(otherProps.usdPrice));
|
|
498
|
-
return {
|
|
499
|
-
...otherProps,
|
|
500
|
-
...(tokenAmount !== '0' && {
|
|
501
|
-
balance: {
|
|
502
|
-
amount: tokenAmount,
|
|
503
|
-
usdValue: tokenUsdValue
|
|
504
|
-
}
|
|
505
|
-
})
|
|
506
|
-
};
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
function getSortedTokens(chain, tokens, connectedWallets, otherChainTokens) {
|
|
510
|
-
const fromChainEqueulsToToChain = chain?.name === otherChainTokens[0]?.name;
|
|
511
|
-
if (fromChainEqueulsToToChain) return otherChainTokens;
|
|
512
|
-
const filteredTokens = tokens.filter(token => token.blockchain === chain?.name);
|
|
513
|
-
return sortTokens(getTokensWithBalance(filteredTokens, connectedWallets));
|
|
514
|
-
}
|
|
515
|
-
function tokensAreEqual(tokenA, tokenB) {
|
|
516
|
-
return tokenA?.blockchain === tokenB?.blockchain && tokenA?.symbol === tokenB?.symbol && tokenA?.address === tokenB?.address;
|
|
517
|
-
}
|
|
518
|
-
function getDefaultToken(sortedTokens, otherToken) {
|
|
519
|
-
let selectedToken;
|
|
520
|
-
const firstToken = sortedTokens[0];
|
|
521
|
-
const secondToken = sortedTokens[1];
|
|
522
|
-
if (sortedTokens.length === 1) selectedToken = firstToken;else if (tokensAreEqual(firstToken, otherToken)) selectedToken = secondToken;else selectedToken = firstToken;
|
|
523
|
-
return selectedToken;
|
|
524
|
-
}
|
|
525
|
-
function sortWalletsBasedOnState(wallets) {
|
|
526
|
-
return wallets.sort((a, b) => Number(b.state === ui.WalletState.CONNECTED) - Number(a.state === ui.WalletState.CONNECTED) || Number(b.state === ui.WalletState.DISCONNECTED || b.state === ui.WalletState.CONNECTING) - Number(a.state === ui.WalletState.DISCONNECTED || a.state === ui.WalletState.CONNECTING));
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
function getOutputRatio(inputUsdValue, outputUsdValue) {
|
|
530
|
-
if (inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) return 0;
|
|
531
|
-
return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
|
|
532
|
-
}
|
|
533
|
-
function outputRatioHasWarning(inputUsdValue, outputRatio) {
|
|
534
|
-
return parseInt(outputRatio.toFixed(2) || '0') <= -10 && inputUsdValue.gte(new BigNumber__default(400)) || parseInt(outputRatio.toFixed(2) || '0') <= -5 && inputUsdValue.gte(new BigNumber__default(1000));
|
|
535
|
-
}
|
|
536
|
-
function hasLimitError(bestRoute) {
|
|
537
|
-
return (bestRoute?.result?.swaps || []).filter(swap => {
|
|
538
|
-
const minimum = !!swap.fromAmountMinValue ? new BigNumber__default(swap.fromAmountMinValue) : null;
|
|
539
|
-
const maximum = !!swap.fromAmountMaxValue ? new BigNumber__default(swap.fromAmountMaxValue) : null;
|
|
540
|
-
const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
|
|
541
|
-
if (isExclusive) {
|
|
542
|
-
return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
|
|
543
|
-
} else {
|
|
544
|
-
return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
|
|
545
|
-
}
|
|
546
|
-
}).length > 0;
|
|
547
|
-
}
|
|
548
|
-
function LimitErrorMessage(bestRoute) {
|
|
549
|
-
if (!bestRoute) return {
|
|
550
|
-
swap: null,
|
|
551
|
-
fromAmountRangeError: '',
|
|
552
|
-
recommendation: ''
|
|
553
|
-
};
|
|
554
|
-
const swap = (bestRoute?.result?.swaps || []).filter(swap => {
|
|
555
|
-
const minimum = !!swap.fromAmountMinValue ? new BigNumber__default(swap.fromAmountMinValue) : null;
|
|
556
|
-
const maximum = !!swap.fromAmountMaxValue ? new BigNumber__default(swap.fromAmountMaxValue) : null;
|
|
557
|
-
const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
|
|
558
|
-
if (isExclusive) {
|
|
559
|
-
return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
|
|
560
|
-
} else {
|
|
561
|
-
return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
|
|
562
|
-
}
|
|
563
|
-
})[0];
|
|
564
|
-
if (!swap) return {
|
|
565
|
-
swap: null,
|
|
566
|
-
fromAmountRangeError: '',
|
|
567
|
-
recommendation: ''
|
|
568
|
-
};
|
|
569
|
-
const minimum = !!swap.fromAmountMinValue ? new BigNumber__default(swap.fromAmountMinValue) : null;
|
|
570
|
-
const maximum = !!swap.fromAmountMaxValue ? new BigNumber__default(swap.fromAmountMaxValue) : null;
|
|
571
|
-
const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
|
|
572
|
-
let fromAmountRangeError = '';
|
|
573
|
-
let recommendation = '';
|
|
574
|
-
if (!isExclusive && !!minimum && minimum.gt(swap.fromAmount)) {
|
|
575
|
-
fromAmountRangeError = `Required: >= ${numberToString(minimum)} ${swap.from.symbol}`;
|
|
576
|
-
recommendation = 'Increase your swap amount';
|
|
577
|
-
} else if (isExclusive && !!minimum && minimum.gte(swap.fromAmount)) {
|
|
578
|
-
fromAmountRangeError = `Required: > ${numberToString(minimum)} ${swap.from.symbol}`;
|
|
579
|
-
recommendation = 'Increase your swap amount';
|
|
580
|
-
}
|
|
581
|
-
if (!isExclusive && !!maximum && maximum.lt(swap.fromAmount)) {
|
|
582
|
-
fromAmountRangeError = `Required: <= ${numberToString(maximum)} ${swap.from.symbol}`;
|
|
583
|
-
recommendation = 'Decrease your swap amount';
|
|
584
|
-
} else if (isExclusive && !!maximum && maximum.lte(swap.fromAmount)) {
|
|
585
|
-
fromAmountRangeError = `Required: < ${numberToString(maximum)} ${swap.from.symbol}`;
|
|
586
|
-
recommendation = 'Decrease your swap amount';
|
|
587
|
-
}
|
|
588
|
-
return {
|
|
589
|
-
swap,
|
|
590
|
-
fromAmountRangeError,
|
|
591
|
-
recommendation
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
function getSwapButtonState(loadingMetaStatus, connectedWallets, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount) {
|
|
595
|
-
if (loadingMetaStatus !== 'success') return {
|
|
596
|
-
title: 'Connect Wallet',
|
|
597
|
-
disabled: true
|
|
598
|
-
};
|
|
599
|
-
if (connectedWallets.length == 0) return {
|
|
600
|
-
title: 'Connect Wallet',
|
|
601
|
-
disabled: false
|
|
602
|
-
};
|
|
603
|
-
if (loading) return {
|
|
604
|
-
title: 'Finding Best Route...',
|
|
605
|
-
disabled: true
|
|
606
|
-
};else if (!inputAmount || inputAmount === '0') return {
|
|
607
|
-
title: 'Enter an amount',
|
|
608
|
-
disabled: true
|
|
609
|
-
};else if (!bestRoute || !bestRoute.result) return {
|
|
610
|
-
title: 'Swap',
|
|
611
|
-
disabled: true
|
|
612
|
-
};else if (hasLimitError) return {
|
|
613
|
-
title: 'Limit Error',
|
|
614
|
-
disabled: true
|
|
615
|
-
};else if (highValueLoss) return {
|
|
616
|
-
title: 'Price impact is too high!',
|
|
617
|
-
disabled: true
|
|
618
|
-
};else if (priceImpactCanNotBeComputed) return {
|
|
619
|
-
title: 'USD price is unknown, price impact might be high!',
|
|
620
|
-
disabled: false,
|
|
621
|
-
hasWarning: true
|
|
622
|
-
};else if (needsToWarnEthOnPath) return {
|
|
623
|
-
title: 'The route goes through Ethereum. Continue?',
|
|
624
|
-
disabled: false,
|
|
625
|
-
hasWarning: true
|
|
626
|
-
};else return {
|
|
627
|
-
title: 'Swap',
|
|
628
|
-
disabled: false
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
|
|
632
|
-
return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0 && !!bestRoute.result);
|
|
633
|
-
}
|
|
634
|
-
function requiredWallets(route) {
|
|
635
|
-
const wallets = [];
|
|
636
|
-
route?.result?.swaps.forEach(swap => {
|
|
637
|
-
const currentStepFromBlockchain = swap.from.blockchain;
|
|
638
|
-
const currentStepToBlockchain = swap.to.blockchain;
|
|
639
|
-
let lastAddedWallet = wallets[wallets.length - 1];
|
|
640
|
-
if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
|
|
641
|
-
lastAddedWallet = wallets[wallets.length - 1];
|
|
642
|
-
if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
|
|
643
|
-
});
|
|
644
|
-
return wallets;
|
|
645
|
-
}
|
|
646
|
-
const getUsdPrice$1 = (blockchain, symbol, address, allTokens) => {
|
|
647
|
-
const token = allTokens?.find(t => t.blockchain === blockchain && t.symbol?.toUpperCase() === symbol?.toUpperCase() && t.address === address);
|
|
648
|
-
return token?.usdPrice || null;
|
|
649
|
-
};
|
|
650
|
-
function getUsdFeeOfStep(step, allTokens) {
|
|
651
|
-
let totalFeeInUsd = ZERO;
|
|
652
|
-
for (let i = 0; i < step.fee.length; i++) {
|
|
653
|
-
const fee = step.fee[i];
|
|
654
|
-
if (fee.expenseType === 'DECREASE_FROM_OUTPUT') continue;
|
|
655
|
-
const unitPrice = getUsdPrice$1(fee.asset.blockchain, fee.asset.symbol, fee.asset.address, allTokens);
|
|
656
|
-
totalFeeInUsd = totalFeeInUsd.plus(new BigNumber__default(fee.amount).multipliedBy(unitPrice || 0));
|
|
657
|
-
}
|
|
658
|
-
return totalFeeInUsd;
|
|
659
|
-
}
|
|
660
|
-
function getTotalFeeInUsd(bestRoute, allTokens) {
|
|
661
|
-
return bestRoute?.result?.swaps.reduce((totalFee, step) => totalFee.plus(getUsdFeeOfStep(step, allTokens)), ZERO) || null;
|
|
662
|
-
}
|
|
663
|
-
function hasHighFee(totalFeeInUsd) {
|
|
664
|
-
if (!totalFeeInUsd) return false;
|
|
665
|
-
return !totalFeeInUsd.lt(new BigNumber__default(30));
|
|
666
|
-
}
|
|
667
|
-
function getMinRequiredSlippage(route) {
|
|
668
|
-
const slippages = route.result?.swaps.map(slippage => slippage.recommendedSlippage);
|
|
669
|
-
return slippages?.map(s => s?.slippage || '0')?.filter(s => parseFloat(s) > 0)?.sort((a, b) => parseFloat(b) - parseFloat(a))?.find(() => true) || null;
|
|
670
|
-
}
|
|
671
|
-
function hasProperSlippage(userSlippage, minRequiredSlippage) {
|
|
672
|
-
if (!minRequiredSlippage) return true;
|
|
673
|
-
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
674
|
-
}
|
|
675
|
-
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, affiliateRef, initialRoute) {
|
|
676
|
-
const selectedWalletsMap = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = selectedWallet.address, selectedWalletsMap), {});
|
|
677
|
-
const connectedWallets = [];
|
|
678
|
-
wallets.forEach(wallet => {
|
|
679
|
-
const chainAndAccounts = connectedWallets.find(connectedWallet => connectedWallet.blockchain === wallet.chain);
|
|
680
|
-
if (!!chainAndAccounts) chainAndAccounts.addresses.push(wallet.address);else connectedWallets.push({
|
|
681
|
-
blockchain: wallet.chain,
|
|
682
|
-
addresses: [wallet.address]
|
|
683
|
-
});
|
|
684
|
-
});
|
|
685
|
-
const checkPrerequisites = !!initialRoute;
|
|
686
|
-
const filteredBlockchains = removeDuplicateFrom((initialRoute?.result?.swaps || []).reduce((blockchains, swap) => (blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains), []));
|
|
687
|
-
const requestBody = {
|
|
688
|
-
amount: inputAmount.toString(),
|
|
689
|
-
affiliateRef,
|
|
690
|
-
checkPrerequisites,
|
|
691
|
-
from: {
|
|
692
|
-
address: fromToken.address,
|
|
693
|
-
blockchain: fromToken.blockchain,
|
|
694
|
-
symbol: fromToken.symbol
|
|
695
|
-
},
|
|
696
|
-
to: {
|
|
697
|
-
address: toToken.address,
|
|
698
|
-
blockchain: toToken.blockchain,
|
|
699
|
-
symbol: toToken.symbol
|
|
700
|
-
},
|
|
701
|
-
connectedWallets,
|
|
702
|
-
selectedWallets: selectedWalletsMap,
|
|
703
|
-
swapperGroups: disabledLiquiditySources,
|
|
704
|
-
swappersGroupsExclude: true,
|
|
705
|
-
slippage: slippage.toString(),
|
|
706
|
-
...(checkPrerequisites && {
|
|
707
|
-
blockchains: filteredBlockchains
|
|
708
|
-
})
|
|
709
|
-
};
|
|
710
|
-
return requestBody;
|
|
711
|
-
}
|
|
712
|
-
function getWalletsForNewSwap(selectedWallets) {
|
|
713
|
-
const wallets = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = {
|
|
714
|
-
address: selectedWallet.address,
|
|
715
|
-
walletType: selectedWallet.walletType
|
|
716
|
-
}, selectedWalletsMap), {});
|
|
717
|
-
return wallets;
|
|
718
|
-
}
|
|
719
|
-
function getRouteOutputAmount(route) {
|
|
720
|
-
return route?.result?.outputAmount || null;
|
|
721
|
-
}
|
|
722
|
-
function getPercentageChange(oldValue, newValue) {
|
|
723
|
-
if (!oldValue || !newValue) return null;
|
|
724
|
-
return new BigNumber__default(newValue).div(new BigNumber__default(oldValue)).minus(1).multipliedBy(100);
|
|
725
|
-
}
|
|
726
|
-
function isOutputAmountChangedALot(oldRoute, newRoute) {
|
|
727
|
-
const oldOutputAmount = getRouteOutputAmount(oldRoute);
|
|
728
|
-
const newOutputAmount = getRouteOutputAmount(newRoute);
|
|
729
|
-
if (!oldOutputAmount || !newOutputAmount) return false;
|
|
730
|
-
const percentageChange = getPercentageChange(oldOutputAmount, newOutputAmount);
|
|
731
|
-
if (!percentageChange) return true;
|
|
732
|
-
return percentageChange.toNumber() <= -1;
|
|
733
|
-
}
|
|
734
|
-
function getBalanceWarnings(route, selectedWallets) {
|
|
735
|
-
const fee = route.validationStatus;
|
|
736
|
-
const requiredWallets = getRequiredChains(route);
|
|
737
|
-
const walletsSortedByRequiredWallets = selectedWallets.sort((selectedWallet1, selectedWallet2) => requiredWallets.indexOf(selectedWallet1.chain) - requiredWallets.indexOf(selectedWallet2.chain));
|
|
738
|
-
return walletsSortedByRequiredWallets.flatMap(wallet => getRequiredBalanceOfWallet(wallet, fee) || []).filter(asset => !asset.ok).map(asset => {
|
|
739
|
-
const symbol = asset.asset.symbol;
|
|
740
|
-
const currentAmount = numberToString(new BigNumber__default(asset.currentAmount.amount).shiftedBy(-asset.currentAmount.decimals), 8);
|
|
741
|
-
const requiredAmount = numberToString(new BigNumber__default(asset.requiredAmount.amount).shiftedBy(-asset.requiredAmount.decimals), 8);
|
|
742
|
-
let reason = '';
|
|
743
|
-
if (asset.reason === 'FEE') reason = ' for network fee';
|
|
744
|
-
if (asset.reason === 'INPUT_ASSET') reason = ' for swap';
|
|
745
|
-
if (asset.reason === 'FEE_AND_INPUT_ASSET') reason = ' for input and network fee';
|
|
746
|
-
const warningMessage = `Needs ≈ ${requiredAmount} ${symbol}${reason}, but you have ${currentAmount} ${symbol} in your ${asset.asset.blockchain} wallet.`;
|
|
747
|
-
return warningMessage;
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
function calcOutputUsdValue(outputAmount, tokenPrice) {
|
|
751
|
-
const amount = !!outputAmount ? new BigNumber__default(outputAmount) : ZERO;
|
|
752
|
-
return amount.multipliedBy(tokenPrice || 0);
|
|
753
|
-
}
|
|
754
|
-
function isNetworkStatusInWarningState(pendingSwapStep) {
|
|
755
|
-
return !!pendingSwapStep && pendingSwapStep.networkStatus !== null && pendingSwapStep.networkStatus !== queueManagerRangoPreset.PendingSwapNetworkStatus.NetworkChanged;
|
|
756
|
-
}
|
|
757
|
-
function getSwapMessages(pendingSwap, currentStep) {
|
|
758
|
-
const textForRemove = 'bellow button or';
|
|
759
|
-
let message = pendingSwap.extraMessage;
|
|
760
|
-
let detailedMessage = pendingSwap.extraMessageDetail;
|
|
761
|
-
if (pendingSwap.networkStatusExtraMessageDetail?.includes(textForRemove)) {
|
|
762
|
-
pendingSwap.networkStatusExtraMessageDetail = pendingSwap.networkStatusExtraMessageDetail.replace(textForRemove, '');
|
|
763
|
-
}
|
|
764
|
-
const networkWarningState = isNetworkStatusInWarningState(currentStep);
|
|
765
|
-
if (networkWarningState) {
|
|
766
|
-
message = pendingSwap.networkStatusExtraMessage || '';
|
|
767
|
-
detailedMessage = pendingSwap.networkStatusExtraMessageDetail || '';
|
|
768
|
-
switch (currentStep?.networkStatus) {
|
|
769
|
-
case queueManagerRangoPreset.PendingSwapNetworkStatus.WaitingForConnectingWallet:
|
|
770
|
-
message = message || 'Waiting for connecting wallet';
|
|
771
|
-
break;
|
|
772
|
-
case queueManagerRangoPreset.PendingSwapNetworkStatus.WaitingForQueue:
|
|
773
|
-
message = message || 'Waiting for other running tasks to be finished';
|
|
774
|
-
break;
|
|
775
|
-
case queueManagerRangoPreset.PendingSwapNetworkStatus.WaitingForNetworkChange:
|
|
776
|
-
message = message || 'Waiting for changing wallet network';
|
|
777
|
-
break;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
detailedMessage = detailedMessage || '';
|
|
781
|
-
message = message || '';
|
|
782
|
-
const isRpc = message?.indexOf('code') !== -1 && message?.indexOf('reason') !== -1;
|
|
783
|
-
return {
|
|
784
|
-
shortMessage: message,
|
|
785
|
-
detailedMessage: {
|
|
786
|
-
content: detailedMessage,
|
|
787
|
-
long: isRpc
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
function getLastConvertedTokenInFailedSwap(pendingSwap) {
|
|
792
|
-
let resultToken = null;
|
|
793
|
-
if (pendingSwap.status === 'failed') {
|
|
794
|
-
const lastSuccessStep = pendingSwap.steps.slice().reverse().filter(step => step.status === 'success')[0];
|
|
795
|
-
if (lastSuccessStep) {
|
|
796
|
-
resultToken = {
|
|
797
|
-
blockchain: lastSuccessStep.toBlockchain,
|
|
798
|
-
symbol: lastSuccessStep.toSymbol,
|
|
799
|
-
outputAmount: lastSuccessStep.outputAmount,
|
|
800
|
-
address: lastSuccessStep.toSymbolAddress
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return resultToken;
|
|
805
|
-
}
|
|
806
|
-
function shouldRetrySwap(pendingSwap) {
|
|
807
|
-
return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.subscribeWithSelector((set, get) => ({
|
|
811
|
-
connectedWallets: [],
|
|
812
|
-
selectedWallets: [],
|
|
813
|
-
connectWallet: accounts => {
|
|
814
|
-
const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
|
|
815
|
-
set(state => ({
|
|
816
|
-
connectedWallets: state.connectedWallets.filter(wallet => wallet.walletType !== accounts[0].walletType).concat(accounts.map(account => ({
|
|
817
|
-
balances: [],
|
|
818
|
-
address: account.address,
|
|
819
|
-
chain: account.chain,
|
|
820
|
-
loading: true,
|
|
821
|
-
walletType: account.walletType,
|
|
822
|
-
error: false,
|
|
823
|
-
explorerUrl: null
|
|
824
|
-
})))
|
|
825
|
-
}));
|
|
826
|
-
accounts.forEach(async account => getOneOfWalletsDetails(account));
|
|
827
|
-
},
|
|
828
|
-
disconnectWallet: walletType => {
|
|
829
|
-
set(state => ({
|
|
830
|
-
connectedWallets: state.connectedWallets.filter(balance => balance.walletType !== walletType),
|
|
831
|
-
selectedWallets: state.selectedWallets.filter(wallet => wallet.walletType != walletType)
|
|
832
|
-
}));
|
|
833
|
-
},
|
|
834
|
-
initSelectedWallets: () => set(state => {
|
|
835
|
-
const requiredChains = getRequiredChains(useBestRouteStore.getState().bestRoute);
|
|
836
|
-
const connectedWallets = state.connectedWallets;
|
|
837
|
-
const selectedWallets = [];
|
|
838
|
-
requiredChains.forEach(chain => {
|
|
839
|
-
const anyWalletSelected = !!state.selectedWallets.find(wallet => wallet.chain === chain);
|
|
840
|
-
if (!anyWalletSelected) {
|
|
841
|
-
const firstWalletWithMatchedChain = connectedWallets.find(wallet => wallet.chain === chain);
|
|
842
|
-
if (!!firstWalletWithMatchedChain) selectedWallets.push({
|
|
843
|
-
address: firstWalletWithMatchedChain.address,
|
|
844
|
-
chain: firstWalletWithMatchedChain.chain,
|
|
845
|
-
walletType: firstWalletWithMatchedChain.walletType
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
return {
|
|
850
|
-
selectedWallets: state.selectedWallets.concat(selectedWallets)
|
|
851
|
-
};
|
|
852
|
-
}),
|
|
853
|
-
setSelectedWallet: wallet => set(state => ({
|
|
854
|
-
selectedWallets: state.selectedWallets.filter(selectedWallet => selectedWallet.chain !== wallet.chain).concat({
|
|
855
|
-
chain: wallet.chain,
|
|
856
|
-
address: wallet.address,
|
|
857
|
-
walletType: wallet.walletType
|
|
858
|
-
})
|
|
859
|
-
})),
|
|
860
|
-
clearConnectedWallet: () => set(() => ({
|
|
861
|
-
connectedWallets: [],
|
|
862
|
-
selectedWallets: []
|
|
863
|
-
})),
|
|
864
|
-
getOneOfWalletsDetails: async account => {
|
|
865
|
-
const tokens = useMetaStore.getState().meta.tokens;
|
|
866
|
-
set(state => ({
|
|
867
|
-
connectedWallets: state.connectedWallets.map(balance => {
|
|
868
|
-
return balance.address === account.address && balance.chain === account.chain ? {
|
|
869
|
-
...balance,
|
|
870
|
-
loading: true
|
|
871
|
-
} : balance;
|
|
872
|
-
})
|
|
873
|
-
}));
|
|
874
|
-
try {
|
|
875
|
-
const response = await httpService().getWalletsDetails([{
|
|
876
|
-
address: account.address,
|
|
877
|
-
blockchain: account.chain
|
|
878
|
-
}]);
|
|
879
|
-
const retrivedBalance = response.wallets[0];
|
|
880
|
-
if (retrivedBalance) {
|
|
881
|
-
set(state => ({
|
|
882
|
-
connectedWallets: state.connectedWallets.map(connectedWallet => {
|
|
883
|
-
return isAccountAndWalletMatched(account, connectedWallet) ? makeBalanceFor(account, retrivedBalance, tokens) : connectedWallet;
|
|
884
|
-
})
|
|
885
|
-
}));
|
|
886
|
-
} else throw new Error('Wallet not found');
|
|
887
|
-
} catch (error) {
|
|
888
|
-
set(state => ({
|
|
889
|
-
connectedWallets: state.connectedWallets.map(balance => {
|
|
890
|
-
return isAccountAndWalletMatched(account, balance) ? resetConnectedWalletState(balance) : balance;
|
|
891
|
-
})
|
|
892
|
-
}));
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}))));
|
|
896
|
-
useWalletsStore.subscribe(state => state.connectedWallets, connectedWallets => {
|
|
897
|
-
useBestRouteStore.setState(_ref => {
|
|
898
|
-
let {
|
|
899
|
-
sourceTokens,
|
|
900
|
-
destinationTokens
|
|
901
|
-
} = _ref;
|
|
902
|
-
const sourceTokensWithBalance = getTokensWithBalance(sourceTokens, connectedWallets);
|
|
903
|
-
const destinationTokensWithBalance = getTokensWithBalance(destinationTokens, connectedWallets);
|
|
904
|
-
return {
|
|
905
|
-
sourceTokens: sortTokens(sourceTokensWithBalance),
|
|
906
|
-
destinationTokens: sortTokens(destinationTokensWithBalance)
|
|
907
|
-
};
|
|
908
|
-
});
|
|
909
|
-
}, {
|
|
910
|
-
equalityFn: shallow.shallow
|
|
911
|
-
});
|
|
912
|
-
const fetchingBalanceSelector = state => !!state.connectedWallets.find(wallet => wallet.loading);
|
|
913
|
-
|
|
914
|
-
const getUsdValue = (token, amount) => new BigNumber__default(amount || ZERO).multipliedBy(token?.usdPrice || 0);
|
|
915
|
-
const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
916
|
-
fromChain: null,
|
|
917
|
-
fromToken: null,
|
|
918
|
-
inputAmount: '',
|
|
919
|
-
outputAmount: null,
|
|
920
|
-
inputUsdValue: new BigNumber__default(0),
|
|
921
|
-
outputUsdValue: new BigNumber__default(0),
|
|
922
|
-
toChain: null,
|
|
923
|
-
toToken: null,
|
|
924
|
-
bestRoute: null,
|
|
925
|
-
loading: false,
|
|
926
|
-
error: '',
|
|
927
|
-
sourceTokens: [],
|
|
928
|
-
destinationTokens: [],
|
|
929
|
-
setBestRoute: bestRoute => set(state => {
|
|
930
|
-
let outputAmount = null;
|
|
931
|
-
let outputUsdValue = ZERO;
|
|
932
|
-
if (!isPositiveNumber(state.inputAmount)) return {};
|
|
933
|
-
if (!!bestRoute) {
|
|
934
|
-
outputAmount = !!bestRoute.result?.outputAmount ? new BigNumber__default(bestRoute.result?.outputAmount) : null;
|
|
935
|
-
outputUsdValue = calcOutputUsdValue(bestRoute.result?.outputAmount, getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice);
|
|
936
|
-
}
|
|
937
|
-
return {
|
|
938
|
-
bestRoute,
|
|
939
|
-
...(!!bestRoute && {
|
|
940
|
-
outputAmount,
|
|
941
|
-
outputUsdValue
|
|
942
|
-
})
|
|
943
|
-
};
|
|
944
|
-
}),
|
|
945
|
-
resetRoute: () => set(() => ({
|
|
946
|
-
loading: true,
|
|
947
|
-
error: '',
|
|
948
|
-
bestRoute: null,
|
|
949
|
-
outputAmount: null,
|
|
950
|
-
outputUsdValue: new BigNumber__default(0)
|
|
951
|
-
})),
|
|
952
|
-
setFromChain: (chain, setDefaultToken) => {
|
|
953
|
-
set(state => {
|
|
954
|
-
if (state.fromChain?.name === chain?.name) return {};
|
|
955
|
-
const tokens = useMetaStore.getState().meta.tokens;
|
|
956
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
957
|
-
const sortedTokens = getSortedTokens(chain, tokens, connectedWallets, state.destinationTokens);
|
|
958
|
-
const fromToken = getDefaultToken(sortedTokens, state.toToken);
|
|
959
|
-
return {
|
|
960
|
-
fromChain: chain,
|
|
961
|
-
sourceTokens: sortedTokens,
|
|
962
|
-
...(setDefaultToken && {
|
|
963
|
-
fromToken
|
|
964
|
-
}),
|
|
965
|
-
...(!!state.inputAmount && {
|
|
966
|
-
inputUsdValue: getUsdValue(fromToken, state.inputAmount)
|
|
967
|
-
})
|
|
968
|
-
};
|
|
969
|
-
});
|
|
970
|
-
},
|
|
971
|
-
setFromToken: token => set(state => ({
|
|
972
|
-
fromToken: token,
|
|
973
|
-
...(!!state.inputAmount && {
|
|
974
|
-
inputUsdValue: getUsdValue(token, state.inputAmount)
|
|
975
|
-
})
|
|
976
|
-
})),
|
|
977
|
-
setToChain: (chain, setDefaultToken) => {
|
|
978
|
-
set(state => {
|
|
979
|
-
if (state.toChain?.name === chain?.name) return {};
|
|
980
|
-
const tokens = useMetaStore.getState().meta.tokens;
|
|
981
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
982
|
-
const sortedTokens = getSortedTokens(chain, tokens, connectedWallets, state.destinationTokens);
|
|
983
|
-
return {
|
|
984
|
-
toChain: chain,
|
|
985
|
-
destinationTokens: sortedTokens,
|
|
986
|
-
...(setDefaultToken && {
|
|
987
|
-
toToken: getDefaultToken(sortedTokens, state.fromToken)
|
|
988
|
-
})
|
|
989
|
-
};
|
|
990
|
-
});
|
|
991
|
-
},
|
|
992
|
-
setToToken: token => set(() => ({
|
|
993
|
-
toToken: token
|
|
994
|
-
})),
|
|
995
|
-
setInputAmount: amount => {
|
|
996
|
-
set(state => ({
|
|
997
|
-
inputAmount: amount,
|
|
998
|
-
...(!amount && {
|
|
999
|
-
outputAmount: new BigNumber__default(0),
|
|
1000
|
-
outputUsdValue: new BigNumber__default(0),
|
|
1001
|
-
bestRoute: null,
|
|
1002
|
-
error: ''
|
|
1003
|
-
}),
|
|
1004
|
-
...(!!state.fromToken && {
|
|
1005
|
-
inputUsdValue: getUsdValue(state.fromToken, amount)
|
|
1006
|
-
})
|
|
1007
|
-
}));
|
|
1008
|
-
},
|
|
1009
|
-
retry: pendingSwap => {
|
|
1010
|
-
const {
|
|
1011
|
-
tokens,
|
|
1012
|
-
blockchains
|
|
1013
|
-
} = useMetaStore.getState().meta;
|
|
1014
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
1015
|
-
const failedIndex = pendingSwap.status === 'failed' ? pendingSwap.steps.findIndex(s => s.status === 'failed') : null;
|
|
1016
|
-
if (failedIndex === null || failedIndex < 0) return;
|
|
1017
|
-
const firstStep = pendingSwap.steps[0];
|
|
1018
|
-
const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
|
|
1019
|
-
const fromChain = blockchains.find(blockchain => blockchain.name === firstStep.fromBlockchain) || null;
|
|
1020
|
-
const toChain = blockchains.find(blockchain => blockchain.name === lastStep.toBlockchain) || null;
|
|
1021
|
-
const fromToken = tokens.find(token => tokensAreEqual(token, {
|
|
1022
|
-
blockchain: firstStep.fromBlockchain,
|
|
1023
|
-
symbol: firstStep.fromSymbol,
|
|
1024
|
-
address: firstStep.fromSymbolAddress
|
|
1025
|
-
}));
|
|
1026
|
-
const toToken = tokens.find(token => tokensAreEqual(token, {
|
|
1027
|
-
blockchain: lastStep.toBlockchain,
|
|
1028
|
-
symbol: lastStep.toSymbol,
|
|
1029
|
-
address: lastStep.toSymbolAddress
|
|
1030
|
-
}));
|
|
1031
|
-
const sortedSourceTokens = getSortedTokens(fromChain, tokens, connectedWallets, []);
|
|
1032
|
-
const sortedDestinationTokens = getSortedTokens(toChain, tokens, connectedWallets, []);
|
|
1033
|
-
const inputAmount = pendingSwap.inputAmount;
|
|
1034
|
-
set({
|
|
1035
|
-
fromChain,
|
|
1036
|
-
fromToken,
|
|
1037
|
-
inputAmount,
|
|
1038
|
-
outputAmount: null,
|
|
1039
|
-
inputUsdValue: getUsdValue(fromToken || null, inputAmount),
|
|
1040
|
-
outputUsdValue: new BigNumber__default(0),
|
|
1041
|
-
toChain,
|
|
1042
|
-
toToken,
|
|
1043
|
-
bestRoute: null,
|
|
1044
|
-
loading: false,
|
|
1045
|
-
error: '',
|
|
1046
|
-
sourceTokens: sortedSourceTokens,
|
|
1047
|
-
destinationTokens: sortedDestinationTokens
|
|
1048
|
-
});
|
|
1049
|
-
},
|
|
1050
|
-
switchFromAndTo: () => set(state => ({
|
|
1051
|
-
fromChain: state.toChain,
|
|
1052
|
-
fromToken: state.toToken,
|
|
1053
|
-
toChain: state.fromChain,
|
|
1054
|
-
toToken: state.fromToken,
|
|
1055
|
-
sourceTokens: state.destinationTokens,
|
|
1056
|
-
destinationTokens: state.sourceTokens,
|
|
1057
|
-
inputAmount: state.outputAmount?.toString() || '',
|
|
1058
|
-
inputUsdValue: getUsdValue(state.toToken, state.outputAmount?.toString() || '')
|
|
1059
|
-
}))
|
|
1060
|
-
}))));
|
|
1061
|
-
const bestRoute = (bestRouteStore, settingsStore) => {
|
|
1062
|
-
let abortController = null;
|
|
1063
|
-
const fetchBestRoute = () => {
|
|
1064
|
-
const {
|
|
1065
|
-
fromToken,
|
|
1066
|
-
toToken,
|
|
1067
|
-
inputAmount,
|
|
1068
|
-
resetRoute
|
|
1069
|
-
} = bestRouteStore.getState();
|
|
1070
|
-
const {
|
|
1071
|
-
slippage,
|
|
1072
|
-
customSlippage,
|
|
1073
|
-
disabledLiquiditySources,
|
|
1074
|
-
affiliateRef
|
|
1075
|
-
} = settingsStore.getState();
|
|
1076
|
-
if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
|
|
1077
|
-
abortController?.abort();
|
|
1078
|
-
abortController = new AbortController();
|
|
1079
|
-
const userSlippage = !!customSlippage ? customSlippage : slippage;
|
|
1080
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
|
|
1081
|
-
if (!bestRouteStore.getState().loading) {
|
|
1082
|
-
resetRoute();
|
|
1083
|
-
}
|
|
1084
|
-
httpService().getBestRoute(requestBody, {
|
|
1085
|
-
signal: abortController.signal
|
|
1086
|
-
}).then(res => {
|
|
1087
|
-
const {
|
|
1088
|
-
setBestRoute
|
|
1089
|
-
} = bestRouteStore.getState();
|
|
1090
|
-
setBestRoute(res);
|
|
1091
|
-
bestRouteStore.setState({
|
|
1092
|
-
loading: false
|
|
1093
|
-
});
|
|
1094
|
-
abortController = null;
|
|
1095
|
-
}).catch(error => {
|
|
1096
|
-
if (error.code === 'ERR_CANCELED') return;
|
|
1097
|
-
bestRouteStore.setState({
|
|
1098
|
-
error: error.message,
|
|
1099
|
-
loading: false
|
|
1100
|
-
});
|
|
1101
|
-
});
|
|
1102
|
-
};
|
|
1103
|
-
const debouncedFetchBestRoute = debounce(fetchBestRoute, 600);
|
|
1104
|
-
const bestRouteParamsListener = () => {
|
|
1105
|
-
const {
|
|
1106
|
-
fromToken,
|
|
1107
|
-
toToken,
|
|
1108
|
-
inputAmount,
|
|
1109
|
-
inputUsdValue,
|
|
1110
|
-
resetRoute
|
|
1111
|
-
} = useBestRouteStore.getState();
|
|
1112
|
-
if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0)) return bestRouteStore.setState({
|
|
1113
|
-
loading: false
|
|
1114
|
-
});
|
|
1115
|
-
if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
|
|
1116
|
-
loading: false,
|
|
1117
|
-
bestRoute: null,
|
|
1118
|
-
outputAmount: new BigNumber__default(inputAmount),
|
|
1119
|
-
outputUsdValue: inputUsdValue
|
|
1120
|
-
});
|
|
1121
|
-
if (!bestRouteStore.getState().loading) resetRoute();
|
|
1122
|
-
debouncedFetchBestRoute();
|
|
1123
|
-
};
|
|
1124
|
-
useBestRouteStore.subscribe(state => ({
|
|
1125
|
-
fromChain: state.fromChain,
|
|
1126
|
-
fromToken: state.fromToken,
|
|
1127
|
-
toChain: state.toChain,
|
|
1128
|
-
toToken: state.toToken,
|
|
1129
|
-
inputAmount: state.inputAmount
|
|
1130
|
-
}), bestRouteParamsListener, {
|
|
1131
|
-
equalityFn: (prevState, currentState) => {
|
|
1132
|
-
if (isRouteParametersChanged({
|
|
1133
|
-
store: 'bestRoute',
|
|
1134
|
-
prevState,
|
|
1135
|
-
currentState
|
|
1136
|
-
})) return false;else return true;
|
|
1137
|
-
}
|
|
1138
|
-
});
|
|
1139
|
-
useSettingsStore.subscribe(state => ({
|
|
1140
|
-
slippage: state.slippage,
|
|
1141
|
-
customSlippage: state.customSlippage,
|
|
1142
|
-
disabledLiquiditySources: state.disabledLiquiditySources,
|
|
1143
|
-
infiniteApprove: state.infiniteApprove
|
|
1144
|
-
}), bestRouteParamsListener, {
|
|
1145
|
-
equalityFn: (prevState, currentState) => {
|
|
1146
|
-
if (isRouteParametersChanged({
|
|
1147
|
-
store: 'settings',
|
|
1148
|
-
prevState,
|
|
1149
|
-
currentState
|
|
1150
|
-
})) return false;else return true;
|
|
1151
|
-
}
|
|
1152
|
-
});
|
|
1153
|
-
return {
|
|
1154
|
-
fetchBestRoute
|
|
1155
|
-
};
|
|
1156
|
-
};
|
|
1157
|
-
const {
|
|
1158
|
-
fetchBestRoute
|
|
1159
|
-
} = /*#__PURE__*/bestRoute(useBestRouteStore, useSettingsStore);
|
|
1160
|
-
|
|
1161
|
-
var SearchParams;
|
|
1162
|
-
(function (SearchParams) {
|
|
1163
|
-
SearchParams["FROM_CHAIN"] = "fromChain";
|
|
1164
|
-
SearchParams["FROM_TOKEN"] = "fromToken";
|
|
1165
|
-
SearchParams["TO_CHAIN"] = "toChain";
|
|
1166
|
-
SearchParams["TO_TOKEN"] = "toToken";
|
|
1167
|
-
SearchParams["FROM_AMOUNT"] = "fromAmount";
|
|
1168
|
-
})(SearchParams || (SearchParams = {}));
|
|
1169
|
-
|
|
1170
|
-
const navigationRoutes = {
|
|
1171
|
-
home: '/',
|
|
1172
|
-
fromChain: 'from-chain',
|
|
1173
|
-
fromToken: 'from-token',
|
|
1174
|
-
toChain: 'to-chain',
|
|
1175
|
-
toToken: 'to-token',
|
|
1176
|
-
settings: 'settings',
|
|
1177
|
-
liquiditySources: '/settings/liquidity-sources',
|
|
1178
|
-
swaps: 'swaps',
|
|
1179
|
-
wallets: 'wallets',
|
|
1180
|
-
confirmSwap: 'confirm-swap',
|
|
1181
|
-
swapDetails: 'swaps/:requestId'
|
|
1182
|
-
};
|
|
1183
|
-
|
|
1184
|
-
const useUiStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
|
|
1185
|
-
connectWalletsButtonDisabled: false,
|
|
1186
|
-
selectedSwapRequestId: null,
|
|
1187
|
-
currentPage: '',
|
|
1188
|
-
toggleConnectWalletsButton: () => set(state => ({
|
|
1189
|
-
connectWalletsButtonDisabled: !state.connectWalletsButtonDisabled
|
|
1190
|
-
})),
|
|
1191
|
-
setSelectedSwap: requestId => set({
|
|
1192
|
-
selectedSwapRequestId: requestId
|
|
1193
|
-
}),
|
|
1194
|
-
setCurrentPage: path => set({
|
|
1195
|
-
currentPage: path
|
|
1196
|
-
})
|
|
1197
|
-
})));
|
|
1198
|
-
|
|
1199
|
-
function UpdateUrl() {
|
|
1200
|
-
const firstRender = React.useRef(true);
|
|
1201
|
-
const [searchParams, setSearchParams] = reactRouterDom.useSearchParams();
|
|
1202
|
-
const location = reactRouterDom.useLocation();
|
|
1203
|
-
const firstRenderSearchParams = React.useRef(location.search);
|
|
1204
|
-
const searchParamsRef = React.useRef({});
|
|
1205
|
-
const fromChain = useBestRouteStore.use.fromChain();
|
|
1206
|
-
const toChain = useBestRouteStore.use.toChain();
|
|
1207
|
-
const fromToken = useBestRouteStore.use.fromToken();
|
|
1208
|
-
const toToken = useBestRouteStore.use.toToken();
|
|
1209
|
-
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
1210
|
-
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
1211
|
-
const setToChain = useBestRouteStore.use.setToChain();
|
|
1212
|
-
const setToToken = useBestRouteStore.use.setToToken();
|
|
1213
|
-
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
1214
|
-
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
1215
|
-
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
1216
|
-
const {
|
|
1217
|
-
blockchains,
|
|
1218
|
-
tokens
|
|
1219
|
-
} = useMetaStore.use.meta();
|
|
1220
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
1221
|
-
React.useEffect(() => {
|
|
1222
|
-
const params = {};
|
|
1223
|
-
reactRouterDom.createSearchParams(firstRenderSearchParams.current).forEach((value, key) => {
|
|
1224
|
-
params[key] = value;
|
|
1225
|
-
});
|
|
1226
|
-
searchParamsRef.current = params;
|
|
1227
|
-
const requestId = location.pathname.split(navigationRoutes.swaps + '/')[1] || null;
|
|
1228
|
-
if (requestId) setSelectedSwap(requestId);
|
|
1229
|
-
}, []);
|
|
1230
|
-
React.useEffect(() => {
|
|
1231
|
-
if (!firstRender.current) {
|
|
1232
|
-
let fromChainString = '',
|
|
1233
|
-
fromTokenString = '',
|
|
1234
|
-
toChainString = '',
|
|
1235
|
-
toTokenString = '',
|
|
1236
|
-
fromAmount = '';
|
|
1237
|
-
if (loadingStatus !== 'success') {
|
|
1238
|
-
fromChainString = searchParamsRef.current[SearchParams.FROM_CHAIN];
|
|
1239
|
-
fromTokenString = searchParamsRef.current[SearchParams.FROM_TOKEN];
|
|
1240
|
-
toChainString = searchParamsRef.current[SearchParams.TO_CHAIN];
|
|
1241
|
-
toTokenString = searchParamsRef.current[SearchParams.TO_TOKEN];
|
|
1242
|
-
fromAmount = searchParamsRef.current[SearchParams.FROM_AMOUNT] || inputAmount;
|
|
1243
|
-
} else {
|
|
1244
|
-
if (location.state === 'redirect') return;
|
|
1245
|
-
fromChainString = fromChain?.name || '';
|
|
1246
|
-
fromTokenString = (fromToken?.symbol || '') + (fromToken?.address ? `--${fromToken?.address}` : '');
|
|
1247
|
-
toChainString = toChain?.name || '';
|
|
1248
|
-
toTokenString = (toToken?.symbol || '') + (toToken?.address ? `--${toToken?.address}` : '');
|
|
1249
|
-
fromAmount = inputAmount;
|
|
1250
|
-
}
|
|
1251
|
-
setSearchParams({
|
|
1252
|
-
...(fromChainString && {
|
|
1253
|
-
[SearchParams.FROM_CHAIN]: fromChainString
|
|
1254
|
-
}),
|
|
1255
|
-
...(fromTokenString && {
|
|
1256
|
-
[SearchParams.FROM_TOKEN]: fromTokenString
|
|
1257
|
-
}),
|
|
1258
|
-
...(toChainString && {
|
|
1259
|
-
[SearchParams.TO_CHAIN]: toChainString
|
|
1260
|
-
}),
|
|
1261
|
-
...(toTokenString && {
|
|
1262
|
-
[SearchParams.TO_TOKEN]: toTokenString
|
|
1263
|
-
}),
|
|
1264
|
-
...(fromAmount && {
|
|
1265
|
-
[SearchParams.FROM_AMOUNT]: fromAmount.toString()
|
|
1266
|
-
})
|
|
1267
|
-
}, {
|
|
1268
|
-
replace: true
|
|
1269
|
-
});
|
|
1270
|
-
}
|
|
1271
|
-
firstRender.current = false;
|
|
1272
|
-
}, [location.pathname, inputAmount, fromChain, fromToken, toChain, toToken]);
|
|
1273
|
-
React.useEffect(() => {
|
|
1274
|
-
if (loadingStatus === 'success') {
|
|
1275
|
-
const fromChainString = searchParams.get(SearchParams.FROM_CHAIN);
|
|
1276
|
-
const fromTokenString = searchParams.get(SearchParams.FROM_TOKEN);
|
|
1277
|
-
const toChainString = searchParams.get(SearchParams.TO_CHAIN);
|
|
1278
|
-
const toTokenString = searchParams.get(SearchParams.TO_TOKEN);
|
|
1279
|
-
const fromAmount = searchParams.get(SearchParams.FROM_AMOUNT);
|
|
1280
|
-
const fromChain = blockchains.find(blockchain => blockchain.name === fromChainString);
|
|
1281
|
-
const fromToken = searchParamsToToken(tokens, fromTokenString, fromChain || null);
|
|
1282
|
-
const toChain = blockchains.find(blockchain => blockchain.name === toChainString);
|
|
1283
|
-
const toToken = searchParamsToToken(tokens, toTokenString, toChain || null);
|
|
1284
|
-
if (!!fromChain) {
|
|
1285
|
-
setFromChain(fromChain);
|
|
1286
|
-
if (!!fromToken) setFromToken(fromToken);
|
|
1287
|
-
}
|
|
1288
|
-
if (!!toChain) {
|
|
1289
|
-
setToChain(toChain);
|
|
1290
|
-
if (!!toToken) setToToken(toToken);
|
|
1291
|
-
}
|
|
1292
|
-
if (fromAmount) setInputAmount(fromAmount);
|
|
1293
|
-
}
|
|
1294
|
-
}, [loadingStatus]);
|
|
1295
|
-
return null;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
function AppRouter(_ref) {
|
|
1299
|
-
let {
|
|
1300
|
-
children,
|
|
1301
|
-
...props
|
|
1302
|
-
} = _ref;
|
|
1303
|
-
const isRouterInContext = reactRouter.useInRouterContext();
|
|
1304
|
-
const Router = isRouterInContext ? React.Fragment : reactRouter.MemoryRouter;
|
|
1305
|
-
const {
|
|
1306
|
-
blockchains
|
|
1307
|
-
} = useMetaStore.use.meta();
|
|
1308
|
-
const evmChains = blockchains.filter(rangoTypes.isEvmBlockchain);
|
|
1309
|
-
queueManagerRangoPreset.useQueueManager({
|
|
1310
|
-
lastConnectedWallet: props.lastConnectedWallet,
|
|
1311
|
-
clearDisconnectedWallet: props.clearDisconnectedWallet,
|
|
1312
|
-
disconnectedWallet: props.disconnectedWallet,
|
|
1313
|
-
evmChains,
|
|
1314
|
-
notifier: () => {}
|
|
1315
|
-
});
|
|
1316
|
-
return React__default.createElement(React__default.Fragment, null, React__default.createElement(Router, null, children), isRouterInContext && React__default.createElement(UpdateUrl, null));
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
function useNavigateBack() {
|
|
1320
|
-
const isRouterInContext = reactRouterDom.useInRouterContext();
|
|
1321
|
-
const navigate = reactRouterDom.useNavigate();
|
|
1322
|
-
const navigateBackFrom = currentRoute => {
|
|
1323
|
-
if (currentRoute === navigationRoutes.swapDetails) return navigate('/' + navigationRoutes.swaps, {
|
|
1324
|
-
replace: true
|
|
1325
|
-
});
|
|
1326
|
-
if (!isRouterInContext || window.history.state && window.history.state.idx > 0) navigate(-1);else {
|
|
1327
|
-
if ([navigationRoutes.fromChain, navigationRoutes.fromToken, navigationRoutes.toChain, navigationRoutes.toToken, navigationRoutes.settings, navigationRoutes.wallets, navigationRoutes.swaps, navigationRoutes.confirmSwap].includes(currentRoute)) navigate(navigationRoutes.home, {
|
|
1328
|
-
replace: true
|
|
1329
|
-
});else if (currentRoute === navigationRoutes.liquiditySources) navigate('/' + navigationRoutes.settings, {
|
|
1330
|
-
replace: true
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
return {
|
|
1335
|
-
navigateBackFrom
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
const Box = /*#__PURE__*/ui.styled('div', {
|
|
1340
|
-
display: 'flex',
|
|
1341
|
-
flexDirection: 'column',
|
|
1342
|
-
width: '100%',
|
|
1343
|
-
overflow: 'hidden'
|
|
1344
|
-
});
|
|
1345
|
-
const Container = /*#__PURE__*/ui.styled('div', {
|
|
1346
|
-
boxSizing: 'border-box',
|
|
1347
|
-
borderRadius: '$5',
|
|
1348
|
-
padding: '$8 $16 $16 $16',
|
|
1349
|
-
variants: {
|
|
1350
|
-
type: {
|
|
1351
|
-
filled: {
|
|
1352
|
-
backgroundColor: '$neutral100'
|
|
1353
|
-
},
|
|
1354
|
-
outlined: {
|
|
1355
|
-
border: '1px solid $neutral100'
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
},
|
|
1359
|
-
defaultVariants: {
|
|
1360
|
-
type: 'filled'
|
|
1361
|
-
},
|
|
1362
|
-
'.head': {
|
|
1363
|
-
display: 'flex',
|
|
1364
|
-
justifyContent: 'space-between',
|
|
1365
|
-
alignItems: 'center',
|
|
1366
|
-
minHeight: '32px',
|
|
1367
|
-
'.usd-value': {
|
|
1368
|
-
paddingLeft: '$8'
|
|
1369
|
-
}
|
|
1370
|
-
},
|
|
1371
|
-
'.form': {
|
|
1372
|
-
display: 'flex',
|
|
1373
|
-
width: '100%',
|
|
1374
|
-
padding: '$2 0',
|
|
1375
|
-
'.selectors': {
|
|
1376
|
-
width: '35%',
|
|
1377
|
-
'._text': {
|
|
1378
|
-
whiteSpace: 'nowrap',
|
|
1379
|
-
overflow: 'hidden',
|
|
1380
|
-
textOverflow: 'ellipsis'
|
|
1381
|
-
}
|
|
1382
|
-
},
|
|
1383
|
-
'.amount': {
|
|
1384
|
-
width: '30%'
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
});
|
|
1388
|
-
const ImagePlaceholder = /*#__PURE__*/ui.styled('span', {
|
|
1389
|
-
width: '24px',
|
|
1390
|
-
height: '24px',
|
|
1391
|
-
backgroundColor: '$neutral100',
|
|
1392
|
-
borderRadius: '99999px'
|
|
1393
|
-
});
|
|
1394
|
-
const OutputContainer = /*#__PURE__*/ui.styled('div', {
|
|
1395
|
-
windth: '100%',
|
|
1396
|
-
height: '$48',
|
|
1397
|
-
borderRadius: '$5',
|
|
1398
|
-
backgroundColor: '$surface',
|
|
1399
|
-
border: '1px solid transparent',
|
|
1400
|
-
position: 'relative',
|
|
1401
|
-
display: 'flex',
|
|
1402
|
-
alignItems: 'center',
|
|
1403
|
-
paddingLeft: '$8',
|
|
1404
|
-
paddingRight: '$8'
|
|
1405
|
-
});
|
|
1406
|
-
function TokenPreview(props) {
|
|
1407
|
-
const {
|
|
1408
|
-
chain,
|
|
1409
|
-
token,
|
|
1410
|
-
loadingStatus,
|
|
1411
|
-
percentageChange
|
|
1412
|
-
} = props;
|
|
1413
|
-
const {
|
|
1414
|
-
t
|
|
1415
|
-
} = reactI18next.useTranslation();
|
|
1416
|
-
const ItemSuffix = React__default.createElement("div", {
|
|
1417
|
-
style: {
|
|
1418
|
-
display: 'flex',
|
|
1419
|
-
justifyContent: 'center',
|
|
1420
|
-
alignItems: 'center'
|
|
1421
|
-
}
|
|
1422
|
-
}, loadingStatus === 'failed' && React__default.createElement(ui.InfoCircleIcon, {
|
|
1423
|
-
color: "error",
|
|
1424
|
-
size: 24
|
|
1425
|
-
}));
|
|
1426
|
-
return React__default.createElement(Box, null, React__default.createElement(Container, {
|
|
1427
|
-
type: 'outlined'
|
|
1428
|
-
}, React__default.createElement("div", {
|
|
1429
|
-
className: "head"
|
|
1430
|
-
}, React__default.createElement(ui.Typography, {
|
|
1431
|
-
variant: "body2",
|
|
1432
|
-
color: "neutral800"
|
|
1433
|
-
}, props.label), React__default.createElement("div", null, percentageChange, props.usdValue && React__default.createElement(ui.Typography, {
|
|
1434
|
-
variant: "caption",
|
|
1435
|
-
color: "neutral600",
|
|
1436
|
-
className: "usd-value"
|
|
1437
|
-
}, `$${numberToString(props.usdValue)}`))), React__default.createElement("div", {
|
|
1438
|
-
className: "form"
|
|
1439
|
-
}, React__default.createElement(ui.Button, {
|
|
1440
|
-
className: "selectors",
|
|
1441
|
-
variant: "outlined",
|
|
1442
|
-
loading: loadingStatus === 'loading',
|
|
1443
|
-
prefix: loadingStatus === 'success' && chain ? React__default.createElement(ui.Image, {
|
|
1444
|
-
src: chain.logo,
|
|
1445
|
-
size: 24
|
|
1446
|
-
}) : React__default.createElement(ImagePlaceholder, null),
|
|
1447
|
-
suffix: ItemSuffix,
|
|
1448
|
-
align: "start",
|
|
1449
|
-
size: "large"
|
|
1450
|
-
}, loadingStatus === 'success' && chain ? chain.displayName : t('Chain')), React__default.createElement(ui.Spacer, {
|
|
1451
|
-
size: 12
|
|
1452
|
-
}), React__default.createElement(ui.Button, {
|
|
1453
|
-
className: "selectors",
|
|
1454
|
-
variant: "outlined",
|
|
1455
|
-
loading: loadingStatus === 'loading',
|
|
1456
|
-
prefix: loadingStatus === 'success' && token ? React__default.createElement(ui.Image, {
|
|
1457
|
-
src: token.image,
|
|
1458
|
-
size: 24
|
|
1459
|
-
}) : React__default.createElement(ImagePlaceholder, null),
|
|
1460
|
-
suffix: ItemSuffix,
|
|
1461
|
-
size: "large",
|
|
1462
|
-
align: "start"
|
|
1463
|
-
}, loadingStatus === 'success' && token ? token.symbol : t('Token')), React__default.createElement(ui.Spacer, {
|
|
1464
|
-
size: 12
|
|
1465
|
-
}), React__default.createElement("div", {
|
|
1466
|
-
className: "amount"
|
|
1467
|
-
}, React__default.createElement(OutputContainer, null, React__default.createElement(ui.Typography, {
|
|
1468
|
-
variant: "h4"
|
|
1469
|
-
}, props.amount))))));
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
const Container$1 = /*#__PURE__*/ui.styled('div', {
|
|
1473
|
-
display: 'flex',
|
|
1474
|
-
alignItems: 'center',
|
|
1475
|
-
justifyContent: 'space-between',
|
|
1476
|
-
padding: '$8',
|
|
1477
|
-
borderRadius: '$5',
|
|
1478
|
-
backgroundColor: '$neutral100',
|
|
1479
|
-
color: '$neutral800',
|
|
1480
|
-
fontSize: '$12',
|
|
1481
|
-
'.routes': {
|
|
1482
|
-
display: 'flex',
|
|
1483
|
-
alignItems: 'center'
|
|
1484
|
-
},
|
|
1485
|
-
'.fee': {
|
|
1486
|
-
display: 'flex',
|
|
1487
|
-
alignItems: 'center'
|
|
1488
|
-
}
|
|
1489
|
-
});
|
|
1490
|
-
function RoutesOverview(props) {
|
|
1491
|
-
if (!props.routes) return null;
|
|
1492
|
-
const swaps = props.routes.result?.swaps;
|
|
1493
|
-
return React__default.createElement(Container$1, null, React__default.createElement("div", {
|
|
1494
|
-
className: "routes"
|
|
1495
|
-
}, swaps?.map((swap, idx) => {
|
|
1496
|
-
const isLast = idx + 1 == swaps.length;
|
|
1497
|
-
return React__default.createElement(React__default.Fragment, {
|
|
1498
|
-
key: idx
|
|
1499
|
-
}, React__default.createElement("div", {
|
|
1500
|
-
className: "route"
|
|
1501
|
-
}, swap.from.symbol), React__default.createElement(ui.ChevronRightIcon, {
|
|
1502
|
-
size: 12
|
|
1503
|
-
}), isLast ? React__default.createElement("div", {
|
|
1504
|
-
className: "route"
|
|
1505
|
-
}, swap.to.symbol) : null);
|
|
1506
|
-
})), props.totalFee ? React__default.createElement("div", {
|
|
1507
|
-
className: "fee"
|
|
1508
|
-
}, React__default.createElement(ui.GasIcon, {
|
|
1509
|
-
size: 12
|
|
1510
|
-
}), React__default.createElement(ui.Spacer, {
|
|
1511
|
-
size: 4
|
|
1512
|
-
}), "$", props.totalFee) : null);
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
var ConfirmSwapErrorTypes;
|
|
1516
|
-
(function (ConfirmSwapErrorTypes) {
|
|
1517
|
-
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["NO_ROUTE"] = 0] = "NO_ROUTE";
|
|
1518
|
-
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS"] = 1] = "ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS";
|
|
1519
|
-
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["REQUEST_FAILED"] = 2] = "REQUEST_FAILED";
|
|
1520
|
-
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_SLIPPAGE"] = 3] = "INSUFFICIENT_SLIPPAGE";
|
|
1521
|
-
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
1522
|
-
})(ConfirmSwapErrorTypes || (ConfirmSwapErrorTypes = {}));
|
|
1523
|
-
var ConfirmSwapWarningTypes;
|
|
1524
|
-
(function (ConfirmSwapWarningTypes) {
|
|
1525
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_UPDATED"] = 0] = "ROUTE_UPDATED";
|
|
1526
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_SWAPPERS_UPDATED"] = 1] = "ROUTE_SWAPPERS_UPDATED";
|
|
1527
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_COINS_UPDATED"] = 2] = "ROUTE_COINS_UPDATED";
|
|
1528
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_AND_OUTPUT_AMOUNT_UPDATED"] = 3] = "ROUTE_AND_OUTPUT_AMOUNT_UPDATED";
|
|
1529
|
-
})(ConfirmSwapWarningTypes || (ConfirmSwapWarningTypes = {}));
|
|
1530
|
-
|
|
1531
|
-
function useConfirmSwap() {
|
|
1532
|
-
const fromToken = useBestRouteStore.use.fromToken();
|
|
1533
|
-
const toToken = useBestRouteStore.use.toToken();
|
|
1534
|
-
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
1535
|
-
const initialRoute = useBestRouteStore.use.bestRoute();
|
|
1536
|
-
const setBestRoute = useBestRouteStore.use.setBestRoute();
|
|
1537
|
-
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
1538
|
-
const affiliateRef = useSettingsStore.use.affiliateRef();
|
|
1539
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
1540
|
-
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
1541
|
-
const meta = useMetaStore.use.meta();
|
|
1542
|
-
const customSlippage = useSettingsStore.use.customSlippage();
|
|
1543
|
-
const slippage = useSettingsStore.use.slippage();
|
|
1544
|
-
const disabledLiquiditySources = useSettingsStore.use.disabledLiquiditySources();
|
|
1545
|
-
const userSlippage = customSlippage || slippage;
|
|
1546
|
-
const proceedAnywayRef = React.useRef(false);
|
|
1547
|
-
const confiremedRouteRef = React.useRef(null);
|
|
1548
|
-
let abortControllerRef = React.useRef(null);
|
|
1549
|
-
const [loading, setLoading] = React.useState(false);
|
|
1550
|
-
const [errors, setErrors] = React.useState([]);
|
|
1551
|
-
const [warnings, setWarnings] = React.useState([]);
|
|
1552
|
-
React.useEffect(() => {
|
|
1553
|
-
return () => abortControllerRef.current?.abort();
|
|
1554
|
-
}, []);
|
|
1555
|
-
if (!fromToken || !toToken || !inputAmount || !initialRoute) return {
|
|
1556
|
-
loading: false,
|
|
1557
|
-
warnings: [],
|
|
1558
|
-
errors: [],
|
|
1559
|
-
confirmSwap: null
|
|
1560
|
-
};
|
|
1561
|
-
const confirmSwap = async () => {
|
|
1562
|
-
if (proceedAnywayRef.current) {
|
|
1563
|
-
const swapSettings = {
|
|
1564
|
-
slippage: userSlippage.toString(),
|
|
1565
|
-
disabledSwappersGroups: disabledLiquiditySources
|
|
1566
|
-
};
|
|
1567
|
-
if (errors.length > 0) setErrors([]);
|
|
1568
|
-
if (warnings.length > 0) setWarnings([]);
|
|
1569
|
-
proceedAnywayRef.current = false;
|
|
1570
|
-
if (confiremedRouteRef.current) {
|
|
1571
|
-
const newSwap = queueManagerRangoPreset.calculatePendingSwap(inputAmount.toString(), confiremedRouteRef.current, getWalletsForNewSwap(selectedWallets), swapSettings, false, meta);
|
|
1572
|
-
return newSwap;
|
|
1573
|
-
}
|
|
1574
|
-
return;
|
|
1575
|
-
}
|
|
1576
|
-
abortControllerRef.current = new AbortController();
|
|
1577
|
-
setLoading(true);
|
|
1578
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, connectedWallets, selectedWallets, disabledLiquiditySources, userSlippage, affiliateRef, initialRoute);
|
|
1579
|
-
try {
|
|
1580
|
-
const confiremedRoute = await httpService().getBestRoute(requestBody, {
|
|
1581
|
-
signal: abortControllerRef.current?.signal
|
|
1582
|
-
});
|
|
1583
|
-
abortControllerRef.current = null;
|
|
1584
|
-
setLoading(false);
|
|
1585
|
-
if (!confiremedRoute.result || !new BigNumber__default(confiremedRoute.requestAmount).isEqualTo(new BigNumber__default(inputAmount || '-1'))) {
|
|
1586
|
-
setErrors(prevState => prevState.concat({
|
|
1587
|
-
type: ConfirmSwapErrorTypes.NO_ROUTE
|
|
1588
|
-
}));
|
|
1589
|
-
return;
|
|
1590
|
-
}
|
|
1591
|
-
const confirmSwapState = {
|
|
1592
|
-
errors: [],
|
|
1593
|
-
warnings: []
|
|
1594
|
-
};
|
|
1595
|
-
const routeChanged = isRouteChanged(initialRoute, confiremedRoute);
|
|
1596
|
-
if (routeChanged) {
|
|
1597
|
-
setBestRoute(confiremedRoute);
|
|
1598
|
-
const newRouteOutputUsdValue = new BigNumber__default(confiremedRoute.result?.outputAmount || '0').multipliedBy(toToken.usdPrice || 0);
|
|
1599
|
-
const outputRatio = getOutputRatio(inputUsdValue, newRouteOutputUsdValue);
|
|
1600
|
-
const highValueLoss = outputRatioHasWarning(inputUsdValue, outputRatio);
|
|
1601
|
-
if (highValueLoss) confirmSwapState.errors.push({
|
|
1602
|
-
type: ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS
|
|
1603
|
-
});else if (isOutputAmountChangedALot(initialRoute, confiremedRoute)) confirmSwapState.warnings.push({
|
|
1604
|
-
type: ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
1605
|
-
newOutputAmount: numberToString(getRouteOutputAmount(confiremedRoute)),
|
|
1606
|
-
percentageChange: numberToString(getPercentageChange(getRouteOutputAmount(initialRoute), getRouteOutputAmount(confiremedRoute)), null, 2)
|
|
1607
|
-
});else if (isRouteInternalCoinsUpdated(initialRoute, confiremedRoute)) confirmSwapState.warnings.push({
|
|
1608
|
-
type: ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED
|
|
1609
|
-
});else if (isNumberOfSwapsChanged(initialRoute, confiremedRoute)) confirmSwapState.warnings.push({
|
|
1610
|
-
type: ConfirmSwapWarningTypes.ROUTE_UPDATED
|
|
1611
|
-
});else if (isRouteSwappersUpdated(initialRoute, confiremedRoute)) confirmSwapState.warnings.push({
|
|
1612
|
-
type: ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED
|
|
1613
|
-
});
|
|
1614
|
-
}
|
|
1615
|
-
const balanceWarnings = getBalanceWarnings(confiremedRoute, selectedWallets);
|
|
1616
|
-
const enoughBalance = balanceWarnings.length === 0;
|
|
1617
|
-
if (!enoughBalance) confirmSwapState.errors.push({
|
|
1618
|
-
type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
|
|
1619
|
-
messages: balanceWarnings
|
|
1620
|
-
});
|
|
1621
|
-
const minRequiredSlippage = getMinRequiredSlippage(initialRoute);
|
|
1622
|
-
if (!hasProperSlippage(userSlippage.toString(), minRequiredSlippage)) confirmSwapState.errors.push({
|
|
1623
|
-
type: ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE,
|
|
1624
|
-
minRequiredSlippage
|
|
1625
|
-
});
|
|
1626
|
-
const noErrors = confirmSwapState.errors.length === 0;
|
|
1627
|
-
const noWarnings = confirmSwapState.warnings.length === 0;
|
|
1628
|
-
if ((noErrors || !noErrors && proceedAnywayRef.current) && (noWarnings || !noWarnings && proceedAnywayRef.current)) {
|
|
1629
|
-
const swapSettings = {
|
|
1630
|
-
slippage: userSlippage.toString(),
|
|
1631
|
-
disabledSwappersGroups: disabledLiquiditySources
|
|
1632
|
-
};
|
|
1633
|
-
const newSwap = queueManagerRangoPreset.calculatePendingSwap(inputAmount.toString(), confiremedRoute, getWalletsForNewSwap(selectedWallets), swapSettings, false, meta);
|
|
1634
|
-
return newSwap;
|
|
1635
|
-
} else if (!proceedAnywayRef.current) {
|
|
1636
|
-
proceedAnywayRef.current = true;
|
|
1637
|
-
setErrors(confirmSwapState.errors);
|
|
1638
|
-
setWarnings(confirmSwapState.warnings);
|
|
1639
|
-
confiremedRouteRef.current = confiremedRoute;
|
|
1640
|
-
}
|
|
1641
|
-
return;
|
|
1642
|
-
} catch (error) {
|
|
1643
|
-
if (error?.code === 'ERR_CANCELED') {
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
const status = error?.response?.status;
|
|
1647
|
-
setLoading(false);
|
|
1648
|
-
setErrors([{
|
|
1649
|
-
type: ConfirmSwapErrorTypes.REQUEST_FAILED,
|
|
1650
|
-
status
|
|
1651
|
-
}]);
|
|
1652
|
-
return;
|
|
1653
|
-
}
|
|
1654
|
-
};
|
|
1655
|
-
return {
|
|
1656
|
-
loading,
|
|
1657
|
-
warnings,
|
|
1658
|
-
errors,
|
|
1659
|
-
confirmSwap
|
|
1660
|
-
};
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
function ChangeSlippageButton() {
|
|
1664
|
-
const navigate = reactRouterDom.useNavigate();
|
|
1665
|
-
return React__default.createElement(ui.Button, {
|
|
1666
|
-
type: "primary",
|
|
1667
|
-
variant: "outlined",
|
|
1668
|
-
size: "small",
|
|
1669
|
-
onClick: () => navigate('/' + navigationRoutes.settings)
|
|
1670
|
-
}, "Change Slippage");
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
const StyledMessage = /*#__PURE__*/ui.styled(ui.Typography, {
|
|
1674
|
-
color: '$error500 !important'
|
|
1675
|
-
});
|
|
1676
|
-
function MinRequiredSlippage(_ref) {
|
|
1677
|
-
let {
|
|
1678
|
-
minRequiredSlippage
|
|
1679
|
-
} = _ref;
|
|
1680
|
-
return React__default.createElement(StyledMessage, {
|
|
1681
|
-
variant: "body2"
|
|
1682
|
-
}, "We recommend you to increase slippage to at least \u00A0", minRequiredSlippage, "\u00A0 for this route.", React__default.createElement(ui.Spacer, {
|
|
1683
|
-
size: 8,
|
|
1684
|
-
direction: "vertical"
|
|
1685
|
-
}), React__default.createElement(ChangeSlippageButton, null));
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
const List = /*#__PURE__*/ui.styled('ul', {
|
|
1689
|
-
padding: 0,
|
|
1690
|
-
margin: 0,
|
|
1691
|
-
variants: {
|
|
1692
|
-
showListStyle: {
|
|
1693
|
-
true: {
|
|
1694
|
-
paddingLeft: '$24'
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
const ListItem = /*#__PURE__*/ui.styled('li', {
|
|
1700
|
-
variants: {
|
|
1701
|
-
showListStyle: {
|
|
1702
|
-
true: {
|
|
1703
|
-
listStyleType: 'disc',
|
|
1704
|
-
listStylePosition: 'outside'
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
});
|
|
1709
|
-
const Message = /*#__PURE__*/ui.styled(ui.Typography, {
|
|
1710
|
-
display: 'block'
|
|
1711
|
-
});
|
|
1712
|
-
function BalanceErrors(_ref) {
|
|
1713
|
-
let {
|
|
1714
|
-
messages
|
|
1715
|
-
} = _ref;
|
|
1716
|
-
const showListStyle = messages.length > 1;
|
|
1717
|
-
return React__default.createElement(React__default.Fragment, null, React__default.createElement(ui.Typography, {
|
|
1718
|
-
className: "title",
|
|
1719
|
-
variant: "title",
|
|
1720
|
-
color: 'error'
|
|
1721
|
-
}, "Insufficent Balance:"), React__default.createElement(ui.Spacer, {
|
|
1722
|
-
size: 8,
|
|
1723
|
-
direction: "vertical"
|
|
1724
|
-
}), React__default.createElement(List, {
|
|
1725
|
-
showListStyle: showListStyle
|
|
1726
|
-
}, messages.map((warning, index) => React__default.createElement(ListItem, {
|
|
1727
|
-
showListStyle: showListStyle,
|
|
1728
|
-
key: index
|
|
1729
|
-
}, React__default.createElement(Message, {
|
|
1730
|
-
variant: "body2"
|
|
1731
|
-
}, warning)))));
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
function ConfirmSwapErrors(errors) {
|
|
1735
|
-
return errors.flatMap(error => {
|
|
1736
|
-
switch (error.type) {
|
|
1737
|
-
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
1738
|
-
return 'No routes found. Please try again later.';
|
|
1739
|
-
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
1740
|
-
return `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`;
|
|
1741
|
-
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
1742
|
-
return 'Route updated and price impact is too high, try again later!';
|
|
1743
|
-
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
1744
|
-
return React__default.createElement(MinRequiredSlippage, {
|
|
1745
|
-
minRequiredSlippage: error.minRequiredSlippage
|
|
1746
|
-
});
|
|
1747
|
-
case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
|
|
1748
|
-
return React__default.createElement(BalanceErrors, {
|
|
1749
|
-
messages: error.messages
|
|
1750
|
-
});
|
|
1751
|
-
default:
|
|
1752
|
-
return [];
|
|
1753
|
-
}
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
function ConfirmSwapWarnings(warnings) {
|
|
1758
|
-
return warnings.flatMap(warning => {
|
|
1759
|
-
switch (warning.type) {
|
|
1760
|
-
case ConfirmSwapWarningTypes.ROUTE_UPDATED:
|
|
1761
|
-
return "Route has been updated.";
|
|
1762
|
-
case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
1763
|
-
return `Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`;
|
|
1764
|
-
case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
|
|
1765
|
-
return "Route swappers has been updated.";
|
|
1766
|
-
case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
|
|
1767
|
-
return "Route internal coins has been updated.";
|
|
1768
|
-
default:
|
|
1769
|
-
return [];
|
|
1770
|
-
}
|
|
1771
|
-
});
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
function HighSlippageWarning(props) {
|
|
1775
|
-
const {
|
|
1776
|
-
selectedSlippage
|
|
1777
|
-
} = props;
|
|
1778
|
-
return React__default.createElement(ui.Alert, {
|
|
1779
|
-
type: "warning",
|
|
1780
|
-
footer: React__default.createElement(ChangeSlippageButton, null)
|
|
1781
|
-
}, "Caution, your slippage is high (=", selectedSlippage, "). Your trade may be front run.");
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
function ConfirmSwapExtraMessages(props) {
|
|
1785
|
-
const {
|
|
1786
|
-
selectedSlippage
|
|
1787
|
-
} = props;
|
|
1788
|
-
const highSlippage = selectedSlippage >= HIGH_SLIPPAGE;
|
|
1789
|
-
return React__default.createElement(React__default.Fragment, null, highSlippage && React__default.createElement(HighSlippageWarning, {
|
|
1790
|
-
selectedSlippage: selectedSlippage
|
|
1791
|
-
}));
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
function PercentageChange(props) {
|
|
1795
|
-
const {
|
|
1796
|
-
inputUsdValue,
|
|
1797
|
-
outputUsdValue
|
|
1798
|
-
} = props;
|
|
1799
|
-
if (!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)) return null;
|
|
1800
|
-
const percentageChange = getPercentageChange(inputUsdValue.toNumber(), outputUsdValue.toNumber());
|
|
1801
|
-
const showPercentageChange = percentageChange?.lt(0);
|
|
1802
|
-
return React__default.createElement(React__default.Fragment, null, showPercentageChange && React__default.createElement(ui.Typography, {
|
|
1803
|
-
variant: "caption",
|
|
1804
|
-
color: "$error500"
|
|
1805
|
-
}, `(${numberToString(percentageChange, 0, 2)}%)`));
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
function ConfirmSwapPage() {
|
|
1809
|
-
const navigate = reactRouterDom.useNavigate();
|
|
1810
|
-
const {
|
|
1811
|
-
navigateBackFrom
|
|
1812
|
-
} = useNavigateBack();
|
|
1813
|
-
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
1814
|
-
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
1815
|
-
const fetchingBestRouteError = useBestRouteStore.use.error();
|
|
1816
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
1817
|
-
const {
|
|
1818
|
-
blockchains,
|
|
1819
|
-
tokens
|
|
1820
|
-
} = useMetaStore.use.meta();
|
|
1821
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
1822
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
1823
|
-
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
1824
|
-
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
1825
|
-
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
1826
|
-
const slippage = useSettingsStore.use.slippage();
|
|
1827
|
-
const customSlippage = useSettingsStore.use.customSlippage();
|
|
1828
|
-
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
1829
|
-
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
1830
|
-
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
1831
|
-
const [dbErrorMessage, setDbErrorMessage] = React.useState('');
|
|
1832
|
-
const bestRouteloadingStatus = getBestRouteStatus(fetchingBestRoute, !!fetchingBestRouteError);
|
|
1833
|
-
const {
|
|
1834
|
-
manager
|
|
1835
|
-
} = queueManagerReact.useManager();
|
|
1836
|
-
const {
|
|
1837
|
-
loading: fetchingConfirmedRoute,
|
|
1838
|
-
errors,
|
|
1839
|
-
warnings,
|
|
1840
|
-
confirmSwap
|
|
1841
|
-
} = useConfirmSwap();
|
|
1842
|
-
const selectedSlippage = customSlippage || slippage;
|
|
1843
|
-
const showHighSlippageWarning = !errors.find(error => error.type === ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE);
|
|
1844
|
-
const {
|
|
1845
|
-
getWalletInfo,
|
|
1846
|
-
connect
|
|
1847
|
-
} = walletsCore.useWallets();
|
|
1848
|
-
const confirmDisabled = fetchingBestRoute || !requiredWallets(bestRoute).every(chain => selectedWallets.map(wallet => wallet.chain).includes(chain));
|
|
1849
|
-
const firstStep = bestRoute?.result?.swaps[0];
|
|
1850
|
-
const lastStep = bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
1851
|
-
const fromAmount = numberToString(firstStep?.fromAmount, 4, 6);
|
|
1852
|
-
const toAmount = numberToString(lastStep?.toAmount, 4, 6);
|
|
1853
|
-
React.useEffect(() => {
|
|
1854
|
-
initSelectedWallets();
|
|
1855
|
-
}, []);
|
|
1856
|
-
const selectableWallets = getSelectableWallets(connectedWallets, selectedWallets, getWalletInfo);
|
|
1857
|
-
const handleConnectChain = wallet => {
|
|
1858
|
-
const network = wallet;
|
|
1859
|
-
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
|
|
1860
|
-
};
|
|
1861
|
-
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
1862
|
-
return React__default.createElement(ui.ConfirmSwap, {
|
|
1863
|
-
requiredWallets: getRequiredChains(bestRoute),
|
|
1864
|
-
selectableWallets: selectableWallets,
|
|
1865
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.confirmSwap),
|
|
1866
|
-
onConfirm: async () => {
|
|
1867
|
-
confirmSwap?.().then(async swap => {
|
|
1868
|
-
if (swap) {
|
|
1869
|
-
try {
|
|
1870
|
-
await manager?.create('swap', {
|
|
1871
|
-
swapDetails: swap
|
|
1872
|
-
}, {
|
|
1873
|
-
id: swap.requestId
|
|
1874
|
-
});
|
|
1875
|
-
setSelectedSwap(swap.requestId);
|
|
1876
|
-
navigate('/' + navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
1877
|
-
replace: true
|
|
1878
|
-
});
|
|
1879
|
-
setTimeout(() => {
|
|
1880
|
-
setInputAmount('');
|
|
1881
|
-
}, 0);
|
|
1882
|
-
} catch (e) {
|
|
1883
|
-
setDbErrorMessage('Error: ' + e?.message);
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
});
|
|
1887
|
-
},
|
|
1888
|
-
onChange: wallet => setSelectedWallet(wallet),
|
|
1889
|
-
confirmDisabled: loadingMetaStatus !== 'success' || confirmDisabled,
|
|
1890
|
-
handleConnectChain: wallet => handleConnectChain(wallet),
|
|
1891
|
-
isExperimentalChain: wallet => getKeplrCompatibleConnectedWallets(selectableWallets).length > 0 ? isExperimentalChain(blockchains, wallet) : false,
|
|
1892
|
-
previewInputs: React__default.createElement(React__default.Fragment, null, React__default.createElement(TokenPreview, {
|
|
1893
|
-
chain: {
|
|
1894
|
-
displayName: firstStep?.from.blockchain || '',
|
|
1895
|
-
logo: firstStep?.from.blockchainLogo || ''
|
|
1896
|
-
},
|
|
1897
|
-
token: {
|
|
1898
|
-
symbol: firstStep?.from.symbol || '',
|
|
1899
|
-
image: firstStep?.from.logo || ''
|
|
1900
|
-
},
|
|
1901
|
-
usdValue: inputUsdValue,
|
|
1902
|
-
amount: fromAmount,
|
|
1903
|
-
label: i18n.t('From'),
|
|
1904
|
-
loadingStatus: loadingMetaStatus !== 'success' ? loadingMetaStatus : bestRouteloadingStatus
|
|
1905
|
-
}), React__default.createElement(ui.Spacer, {
|
|
1906
|
-
size: 12,
|
|
1907
|
-
direction: "vertical"
|
|
1908
|
-
}), React__default.createElement(TokenPreview, {
|
|
1909
|
-
chain: {
|
|
1910
|
-
displayName: lastStep?.to.blockchain || '',
|
|
1911
|
-
logo: lastStep?.to.blockchainLogo || ''
|
|
1912
|
-
},
|
|
1913
|
-
token: {
|
|
1914
|
-
symbol: lastStep?.to.symbol || '',
|
|
1915
|
-
image: lastStep?.to.logo || ''
|
|
1916
|
-
},
|
|
1917
|
-
usdValue: outputUsdValue,
|
|
1918
|
-
amount: toAmount,
|
|
1919
|
-
label: i18n.t('To'),
|
|
1920
|
-
loadingStatus: loadingMetaStatus !== 'success' ? loadingMetaStatus : bestRouteloadingStatus,
|
|
1921
|
-
percentageChange: React__default.createElement(PercentageChange, {
|
|
1922
|
-
inputUsdValue: inputUsdValue,
|
|
1923
|
-
outputUsdValue: outputUsdValue
|
|
1924
|
-
})
|
|
1925
|
-
})),
|
|
1926
|
-
previewRoutes: React__default.createElement(RoutesOverview, {
|
|
1927
|
-
routes: bestRoute,
|
|
1928
|
-
totalFee: numberToString(totalFeeInUsd, 0, 2)
|
|
1929
|
-
}),
|
|
1930
|
-
loading: fetchingConfirmedRoute,
|
|
1931
|
-
errors: dbErrorMessage ? [dbErrorMessage, ...ConfirmSwapErrors(errors)] : ConfirmSwapErrors(errors),
|
|
1932
|
-
warnings: ConfirmSwapWarnings(warnings),
|
|
1933
|
-
extraMessages: React__default.createElement(React__default.Fragment, null, loadingMetaStatus === 'failed' && React__default.createElement(ui.LoadingFailedAlert, null), loadingMetaStatus === 'failed' && showHighSlippageWarning && React__default.createElement(ui.Spacer, {
|
|
1934
|
-
direction: "vertical"
|
|
1935
|
-
}), showHighSlippageWarning && React__default.createElement(ConfirmSwapExtraMessages, {
|
|
1936
|
-
selectedSlippage: selectedSlippage
|
|
1937
|
-
})),
|
|
1938
|
-
confirmButtonTitle: warnings.length > 0 || errors.length > 0 ? 'Proceed anyway!' : 'Confirm swap!'
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
const getPendingSwaps = manager => {
|
|
1943
|
-
const result = [];
|
|
1944
|
-
manager?.getAll().forEach((q, id) => {
|
|
1945
|
-
const storage = q.list.getStorage();
|
|
1946
|
-
if (storage?.swapDetails) {
|
|
1947
|
-
result.push({
|
|
1948
|
-
id,
|
|
1949
|
-
swap: storage?.swapDetails
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
});
|
|
1953
|
-
return result.sort((a, b) => Number(b.swap.creationTime) - Number(a.swap.creationTime));
|
|
1954
|
-
};
|
|
1955
|
-
|
|
1956
|
-
const groupSwapsByDate = swaps => {
|
|
1957
|
-
const output = new Map([['today', {
|
|
1958
|
-
title: 'Today',
|
|
1959
|
-
swaps: []
|
|
1960
|
-
}], ['week', {
|
|
1961
|
-
title: 'This week',
|
|
1962
|
-
swaps: []
|
|
1963
|
-
}], ['month', {
|
|
1964
|
-
title: 'This month',
|
|
1965
|
-
swaps: []
|
|
1966
|
-
}], ['year', {
|
|
1967
|
-
title: 'This year',
|
|
1968
|
-
swaps: []
|
|
1969
|
-
}], ['history', {
|
|
1970
|
-
title: 'History',
|
|
1971
|
-
swaps: []
|
|
1972
|
-
}]]);
|
|
1973
|
-
const now = dayjs();
|
|
1974
|
-
swaps.forEach(swap => {
|
|
1975
|
-
const swapDate = dayjs(Number(swap.creationTime));
|
|
1976
|
-
if (now.isSame(swapDate, 'day')) output.get('today')?.swaps.push(swap);else if (now.isSame(swapDate, 'week')) output.get('week')?.swaps.push(swap);else if (now.isSame(swapDate, 'month')) output.get('month')?.swaps.push(swap);else if (now.isSame(swapDate, 'year')) output.get('year')?.swaps.push(swap);else output.get('history')?.swaps.push(swap);
|
|
1977
|
-
});
|
|
1978
|
-
return Array.from(output.values());
|
|
1979
|
-
};
|
|
1980
|
-
|
|
1981
|
-
function HistoryPage() {
|
|
1982
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
1983
|
-
const navigate = reactRouterDom.useNavigate();
|
|
1984
|
-
const {
|
|
1985
|
-
navigateBackFrom
|
|
1986
|
-
} = useNavigateBack();
|
|
1987
|
-
const {
|
|
1988
|
-
manager,
|
|
1989
|
-
state
|
|
1990
|
-
} = queueManagerReact.useManager();
|
|
1991
|
-
const pendingSwaps = getPendingSwaps(manager).map(_ref => {
|
|
1992
|
-
let {
|
|
1993
|
-
swap
|
|
1994
|
-
} = _ref;
|
|
1995
|
-
return swap;
|
|
1996
|
-
});
|
|
1997
|
-
const loading = !state.loadedFromPersistor;
|
|
1998
|
-
return React__default.createElement(ui.History, {
|
|
1999
|
-
list: pendingSwaps,
|
|
2000
|
-
groupBy: groupSwapsByDate,
|
|
2001
|
-
loading: loading,
|
|
2002
|
-
onSwapClick: requestId => {
|
|
2003
|
-
setSelectedSwap(requestId);
|
|
2004
|
-
navigate(`${requestId}`, {
|
|
2005
|
-
replace: true
|
|
2006
|
-
});
|
|
2007
|
-
},
|
|
2008
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.swaps)
|
|
2009
|
-
});
|
|
2010
|
-
}
|
|
2011
|
-
|
|
2012
|
-
const Box$1 = /*#__PURE__*/ui.styled('div', {
|
|
2013
|
-
display: 'flex',
|
|
2014
|
-
flexDirection: 'column',
|
|
2015
|
-
width: '100%',
|
|
2016
|
-
overflow: 'hidden'
|
|
2017
|
-
});
|
|
2018
|
-
const Container$2 = /*#__PURE__*/ui.styled('div', {
|
|
2019
|
-
boxSizing: 'border-box',
|
|
2020
|
-
borderRadius: '$5',
|
|
2021
|
-
padding: '$8 $16 $16 $16',
|
|
2022
|
-
variants: {
|
|
2023
|
-
type: {
|
|
2024
|
-
filled: {
|
|
2025
|
-
backgroundColor: '$neutral100'
|
|
2026
|
-
},
|
|
2027
|
-
outlined: {
|
|
2028
|
-
border: '1px solid $neutral100',
|
|
2029
|
-
backgroundColor: '$surface'
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
},
|
|
2033
|
-
defaultVariants: {
|
|
2034
|
-
type: 'filled'
|
|
2035
|
-
},
|
|
2036
|
-
'.head': {
|
|
2037
|
-
display: 'flex',
|
|
2038
|
-
justifyContent: 'space-between',
|
|
2039
|
-
alignItems: 'center',
|
|
2040
|
-
minHeight: '32px'
|
|
2041
|
-
},
|
|
2042
|
-
'.form': {
|
|
2043
|
-
display: 'flex',
|
|
2044
|
-
width: '100%',
|
|
2045
|
-
padding: '$2 0',
|
|
2046
|
-
'.selectors': {
|
|
2047
|
-
width: '35%',
|
|
2048
|
-
'._text': {
|
|
2049
|
-
whiteSpace: 'nowrap',
|
|
2050
|
-
overflow: 'hidden',
|
|
2051
|
-
textOverflow: 'ellipsis'
|
|
2052
|
-
}
|
|
2053
|
-
},
|
|
2054
|
-
'.amount': {
|
|
2055
|
-
width: '30%'
|
|
2056
|
-
}
|
|
2057
|
-
},
|
|
2058
|
-
'.output-usd': {
|
|
2059
|
-
display: 'flex',
|
|
2060
|
-
div: {
|
|
2061
|
-
display: 'flex',
|
|
2062
|
-
paddingLeft: '$8'
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
});
|
|
2066
|
-
const Options = /*#__PURE__*/ui.styled('div', {
|
|
2067
|
-
display: 'flex',
|
|
2068
|
-
justifyContent: 'flex-end',
|
|
2069
|
-
'.balance': {
|
|
2070
|
-
display: 'flex',
|
|
2071
|
-
alignItems: 'center'
|
|
2072
|
-
}
|
|
2073
|
-
});
|
|
2074
|
-
const ImagePlaceholder$1 = /*#__PURE__*/ui.styled('span', {
|
|
2075
|
-
width: '24px',
|
|
2076
|
-
height: '24px',
|
|
2077
|
-
backgroundColor: '$neutral100',
|
|
2078
|
-
borderRadius: '99999px'
|
|
2079
|
-
});
|
|
2080
|
-
const OutputContainer$1 = /*#__PURE__*/ui.styled('div', {
|
|
2081
|
-
windth: '100%',
|
|
2082
|
-
height: '$48',
|
|
2083
|
-
borderRadius: '$5',
|
|
2084
|
-
backgroundColor: '$surface',
|
|
2085
|
-
border: '1px solid transparent',
|
|
2086
|
-
position: 'relative',
|
|
2087
|
-
display: 'flex',
|
|
2088
|
-
alignItems: 'center',
|
|
2089
|
-
paddingLeft: '$8',
|
|
2090
|
-
paddingRight: '$8'
|
|
2091
|
-
});
|
|
2092
|
-
function TokenInfo(props) {
|
|
2093
|
-
const {
|
|
2094
|
-
type,
|
|
2095
|
-
chain,
|
|
2096
|
-
token
|
|
2097
|
-
} = props;
|
|
2098
|
-
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
2099
|
-
const fromChain = useBestRouteStore.use.fromChain();
|
|
2100
|
-
const toChain = useBestRouteStore.use.toChain();
|
|
2101
|
-
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2102
|
-
const fromToken = useBestRouteStore.use.fromToken();
|
|
2103
|
-
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2104
|
-
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
2105
|
-
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
2106
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
2107
|
-
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
2108
|
-
const navigate = reactRouterDom.useNavigate();
|
|
2109
|
-
const {
|
|
2110
|
-
t
|
|
2111
|
-
} = reactI18next.useTranslation();
|
|
2112
|
-
const tokenBalance = !!fromChain && !!fromToken ? numberToString(getBalanceFromWallet(connectedWallets, fromChain?.name, fromToken?.symbol, fromToken?.address)?.amount || '0', 8) : '0';
|
|
2113
|
-
const tokenBalanceReal = !!fromChain && !!fromToken ? numberToString(getBalanceFromWallet(connectedWallets, fromChain?.name, fromToken?.symbol, fromToken?.address)?.amount || '0', getBalanceFromWallet(connectedWallets, fromChain?.name, fromToken?.symbol, fromToken?.address)?.decimal) : '0';
|
|
2114
|
-
const ItemSuffix = React__default.createElement("div", {
|
|
2115
|
-
style: {
|
|
2116
|
-
display: 'flex',
|
|
2117
|
-
justifyContent: 'center',
|
|
2118
|
-
alignItems: 'center'
|
|
2119
|
-
}
|
|
2120
|
-
}, loadingStatus === 'failed' && React__default.createElement(ui.InfoCircleIcon, {
|
|
2121
|
-
color: "error",
|
|
2122
|
-
size: 24
|
|
2123
|
-
}), React__default.createElement(ui.AngleDownIcon, null));
|
|
2124
|
-
return React__default.createElement(Box$1, null, React__default.createElement(Container$2, {
|
|
2125
|
-
type: props.type === 'From' ? 'filled' : 'outlined'
|
|
2126
|
-
}, React__default.createElement("div", {
|
|
2127
|
-
className: "head"
|
|
2128
|
-
}, React__default.createElement(ui.Typography, {
|
|
2129
|
-
variant: "body2",
|
|
2130
|
-
color: "neutral800"
|
|
2131
|
-
}, t(type)), props.type === 'From' ? React__default.createElement(Options, null, React__default.createElement("div", {
|
|
2132
|
-
className: "balance",
|
|
2133
|
-
onClick: () => {
|
|
2134
|
-
if (tokenBalance !== '0') setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
2135
|
-
}
|
|
2136
|
-
}, React__default.createElement(ui.Typography, {
|
|
2137
|
-
variant: "body3",
|
|
2138
|
-
color: "neutral600"
|
|
2139
|
-
}, `${t('Balance')}: ${tokenBalance} ${fromToken?.symbol || ''}`), React__default.createElement(ui.Spacer, {
|
|
2140
|
-
size: 4
|
|
2141
|
-
}), React__default.createElement(ui.Button, {
|
|
2142
|
-
type: "primary",
|
|
2143
|
-
variant: "ghost",
|
|
2144
|
-
size: "compact"
|
|
2145
|
-
}, t('Max')))) : React__default.createElement("div", {
|
|
2146
|
-
className: "output-usd"
|
|
2147
|
-
}, React__default.createElement(PercentageChange, {
|
|
2148
|
-
inputUsdValue: inputUsdValue,
|
|
2149
|
-
outputUsdValue: props.outputUsdValue
|
|
2150
|
-
}), React__default.createElement("div", null, React__default.createElement(ui.Typography, {
|
|
2151
|
-
variant: "caption",
|
|
2152
|
-
color: "neutral600"
|
|
2153
|
-
}, `$${numberToString(props.outputUsdValue)}`)))), React__default.createElement("div", {
|
|
2154
|
-
className: "form"
|
|
2155
|
-
}, React__default.createElement(ui.Button, {
|
|
2156
|
-
className: "selectors",
|
|
2157
|
-
onClick: () => {
|
|
2158
|
-
navigate(`${props.type.toLowerCase()}-chain`);
|
|
2159
|
-
},
|
|
2160
|
-
variant: "outlined",
|
|
2161
|
-
disabled: loadingStatus === 'failed',
|
|
2162
|
-
loading: loadingStatus === 'loading',
|
|
2163
|
-
prefix: loadingStatus === 'success' && chain ? React__default.createElement(ui.Image, {
|
|
2164
|
-
src: chain.logo,
|
|
2165
|
-
size: 24
|
|
2166
|
-
}) : React__default.createElement(ImagePlaceholder$1, null),
|
|
2167
|
-
suffix: ItemSuffix,
|
|
2168
|
-
align: "start",
|
|
2169
|
-
size: "large"
|
|
2170
|
-
}, loadingStatus === 'success' && chain ? chain.displayName : t('Chain')), React__default.createElement(ui.Spacer, {
|
|
2171
|
-
size: 12
|
|
2172
|
-
}), React__default.createElement(ui.Button, {
|
|
2173
|
-
className: "selectors",
|
|
2174
|
-
onClick: () => {
|
|
2175
|
-
navigate(`${props.type.toLowerCase()}-token`);
|
|
2176
|
-
},
|
|
2177
|
-
variant: "outlined",
|
|
2178
|
-
disabled: loadingStatus === 'failed' || type === 'From' && !fromChain || type === 'To' && !toChain,
|
|
2179
|
-
loading: loadingStatus === 'loading',
|
|
2180
|
-
prefix: loadingStatus === 'success' && token ? React__default.createElement(ui.Image, {
|
|
2181
|
-
src: token.image,
|
|
2182
|
-
size: 24
|
|
2183
|
-
}) : React__default.createElement(ImagePlaceholder$1, null),
|
|
2184
|
-
suffix: ItemSuffix,
|
|
2185
|
-
size: "large",
|
|
2186
|
-
align: "start"
|
|
2187
|
-
}, loadingStatus === 'success' && token ? token.symbol : t('Token')), React__default.createElement(ui.Spacer, {
|
|
2188
|
-
size: 12
|
|
2189
|
-
}), React__default.createElement("div", {
|
|
2190
|
-
className: "amount"
|
|
2191
|
-
}, props.type === 'From' ? React__default.createElement(ui.TextField, {
|
|
2192
|
-
type: "number",
|
|
2193
|
-
size: "large",
|
|
2194
|
-
autoFocus: true,
|
|
2195
|
-
placeholder: "0",
|
|
2196
|
-
style: {
|
|
2197
|
-
position: 'relative',
|
|
2198
|
-
backgroundColor: '$background !important'
|
|
2199
|
-
},
|
|
2200
|
-
suffix: React__default.createElement("span", {
|
|
2201
|
-
style: {
|
|
2202
|
-
position: 'absolute',
|
|
2203
|
-
right: '4px',
|
|
2204
|
-
bottom: '2px'
|
|
2205
|
-
}
|
|
2206
|
-
}, React__default.createElement(ui.Typography, {
|
|
2207
|
-
variant: "caption",
|
|
2208
|
-
color: "neutral800"
|
|
2209
|
-
}, `$${numberToString(inputUsdValue)}`)),
|
|
2210
|
-
value: props.inputAmount || '',
|
|
2211
|
-
min: 0,
|
|
2212
|
-
onChange: props.type === 'From' ? event => {
|
|
2213
|
-
props.onAmountChange(event.target.value);
|
|
2214
|
-
} : undefined
|
|
2215
|
-
}) : React__default.createElement(OutputContainer$1, null, React__default.createElement(ui.Typography, {
|
|
2216
|
-
variant: "h4"
|
|
2217
|
-
}, fetchingBestRoute && '?', !!bestRoute?.result && `≈ ${numberToString(props.outputAmount)}`, (!inputAmount || inputAmount === '0') && '0'))))));
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
const Container$3 = /*#__PURE__*/_.styled('div', {
|
|
2221
|
-
display: 'flex',
|
|
2222
|
-
width: '100%',
|
|
2223
|
-
justifyContent: 'end',
|
|
2224
|
-
alignItems: 'center',
|
|
2225
|
-
paddingTop: '$16'
|
|
2226
|
-
});
|
|
2227
|
-
const Logo = /*#__PURE__*/_.styled('svg', {
|
|
2228
|
-
fill: '$foreground',
|
|
2229
|
-
width: '$24',
|
|
2230
|
-
margin: '0 $8 0 $16'
|
|
2231
|
-
});
|
|
2232
|
-
const StyledAnchor = /*#__PURE__*/_.styled('a', {
|
|
2233
|
-
display: 'flex',
|
|
2234
|
-
justifyContent: 'center',
|
|
2235
|
-
alignItems: 'center',
|
|
2236
|
-
textDecoration: 'none'
|
|
2237
|
-
});
|
|
2238
|
-
function BottomLogo() {
|
|
2239
|
-
const {
|
|
2240
|
-
t
|
|
2241
|
-
} = reactI18next.useTranslation();
|
|
2242
|
-
return React__default.createElement(Container$3, null, React__default.createElement(ui.Typography, {
|
|
2243
|
-
variant: "caption",
|
|
2244
|
-
color: "$neutral600"
|
|
2245
|
-
}, t('Powered By')), React__default.createElement(StyledAnchor, {
|
|
2246
|
-
href: "https://rango.exchange",
|
|
2247
|
-
target: "_blank"
|
|
2248
|
-
}, React__default.createElement(Logo, {
|
|
2249
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2250
|
-
viewBox: "0 0 33.68 29"
|
|
2251
|
-
}, React__default.createElement("defs", null), React__default.createElement("g", {
|
|
2252
|
-
id: "Layer_2",
|
|
2253
|
-
"data-name": "Layer 2"
|
|
2254
|
-
}, React__default.createElement("g", {
|
|
2255
|
-
id: "Layer_1-2",
|
|
2256
|
-
"data-name": "Layer 1"
|
|
2257
|
-
}, React__default.createElement("path", {
|
|
2258
|
-
d: "M33.68,18.05A17.93,17.93,0,0,0,28.34,5.29,18.31,18.31,0,0,0,15.45,0H13.54V7.41L6.07,0H.69L9.83,9.07H0V11A17.93,17.93,0,0,0,5.34,23.71,18.32,18.32,0,0,0,18.24,29h1.9V21.59l7.38,7.31h5.39l-9-9h9.82ZM17.37,16.16H12.49a1.93,1.93,0,0,0-1.35.55,1.89,1.89,0,0,0-.56,1.34,1.85,1.85,0,0,0,.56,1.33,1.93,1.93,0,0,0,1.35.55h3.84V25.1A14.43,14.43,0,0,1,8,21a14.21,14.21,0,0,1-4.1-8.2H21.2a1.86,1.86,0,0,0,.74-.13,1.92,1.92,0,0,0,.64-.4,2,2,0,0,0,.43-.62,1.88,1.88,0,0,0,0-1.47,2,2,0,0,0-.43-.62,1.92,1.92,0,0,0-.64-.4,1.86,1.86,0,0,0-.74-.13H17.35V3.9A14.43,14.43,0,0,1,25.64,8a14.19,14.19,0,0,1,4.11,8.2Zm2.12-5.27a1.43,1.43,0,0,1,.26-.83,1.52,1.52,0,0,1,.67-.56,1.55,1.55,0,0,1,.88-.08,1.51,1.51,0,0,1,.77.4,1.54,1.54,0,0,1,.42.77,1.41,1.41,0,0,1-.09.86,1.47,1.47,0,0,1-.55.68,1.56,1.56,0,0,1-.84.25,1.52,1.52,0,0,1-1.52-1.49Z"
|
|
2259
|
-
}), React__default.createElement("path", {
|
|
2260
|
-
d: "M21.7,11.57a.68.68,0,0,0-.12-.38.64.64,0,0,0-.31-.25.68.68,0,0,0-.75.15.61.61,0,0,0-.19.35.62.62,0,0,0,0,.4.67.67,0,0,0,.25.3.69.69,0,0,0,.39.12.7.7,0,0,0,.49-.2A.68.68,0,0,0,21.7,11.57Z"
|
|
2261
|
-
})))), React__default.createElement(ui.Typography, {
|
|
2262
|
-
variant: "body2"
|
|
2263
|
-
}, "RANGO")));
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2266
|
-
function SwithFromAndTo(_ref) {
|
|
2267
|
-
let {
|
|
2268
|
-
count
|
|
2269
|
-
} = _ref;
|
|
2270
|
-
const firstRender = React.useRef(true);
|
|
2271
|
-
const [searchParams, setSearchParams] = reactRouterDom.useSearchParams();
|
|
2272
|
-
const outputAmount = useBestRouteStore.use.outputAmount();
|
|
2273
|
-
React.useEffect(() => {
|
|
2274
|
-
if (!firstRender.current) {
|
|
2275
|
-
const fromChainString = searchParams.get(SearchParams.FROM_CHAIN);
|
|
2276
|
-
const fromTokenString = searchParams.get(SearchParams.FROM_TOKEN);
|
|
2277
|
-
const toChainString = searchParams.get(SearchParams.TO_CHAIN);
|
|
2278
|
-
const toTokenString = searchParams.get(SearchParams.TO_TOKEN);
|
|
2279
|
-
setSearchParams({
|
|
2280
|
-
...(toChainString && {
|
|
2281
|
-
[SearchParams.FROM_CHAIN]: toChainString
|
|
2282
|
-
}),
|
|
2283
|
-
...(toTokenString && {
|
|
2284
|
-
[SearchParams.FROM_TOKEN]: toTokenString
|
|
2285
|
-
}),
|
|
2286
|
-
...(fromChainString && {
|
|
2287
|
-
[SearchParams.TO_CHAIN]: fromChainString
|
|
2288
|
-
}),
|
|
2289
|
-
...(fromTokenString && {
|
|
2290
|
-
[SearchParams.TO_TOKEN]: fromTokenString
|
|
2291
|
-
}),
|
|
2292
|
-
...(outputAmount && {
|
|
2293
|
-
[SearchParams.FROM_AMOUNT]: outputAmount.toString()
|
|
2294
|
-
})
|
|
2295
|
-
});
|
|
2296
|
-
} else {
|
|
2297
|
-
firstRender.current = false;
|
|
2298
|
-
}
|
|
2299
|
-
}, [count]);
|
|
2300
|
-
return null;
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
|
-
const Footer = /*#__PURE__*/ui.styled('div', {
|
|
2304
|
-
display: 'flex',
|
|
2305
|
-
flexDirection: 'column',
|
|
2306
|
-
width: '100%',
|
|
2307
|
-
paddingTop: '$16'
|
|
2308
|
-
});
|
|
2309
|
-
|
|
2310
|
-
const errorMessages = {
|
|
2311
|
-
genericServerError: 'Error connecting server, please reload the app and try again'
|
|
2312
|
-
};
|
|
2313
|
-
|
|
2314
|
-
const ButtonsContainer = /*#__PURE__*/ui.styled('div', {
|
|
2315
|
-
display: 'flex'
|
|
2316
|
-
});
|
|
2317
|
-
function HeaderButtons(props) {
|
|
2318
|
-
const {
|
|
2319
|
-
onClickRefresh
|
|
2320
|
-
} = props;
|
|
2321
|
-
const navigate = reactRouterDom.useNavigate();
|
|
2322
|
-
return React__default.createElement(ButtonsContainer, null, React__default.createElement(ui.Tooltip, {
|
|
2323
|
-
content: "Refresh"
|
|
2324
|
-
}, React__default.createElement(ui.Button, {
|
|
2325
|
-
variant: "ghost",
|
|
2326
|
-
onClick: onClickRefresh,
|
|
2327
|
-
disabled: !onClickRefresh
|
|
2328
|
-
}, React__default.createElement(ui.RetryIcon, {
|
|
2329
|
-
size: 24,
|
|
2330
|
-
disabled: !onClickRefresh
|
|
2331
|
-
}))), React__default.createElement(ui.Tooltip, {
|
|
2332
|
-
content: "Transactions History"
|
|
2333
|
-
}, React__default.createElement(ui.Button, {
|
|
2334
|
-
variant: "ghost",
|
|
2335
|
-
onClick: () => navigate(navigationRoutes.swaps)
|
|
2336
|
-
}, React__default.createElement(ui.HistoryIcon, {
|
|
2337
|
-
size: 24
|
|
2338
|
-
}))), React__default.createElement(ui.Tooltip, {
|
|
2339
|
-
content: "Settings"
|
|
2340
|
-
}, React__default.createElement(ui.Button, {
|
|
2341
|
-
variant: "ghost",
|
|
2342
|
-
onClick: () => navigate(navigationRoutes.settings)
|
|
2343
|
-
}, React__default.createElement(ui.SettingsIcon, {
|
|
2344
|
-
size: 24
|
|
2345
|
-
}))));
|
|
2346
|
-
}
|
|
2347
|
-
|
|
2348
|
-
const Container$4 = /*#__PURE__*/ui.styled('div', {
|
|
2349
|
-
display: 'flex',
|
|
2350
|
-
flexDirection: 'column'
|
|
2351
|
-
});
|
|
2352
|
-
const FromContainer = /*#__PURE__*/ui.styled('div', {
|
|
2353
|
-
position: 'relative',
|
|
2354
|
-
paddingBottom: '$12'
|
|
2355
|
-
});
|
|
2356
|
-
const SwitchButtonContainer = /*#__PURE__*/ui.styled('div', {
|
|
2357
|
-
position: 'absolute',
|
|
2358
|
-
bottom: '-12px',
|
|
2359
|
-
left: '50%',
|
|
2360
|
-
transform: 'translate(-50%, 10%)'
|
|
2361
|
-
});
|
|
2362
|
-
const BestRouteContainer = /*#__PURE__*/ui.styled('div', {
|
|
2363
|
-
width: '100%',
|
|
2364
|
-
paddingTop: '$16'
|
|
2365
|
-
});
|
|
2366
|
-
const Alerts = /*#__PURE__*/ui.styled('div', {
|
|
2367
|
-
width: '100%',
|
|
2368
|
-
paddingTop: '$16'
|
|
2369
|
-
});
|
|
2370
|
-
function Home() {
|
|
2371
|
-
const isRouterInContext = reactRouterDom.useInRouterContext();
|
|
2372
|
-
const navigate = reactRouterDom.useNavigate();
|
|
2373
|
-
const [count, setCount] = React.useState(0);
|
|
2374
|
-
const fromChain = useBestRouteStore.use.fromChain();
|
|
2375
|
-
const fromToken = useBestRouteStore.use.fromToken();
|
|
2376
|
-
const toChain = useBestRouteStore.use.toChain();
|
|
2377
|
-
const toToken = useBestRouteStore.use.toToken();
|
|
2378
|
-
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2379
|
-
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2380
|
-
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
2381
|
-
const outputAmount = useBestRouteStore.use.outputAmount();
|
|
2382
|
-
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
2383
|
-
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
2384
|
-
const tokens = useMetaStore.use.meta().tokens;
|
|
2385
|
-
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
2386
|
-
const bestRouteError = useBestRouteStore.use.error();
|
|
2387
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
2388
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
2389
|
-
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
2390
|
-
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
2391
|
-
const errorMessage = loadingMetaStatus === 'failed' ? errorMessages.genericServerError : bestRouteError;
|
|
2392
|
-
const needsToWarnEthOnPath = false;
|
|
2393
|
-
const showBestRoute = inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
|
|
2394
|
-
const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
|
|
2395
|
-
const highValueLoss = outputRatioHasWarning(inputUsdValue, outToInRatio);
|
|
2396
|
-
const {
|
|
2397
|
-
fromAmountRangeError,
|
|
2398
|
-
recommendation,
|
|
2399
|
-
swap
|
|
2400
|
-
} = LimitErrorMessage(bestRoute);
|
|
2401
|
-
const priceImpactCanNotBeComputed = !canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue);
|
|
2402
|
-
const swapButtonState = getSwapButtonState(loadingMetaStatus, connectedWallets, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount);
|
|
2403
|
-
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
2404
|
-
const highFee = hasHighFee(totalFeeInUsd);
|
|
2405
|
-
React.useEffect(() => {
|
|
2406
|
-
setCurrentPage(navigationRoutes.home);
|
|
2407
|
-
return setCurrentPage.bind(null, '');
|
|
2408
|
-
}, []);
|
|
2409
|
-
return React__default.createElement(Container$4, null, React__default.createElement(ui.Header, {
|
|
2410
|
-
title: "SWAP",
|
|
2411
|
-
suffix: React__default.createElement(HeaderButtons, {
|
|
2412
|
-
onClickRefresh: !!bestRoute || bestRouteError ? fetchBestRoute : undefined
|
|
2413
|
-
})
|
|
2414
|
-
}), React__default.createElement(FromContainer, null, React__default.createElement(TokenInfo, {
|
|
2415
|
-
type: "From",
|
|
2416
|
-
chain: fromChain,
|
|
2417
|
-
token: fromToken,
|
|
2418
|
-
onAmountChange: setInputAmount,
|
|
2419
|
-
inputAmount: inputAmount
|
|
2420
|
-
}), React__default.createElement(SwitchButtonContainer, null, React__default.createElement(ui.Button, {
|
|
2421
|
-
variant: "ghost",
|
|
2422
|
-
onClick: () => {
|
|
2423
|
-
switchFromAndTo();
|
|
2424
|
-
setCount(prev => prev + 1);
|
|
2425
|
-
}
|
|
2426
|
-
}, React__default.createElement(ui.VerticalSwapIcon, {
|
|
2427
|
-
size: 32
|
|
2428
|
-
}), isRouterInContext && React__default.createElement(SwithFromAndTo, {
|
|
2429
|
-
count: count
|
|
2430
|
-
})))), React__default.createElement(TokenInfo, {
|
|
2431
|
-
type: "To",
|
|
2432
|
-
chain: toChain,
|
|
2433
|
-
token: toToken,
|
|
2434
|
-
outputAmount: outputAmount ? new BigNumber__default(outputAmount) : new BigNumber__default(0),
|
|
2435
|
-
outputUsdValue: outputUsdValue
|
|
2436
|
-
}), showBestRoute && React__default.createElement(BestRouteContainer, null, React__default.createElement(ui.BestRoute, {
|
|
2437
|
-
error: bestRouteError,
|
|
2438
|
-
loading: fetchingBestRoute,
|
|
2439
|
-
data: getFormatedBestRoute(bestRoute),
|
|
2440
|
-
totalFee: numberToString(totalFeeInUsd, 0, 2),
|
|
2441
|
-
feeWarning: highFee,
|
|
2442
|
-
totalTime: secondsToString(totalArrivalTime(bestRoute))
|
|
2443
|
-
})), (errorMessage || hasLimitError(bestRoute)) && React__default.createElement(Alerts, null, errorMessage && React__default.createElement(ui.Alert, {
|
|
2444
|
-
type: "error"
|
|
2445
|
-
}, errorMessage), hasLimitError(bestRoute) && React__default.createElement(ui.Alert, {
|
|
2446
|
-
type: "error",
|
|
2447
|
-
title: `${swap?.swapperId} Limit`
|
|
2448
|
-
}, React__default.createElement(React__default.Fragment, null, React__default.createElement(ui.Typography, {
|
|
2449
|
-
variant: "body2"
|
|
2450
|
-
}, `${fromAmountRangeError}, Yours: ${numberToString(swap?.fromAmount || null)} ${swap?.from.symbol}`), React__default.createElement(ui.Typography, {
|
|
2451
|
-
variant: "body2"
|
|
2452
|
-
}, recommendation)))), React__default.createElement(Footer, null, React__default.createElement(ui.Button, {
|
|
2453
|
-
type: "primary",
|
|
2454
|
-
align: "grow",
|
|
2455
|
-
size: "large",
|
|
2456
|
-
disabled: swapButtonState.disabled,
|
|
2457
|
-
onClick: () => {
|
|
2458
|
-
if (swapButtonState.title === 'Connect Wallet') navigate(navigationRoutes.wallets);else {
|
|
2459
|
-
navigate(navigationRoutes.confirmSwap, {
|
|
2460
|
-
replace: true
|
|
2461
|
-
});
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
}, swapButtonState.title), React__default.createElement(BottomLogo, null)));
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
function LiquiditySourcePage(_ref) {
|
|
2468
|
-
let {
|
|
2469
|
-
supportedSwappers
|
|
2470
|
-
} = _ref;
|
|
2471
|
-
const swappers = useMetaStore.use.meta().swappers;
|
|
2472
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
2473
|
-
const toggleLiquiditySource = useSettingsStore.use.toggleLiquiditySource();
|
|
2474
|
-
const disabledLiquiditySources = useSettingsStore.use.disabledLiquiditySources();
|
|
2475
|
-
const toggleAllLiquiditySources = useSettingsStore.use.toggleAllLiquiditySources();
|
|
2476
|
-
const {
|
|
2477
|
-
navigateBackFrom
|
|
2478
|
-
} = useNavigateBack();
|
|
2479
|
-
const uniqueSwappersGroups = [];
|
|
2480
|
-
removeDuplicateFrom(swappers.map(s => s.swapperGroup)).map(swapperGroup => {
|
|
2481
|
-
return swappers.find(s => s.swapperGroup === swapperGroup);
|
|
2482
|
-
}).find(s => {
|
|
2483
|
-
if (s) {
|
|
2484
|
-
for (const type of s.types) {
|
|
2485
|
-
uniqueSwappersGroups.push({
|
|
2486
|
-
title: s.swapperGroup,
|
|
2487
|
-
logo: s.logo,
|
|
2488
|
-
type,
|
|
2489
|
-
selected: !disabledLiquiditySources.includes(s.swapperGroup)
|
|
2490
|
-
});
|
|
2491
|
-
}
|
|
2492
|
-
}
|
|
2493
|
-
});
|
|
2494
|
-
return React__default.createElement(ui.LiquiditySourcesSelector, {
|
|
2495
|
-
toggleAll: toggleAllLiquiditySources,
|
|
2496
|
-
list: supportedSwappers ? uniqueSwappersGroups.filter(item => supportedSwappers.filter(s => s === item.title).length > 0) : uniqueSwappersGroups,
|
|
2497
|
-
onChange: liquiditySource => toggleLiquiditySource(liquiditySource.title),
|
|
2498
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.liquiditySources),
|
|
2499
|
-
loadingStatus: loadingMetaStatus
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
|
|
2503
|
-
function SelectChainPage(props) {
|
|
2504
|
-
const {
|
|
2505
|
-
type,
|
|
2506
|
-
supportedChains
|
|
2507
|
-
} = props;
|
|
2508
|
-
const blockchains = supportedChains ? useMetaStore.use.meta().blockchains.filter(chain => supportedChains.includes(chain.name)) : useMetaStore.use.meta().blockchains;
|
|
2509
|
-
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
2510
|
-
const fromChain = useBestRouteStore.use.fromChain();
|
|
2511
|
-
const toChain = useBestRouteStore.use.toChain();
|
|
2512
|
-
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
2513
|
-
const setToChain = useBestRouteStore.use.setToChain();
|
|
2514
|
-
const {
|
|
2515
|
-
navigateBackFrom
|
|
2516
|
-
} = useNavigateBack();
|
|
2517
|
-
return React__default.createElement(ui.BlockchainSelector, {
|
|
2518
|
-
type: type === 'from' ? 'Source' : 'Destination',
|
|
2519
|
-
list: blockchains,
|
|
2520
|
-
selected: type === 'from' ? fromChain : toChain,
|
|
2521
|
-
loadingStatus: loadingStatus,
|
|
2522
|
-
onChange: chain => {
|
|
2523
|
-
if (type === 'from') setFromChain(chain, true);else setToChain(chain, true);
|
|
2524
|
-
navigateBackFrom(navigationRoutes.fromChain);
|
|
2525
|
-
},
|
|
2526
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.fromChain)
|
|
2527
|
-
});
|
|
2528
|
-
}
|
|
2529
|
-
|
|
2530
|
-
function SelectTokenPage(props) {
|
|
2531
|
-
const {
|
|
2532
|
-
navigateBackFrom
|
|
2533
|
-
} = useNavigateBack();
|
|
2534
|
-
const {
|
|
2535
|
-
type,
|
|
2536
|
-
supportedTokens
|
|
2537
|
-
} = props;
|
|
2538
|
-
const sourceTokens = useBestRouteStore.use.sourceTokens();
|
|
2539
|
-
const destinationTokens = useBestRouteStore.use.destinationTokens();
|
|
2540
|
-
const supportedSourceTokens = supportedTokens ? sourceTokens.filter(token => supportedTokens.some(supportedToken => tokensAreEqual(supportedToken, token))) : sourceTokens;
|
|
2541
|
-
const supportedDestinationTokens = supportedTokens ? destinationTokens.filter(token => supportedTokens.some(supportedToken => tokensAreEqual(supportedToken, token))) : destinationTokens;
|
|
2542
|
-
const fromToken = useBestRouteStore.use.fromToken();
|
|
2543
|
-
const toToken = useBestRouteStore.use.toToken();
|
|
2544
|
-
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
2545
|
-
const setToToken = useBestRouteStore.use.setToToken();
|
|
2546
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
2547
|
-
return React__default.createElement(ui.TokenSelector, {
|
|
2548
|
-
type: type === 'from' ? 'Source' : 'Destination',
|
|
2549
|
-
list: type == 'from' ? supportedSourceTokens : supportedDestinationTokens,
|
|
2550
|
-
selected: type === 'from' ? fromToken : toToken,
|
|
2551
|
-
onChange: token => {
|
|
2552
|
-
if (type === 'from') setFromToken(token);else setToToken(token);
|
|
2553
|
-
navigateBackFrom(navigationRoutes.fromToken);
|
|
2554
|
-
},
|
|
2555
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.fromToken),
|
|
2556
|
-
loadingStatus: loadingMetaStatus
|
|
2557
|
-
});
|
|
2558
|
-
}
|
|
2559
|
-
|
|
2560
|
-
function SettingsPage(_ref) {
|
|
2561
|
-
let {
|
|
2562
|
-
supportedSwappers,
|
|
2563
|
-
singleTheme
|
|
2564
|
-
} = _ref;
|
|
2565
|
-
const slippage = useSettingsStore.use.slippage();
|
|
2566
|
-
const setSlippage = useSettingsStore.use.setSlippage();
|
|
2567
|
-
const disabledLiquiditySources = useSettingsStore.use.disabledLiquiditySources();
|
|
2568
|
-
const customSlippage = useSettingsStore.use.customSlippage();
|
|
2569
|
-
const setCustomSlippage = useSettingsStore.use.setCustomSlippage();
|
|
2570
|
-
const theme = useSettingsStore.use.theme();
|
|
2571
|
-
const setTheme = useSettingsStore.use.setTheme();
|
|
2572
|
-
const swappers = useMetaStore.use.meta().swappers;
|
|
2573
|
-
const navigate = reactRouterDom.useNavigate();
|
|
2574
|
-
const {
|
|
2575
|
-
navigateBackFrom
|
|
2576
|
-
} = useNavigateBack();
|
|
2577
|
-
const infiniteApprove = useSettingsStore.use.infiniteApprove();
|
|
2578
|
-
const toggleInfiniteApprove = useSettingsStore.use.toggleInfiniteApprove();
|
|
2579
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
2580
|
-
const uniqueSwappersGroups = [];
|
|
2581
|
-
removeDuplicateFrom(swappers.map(s => s.swapperGroup)).map(swapperGroup => {
|
|
2582
|
-
return swappers.find(s => s.swapperGroup === swapperGroup);
|
|
2583
|
-
}).find(s => {
|
|
2584
|
-
if (s) {
|
|
2585
|
-
for (const type of s.types) {
|
|
2586
|
-
uniqueSwappersGroups.push({
|
|
2587
|
-
title: s.swapperGroup,
|
|
2588
|
-
logo: s.logo,
|
|
2589
|
-
type,
|
|
2590
|
-
selected: !disabledLiquiditySources.includes(s.swapperGroup)
|
|
2591
|
-
});
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
});
|
|
2595
|
-
supportedSwappers && uniqueSwappersGroups.filter(item => supportedSwappers.filter(s => s === item.title).length > 0);
|
|
2596
|
-
const supportedUniqueSwappersGroups = supportedSwappers ? uniqueSwappersGroups.filter(item => supportedSwappers.filter(s => s === item.title).length > 0) : uniqueSwappersGroups;
|
|
2597
|
-
return React__default.createElement(ui.Settings, {
|
|
2598
|
-
slippages: SLIPPAGES,
|
|
2599
|
-
selectedSlippage: slippage,
|
|
2600
|
-
onSlippageChange: slippage => setSlippage(slippage),
|
|
2601
|
-
onLiquiditySourcesClick: () => navigate(navigationRoutes.liquiditySources),
|
|
2602
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.settings),
|
|
2603
|
-
liquiditySources: supportedUniqueSwappersGroups,
|
|
2604
|
-
selectedLiquiditySources: supportedUniqueSwappersGroups.filter(s => s.selected),
|
|
2605
|
-
singleTheme: singleTheme,
|
|
2606
|
-
customSlippage: customSlippage,
|
|
2607
|
-
onCustomSlippageChange: setCustomSlippage,
|
|
2608
|
-
minSlippage: MIN_SLIPPGAE,
|
|
2609
|
-
maxSlippage: MAX_SLIPPAGE,
|
|
2610
|
-
selectedTheme: theme,
|
|
2611
|
-
onThemeChange: setTheme,
|
|
2612
|
-
infiniteApprove: infiniteApprove,
|
|
2613
|
-
toggleInfiniteApprove: toggleInfiniteApprove,
|
|
2614
|
-
loadingStatus: loadingMetaStatus
|
|
2615
|
-
});
|
|
2616
|
-
}
|
|
2617
|
-
|
|
2618
|
-
const ListContainer = /*#__PURE__*/ui.styled('div', {
|
|
2619
|
-
display: 'grid',
|
|
2620
|
-
gap: '.5rem',
|
|
2621
|
-
gridTemplateColumns: ' repeat(2, minmax(0, 1fr))',
|
|
2622
|
-
alignContent: 'baseline',
|
|
2623
|
-
padding: '0.5rem',
|
|
2624
|
-
overflowY: 'auto'
|
|
2625
|
-
});
|
|
2626
|
-
const LoaderContainer = /*#__PURE__*/ui.styled('div', {
|
|
2627
|
-
display: 'flex',
|
|
2628
|
-
justifyContent: 'center',
|
|
2629
|
-
width: '100%',
|
|
2630
|
-
position: 'absolute',
|
|
2631
|
-
top: '50%'
|
|
2632
|
-
});
|
|
2633
|
-
const AlertContainer = /*#__PURE__*/ui.styled('div', {
|
|
2634
|
-
paddingBottom: '$16'
|
|
2635
|
-
});
|
|
2636
|
-
function WalletsPage(_ref) {
|
|
2637
|
-
let {
|
|
2638
|
-
supportedWallets,
|
|
2639
|
-
multiWallets
|
|
2640
|
-
} = _ref;
|
|
2641
|
-
const {
|
|
2642
|
-
navigateBackFrom
|
|
2643
|
-
} = useNavigateBack();
|
|
2644
|
-
const {
|
|
2645
|
-
state,
|
|
2646
|
-
disconnect,
|
|
2647
|
-
getWalletInfo,
|
|
2648
|
-
connect
|
|
2649
|
-
} = walletsCore.useWallets();
|
|
2650
|
-
const wallets = getlistWallet(state, getWalletInfo, supportedWallets || Object.values(walletsShared.WalletType));
|
|
2651
|
-
const walletsRef = React.useRef();
|
|
2652
|
-
let sortedWallets = walletsShared.detectMobileScreens() ? wallets.filter(wallet => wallet.showOnMobile) : wallets;
|
|
2653
|
-
sortedWallets = sortWalletsBasedOnState(sortedWallets);
|
|
2654
|
-
const [walletErrorMessage, setWalletErrorMessage] = React.useState('');
|
|
2655
|
-
const toggleConnectWalletsButton = useUiStore.use.toggleConnectWalletsButton();
|
|
2656
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
2657
|
-
const {
|
|
2658
|
-
t
|
|
2659
|
-
} = reactI18next.useTranslation();
|
|
2660
|
-
const onSelectWallet = async type => {
|
|
2661
|
-
const wallet = state(type);
|
|
2662
|
-
try {
|
|
2663
|
-
if (walletErrorMessage) setWalletErrorMessage('');
|
|
2664
|
-
if (wallet.connected) {
|
|
2665
|
-
await disconnect(type);
|
|
2666
|
-
} else {
|
|
2667
|
-
if (!multiWallets && !!wallets.find(w => w.state === ui.WalletState.CONNECTED)) {
|
|
2668
|
-
return;
|
|
2669
|
-
}
|
|
2670
|
-
await connect(type);
|
|
2671
|
-
}
|
|
2672
|
-
} catch (e) {
|
|
2673
|
-
setWalletErrorMessage('Error: ' + e?.message);
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2676
|
-
const disconnectConnectingWallets = () => {
|
|
2677
|
-
const connectingWallets = walletsRef.current?.filter(wallet => wallet.state === ui.WalletState.CONNECTING) || [];
|
|
2678
|
-
for (const wallet of connectingWallets) {
|
|
2679
|
-
disconnect(wallet.type);
|
|
2680
|
-
}
|
|
2681
|
-
};
|
|
2682
|
-
React.useEffect(() => {
|
|
2683
|
-
toggleConnectWalletsButton();
|
|
2684
|
-
return () => {
|
|
2685
|
-
disconnectConnectingWallets();
|
|
2686
|
-
toggleConnectWalletsButton();
|
|
2687
|
-
};
|
|
2688
|
-
}, []);
|
|
2689
|
-
React.useEffect(() => {
|
|
2690
|
-
walletsRef.current = wallets;
|
|
2691
|
-
}, [wallets]);
|
|
2692
|
-
return React__default.createElement(ui.SecondaryPage, {
|
|
2693
|
-
title: t('Select Wallet') || '',
|
|
2694
|
-
textField: false,
|
|
2695
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.wallets)
|
|
2696
|
-
}, React__default.createElement(React__default.Fragment, null, walletErrorMessage && React__default.createElement(AlertContainer, null, React__default.createElement(ui.Alert, {
|
|
2697
|
-
type: "error",
|
|
2698
|
-
title: walletErrorMessage
|
|
2699
|
-
})), loadingMetaStatus === 'loading' && React__default.createElement(LoaderContainer, {
|
|
2700
|
-
className: "loader"
|
|
2701
|
-
}, React__default.createElement(ui.Spinner, {
|
|
2702
|
-
size: 24
|
|
2703
|
-
})), loadingMetaStatus === 'failed' && React__default.createElement(ui.LoadingFailedAlert, null), React__default.createElement(ListContainer, null, loadingMetaStatus === 'success' && sortedWallets.map((wallet, index) => React__default.createElement(ui.Wallet, Object.assign({}, wallet, {
|
|
2704
|
-
key: `${index}-${wallet.type}`,
|
|
2705
|
-
onClick: onSelectWallet
|
|
2706
|
-
}))))));
|
|
2707
|
-
}
|
|
2708
|
-
|
|
2709
|
-
function timeSince(timeMillis) {
|
|
2710
|
-
const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
|
|
2711
|
-
let intervalType;
|
|
2712
|
-
let interval = Math.floor(seconds / 31536000);
|
|
2713
|
-
if (interval >= 1) {
|
|
2714
|
-
intervalType = 'year';
|
|
2715
|
-
} else {
|
|
2716
|
-
interval = Math.floor(seconds / 2592000);
|
|
2717
|
-
if (interval >= 1) {
|
|
2718
|
-
intervalType = 'month';
|
|
2719
|
-
} else {
|
|
2720
|
-
interval = Math.floor(seconds / 86400);
|
|
2721
|
-
if (interval >= 1) {
|
|
2722
|
-
intervalType = 'day';
|
|
2723
|
-
} else {
|
|
2724
|
-
interval = Math.floor(seconds / 3600);
|
|
2725
|
-
if (interval >= 1) {
|
|
2726
|
-
intervalType = 'hour';
|
|
2727
|
-
} else {
|
|
2728
|
-
interval = Math.floor(seconds / 60);
|
|
2729
|
-
if (interval >= 1) {
|
|
2730
|
-
intervalType = 'minute';
|
|
2731
|
-
} else {
|
|
2732
|
-
interval = seconds;
|
|
2733
|
-
intervalType = 'second';
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
if (interval > 1 || interval === 0) {
|
|
2740
|
-
intervalType += 's';
|
|
2741
|
-
}
|
|
2742
|
-
return interval + ' ' + intervalType;
|
|
2743
|
-
}
|
|
2744
|
-
function getSwapDate(pendingSwap) {
|
|
2745
|
-
return pendingSwap.finishTime ? `${timeSince(parseInt(pendingSwap.finishTime))} ago` : `${timeSince(parseInt(pendingSwap.creationTime))} ago`;
|
|
2746
|
-
}
|
|
2747
|
-
|
|
2748
|
-
const PlaceholderContainer = /*#__PURE__*/ui.styled('div', {
|
|
2749
|
-
height: '450px'
|
|
2750
|
-
});
|
|
2751
|
-
const LoaderContainer$1 = /*#__PURE__*/ui.styled('div', {
|
|
2752
|
-
display: 'flex',
|
|
2753
|
-
justifyContent: 'center',
|
|
2754
|
-
width: '100%',
|
|
2755
|
-
paddingTop: '33%',
|
|
2756
|
-
flex: 1
|
|
2757
|
-
});
|
|
2758
|
-
function SwapDetailsPlaceholder(props) {
|
|
2759
|
-
const {
|
|
2760
|
-
requestId,
|
|
2761
|
-
loading,
|
|
2762
|
-
onBack
|
|
2763
|
-
} = props;
|
|
2764
|
-
return React__default.createElement(ui.SecondaryPage, {
|
|
2765
|
-
title: "Swap Details",
|
|
2766
|
-
textField: false,
|
|
2767
|
-
onBack: onBack
|
|
2768
|
-
}, React__default.createElement(PlaceholderContainer, null, loading ? React__default.createElement(LoaderContainer$1, null, React__default.createElement(ui.Spinner, {
|
|
2769
|
-
size: 24
|
|
2770
|
-
})) : React__default.createElement(ui.Alert, {
|
|
2771
|
-
type: "secondary",
|
|
2772
|
-
title: `Swap with request ID = ${requestId} not found.`
|
|
2773
|
-
})));
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2776
|
-
function SwapDetailsPage() {
|
|
2777
|
-
const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
|
|
2778
|
-
const {
|
|
2779
|
-
canSwitchNetworkTo,
|
|
2780
|
-
connect
|
|
2781
|
-
} = walletsCore.useWallets();
|
|
2782
|
-
const retry = useBestRouteStore.use.retry();
|
|
2783
|
-
const navigate = reactRouterDom.useNavigate();
|
|
2784
|
-
const {
|
|
2785
|
-
navigateBackFrom
|
|
2786
|
-
} = useNavigateBack();
|
|
2787
|
-
const [isCopied, handleCopy] = ui.useCopyToClipboard(2000);
|
|
2788
|
-
const {
|
|
2789
|
-
manager,
|
|
2790
|
-
state
|
|
2791
|
-
} = queueManagerReact.useManager();
|
|
2792
|
-
const pendingSwaps = getPendingSwaps(manager);
|
|
2793
|
-
const selectedSwap = pendingSwaps.find(_ref => {
|
|
2794
|
-
let {
|
|
2795
|
-
swap
|
|
2796
|
-
} = _ref;
|
|
2797
|
-
return swap.requestId === selectedSwapRequestId;
|
|
2798
|
-
});
|
|
2799
|
-
const onCancel = () => {
|
|
2800
|
-
const swap = manager?.get(selectedSwap?.id);
|
|
2801
|
-
if (swap) queueManagerRangoPreset.cancelSwap(swap);
|
|
2802
|
-
};
|
|
2803
|
-
const swap = selectedSwap?.swap;
|
|
2804
|
-
const loading = !state.loadedFromPersistor;
|
|
2805
|
-
if (!swap) return React__default.createElement(SwapDetailsPlaceholder, {
|
|
2806
|
-
requestId: selectedSwapRequestId || '',
|
|
2807
|
-
loading: loading,
|
|
2808
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails)
|
|
2809
|
-
});
|
|
2810
|
-
const currentStep = queueManagerRangoPreset.getCurrentStep(swap);
|
|
2811
|
-
const currentStepBlockchain = currentStep ? queueManagerRangoPreset.getCurrentBlockchainOfOrNull(swap, currentStep) : null;
|
|
2812
|
-
const currentStepWallet = currentStep ? queueManagerRangoPreset.getRelatedWalletOrNull(swap, currentStep) : null;
|
|
2813
|
-
const currentStepNetworkStatus = currentStep?.networkStatus;
|
|
2814
|
-
const swapMessages = getSwapMessages(swap, currentStep);
|
|
2815
|
-
const networkWarningState = isNetworkStatusInWarningState(currentStep);
|
|
2816
|
-
const swapDate = getSwapDate(swap);
|
|
2817
|
-
const shouldRetry = shouldRetrySwap(swap);
|
|
2818
|
-
const switchNetwork = !!currentStepBlockchain && !!currentStepWallet?.walletType && currentStepNetworkStatus === queueManagerRangoPreset.PendingSwapNetworkStatus.WaitingForNetworkChange && canSwitchNetworkTo(currentStepWallet?.walletType, currentStepBlockchain) ? connect.bind(null, currentStepWallet.walletType, currentStepBlockchain) : undefined;
|
|
2819
|
-
const lastConvertedTokenInFailedSwap = getLastConvertedTokenInFailedSwap(swap);
|
|
2820
|
-
return React__default.createElement(ui.SwapHistory, Object.assign({
|
|
2821
|
-
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails),
|
|
2822
|
-
/* TODO: It was temporarily removed to find a better solution*/
|
|
2823
|
-
/*
|
|
2824
|
-
previewInputs={
|
|
2825
|
-
<>
|
|
2826
|
-
<TokenPreview
|
|
2827
|
-
chain={{
|
|
2828
|
-
displayName: firstStep?.fromBlockchain || '',
|
|
2829
|
-
logo: firstStep?.fromBlockchainLogo || '',
|
|
2830
|
-
}}
|
|
2831
|
-
token={{
|
|
2832
|
-
symbol: firstStep?.fromSymbol || '',
|
|
2833
|
-
image: firstStep?.fromLogo || '',
|
|
2834
|
-
}}
|
|
2835
|
-
amount={fromAmount}
|
|
2836
|
-
label={t('From')}
|
|
2837
|
-
loadingStatus={'success'}
|
|
2838
|
-
/>
|
|
2839
|
-
<Spacer size={12} direction="vertical" />
|
|
2840
|
-
<TokenPreview
|
|
2841
|
-
chain={{
|
|
2842
|
-
displayName: lastStep?.toBlockchain || '',
|
|
2843
|
-
logo: lastStep?.toBlockchainLogo || '',
|
|
2844
|
-
}}
|
|
2845
|
-
token={{
|
|
2846
|
-
symbol: lastStep?.toSymbol || '',
|
|
2847
|
-
image: lastStep?.toLogo || '',
|
|
2848
|
-
}}
|
|
2849
|
-
amount={toAmount}
|
|
2850
|
-
label={t('To')}
|
|
2851
|
-
loadingStatus={'success'}
|
|
2852
|
-
/>
|
|
2853
|
-
</>
|
|
2854
|
-
}
|
|
2855
|
-
*/
|
|
2856
|
-
pendingSwap: getFormatedPendingSwap(swap),
|
|
2857
|
-
onCopy: handleCopy,
|
|
2858
|
-
isCopied: isCopied,
|
|
2859
|
-
onCancel: onCancel,
|
|
2860
|
-
shortMessage: swapMessages.shortMessage,
|
|
2861
|
-
detailedMessage: swapMessages.detailedMessage,
|
|
2862
|
-
currentStepBlockchain: currentStepBlockchain || '',
|
|
2863
|
-
switchNetwork: switchNetwork,
|
|
2864
|
-
type: networkWarningState ? 'warning' : swap.extraMessageSeverity || undefined,
|
|
2865
|
-
date: swapDate
|
|
2866
|
-
}, shouldRetry && {
|
|
2867
|
-
onRetry: () => {
|
|
2868
|
-
retry(swap);
|
|
2869
|
-
setTimeout(() => {
|
|
2870
|
-
navigate(navigationRoutes.home);
|
|
2871
|
-
}, 0);
|
|
2872
|
-
}
|
|
2873
|
-
}, lastConvertedTokenInFailedSwap && {
|
|
2874
|
-
lastConvertedTokenInFailedSwap: {
|
|
2875
|
-
blockchain: lastConvertedTokenInFailedSwap.blockchain,
|
|
2876
|
-
outputAmount: lastConvertedTokenInFailedSwap.outputAmount || '',
|
|
2877
|
-
symbol: lastConvertedTokenInFailedSwap.symbol
|
|
2878
|
-
}
|
|
2879
|
-
}));
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
const getAbsolutePath = path => path.replace('/', '');
|
|
2883
|
-
function AppRoutes(props) {
|
|
2884
|
-
const {
|
|
2885
|
-
config
|
|
2886
|
-
} = props;
|
|
2887
|
-
return reactRouterDom.useRoutes([{
|
|
2888
|
-
path: navigationRoutes.home,
|
|
2889
|
-
element: React__default.createElement(Home, null)
|
|
2890
|
-
}, {
|
|
2891
|
-
path: navigationRoutes.fromChain,
|
|
2892
|
-
element: React__default.createElement(SelectChainPage, {
|
|
2893
|
-
type: "from",
|
|
2894
|
-
supportedChains: config?.from?.blockchains
|
|
2895
|
-
})
|
|
2896
|
-
}, {
|
|
2897
|
-
path: navigationRoutes.toChain,
|
|
2898
|
-
element: React__default.createElement(SelectChainPage, {
|
|
2899
|
-
type: "to",
|
|
2900
|
-
supportedChains: config?.to?.blockchains
|
|
2901
|
-
})
|
|
2902
|
-
}, {
|
|
2903
|
-
path: navigationRoutes.fromToken,
|
|
2904
|
-
element: React__default.createElement(SelectTokenPage, {
|
|
2905
|
-
type: "from",
|
|
2906
|
-
supportedTokens: config?.from?.tokens
|
|
2907
|
-
})
|
|
2908
|
-
}, {
|
|
2909
|
-
path: navigationRoutes.toToken,
|
|
2910
|
-
element: React__default.createElement(SelectTokenPage, {
|
|
2911
|
-
type: "to",
|
|
2912
|
-
supportedTokens: config?.to?.tokens
|
|
2913
|
-
})
|
|
2914
|
-
}, {
|
|
2915
|
-
path: navigationRoutes.settings,
|
|
2916
|
-
element: React__default.createElement(SettingsPage, {
|
|
2917
|
-
singleTheme: config?.theme?.singleTheme,
|
|
2918
|
-
supportedSwappers: config?.liquiditySources
|
|
2919
|
-
})
|
|
2920
|
-
}, {
|
|
2921
|
-
path: navigationRoutes.liquiditySources,
|
|
2922
|
-
element: React__default.createElement(LiquiditySourcePage, {
|
|
2923
|
-
supportedSwappers: config?.liquiditySources
|
|
2924
|
-
})
|
|
2925
|
-
}, {
|
|
2926
|
-
path: navigationRoutes.swaps,
|
|
2927
|
-
element: React__default.createElement(HistoryPage, null)
|
|
2928
|
-
}, {
|
|
2929
|
-
path: navigationRoutes.swapDetails,
|
|
2930
|
-
element: React__default.createElement(SwapDetailsPage, null)
|
|
2931
|
-
}, {
|
|
2932
|
-
path: navigationRoutes.wallets,
|
|
2933
|
-
element: React__default.createElement(WalletsPage, {
|
|
2934
|
-
supportedWallets: config?.wallets,
|
|
2935
|
-
multiWallets: typeof config?.multiWallets === 'undefined' ? true : config.multiWallets
|
|
2936
|
-
})
|
|
2937
|
-
}, {
|
|
2938
|
-
path: getAbsolutePath(navigationRoutes.confirmSwap),
|
|
2939
|
-
element: React__default.createElement(ConfirmSwapPage, null)
|
|
2940
|
-
}]);
|
|
2941
|
-
}
|
|
2942
|
-
|
|
2943
|
-
const Header = /*#__PURE__*/ui.styled('div', {
|
|
2944
|
-
display: 'flex',
|
|
2945
|
-
width: '100%',
|
|
2946
|
-
justifyContent: 'end',
|
|
2947
|
-
'.balance': {
|
|
2948
|
-
display: 'flex'
|
|
2949
|
-
}
|
|
2950
|
-
});
|
|
2951
|
-
const WalletImageContainer = /*#__PURE__*/ui.styled('div', {
|
|
2952
|
-
marginLeft: -15,
|
|
2953
|
-
marginRight: '$6',
|
|
2954
|
-
'& img': {
|
|
2955
|
-
borderRadius: '50%'
|
|
2956
|
-
}
|
|
2957
|
-
});
|
|
2958
|
-
function Layout(_ref) {
|
|
2959
|
-
let {
|
|
2960
|
-
config
|
|
2961
|
-
} = _ref;
|
|
2962
|
-
const navigate = reactRouterDom.useNavigate();
|
|
2963
|
-
const {
|
|
2964
|
-
connectedWallets,
|
|
2965
|
-
selectedWallets
|
|
2966
|
-
} = useWalletsStore();
|
|
2967
|
-
const {
|
|
2968
|
-
getWalletInfo
|
|
2969
|
-
} = walletsCore.useWallets();
|
|
2970
|
-
const connectedWalletsImages = removeDuplicateFrom(getSelectableWallets(connectedWallets, selectedWallets, getWalletInfo).map(w => w.image));
|
|
2971
|
-
const {
|
|
2972
|
-
blockchains,
|
|
2973
|
-
tokens
|
|
2974
|
-
} = useMetaStore.use.meta();
|
|
2975
|
-
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
2976
|
-
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
2977
|
-
const setToChain = useBestRouteStore.use.setToChain();
|
|
2978
|
-
const setToToken = useBestRouteStore.use.setToToken();
|
|
2979
|
-
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2980
|
-
const setAffiliateRef = useSettingsStore.use.setAffiliateRef();
|
|
2981
|
-
const totalBalance = calculateWalletUsdValue(connectedWallets);
|
|
2982
|
-
const connectWalletsButtonDisabled = useUiStore.use.connectWalletsButtonDisabled();
|
|
2983
|
-
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
2984
|
-
const fetchingBalance = useWalletsStore(fetchingBalanceSelector);
|
|
2985
|
-
const {
|
|
2986
|
-
t
|
|
2987
|
-
} = reactI18next.useTranslation();
|
|
2988
|
-
React.useEffect(() => {
|
|
2989
|
-
if (loadingMetaStatus === 'success') {
|
|
2990
|
-
const chain = blockchains.find(chain => chain.name === config?.to?.blockchain);
|
|
2991
|
-
const token = tokens.find(t => tokensAreEqual(t, config?.to?.token || null));
|
|
2992
|
-
setToChain(chain || null);
|
|
2993
|
-
setToToken(token || null);
|
|
2994
|
-
}
|
|
2995
|
-
}, [config?.to?.token, config?.to?.blockchain, loadingMetaStatus]);
|
|
2996
|
-
React.useEffect(() => {
|
|
2997
|
-
setInputAmount(config?.amount?.toString() || '');
|
|
2998
|
-
}, [config?.amount]);
|
|
2999
|
-
React.useEffect(() => {
|
|
3000
|
-
if (loadingMetaStatus === 'success') {
|
|
3001
|
-
const chain = blockchains.find(chain => chain.name === config?.from?.blockchain);
|
|
3002
|
-
const token = tokens.find(t => tokensAreEqual(t, config?.from?.token || null));
|
|
3003
|
-
setFromChain(chain || null);
|
|
3004
|
-
setFromToken(token || null);
|
|
3005
|
-
}
|
|
3006
|
-
}, [config?.from?.token, config?.from?.blockchain, loadingMetaStatus]);
|
|
3007
|
-
React.useEffect(() => {
|
|
3008
|
-
setAffiliateRef(config?.affiliateRef || null);
|
|
3009
|
-
}, [config?.affiliateRef]);
|
|
3010
|
-
return React__default.createElement(React__default.Fragment, null, React__default.createElement(Header, null, React__default.createElement(ui.Button, {
|
|
3011
|
-
size: "small",
|
|
3012
|
-
suffix: React__default.createElement(ui.AddWalletIcon, {
|
|
3013
|
-
size: 20
|
|
3014
|
-
}),
|
|
3015
|
-
variant: "ghost",
|
|
3016
|
-
flexContent: true,
|
|
3017
|
-
loading: loadingMetaStatus === 'loading',
|
|
3018
|
-
disabled: loadingMetaStatus === 'failed',
|
|
3019
|
-
onClick: () => {
|
|
3020
|
-
if (!connectWalletsButtonDisabled) navigate(navigationRoutes.wallets);
|
|
3021
|
-
}
|
|
3022
|
-
}, connectedWalletsImages?.length ? connectedWalletsImages.map((walletImage, index) => React__default.createElement(WalletImageContainer, {
|
|
3023
|
-
key: index
|
|
3024
|
-
}, React__default.createElement(ui.Image, {
|
|
3025
|
-
src: walletImage,
|
|
3026
|
-
size: 24
|
|
3027
|
-
}))) : React__default.createElement(React__default.Fragment, null), React__default.createElement("div", {
|
|
3028
|
-
className: "balance"
|
|
3029
|
-
}, React__default.createElement(ui.Typography, {
|
|
3030
|
-
variant: "body2"
|
|
3031
|
-
}, !connectedWallets?.length ? t('Connect Wallet') : `$${totalBalance || 0}`), fetchingBalance && React__default.createElement(ui.Spinner, null)))), React__default.createElement(AppRoutes, {
|
|
3032
|
-
config: config
|
|
3033
|
-
}));
|
|
3034
|
-
}
|
|
3035
|
-
|
|
3036
|
-
const globalFont = fontFamily => ui.globalCss({
|
|
3037
|
-
'@import': ["url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap')", "url('https://fonts.cdnfonts.com/css/times-new-roman')"],
|
|
3038
|
-
body: {
|
|
3039
|
-
fontFamily
|
|
3040
|
-
}
|
|
3041
|
-
})();
|
|
3042
|
-
|
|
3043
|
-
function usePrevious(value) {
|
|
3044
|
-
// The ref object is a generic container whose current property is mutable ...
|
|
3045
|
-
// ... and can hold any value, similar to an instance property on a class
|
|
3046
|
-
const ref = React.useRef();
|
|
3047
|
-
// Store current value in ref
|
|
3048
|
-
React.useEffect(() => {
|
|
3049
|
-
ref.current = value;
|
|
3050
|
-
}, [value]); // Only re-run if value changes
|
|
3051
|
-
// Return previous value (happens before update in useEffect above)
|
|
3052
|
-
return ref.current;
|
|
3053
|
-
}
|
|
3054
|
-
|
|
3055
|
-
function useTheme(_ref) {
|
|
3056
|
-
let {
|
|
3057
|
-
colors: themeColors,
|
|
3058
|
-
fontFamily = 'Roboto',
|
|
3059
|
-
borderRadius = 8,
|
|
3060
|
-
mode = 'auto'
|
|
3061
|
-
} = _ref;
|
|
3062
|
-
const theme = useSettingsStore.use.theme();
|
|
3063
|
-
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
3064
|
-
const setTheme = useSettingsStore.use.setTheme();
|
|
3065
|
-
const light = themeColors?.light;
|
|
3066
|
-
const dark = themeColors?.dark;
|
|
3067
|
-
const neutral = light?.neutral || '#fafafa';
|
|
3068
|
-
const background = light?.background || '#fff';
|
|
3069
|
-
const foreground = light?.foreground || '#000';
|
|
3070
|
-
const darkColors = {
|
|
3071
|
-
...ui.generateRangeColors('primary', 'dark', dark?.primary),
|
|
3072
|
-
...ui.generateRangeColors('error', 'dark', dark?.error),
|
|
3073
|
-
...ui.generateRangeColors('warning', 'dark', dark?.warning),
|
|
3074
|
-
...ui.generateRangeColors('success', 'dark', dark?.success),
|
|
3075
|
-
...ui.generateRangeColors('neutral', 'dark', dark?.neutral),
|
|
3076
|
-
surface: dark?.surface,
|
|
3077
|
-
background: dark?.background,
|
|
3078
|
-
foreground: dark?.foreground
|
|
3079
|
-
};
|
|
3080
|
-
const lightColors = {
|
|
3081
|
-
surface: light?.surface || '#fff',
|
|
3082
|
-
...ui.generateRangeColors('primary', 'light', light?.primary || '#5FA425'),
|
|
3083
|
-
...ui.generateRangeColors('error', 'light', light?.error || '#FF0000'),
|
|
3084
|
-
...ui.generateRangeColors('warning', 'light', light?.warning || '#F5A623'),
|
|
3085
|
-
...ui.generateRangeColors('success', 'light', light?.success || '#0070F3'),
|
|
3086
|
-
...ui.generateRangeColors('neutral', 'light', neutral),
|
|
3087
|
-
background,
|
|
3088
|
-
foreground
|
|
3089
|
-
};
|
|
3090
|
-
const customLightTheme = ui.createTheme({
|
|
3091
|
-
colors: lightColors,
|
|
3092
|
-
radii: {
|
|
3093
|
-
5: `${borderRadius}px`
|
|
3094
|
-
},
|
|
3095
|
-
shadows: {
|
|
3096
|
-
s: `0px 3px 5px 3px ${light?.neutral || '#f0f2f5'} ,0px 6px 10px 3px ${light?.neutral || '#f0f2f5'}, 0px 1px 18px 3px ${light?.neutral || '#f0f2f5'}`
|
|
3097
|
-
}
|
|
3098
|
-
});
|
|
3099
|
-
const customDarkTheme = ui.createTheme({
|
|
3100
|
-
colors: {
|
|
3101
|
-
...lightColors,
|
|
3102
|
-
...ui.generateRangeColors('neutral', 'dark', '#111111'),
|
|
3103
|
-
foreground: background,
|
|
3104
|
-
background: foreground,
|
|
3105
|
-
surface: '#000',
|
|
3106
|
-
...JSON.parse(JSON.stringify(darkColors))
|
|
3107
|
-
},
|
|
3108
|
-
radii: {
|
|
3109
|
-
5: `${borderRadius}px`
|
|
3110
|
-
},
|
|
3111
|
-
shadows: {
|
|
3112
|
-
s: `0px 3px 5px 3px ${dark?.neutral || '#222'}, 0px 6px 10px 3px ${dark?.neutral || '#222'}, 0px 1px 18px 3px ${dark?.neutral || '#222'}`
|
|
3113
|
-
}
|
|
3114
|
-
});
|
|
3115
|
-
const [OSTheme, setOSTheme] = React.useState('light');
|
|
3116
|
-
React.useEffect(() => {
|
|
3117
|
-
(async () => {
|
|
3118
|
-
await fetchMeta();
|
|
3119
|
-
})();
|
|
3120
|
-
const switchTheme = event => {
|
|
3121
|
-
if (event.matches) setOSTheme('dark');else setOSTheme('light');
|
|
3122
|
-
};
|
|
3123
|
-
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
3124
|
-
setOSTheme('dark');
|
|
3125
|
-
}
|
|
3126
|
-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', switchTheme);
|
|
3127
|
-
return () => {
|
|
3128
|
-
window.matchMedia('(prefers-color-scheme: dark)').removeEventListener('change', switchTheme);
|
|
3129
|
-
};
|
|
3130
|
-
}, []);
|
|
3131
|
-
React.useEffect(() => {
|
|
3132
|
-
if (mode !== 'auto') setTheme(mode);
|
|
3133
|
-
}, [mode]);
|
|
3134
|
-
const prevFont = usePrevious(fontFamily);
|
|
3135
|
-
React.useLayoutEffect(() => {
|
|
3136
|
-
const {
|
|
3137
|
-
classList
|
|
3138
|
-
} = document.body;
|
|
3139
|
-
if (prevFont) classList.remove(`font_${prevFont.replace(/ /g, '')}`);
|
|
3140
|
-
classList.add(`font_${fontFamily.replace(/ /g, '')}`);
|
|
3141
|
-
}, [fontFamily]);
|
|
3142
|
-
const getActiveTheme = () => {
|
|
3143
|
-
if (theme === 'auto') return OSTheme === 'dark' ? customDarkTheme : customLightTheme;else return theme === 'dark' ? customDarkTheme : customLightTheme;
|
|
3144
|
-
};
|
|
3145
|
-
return {
|
|
3146
|
-
activeTheme: getActiveTheme()
|
|
3147
|
-
};
|
|
3148
|
-
}
|
|
3149
|
-
|
|
3150
|
-
function useSelectLanguage() {
|
|
3151
|
-
const {
|
|
3152
|
-
i18n
|
|
3153
|
-
} = reactI18next.useTranslation();
|
|
3154
|
-
// @ts-ignore
|
|
3155
|
-
const currentLanguage = i18n?.language || 'en';
|
|
3156
|
-
const changeLanguage = value => {
|
|
3157
|
-
if (currentLanguage !== value) {
|
|
3158
|
-
// @ts-ignore
|
|
3159
|
-
i18n.changeLanguage(value);
|
|
3160
|
-
}
|
|
3161
|
-
};
|
|
3162
|
-
return {
|
|
3163
|
-
changeLanguage,
|
|
3164
|
-
currentLanguage
|
|
3165
|
-
};
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
|
-
var swap = "SWAP";
|
|
3169
|
-
var From = "You sell";
|
|
3170
|
-
var To = "You receive";
|
|
3171
|
-
var Balance = "Balance";
|
|
3172
|
-
var Max = "Max";
|
|
3173
|
-
var Chain = "Chain";
|
|
3174
|
-
var Token = "Token";
|
|
3175
|
-
var Source = "Source";
|
|
3176
|
-
var Destination = "Destination";
|
|
3177
|
-
var en = {
|
|
3178
|
-
swap: swap,
|
|
3179
|
-
"Connect Wallet": "Connect Wallet",
|
|
3180
|
-
"Powered By": "Powered By",
|
|
3181
|
-
From: From,
|
|
3182
|
-
To: To,
|
|
3183
|
-
Balance: Balance,
|
|
3184
|
-
Max: Max,
|
|
3185
|
-
Chain: Chain,
|
|
3186
|
-
Token: Token,
|
|
3187
|
-
Source: Source,
|
|
3188
|
-
Destination: Destination,
|
|
3189
|
-
"Select Wallet": "Connect Your Wallet"
|
|
3190
|
-
};
|
|
3191
|
-
|
|
3192
|
-
var swap$1 = "TAKAS";
|
|
3193
|
-
var From$1 = "İtibaren";
|
|
3194
|
-
var To$1 = "İle";
|
|
3195
|
-
var Max$1 = "maks.";
|
|
3196
|
-
var Chain$1 = "Zincir";
|
|
3197
|
-
var Token$1 = "Jeton";
|
|
3198
|
-
var tr = {
|
|
3199
|
-
swap: swap$1,
|
|
3200
|
-
"Select Wallet": "Cüzdan Seç",
|
|
3201
|
-
"Powered By": "Tarafından desteklenmektedir",
|
|
3202
|
-
"Connect Wallet": "Cüzdanı Bağla",
|
|
3203
|
-
From: From$1,
|
|
3204
|
-
To: To$1,
|
|
3205
|
-
Max: Max$1,
|
|
3206
|
-
Chain: Chain$1,
|
|
3207
|
-
Token: Token$1
|
|
3208
|
-
};
|
|
3209
|
-
|
|
3210
|
-
const languages = ['en', 'tr'];
|
|
3211
|
-
i18n__default.use(Backend)
|
|
3212
|
-
// detect user language
|
|
3213
|
-
.use(LanguageDetector)
|
|
3214
|
-
// pass the i18n instance to react-i18next.
|
|
3215
|
-
.use(reactI18next.initReactI18next).init({
|
|
3216
|
-
resources: {
|
|
3217
|
-
en: {
|
|
3218
|
-
translation: en
|
|
3219
|
-
},
|
|
3220
|
-
tr: {
|
|
3221
|
-
translation: tr
|
|
3222
|
-
}
|
|
3223
|
-
},
|
|
3224
|
-
fallbackLng: 'en',
|
|
3225
|
-
debug: true,
|
|
3226
|
-
whitelist: languages
|
|
3227
|
-
});
|
|
3228
|
-
|
|
3229
|
-
function QueueManager(props) {
|
|
3230
|
-
const {
|
|
3231
|
-
providers,
|
|
3232
|
-
getSigners,
|
|
3233
|
-
state,
|
|
3234
|
-
connect,
|
|
3235
|
-
canSwitchNetworkTo,
|
|
3236
|
-
getWalletInfo
|
|
3237
|
-
} = walletsCore.useWallets();
|
|
3238
|
-
const swapQueueDef = React.useMemo(() => {
|
|
3239
|
-
return queueManagerRangoPreset.makeQueueDefinition({
|
|
3240
|
-
API_KEY: getConfig('API_KEY')
|
|
3241
|
-
});
|
|
3242
|
-
}, []);
|
|
3243
|
-
const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
|
|
3244
|
-
const {
|
|
3245
|
-
blockchains
|
|
3246
|
-
} = useMetaStore.use.meta();
|
|
3247
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
3248
|
-
const wallets = {
|
|
3249
|
-
blockchains: connectedWallets.map(wallet => ({
|
|
3250
|
-
accounts: [wallet],
|
|
3251
|
-
name: wallet.chain
|
|
3252
|
-
}))
|
|
3253
|
-
};
|
|
3254
|
-
const switchNetwork = (wallet, network) => {
|
|
3255
|
-
if (!canSwitchNetworkTo(wallet, network)) {
|
|
3256
|
-
return undefined;
|
|
3257
|
-
}
|
|
3258
|
-
return connect(wallet, network);
|
|
3259
|
-
};
|
|
3260
|
-
// TODO: this code copy & pasted from rango, should be refactored.
|
|
3261
|
-
const allBlockchains = blockchains.filter(blockchain => blockchain.enabled).reduce((blockchainsObj, blockchain) => (blockchainsObj[blockchain.name] = blockchain, blockchainsObj), {});
|
|
3262
|
-
const evmBasedChains = blockchains.filter(rangoSdk.isEvmBlockchain);
|
|
3263
|
-
const getSupportedChainNames = type => {
|
|
3264
|
-
const {
|
|
3265
|
-
supportedChains
|
|
3266
|
-
} = getWalletInfo(type);
|
|
3267
|
-
return walletAndSupportedChainsNames(supportedChains);
|
|
3268
|
-
};
|
|
3269
|
-
const allProviders = providers();
|
|
3270
|
-
const notifier = data => {
|
|
3271
|
-
const lastStep = data.swap?.steps[data.swap.steps.length - 1];
|
|
3272
|
-
const outputAmount = data.step?.outputAmount || '';
|
|
3273
|
-
const step = data.step || lastStep;
|
|
3274
|
-
if (data.eventType === 'task_completed' || data.eventType === 'step_completed_with_output' && lastStep?.id !== data.step?.id || !!outputAmount) {
|
|
3275
|
-
const fromAccount = connectedWallets.find(account => account.chain === step?.fromBlockchain);
|
|
3276
|
-
const toAccount = step?.fromBlockchain !== step?.toBlockchain && connectedWallets.find(wallet => wallet.chain === step?.toBlockchain);
|
|
3277
|
-
fromAccount && getOneOfWalletsDetails(fromAccount);
|
|
3278
|
-
toAccount && getOneOfWalletsDetails(toAccount);
|
|
3279
|
-
}
|
|
3280
|
-
};
|
|
3281
|
-
const context = {
|
|
3282
|
-
meta: {
|
|
3283
|
-
blockchains: allBlockchains,
|
|
3284
|
-
evmBasedChains: evmBasedChains,
|
|
3285
|
-
evmNetworkChainInfo: walletsShared.convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
|
|
3286
|
-
getSupportedChainNames
|
|
3287
|
-
},
|
|
3288
|
-
getSigners,
|
|
3289
|
-
//todo: remove Network type
|
|
3290
|
-
//@ts-ignore
|
|
3291
|
-
wallets,
|
|
3292
|
-
providers: allProviders,
|
|
3293
|
-
switchNetwork,
|
|
3294
|
-
connect,
|
|
3295
|
-
state,
|
|
3296
|
-
notifier
|
|
3297
|
-
};
|
|
3298
|
-
return React__default.createElement(queueManagerReact.Provider, {
|
|
3299
|
-
queuesDefs: [swapQueueDef],
|
|
3300
|
-
context: context,
|
|
3301
|
-
onPersistedDataLoaded: manager => {
|
|
3302
|
-
queueManagerRangoPreset.checkWaitingForNetworkChange(manager);
|
|
3303
|
-
},
|
|
3304
|
-
isPaused: false
|
|
3305
|
-
}, props.children);
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
const Widget = _ref => {
|
|
3309
|
-
let {
|
|
3310
|
-
config
|
|
3311
|
-
} = _ref;
|
|
3312
|
-
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
3313
|
-
const {
|
|
3314
|
-
activeTheme
|
|
3315
|
-
} = useTheme({
|
|
3316
|
-
...config?.theme
|
|
3317
|
-
});
|
|
3318
|
-
const {
|
|
3319
|
-
blockchains
|
|
3320
|
-
} = useMetaStore.use.meta();
|
|
3321
|
-
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
3322
|
-
const connectWallet = useWalletsStore.use.connectWallet();
|
|
3323
|
-
const {
|
|
3324
|
-
changeLanguage
|
|
3325
|
-
} = useSelectLanguage();
|
|
3326
|
-
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
3327
|
-
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] = React.useState('');
|
|
3328
|
-
const [disconnectedWallet, setDisconnectedWallet] = React.useState();
|
|
3329
|
-
const currentPage = useUiStore.use.currentPage();
|
|
3330
|
-
const evmBasedChainNames = blockchains.filter(rangoSdk.isEvmBlockchain).map(chain => chain.name);
|
|
3331
|
-
React.useMemo(() => {
|
|
3332
|
-
if (config?.apiKey) {
|
|
3333
|
-
initConfig({
|
|
3334
|
-
API_KEY: config?.apiKey
|
|
3335
|
-
});
|
|
3336
|
-
}
|
|
3337
|
-
}, [config]);
|
|
3338
|
-
const onUpdateState = (type, event, value, state, supportedChains) => {
|
|
3339
|
-
if (event === walletsCore.Events.ACCOUNTS) {
|
|
3340
|
-
if (value) {
|
|
3341
|
-
const supportedChainNames = walletAndSupportedChainsNames(supportedChains);
|
|
3342
|
-
const data = prepareAccountsForWalletStore(type, value, evmBasedChainNames, supportedChainNames);
|
|
3343
|
-
connectWallet(data);
|
|
3344
|
-
} else {
|
|
3345
|
-
disconnectWallet(type);
|
|
3346
|
-
}
|
|
3347
|
-
}
|
|
3348
|
-
if (event === walletsCore.Events.ACCOUNTS && state.connected) {
|
|
3349
|
-
const key = `${type}-${state.network}-${value}`;
|
|
3350
|
-
if (state.connected) {
|
|
3351
|
-
setLastConnectedWalletWithNetwork(key);
|
|
3352
|
-
}
|
|
3353
|
-
}
|
|
3354
|
-
if (event === walletsCore.Events.NETWORK && state.network) {
|
|
3355
|
-
const key = `${type}-${state.network}`;
|
|
3356
|
-
setLastConnectedWalletWithNetwork(key);
|
|
3357
|
-
}
|
|
3358
|
-
};
|
|
3359
|
-
let providers = providerAll.allProviders();
|
|
3360
|
-
React.useEffect(() => {
|
|
3361
|
-
const wallets = config?.wallets;
|
|
3362
|
-
clearConnectedWallet();
|
|
3363
|
-
providers = !wallets ? providerAll.allProviders() : providerAll.allProviders().filter(provider => {
|
|
3364
|
-
const type = provider.config.type;
|
|
3365
|
-
return wallets.find(w => w === type);
|
|
3366
|
-
});
|
|
3367
|
-
}, [config?.wallets]);
|
|
3368
|
-
React.useEffect(() => {
|
|
3369
|
-
changeLanguage(config?.language || 'en');
|
|
3370
|
-
}, [config?.language]);
|
|
3371
|
-
return React__default.createElement(walletsCore.Provider, {
|
|
3372
|
-
allBlockChains: blockchains,
|
|
3373
|
-
providers: providers,
|
|
3374
|
-
onUpdateState: onUpdateState
|
|
3375
|
-
}, React__default.createElement("div", {
|
|
3376
|
-
id: "swap-container",
|
|
3377
|
-
className: activeTheme
|
|
3378
|
-
}, React__default.createElement(QueueManager, null, React__default.createElement(ui.SwapContainer, {
|
|
3379
|
-
fixedHeight: currentPage !== navigationRoutes.home
|
|
3380
|
-
}, React__default.createElement(AppRouter, {
|
|
3381
|
-
lastConnectedWallet: lastConnectedWalletWithNetwork,
|
|
3382
|
-
disconnectedWallet: disconnectedWallet,
|
|
3383
|
-
clearDisconnectedWallet: () => {
|
|
3384
|
-
setDisconnectedWallet(undefined);
|
|
3385
|
-
}
|
|
3386
|
-
}, React__default.createElement(Layout, {
|
|
3387
|
-
config: config
|
|
3388
|
-
}))))));
|
|
3389
|
-
};
|
|
3390
|
-
|
|
3391
|
-
Object.defineProperty(exports, 'WalletType', {
|
|
3392
|
-
enumerable: true,
|
|
3393
|
-
get: function () {
|
|
3394
|
-
return walletsShared.WalletType;
|
|
3395
|
-
}
|
|
3396
|
-
});
|
|
3397
|
-
exports.Widget = Widget;
|
|
3398
|
-
//# sourceMappingURL=widget-embedded.cjs.development.js.map
|