@rango-dev/widget-embedded 0.1.11-next.9 → 0.1.12
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/App.d.ts.map +1 -1
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmSwapErrors.d.ts +1 -1
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +1 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts +1 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/warnings/BalanceErrors.d.ts +7 -0
- package/dist/components/warnings/BalanceErrors.d.ts.map +1 -0
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib.d.ts +4 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +0 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/httpService.d.ts +2 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/meta.d.ts.map +1 -1
- package/dist/types/config.d.ts +78 -9
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/routing.d.ts +8 -8
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +7 -0
- package/dist/utils/configs.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +1 -0
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +4 -4
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -2
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +346 -277
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +346 -277
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +342 -278
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +9 -9
- package/src/App.tsx +10 -16
- package/src/QueueManager.tsx +9 -3
- package/src/app.css +0 -15
- package/src/components/ConfirmSwapErrors.tsx +8 -16
- package/src/components/ConfirmSwapWarnings.tsx +5 -15
- package/src/components/SwapDetailsPlaceholder.tsx +8 -1
- package/src/components/TokenInfo.tsx +6 -5
- package/src/components/warnings/BalanceErrors.tsx +45 -0
- package/src/globalStyles.ts +4 -0
- package/src/hooks/useConfirmSwap.ts +5 -5
- package/src/hooks/useTheme.ts +2 -2
- package/src/index.tsx +1 -1
- package/src/lib.tsx +16 -15
- package/src/pages/ConfirmSwapPage.tsx +4 -2
- package/src/pages/HistoryPage.tsx +4 -1
- package/src/pages/Home.tsx +6 -8
- package/src/pages/SwapDetailsPage.tsx +8 -21
- package/src/pages/WalletsPage.tsx +2 -2
- package/src/services/httpService.ts +9 -4
- package/src/store/bestRoute.ts +7 -5
- package/src/store/meta.ts +6 -4
- package/src/store/wallets.ts +2 -2
- package/src/types/config.ts +79 -12
- package/src/types/routing.ts +4 -4
- package/src/utils/configs.ts +30 -0
- package/src/utils/numbers.ts +4 -0
- package/src/utils/routing.ts +31 -11
- package/src/utils/swap.ts +16 -5
- package/src/utils/time.ts +2 -8
- package/dist/components/warnings/BalanceWarnings.d.ts +0 -7
- package/dist/components/warnings/BalanceWarnings.d.ts.map +0 -1
- package/src/components/warnings/BalanceWarnings.tsx +0 -40
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { WalletState, Typography, InfoCircleIcon, AngleDownIcon, Spacer, Button, Image, TextField, styled, Tooltip, RetryIcon, HistoryIcon, SettingsIcon, Header as Header$1, VerticalSwapIcon, BestRoute, Alert, ChevronRightIcon, GasIcon, ConfirmSwap, History, LiquiditySourcesSelector, BlockchainSelector, TokenSelector, Settings, SecondaryPage, Spinner, LoadingFailedAlert, Wallet, SwapHistory, AddWalletIcon, globalCss, createTheme, SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useRef, useEffect, useState, useLayoutEffect } from 'react';
|
|
2
|
+
import React, { useRef, useEffect, useState, useLayoutEffect, useMemo } from 'react';
|
|
3
3
|
import { useInRouterContext as useInRouterContext$1, MemoryRouter, useLocation as useLocation$1, useNavigate as useNavigate$1 } from 'react-router';
|
|
4
|
-
import { PendingSwapNetworkStatus, useQueueManager, calculatePendingSwap, getCurrentStep, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, cancelSwap,
|
|
4
|
+
import { PendingSwapNetworkStatus, useQueueManager, calculatePendingSwap, getCurrentStep, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, cancelSwap, makeQueueDefinition, checkWaitingForNetworkChange } from '@rango-dev/queue-manager-rango-preset';
|
|
5
5
|
import { isCosmosBlockchain, isEvmBlockchain } from 'rango-types';
|
|
6
6
|
import { useSearchParams, useLocation, createSearchParams, useNavigate, useInRouterContext, useRoutes } from 'react-router-dom';
|
|
7
7
|
import { create } from 'zustand';
|
|
8
8
|
import BigNumber, { BigNumber as BigNumber$1 } from 'bignumber.js';
|
|
9
|
-
import { Network, isEvmAddress, KEPLR_COMPATIBLE_WALLETS, detectInstallLink, WalletType, getCosmosExperimentalChainInfo, detectMobileScreens, convertEvmBlockchainMetaToEvmChainInfo } from '@rango-dev/wallets-shared';
|
|
10
|
-
import { readAccountAddress, useWallets, Provider as Provider$1, Events } from '@rango-dev/wallets-core';
|
|
11
9
|
import { persist, subscribeWithSelector } from 'zustand/middleware';
|
|
12
10
|
import { RangoClient, isEvmBlockchain as isEvmBlockchain$1 } from 'rango-sdk';
|
|
11
|
+
import { Network, isEvmAddress, KEPLR_COMPATIBLE_WALLETS, detectInstallLink, WalletType, getCosmosExperimentalChainInfo, detectMobileScreens, convertEvmBlockchainMetaToEvmChainInfo } from '@rango-dev/wallets-shared';
|
|
12
|
+
export { WalletType } from '@rango-dev/wallets-shared';
|
|
13
|
+
import { readAccountAddress, useWallets, Provider as Provider$1, Events } from '@rango-dev/wallets-core';
|
|
13
14
|
import { shallow } from 'zustand/shallow';
|
|
14
15
|
import { useTranslation, initReactI18next } from 'react-i18next';
|
|
15
16
|
import { styled as styled$1 } from '@rango-dev/ui/src/theme';
|
|
@@ -117,6 +118,206 @@ const decimalNumber = function (number, toFixed) {
|
|
|
117
118
|
}
|
|
118
119
|
return parseFloat(number).toFixed(toFixed);
|
|
119
120
|
};
|
|
121
|
+
const isPositiveNumber = text => !!text && parseFloat(text) > 0;
|
|
122
|
+
|
|
123
|
+
function searchParamsToToken(tokens, searchParams, chain) {
|
|
124
|
+
if (!chain) return null;
|
|
125
|
+
return tokens.find(token => {
|
|
126
|
+
const symbolAndAddress = searchParams?.split('--');
|
|
127
|
+
if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
|
|
128
|
+
return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
|
|
129
|
+
}) || null;
|
|
130
|
+
}
|
|
131
|
+
function getBestRouteToTokenUsdPrice(bestRoute) {
|
|
132
|
+
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
133
|
+
}
|
|
134
|
+
function isNumberOfSwapsChanged(route1, route2) {
|
|
135
|
+
const route1Swaps = route1.result?.swaps || [];
|
|
136
|
+
const route2Swaps = route2.result?.swaps || [];
|
|
137
|
+
return route1Swaps.length !== route2Swaps.length;
|
|
138
|
+
}
|
|
139
|
+
function isRouteSwappersUpdated(route1, route2) {
|
|
140
|
+
const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
|
|
141
|
+
const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
|
|
142
|
+
return !areEqual(route1Swappers, route2Swappers);
|
|
143
|
+
}
|
|
144
|
+
function isRouteInternalCoinsUpdated(route1, route2) {
|
|
145
|
+
const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
146
|
+
const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
147
|
+
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
148
|
+
}
|
|
149
|
+
function isRouteChanged(route1, route2) {
|
|
150
|
+
return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
|
|
151
|
+
}
|
|
152
|
+
function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
153
|
+
if (fee === null) return null;
|
|
154
|
+
const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
|
|
155
|
+
if (!relatedFeeStatus) return null;
|
|
156
|
+
return relatedFeeStatus.requiredAssets;
|
|
157
|
+
}
|
|
158
|
+
function isRouteParametersChanged(params) {
|
|
159
|
+
if (params.store === 'bestRoute') {
|
|
160
|
+
const {
|
|
161
|
+
prevState,
|
|
162
|
+
currentState
|
|
163
|
+
} = params;
|
|
164
|
+
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);
|
|
165
|
+
} else if (params.store === 'settings') {
|
|
166
|
+
const {
|
|
167
|
+
prevState,
|
|
168
|
+
currentState
|
|
169
|
+
} = params;
|
|
170
|
+
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
function getFormatedBestRoute(bestRoute) {
|
|
175
|
+
if (!bestRoute) return null;
|
|
176
|
+
const formatedSwaps = (bestRoute.result?.swaps || []).map(swap => ({
|
|
177
|
+
...swap,
|
|
178
|
+
fromAmount: numberToString(swap.fromAmount, 6, 6),
|
|
179
|
+
toAmount: numberToString(swap.toAmount, 6, 6)
|
|
180
|
+
}));
|
|
181
|
+
return {
|
|
182
|
+
...bestRoute,
|
|
183
|
+
...(bestRoute.result && {
|
|
184
|
+
result: {
|
|
185
|
+
...bestRoute.result,
|
|
186
|
+
swaps: formatedSwaps
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function getFormatedPendingSwap(pendingSwap) {
|
|
192
|
+
const formatedSteps = pendingSwap.steps.map(step => ({
|
|
193
|
+
...step,
|
|
194
|
+
feeInUsd: numberToString(step.feeInUsd, 4, 4),
|
|
195
|
+
outputAmount: numberToString(step.outputAmount, 6, 6),
|
|
196
|
+
expectedOutputAmountHumanReadable: numberToString(step.expectedOutputAmountHumanReadable, 6, 6)
|
|
197
|
+
}));
|
|
198
|
+
return {
|
|
199
|
+
...pendingSwap,
|
|
200
|
+
inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
|
|
201
|
+
steps: formatedSteps
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//todo: refactor bestRoute store and add loadingStatus
|
|
205
|
+
const getBestRouteStatus = (loading, error) => {
|
|
206
|
+
if (loading) return 'loading';
|
|
207
|
+
if (error) return 'failed';else return 'success';
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const createSelectors = _store => {
|
|
211
|
+
let store = _store;
|
|
212
|
+
store.use = {};
|
|
213
|
+
for (let k of Object.keys(store.getState())) {
|
|
214
|
+
store.use[k] = () => store(s => s[k]);
|
|
215
|
+
}
|
|
216
|
+
return store;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
220
|
+
let configs = {
|
|
221
|
+
API_KEY: RANGO_PUBLIC_API_KEY
|
|
222
|
+
};
|
|
223
|
+
function getConfig(name) {
|
|
224
|
+
return configs[name];
|
|
225
|
+
}
|
|
226
|
+
function initConfig(nextConfigs) {
|
|
227
|
+
let clonedConfigs;
|
|
228
|
+
if (typeof structuredClone === 'function') {
|
|
229
|
+
clonedConfigs = structuredClone(nextConfigs);
|
|
230
|
+
} else {
|
|
231
|
+
clonedConfigs = JSON.parse(JSON.stringify(nextConfigs));
|
|
232
|
+
}
|
|
233
|
+
configs = clonedConfigs;
|
|
234
|
+
return configs;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let rango = undefined;
|
|
238
|
+
const httpService = () => {
|
|
239
|
+
if (rango) return rango;
|
|
240
|
+
rango = new RangoClient(getConfig('API_KEY'));
|
|
241
|
+
return rango;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
245
|
+
const DEFAULT_SLIPPAGE = 1;
|
|
246
|
+
const HIGH_SLIPPAGE = 5;
|
|
247
|
+
const MAX_SLIPPAGE = 100;
|
|
248
|
+
const MIN_SLIPPGAE = 0;
|
|
249
|
+
|
|
250
|
+
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()(set => ({
|
|
251
|
+
meta: {
|
|
252
|
+
blockchains: [],
|
|
253
|
+
popularTokens: [],
|
|
254
|
+
swappers: [],
|
|
255
|
+
tokens: []
|
|
256
|
+
},
|
|
257
|
+
loadingStatus: 'loading',
|
|
258
|
+
fetchMeta: async () => {
|
|
259
|
+
try {
|
|
260
|
+
const response = await httpService().getAllMetadata();
|
|
261
|
+
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
262
|
+
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
263
|
+
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
264
|
+
set({
|
|
265
|
+
meta: response,
|
|
266
|
+
loadingStatus: 'success'
|
|
267
|
+
});
|
|
268
|
+
} catch (error) {
|
|
269
|
+
set({
|
|
270
|
+
loadingStatus: 'failed'
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
})));
|
|
275
|
+
|
|
276
|
+
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/persist( /*#__PURE__*/subscribeWithSelector(set => ({
|
|
277
|
+
slippage: DEFAULT_SLIPPAGE,
|
|
278
|
+
customSlippage: null,
|
|
279
|
+
infiniteApprove: false,
|
|
280
|
+
affiliateRef: null,
|
|
281
|
+
disabledLiquiditySources: [],
|
|
282
|
+
theme: 'auto',
|
|
283
|
+
setSlippage: slippage => set(() => ({
|
|
284
|
+
slippage: slippage
|
|
285
|
+
})),
|
|
286
|
+
setCustomSlippage: customSlippage => set(() => ({
|
|
287
|
+
customSlippage: customSlippage
|
|
288
|
+
})),
|
|
289
|
+
setAffiliateRef: affiliateRef => set(() => ({
|
|
290
|
+
affiliateRef
|
|
291
|
+
})),
|
|
292
|
+
toggleAllLiquiditySources: () => set(state => {
|
|
293
|
+
const {
|
|
294
|
+
swappers
|
|
295
|
+
} = useMetaStore.getState().meta;
|
|
296
|
+
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
297
|
+
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
298
|
+
disabledLiquiditySources: []
|
|
299
|
+
};else {
|
|
300
|
+
return {
|
|
301
|
+
disabledLiquiditySources: swappersGroup
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
toggleInfiniteApprove: () => set(state => ({
|
|
306
|
+
infiniteApprove: !state.infiniteApprove
|
|
307
|
+
})),
|
|
308
|
+
toggleLiquiditySource: name => set(state => {
|
|
309
|
+
if (state.disabledLiquiditySources.includes(name)) return {
|
|
310
|
+
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
311
|
+
};else return {
|
|
312
|
+
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
313
|
+
};
|
|
314
|
+
}),
|
|
315
|
+
setTheme: theme => set(() => ({
|
|
316
|
+
theme
|
|
317
|
+
}))
|
|
318
|
+
})), {
|
|
319
|
+
name: 'user-settings'
|
|
320
|
+
})));
|
|
120
321
|
|
|
121
322
|
function getStateWallet(state) {
|
|
122
323
|
switch (true) {
|
|
@@ -421,7 +622,7 @@ function LimitErrorMessage(bestRoute) {
|
|
|
421
622
|
recommendation
|
|
422
623
|
};
|
|
423
624
|
}
|
|
424
|
-
function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath,
|
|
625
|
+
function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount) {
|
|
425
626
|
if (loadingMetaStatus !== 'success') return {
|
|
426
627
|
title: 'Connect Wallet',
|
|
427
628
|
disabled: true
|
|
@@ -433,7 +634,7 @@ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, has
|
|
|
433
634
|
if (loading) return {
|
|
434
635
|
title: 'Finding Best Route...',
|
|
435
636
|
disabled: true
|
|
436
|
-
};else if (
|
|
637
|
+
};else if (!inputAmount || inputAmount === '0') return {
|
|
437
638
|
title: 'Enter an amount',
|
|
438
639
|
disabled: true
|
|
439
640
|
};else if (!bestRoute || !bestRoute.result) return {
|
|
@@ -502,7 +703,7 @@ function hasProperSlippage(userSlippage, minRequiredSlippage) {
|
|
|
502
703
|
if (!minRequiredSlippage) return true;
|
|
503
704
|
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
504
705
|
}
|
|
505
|
-
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage,
|
|
706
|
+
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, affiliateRef, initialRoute) {
|
|
506
707
|
const selectedWalletsMap = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = selectedWallet.address, selectedWalletsMap), {});
|
|
507
708
|
const connectedWallets = [];
|
|
508
709
|
wallets.forEach(wallet => {
|
|
@@ -512,7 +713,8 @@ function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, se
|
|
|
512
713
|
addresses: [wallet.address]
|
|
513
714
|
});
|
|
514
715
|
});
|
|
515
|
-
const
|
|
716
|
+
const checkPrerequisites = !!initialRoute;
|
|
717
|
+
const filteredBlockchains = removeDuplicateFrom((initialRoute?.result?.swaps || []).reduce((blockchains, swap) => (blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains), []));
|
|
516
718
|
const requestBody = {
|
|
517
719
|
amount: inputAmount.toString(),
|
|
518
720
|
affiliateRef,
|
|
@@ -636,155 +838,6 @@ function shouldRetrySwap(pendingSwap) {
|
|
|
636
838
|
return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
|
|
637
839
|
}
|
|
638
840
|
|
|
639
|
-
function searchParamsToToken(tokens, searchParams, chain) {
|
|
640
|
-
if (!chain) return null;
|
|
641
|
-
return tokens.find(token => {
|
|
642
|
-
const symbolAndAddress = searchParams?.split('--');
|
|
643
|
-
if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
|
|
644
|
-
return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
|
|
645
|
-
}) || null;
|
|
646
|
-
}
|
|
647
|
-
function getBestRouteToTokenUsdPrice(bestRoute) {
|
|
648
|
-
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
649
|
-
}
|
|
650
|
-
function isNumberOfSwapsChanged(route1, route2) {
|
|
651
|
-
const route1Swaps = route1.result?.swaps || [];
|
|
652
|
-
const route2Swaps = route2.result?.swaps || [];
|
|
653
|
-
return route1Swaps.length !== route2Swaps.length;
|
|
654
|
-
}
|
|
655
|
-
function isRouteSwappersUpdated(route1, route2) {
|
|
656
|
-
const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
|
|
657
|
-
const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
|
|
658
|
-
return !areEqual(route1Swappers, route2Swappers);
|
|
659
|
-
}
|
|
660
|
-
function isRouteInternalCoinsUpdated(route1, route2) {
|
|
661
|
-
const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
662
|
-
const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
663
|
-
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
664
|
-
}
|
|
665
|
-
function isRouteChanged(route1, route2) {
|
|
666
|
-
return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
|
|
667
|
-
}
|
|
668
|
-
function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
669
|
-
if (fee === null) return null;
|
|
670
|
-
const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
|
|
671
|
-
if (!relatedFeeStatus) return null;
|
|
672
|
-
return relatedFeeStatus.requiredAssets;
|
|
673
|
-
}
|
|
674
|
-
function isRouteParametersChanged(params) {
|
|
675
|
-
if (params.store === 'bestRoute') {
|
|
676
|
-
const {
|
|
677
|
-
prevState,
|
|
678
|
-
currentState
|
|
679
|
-
} = params;
|
|
680
|
-
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);
|
|
681
|
-
} else if (params.store === 'settings') {
|
|
682
|
-
const {
|
|
683
|
-
prevState,
|
|
684
|
-
currentState
|
|
685
|
-
} = params;
|
|
686
|
-
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
687
|
-
}
|
|
688
|
-
return false;
|
|
689
|
-
}
|
|
690
|
-
//todo: refactor bestRoute store and add loadingStatus
|
|
691
|
-
const getBestRouteStatus = (loading, error) => {
|
|
692
|
-
if (loading) return 'loading';
|
|
693
|
-
if (error) return 'failed';else return 'success';
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
const createSelectors = _store => {
|
|
697
|
-
let store = _store;
|
|
698
|
-
store.use = {};
|
|
699
|
-
for (let k of Object.keys(store.getState())) {
|
|
700
|
-
store.use[k] = () => store(s => s[k]);
|
|
701
|
-
}
|
|
702
|
-
return store;
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
// this API key is limited and
|
|
706
|
-
// it is only for test purpose
|
|
707
|
-
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
708
|
-
const httpService = /*#__PURE__*/new RangoClient(process.env.REACT_APP_API_KEY || RANGO_PUBLIC_API_KEY);
|
|
709
|
-
|
|
710
|
-
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
711
|
-
const DEFAULT_SLIPPAGE = 1;
|
|
712
|
-
const HIGH_SLIPPAGE = 5;
|
|
713
|
-
const MAX_SLIPPAGE = 100;
|
|
714
|
-
const MIN_SLIPPGAE = 0;
|
|
715
|
-
|
|
716
|
-
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()(set => ({
|
|
717
|
-
meta: {
|
|
718
|
-
blockchains: [],
|
|
719
|
-
popularTokens: [],
|
|
720
|
-
swappers: [],
|
|
721
|
-
tokens: []
|
|
722
|
-
},
|
|
723
|
-
loadingStatus: 'loading',
|
|
724
|
-
fetchMeta: async () => {
|
|
725
|
-
try {
|
|
726
|
-
const response = await httpService.getAllMetadata();
|
|
727
|
-
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
728
|
-
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
729
|
-
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
730
|
-
set({
|
|
731
|
-
meta: response,
|
|
732
|
-
loadingStatus: 'success'
|
|
733
|
-
});
|
|
734
|
-
} catch (error) {
|
|
735
|
-
set({
|
|
736
|
-
loadingStatus: 'failed'
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
})));
|
|
741
|
-
|
|
742
|
-
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/persist( /*#__PURE__*/subscribeWithSelector(set => ({
|
|
743
|
-
slippage: DEFAULT_SLIPPAGE,
|
|
744
|
-
customSlippage: null,
|
|
745
|
-
infiniteApprove: false,
|
|
746
|
-
affiliateRef: null,
|
|
747
|
-
disabledLiquiditySources: [],
|
|
748
|
-
theme: 'auto',
|
|
749
|
-
setSlippage: slippage => set(() => ({
|
|
750
|
-
slippage: slippage
|
|
751
|
-
})),
|
|
752
|
-
setCustomSlippage: customSlippage => set(() => ({
|
|
753
|
-
customSlippage: customSlippage
|
|
754
|
-
})),
|
|
755
|
-
setAffiliateRef: affiliateRef => set(() => ({
|
|
756
|
-
affiliateRef
|
|
757
|
-
})),
|
|
758
|
-
toggleAllLiquiditySources: () => set(state => {
|
|
759
|
-
const {
|
|
760
|
-
swappers
|
|
761
|
-
} = useMetaStore.getState().meta;
|
|
762
|
-
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
763
|
-
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
764
|
-
disabledLiquiditySources: []
|
|
765
|
-
};else {
|
|
766
|
-
return {
|
|
767
|
-
disabledLiquiditySources: swappersGroup
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
}),
|
|
771
|
-
toggleInfiniteApprove: () => set(state => ({
|
|
772
|
-
infiniteApprove: !state.infiniteApprove
|
|
773
|
-
})),
|
|
774
|
-
toggleLiquiditySource: name => set(state => {
|
|
775
|
-
if (state.disabledLiquiditySources.includes(name)) return {
|
|
776
|
-
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
777
|
-
};else return {
|
|
778
|
-
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
779
|
-
};
|
|
780
|
-
}),
|
|
781
|
-
setTheme: theme => set(() => ({
|
|
782
|
-
theme
|
|
783
|
-
}))
|
|
784
|
-
})), {
|
|
785
|
-
name: 'user-settings'
|
|
786
|
-
})));
|
|
787
|
-
|
|
788
841
|
const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/subscribeWithSelector(set => ({
|
|
789
842
|
accounts: [],
|
|
790
843
|
balances: [],
|
|
@@ -805,7 +858,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#
|
|
|
805
858
|
}));
|
|
806
859
|
accounts.forEach(async account => {
|
|
807
860
|
try {
|
|
808
|
-
const response = await httpService.getWalletsDetails([{
|
|
861
|
+
const response = await httpService().getWalletsDetails([{
|
|
809
862
|
address: account.address,
|
|
810
863
|
blockchain: account.chain
|
|
811
864
|
}]);
|
|
@@ -849,7 +902,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#
|
|
|
849
902
|
}
|
|
850
903
|
});
|
|
851
904
|
return {
|
|
852
|
-
selectedWallets: selectedWallets
|
|
905
|
+
selectedWallets: state.selectedWallets.concat(selectedWallets)
|
|
853
906
|
};
|
|
854
907
|
}),
|
|
855
908
|
setSelectedWallet: wallet => set(state => ({
|
|
@@ -901,7 +954,7 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /
|
|
|
901
954
|
setBestRoute: bestRoute => set(state => {
|
|
902
955
|
let outputAmount = null;
|
|
903
956
|
let outputUsdValue = ZERO;
|
|
904
|
-
if (!state.inputAmount
|
|
957
|
+
if (!isPositiveNumber(state.inputAmount)) return {};
|
|
905
958
|
if (!!bestRoute) {
|
|
906
959
|
outputAmount = !!bestRoute.result?.outputAmount ? new BigNumber(bestRoute.result?.outputAmount) : null;
|
|
907
960
|
outputUsdValue = calcOutputUsdValue(bestRoute.result?.outputAmount, getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice);
|
|
@@ -1036,18 +1089,18 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1036
1089
|
disabledLiquiditySources,
|
|
1037
1090
|
affiliateRef
|
|
1038
1091
|
} = settingsStore.getState();
|
|
1039
|
-
if (!fromToken || !toToken || !inputAmount
|
|
1092
|
+
if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
|
|
1040
1093
|
abortController?.abort();
|
|
1041
1094
|
abortController = new AbortController();
|
|
1042
1095
|
const userSlippage = !!customSlippage ? customSlippage : slippage;
|
|
1043
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage,
|
|
1096
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
|
|
1044
1097
|
if (!bestRouteStore.getState().loading) bestRouteStore.setState({
|
|
1045
1098
|
loading: true,
|
|
1046
1099
|
bestRoute: null,
|
|
1047
1100
|
outputAmount: null,
|
|
1048
1101
|
outputUsdValue: new BigNumber(0)
|
|
1049
1102
|
});
|
|
1050
|
-
httpService.getBestRoute(requestBody, {
|
|
1103
|
+
httpService().getBestRoute(requestBody, {
|
|
1051
1104
|
signal: abortController.signal
|
|
1052
1105
|
}).then(res => {
|
|
1053
1106
|
const {
|
|
@@ -1074,7 +1127,9 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1074
1127
|
inputAmount,
|
|
1075
1128
|
inputUsdValue
|
|
1076
1129
|
} = useBestRouteStore.getState();
|
|
1077
|
-
if (!inputAmount ||
|
|
1130
|
+
if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0)) return bestRouteStore.setState({
|
|
1131
|
+
loading: false
|
|
1132
|
+
});
|
|
1078
1133
|
if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
|
|
1079
1134
|
loading: false,
|
|
1080
1135
|
bestRoute: null,
|
|
@@ -1387,6 +1442,7 @@ function TokenInfo(props) {
|
|
|
1387
1442
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
1388
1443
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
1389
1444
|
const balances = useWalletsStore.use.balances();
|
|
1445
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
1390
1446
|
const navigate = useNavigate();
|
|
1391
1447
|
const {
|
|
1392
1448
|
t
|
|
@@ -1490,12 +1546,13 @@ function TokenInfo(props) {
|
|
|
1490
1546
|
color: "neutrals800"
|
|
1491
1547
|
}, `$${numberToString(inputUsdValue)}`)),
|
|
1492
1548
|
value: props.inputAmount || '',
|
|
1549
|
+
min: 0,
|
|
1493
1550
|
onChange: props.type === 'From' ? event => {
|
|
1494
1551
|
props.onAmountChange(event.target.value);
|
|
1495
1552
|
} : undefined
|
|
1496
1553
|
}) : React.createElement(OutputContainer, null, React.createElement(Typography, {
|
|
1497
1554
|
variant: "h4"
|
|
1498
|
-
},
|
|
1555
|
+
}, fetchingBestRoute && '?', !!bestRoute?.result && `≈ ${numberToString(props.outputAmount)}`, (!inputAmount || inputAmount === '0') && '0'))))));
|
|
1499
1556
|
}
|
|
1500
1557
|
|
|
1501
1558
|
const Container$1 = /*#__PURE__*/styled$1('div', {
|
|
@@ -1679,8 +1736,7 @@ function Home() {
|
|
|
1679
1736
|
swap
|
|
1680
1737
|
} = LimitErrorMessage(bestRoute);
|
|
1681
1738
|
const priceImpactCanNotBeComputed = !canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue);
|
|
1682
|
-
const
|
|
1683
|
-
const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputIsZero);
|
|
1739
|
+
const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount);
|
|
1684
1740
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
1685
1741
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
1686
1742
|
useEffect(() => {
|
|
@@ -1717,7 +1773,7 @@ function Home() {
|
|
|
1717
1773
|
}), showBestRoute && React.createElement(BestRouteContainer, null, React.createElement(BestRoute, {
|
|
1718
1774
|
error: bestRouteError,
|
|
1719
1775
|
loading: fetchingBestRoute,
|
|
1720
|
-
data: bestRoute,
|
|
1776
|
+
data: getFormatedBestRoute(bestRoute),
|
|
1721
1777
|
totalFee: numberToString(totalFeeInUsd, 0, 2),
|
|
1722
1778
|
feeWarning: highFee,
|
|
1723
1779
|
totalTime: secondsToString(totalArrivalTime(bestRoute))
|
|
@@ -1728,9 +1784,7 @@ function Home() {
|
|
|
1728
1784
|
title: `${swap?.swapperId} Limit`
|
|
1729
1785
|
}, React.createElement(React.Fragment, null, React.createElement(Typography, {
|
|
1730
1786
|
variant: "body2"
|
|
1731
|
-
}, fromAmountRangeError
|
|
1732
|
-
variant: "body2"
|
|
1733
|
-
}, "Yours: ", numberToString(swap?.fromAmount || null), swap?.from.symbol), React.createElement("br", null), React.createElement(Typography, {
|
|
1787
|
+
}, `${fromAmountRangeError}, Yours: ${numberToString(swap?.fromAmount || null)} ${swap?.from.symbol}`), React.createElement(Typography, {
|
|
1734
1788
|
variant: "body2"
|
|
1735
1789
|
}, recommendation)))), React.createElement(Footer, null, React.createElement(Button, {
|
|
1736
1790
|
type: "primary",
|
|
@@ -1985,6 +2039,7 @@ var ConfirmSwapErrorTypes;
|
|
|
1985
2039
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS"] = 1] = "ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS";
|
|
1986
2040
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["REQUEST_FAILED"] = 2] = "REQUEST_FAILED";
|
|
1987
2041
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_SLIPPAGE"] = 3] = "INSUFFICIENT_SLIPPAGE";
|
|
2042
|
+
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
1988
2043
|
})(ConfirmSwapErrorTypes || (ConfirmSwapErrorTypes = {}));
|
|
1989
2044
|
var ConfirmSwapWarningTypes;
|
|
1990
2045
|
(function (ConfirmSwapWarningTypes) {
|
|
@@ -1992,7 +2047,6 @@ var ConfirmSwapWarningTypes;
|
|
|
1992
2047
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_SWAPPERS_UPDATED"] = 1] = "ROUTE_SWAPPERS_UPDATED";
|
|
1993
2048
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_COINS_UPDATED"] = 2] = "ROUTE_COINS_UPDATED";
|
|
1994
2049
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_AND_OUTPUT_AMOUNT_UPDATED"] = 3] = "ROUTE_AND_OUTPUT_AMOUNT_UPDATED";
|
|
1995
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
1996
2050
|
})(ConfirmSwapWarningTypes || (ConfirmSwapWarningTypes = {}));
|
|
1997
2051
|
|
|
1998
2052
|
function useConfirmSwap() {
|
|
@@ -2042,9 +2096,9 @@ function useConfirmSwap() {
|
|
|
2042
2096
|
}
|
|
2043
2097
|
abortControllerRef.current = new AbortController();
|
|
2044
2098
|
setLoading(true);
|
|
2045
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage,
|
|
2099
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, affiliateRef, initialRoute);
|
|
2046
2100
|
try {
|
|
2047
|
-
const confiremedRoute = await httpService.getBestRoute(requestBody, {
|
|
2101
|
+
const confiremedRoute = await httpService().getBestRoute(requestBody, {
|
|
2048
2102
|
signal: abortControllerRef.current?.signal
|
|
2049
2103
|
});
|
|
2050
2104
|
abortControllerRef.current = null;
|
|
@@ -2081,8 +2135,8 @@ function useConfirmSwap() {
|
|
|
2081
2135
|
}
|
|
2082
2136
|
const balanceWarnings = getBalanceWarnings(confiremedRoute, selectedWallets);
|
|
2083
2137
|
const enoughBalance = balanceWarnings.length === 0;
|
|
2084
|
-
if (!enoughBalance) confirmSwapState.
|
|
2085
|
-
type:
|
|
2138
|
+
if (!enoughBalance) confirmSwapState.errors.push({
|
|
2139
|
+
type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
|
|
2086
2140
|
messages: balanceWarnings
|
|
2087
2141
|
});
|
|
2088
2142
|
const minRequiredSlippage = getMinRequiredSlippage(initialRoute);
|
|
@@ -2152,31 +2206,6 @@ function MinRequiredSlippage(_ref) {
|
|
|
2152
2206
|
}), React.createElement(ChangeSlippageButton, null));
|
|
2153
2207
|
}
|
|
2154
2208
|
|
|
2155
|
-
function ConfirmSwapErrors(errors) {
|
|
2156
|
-
return errors.flatMap(error => {
|
|
2157
|
-
switch (error.type) {
|
|
2158
|
-
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
2159
|
-
return React.createElement(Typography, {
|
|
2160
|
-
variant: "body2"
|
|
2161
|
-
}, "No routes found. Please try again later.");
|
|
2162
|
-
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
2163
|
-
return React.createElement(Typography, {
|
|
2164
|
-
variant: "body2"
|
|
2165
|
-
}, `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`);
|
|
2166
|
-
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
2167
|
-
return React.createElement(Typography, {
|
|
2168
|
-
variant: "body2"
|
|
2169
|
-
}, "Route updated and price impact is too high, try again later!");
|
|
2170
|
-
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
2171
|
-
return React.createElement(MinRequiredSlippage, {
|
|
2172
|
-
minRequiredSlippage: error.minRequiredSlippage
|
|
2173
|
-
});
|
|
2174
|
-
default:
|
|
2175
|
-
return [];
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
2209
|
const List = /*#__PURE__*/styled('ul', {
|
|
2181
2210
|
variants: {
|
|
2182
2211
|
showListStyle: {
|
|
@@ -2197,47 +2226,63 @@ const ListItem = /*#__PURE__*/styled('li', {
|
|
|
2197
2226
|
}
|
|
2198
2227
|
});
|
|
2199
2228
|
const Message = /*#__PURE__*/styled(Typography, {
|
|
2200
|
-
display: 'block'
|
|
2201
|
-
color: '$warning500 !important'
|
|
2229
|
+
display: 'block'
|
|
2202
2230
|
});
|
|
2203
|
-
function
|
|
2231
|
+
function BalanceErrors(_ref) {
|
|
2204
2232
|
let {
|
|
2205
2233
|
messages
|
|
2206
2234
|
} = _ref;
|
|
2207
2235
|
const showListStyle = messages.length > 1;
|
|
2208
|
-
return React.createElement(
|
|
2236
|
+
return React.createElement(React.Fragment, null, React.createElement(Typography, {
|
|
2237
|
+
className: "title",
|
|
2238
|
+
variant: "title",
|
|
2239
|
+
color: 'error'
|
|
2240
|
+
}, "Insufficent Balance:"), React.createElement(Spacer, {
|
|
2241
|
+
size: 8,
|
|
2242
|
+
direction: "vertical"
|
|
2243
|
+
}), React.createElement(List, {
|
|
2209
2244
|
showListStyle: showListStyle
|
|
2210
2245
|
}, messages.map(warning => React.createElement(ListItem, {
|
|
2211
2246
|
showListStyle: showListStyle
|
|
2212
2247
|
}, React.createElement(Message, {
|
|
2213
2248
|
variant: "body2"
|
|
2214
|
-
}, warning))));
|
|
2249
|
+
}, warning)))));
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
function ConfirmSwapErrors(errors) {
|
|
2253
|
+
return errors.flatMap(error => {
|
|
2254
|
+
switch (error.type) {
|
|
2255
|
+
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
2256
|
+
return 'No routes found. Please try again later.';
|
|
2257
|
+
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
2258
|
+
return `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`;
|
|
2259
|
+
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
2260
|
+
return 'Route updated and price impact is too high, try again later!';
|
|
2261
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
2262
|
+
return React.createElement(MinRequiredSlippage, {
|
|
2263
|
+
minRequiredSlippage: error.minRequiredSlippage
|
|
2264
|
+
});
|
|
2265
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
|
|
2266
|
+
return React.createElement(BalanceErrors, {
|
|
2267
|
+
messages: error.messages
|
|
2268
|
+
});
|
|
2269
|
+
default:
|
|
2270
|
+
return [];
|
|
2271
|
+
}
|
|
2272
|
+
});
|
|
2215
2273
|
}
|
|
2216
2274
|
|
|
2217
2275
|
function ConfirmSwapWarnings(warnings) {
|
|
2218
2276
|
return warnings.flatMap(warning => {
|
|
2219
2277
|
switch (warning.type) {
|
|
2220
2278
|
case ConfirmSwapWarningTypes.ROUTE_UPDATED:
|
|
2221
|
-
return
|
|
2222
|
-
variant: "body2"
|
|
2223
|
-
}, "Route has been updated.");
|
|
2279
|
+
return "Route has been updated.";
|
|
2224
2280
|
case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
2225
|
-
return
|
|
2226
|
-
variant: "body2"
|
|
2227
|
-
}, `Output amount changed to ${warning.newOutputAmount}
|
|
2228
|
-
(${warning.percentageChange}% change).`);
|
|
2281
|
+
return `Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`;
|
|
2229
2282
|
case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
|
|
2230
|
-
return
|
|
2231
|
-
variant: "body2"
|
|
2232
|
-
}, "Route swappers has been updated.");
|
|
2283
|
+
return "Route swappers has been updated.";
|
|
2233
2284
|
case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
|
|
2234
|
-
return
|
|
2235
|
-
variant: "body2"
|
|
2236
|
-
}, "Route internal coins has been updated.");
|
|
2237
|
-
case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
|
|
2238
|
-
return React.createElement(BalanceWarnings, {
|
|
2239
|
-
messages: warning.messages
|
|
2240
|
-
});
|
|
2285
|
+
return "Route internal coins has been updated.";
|
|
2241
2286
|
default:
|
|
2242
2287
|
return [];
|
|
2243
2288
|
}
|
|
@@ -2285,6 +2330,7 @@ function ConfirmSwapPage() {
|
|
|
2285
2330
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
2286
2331
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2287
2332
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
2333
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2288
2334
|
const bestRouteloadingStatus = getBestRouteStatus(fetchingBestRoute, !!fetchingBestRouteError);
|
|
2289
2335
|
const {
|
|
2290
2336
|
manager
|
|
@@ -2315,10 +2361,7 @@ function ConfirmSwapPage() {
|
|
|
2315
2361
|
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
|
|
2316
2362
|
};
|
|
2317
2363
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
2318
|
-
return React.createElement(ConfirmSwap
|
|
2319
|
-
// @ts-ignore
|
|
2320
|
-
, {
|
|
2321
|
-
// @ts-ignore
|
|
2364
|
+
return React.createElement(ConfirmSwap, {
|
|
2322
2365
|
requiredWallets: getRequiredChains(bestRoute),
|
|
2323
2366
|
selectableWallets: selectableWallets,
|
|
2324
2367
|
onBack: navigateBackFrom.bind(null, navigationRoutes.confirmSwap),
|
|
@@ -2327,15 +2370,16 @@ function ConfirmSwapPage() {
|
|
|
2327
2370
|
if (swap) {
|
|
2328
2371
|
manager?.create('swap', {
|
|
2329
2372
|
swapDetails: swap
|
|
2330
|
-
},
|
|
2331
|
-
// @ts-ignore
|
|
2332
|
-
{
|
|
2373
|
+
}, {
|
|
2333
2374
|
id: swap.requestId
|
|
2334
2375
|
});
|
|
2335
2376
|
setSelectedSwap(swap.requestId);
|
|
2336
2377
|
navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
2337
2378
|
replace: true
|
|
2338
2379
|
});
|
|
2380
|
+
setTimeout(() => {
|
|
2381
|
+
setInputAmount('');
|
|
2382
|
+
}, 0);
|
|
2339
2383
|
}
|
|
2340
2384
|
});
|
|
2341
2385
|
},
|
|
@@ -2445,9 +2489,11 @@ function HistoryPage() {
|
|
|
2445
2489
|
} = _ref;
|
|
2446
2490
|
return swap;
|
|
2447
2491
|
});
|
|
2492
|
+
const loading = !manager?.isLoaded();
|
|
2448
2493
|
return React.createElement(History, {
|
|
2449
2494
|
list: pendingSwaps,
|
|
2450
2495
|
groupBy: groupSwapsByDate,
|
|
2496
|
+
loading: loading,
|
|
2451
2497
|
onSwapClick: requestId => {
|
|
2452
2498
|
setSelectedSwap(requestId);
|
|
2453
2499
|
navigate(navigationRoutes.swaps + `/${requestId}`, {
|
|
@@ -2686,8 +2732,9 @@ function WalletsPage(_ref) {
|
|
|
2686
2732
|
textField: false,
|
|
2687
2733
|
onBack: navigateBackFrom.bind(null, navigationRoutes.wallets)
|
|
2688
2734
|
}, React.createElement(React.Fragment, null, walletErrorMessage && React.createElement(AlertContainer, null, React.createElement(Alert, {
|
|
2689
|
-
type: "error"
|
|
2690
|
-
|
|
2735
|
+
type: "error",
|
|
2736
|
+
title: walletErrorMessage
|
|
2737
|
+
})), loadingMetaStatus === 'loading' && React.createElement(LoaderContainer, {
|
|
2691
2738
|
className: "loader"
|
|
2692
2739
|
}, React.createElement(Spinner, {
|
|
2693
2740
|
size: 24
|
|
@@ -2751,12 +2798,19 @@ function timeSince(timeMillis) {
|
|
|
2751
2798
|
return interval + ' ' + intervalType;
|
|
2752
2799
|
}
|
|
2753
2800
|
function getSwapDate(pendingSwap) {
|
|
2754
|
-
return pendingSwap.finishTime ?
|
|
2801
|
+
return pendingSwap.finishTime ? `${timeSince(parseInt(pendingSwap.finishTime))} ago` : `${timeSince(parseInt(pendingSwap.creationTime))} ago`;
|
|
2755
2802
|
}
|
|
2756
2803
|
|
|
2757
2804
|
const PlaceholderContainer = /*#__PURE__*/styled('div', {
|
|
2758
2805
|
height: '450px'
|
|
2759
2806
|
});
|
|
2807
|
+
const LoaderContainer$1 = /*#__PURE__*/styled('div', {
|
|
2808
|
+
display: 'flex',
|
|
2809
|
+
justifyContent: 'center',
|
|
2810
|
+
width: '100%',
|
|
2811
|
+
paddingTop: '33%',
|
|
2812
|
+
flex: 1
|
|
2813
|
+
});
|
|
2760
2814
|
function SwapDetailsPlaceholder(props) {
|
|
2761
2815
|
const {
|
|
2762
2816
|
requestId,
|
|
@@ -2767,7 +2821,7 @@ function SwapDetailsPlaceholder(props) {
|
|
|
2767
2821
|
title: "Swap Details",
|
|
2768
2822
|
textField: false,
|
|
2769
2823
|
onBack: onBack
|
|
2770
|
-
}, React.createElement(PlaceholderContainer, null, loading ? React.createElement(LoaderContainer, null, React.createElement(Spinner, {
|
|
2824
|
+
}, React.createElement(PlaceholderContainer, null, loading ? React.createElement(LoaderContainer$1, null, React.createElement(Spinner, {
|
|
2771
2825
|
size: 24
|
|
2772
2826
|
})) : React.createElement(Alert, {
|
|
2773
2827
|
type: "secondary",
|
|
@@ -2790,12 +2844,6 @@ function SwapDetailsPage() {
|
|
|
2790
2844
|
const {
|
|
2791
2845
|
manager
|
|
2792
2846
|
} = useManager();
|
|
2793
|
-
const [loading, setLoading] = useState(true);
|
|
2794
|
-
useEffect(() => {
|
|
2795
|
-
setTimeout(() => {
|
|
2796
|
-
setLoading(false);
|
|
2797
|
-
}, 5000);
|
|
2798
|
-
}, []);
|
|
2799
2847
|
const pendingSwaps = getPendingSwaps(manager);
|
|
2800
2848
|
const selectedSwap = pendingSwaps.find(_ref => {
|
|
2801
2849
|
let {
|
|
@@ -2808,15 +2856,12 @@ function SwapDetailsPage() {
|
|
|
2808
2856
|
if (swap) cancelSwap(swap);
|
|
2809
2857
|
};
|
|
2810
2858
|
const swap = selectedSwap?.swap;
|
|
2859
|
+
const loading = !manager?.isLoaded();
|
|
2811
2860
|
if (!swap) return React.createElement(SwapDetailsPlaceholder, {
|
|
2812
2861
|
requestId: selectedSwapRequestId || '',
|
|
2813
2862
|
loading: loading,
|
|
2814
2863
|
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails)
|
|
2815
2864
|
});
|
|
2816
|
-
const firstStep = swap.steps[0];
|
|
2817
|
-
const lastStep = swap.steps[swap.steps.length - 1];
|
|
2818
|
-
const fromAmount = numberToString(swap.inputAmount);
|
|
2819
|
-
const toAmount = numberToString(swap.simulationResult.outputAmount);
|
|
2820
2865
|
const currentStep = getCurrentStep(swap);
|
|
2821
2866
|
const currentStepBlockchain = currentStep ? getCurrentBlockchainOfOrNull(swap, currentStep) : null;
|
|
2822
2867
|
const currentStepWallet = currentStep ? getRelatedWalletOrNull(swap, currentStep) : null;
|
|
@@ -2829,38 +2874,41 @@ function SwapDetailsPage() {
|
|
|
2829
2874
|
const lastConvertedTokenInFailedSwap = getLastConvertedTokenInFailedSwap(swap);
|
|
2830
2875
|
return React.createElement(SwapHistory, Object.assign({
|
|
2831
2876
|
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails),
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2877
|
+
/* TODO: It was temporarily removed to find a better solution*/
|
|
2878
|
+
/*
|
|
2879
|
+
previewInputs={
|
|
2880
|
+
<>
|
|
2881
|
+
<TokenPreview
|
|
2882
|
+
chain={{
|
|
2883
|
+
displayName: firstStep?.fromBlockchain || '',
|
|
2884
|
+
logo: firstStep?.fromBlockchainLogo || '',
|
|
2885
|
+
}}
|
|
2886
|
+
token={{
|
|
2887
|
+
symbol: firstStep?.fromSymbol || '',
|
|
2888
|
+
image: firstStep?.fromLogo || '',
|
|
2889
|
+
}}
|
|
2890
|
+
amount={fromAmount}
|
|
2891
|
+
label={t('From')}
|
|
2892
|
+
loadingStatus={'success'}
|
|
2893
|
+
/>
|
|
2894
|
+
<Spacer size={12} direction="vertical" />
|
|
2895
|
+
<TokenPreview
|
|
2896
|
+
chain={{
|
|
2897
|
+
displayName: lastStep?.toBlockchain || '',
|
|
2898
|
+
logo: lastStep?.toBlockchainLogo || '',
|
|
2899
|
+
}}
|
|
2900
|
+
token={{
|
|
2901
|
+
symbol: lastStep?.toSymbol || '',
|
|
2902
|
+
image: lastStep?.toLogo || '',
|
|
2903
|
+
}}
|
|
2904
|
+
amount={toAmount}
|
|
2905
|
+
label={t('To')}
|
|
2906
|
+
loadingStatus={'success'}
|
|
2907
|
+
/>
|
|
2908
|
+
</>
|
|
2909
|
+
}
|
|
2910
|
+
*/
|
|
2911
|
+
pendingSwap: getFormatedPendingSwap(swap),
|
|
2864
2912
|
onCopy: handleCopy,
|
|
2865
2913
|
isCopied: isCopied,
|
|
2866
2914
|
onCancel: onCancel,
|
|
@@ -3036,6 +3084,10 @@ function Layout(_ref) {
|
|
|
3036
3084
|
|
|
3037
3085
|
const globalStyles = /*#__PURE__*/globalCss({
|
|
3038
3086
|
'*': {
|
|
3087
|
+
boxSizing: 'border-box',
|
|
3088
|
+
margin: 0,
|
|
3089
|
+
padding: 0,
|
|
3090
|
+
listStyleType: 'none',
|
|
3039
3091
|
'&::-webkit-scrollbar': {
|
|
3040
3092
|
width: '$8',
|
|
3041
3093
|
height: '$8'
|
|
@@ -3277,6 +3329,11 @@ function QueueManager(props) {
|
|
|
3277
3329
|
canSwitchNetworkTo,
|
|
3278
3330
|
getWalletInfo
|
|
3279
3331
|
} = useWallets();
|
|
3332
|
+
const swapQueueDef = useMemo(() => {
|
|
3333
|
+
return makeQueueDefinition({
|
|
3334
|
+
API_KEY: getConfig('API_KEY')
|
|
3335
|
+
});
|
|
3336
|
+
}, []);
|
|
3280
3337
|
const {
|
|
3281
3338
|
blockchains
|
|
3282
3339
|
} = useMetaStore.use.meta();
|
|
@@ -3335,7 +3392,7 @@ function QueueManager(props) {
|
|
|
3335
3392
|
}, props.children);
|
|
3336
3393
|
}
|
|
3337
3394
|
|
|
3338
|
-
const
|
|
3395
|
+
const Widget = _ref => {
|
|
3339
3396
|
let {
|
|
3340
3397
|
config
|
|
3341
3398
|
} = _ref;
|
|
@@ -3359,6 +3416,13 @@ const SwapBox = _ref => {
|
|
|
3359
3416
|
const [disconnectedWallet, setDisconnectedWallet] = useState();
|
|
3360
3417
|
const currentPage = useUiStore.use.currentPage();
|
|
3361
3418
|
const evmBasedChainNames = blockchains.filter(isEvmBlockchain$1).map(chain => chain.name);
|
|
3419
|
+
useMemo(() => {
|
|
3420
|
+
if (config?.apiKey) {
|
|
3421
|
+
initConfig({
|
|
3422
|
+
API_KEY: config?.apiKey
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
}, [config]);
|
|
3362
3426
|
const onUpdateState = (type, event, value, state, supportedChains) => {
|
|
3363
3427
|
if (event === Events.ACCOUNTS) {
|
|
3364
3428
|
if (value) {
|
|
@@ -3412,5 +3476,5 @@ const SwapBox = _ref => {
|
|
|
3412
3476
|
}))))));
|
|
3413
3477
|
};
|
|
3414
3478
|
|
|
3415
|
-
export {
|
|
3479
|
+
export { Widget };
|
|
3416
3480
|
//# sourceMappingURL=widget-embedded.esm.js.map
|