@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
|
@@ -14,10 +14,10 @@ var reactRouterDom = require('react-router-dom');
|
|
|
14
14
|
var zustand = require('zustand');
|
|
15
15
|
var BigNumber = require('bignumber.js');
|
|
16
16
|
var BigNumber__default = _interopDefault(BigNumber);
|
|
17
|
-
var walletsShared = require('@rango-dev/wallets-shared');
|
|
18
|
-
var walletsCore = require('@rango-dev/wallets-core');
|
|
19
17
|
var middleware = require('zustand/middleware');
|
|
20
18
|
var rangoSdk = require('rango-sdk');
|
|
19
|
+
var walletsShared = require('@rango-dev/wallets-shared');
|
|
20
|
+
var walletsCore = require('@rango-dev/wallets-core');
|
|
21
21
|
var shallow = require('zustand/shallow');
|
|
22
22
|
var reactI18next = require('react-i18next');
|
|
23
23
|
var theme = require('@rango-dev/ui/src/theme');
|
|
@@ -126,6 +126,206 @@ const decimalNumber = function (number, toFixed) {
|
|
|
126
126
|
}
|
|
127
127
|
return parseFloat(number).toFixed(toFixed);
|
|
128
128
|
};
|
|
129
|
+
const isPositiveNumber = text => !!text && parseFloat(text) > 0;
|
|
130
|
+
|
|
131
|
+
function searchParamsToToken(tokens, searchParams, chain) {
|
|
132
|
+
if (!chain) return null;
|
|
133
|
+
return tokens.find(token => {
|
|
134
|
+
const symbolAndAddress = searchParams?.split('--');
|
|
135
|
+
if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
|
|
136
|
+
return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
|
|
137
|
+
}) || null;
|
|
138
|
+
}
|
|
139
|
+
function getBestRouteToTokenUsdPrice(bestRoute) {
|
|
140
|
+
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
141
|
+
}
|
|
142
|
+
function isNumberOfSwapsChanged(route1, route2) {
|
|
143
|
+
const route1Swaps = route1.result?.swaps || [];
|
|
144
|
+
const route2Swaps = route2.result?.swaps || [];
|
|
145
|
+
return route1Swaps.length !== route2Swaps.length;
|
|
146
|
+
}
|
|
147
|
+
function isRouteSwappersUpdated(route1, route2) {
|
|
148
|
+
const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
|
|
149
|
+
const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
|
|
150
|
+
return !areEqual(route1Swappers, route2Swappers);
|
|
151
|
+
}
|
|
152
|
+
function isRouteInternalCoinsUpdated(route1, route2) {
|
|
153
|
+
const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
154
|
+
const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
155
|
+
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
156
|
+
}
|
|
157
|
+
function isRouteChanged(route1, route2) {
|
|
158
|
+
return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
|
|
159
|
+
}
|
|
160
|
+
function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
161
|
+
if (fee === null) return null;
|
|
162
|
+
const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
|
|
163
|
+
if (!relatedFeeStatus) return null;
|
|
164
|
+
return relatedFeeStatus.requiredAssets;
|
|
165
|
+
}
|
|
166
|
+
function isRouteParametersChanged(params) {
|
|
167
|
+
if (params.store === 'bestRoute') {
|
|
168
|
+
const {
|
|
169
|
+
prevState,
|
|
170
|
+
currentState
|
|
171
|
+
} = params;
|
|
172
|
+
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);
|
|
173
|
+
} else if (params.store === 'settings') {
|
|
174
|
+
const {
|
|
175
|
+
prevState,
|
|
176
|
+
currentState
|
|
177
|
+
} = params;
|
|
178
|
+
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
function getFormatedBestRoute(bestRoute) {
|
|
183
|
+
if (!bestRoute) return null;
|
|
184
|
+
const formatedSwaps = (bestRoute.result?.swaps || []).map(swap => ({
|
|
185
|
+
...swap,
|
|
186
|
+
fromAmount: numberToString(swap.fromAmount, 6, 6),
|
|
187
|
+
toAmount: numberToString(swap.toAmount, 6, 6)
|
|
188
|
+
}));
|
|
189
|
+
return {
|
|
190
|
+
...bestRoute,
|
|
191
|
+
...(bestRoute.result && {
|
|
192
|
+
result: {
|
|
193
|
+
...bestRoute.result,
|
|
194
|
+
swaps: formatedSwaps
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function getFormatedPendingSwap(pendingSwap) {
|
|
200
|
+
const formatedSteps = pendingSwap.steps.map(step => ({
|
|
201
|
+
...step,
|
|
202
|
+
feeInUsd: numberToString(step.feeInUsd, 4, 4),
|
|
203
|
+
outputAmount: numberToString(step.outputAmount, 6, 6),
|
|
204
|
+
expectedOutputAmountHumanReadable: numberToString(step.expectedOutputAmountHumanReadable, 6, 6)
|
|
205
|
+
}));
|
|
206
|
+
return {
|
|
207
|
+
...pendingSwap,
|
|
208
|
+
inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
|
|
209
|
+
steps: formatedSteps
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
//todo: refactor bestRoute store and add loadingStatus
|
|
213
|
+
const getBestRouteStatus = (loading, error) => {
|
|
214
|
+
if (loading) return 'loading';
|
|
215
|
+
if (error) return 'failed';else return 'success';
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const createSelectors = _store => {
|
|
219
|
+
let store = _store;
|
|
220
|
+
store.use = {};
|
|
221
|
+
for (let k of Object.keys(store.getState())) {
|
|
222
|
+
store.use[k] = () => store(s => s[k]);
|
|
223
|
+
}
|
|
224
|
+
return store;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
228
|
+
let configs = {
|
|
229
|
+
API_KEY: RANGO_PUBLIC_API_KEY
|
|
230
|
+
};
|
|
231
|
+
function getConfig(name) {
|
|
232
|
+
return configs[name];
|
|
233
|
+
}
|
|
234
|
+
function initConfig(nextConfigs) {
|
|
235
|
+
let clonedConfigs;
|
|
236
|
+
if (typeof structuredClone === 'function') {
|
|
237
|
+
clonedConfigs = structuredClone(nextConfigs);
|
|
238
|
+
} else {
|
|
239
|
+
clonedConfigs = JSON.parse(JSON.stringify(nextConfigs));
|
|
240
|
+
}
|
|
241
|
+
configs = clonedConfigs;
|
|
242
|
+
return configs;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let rango = undefined;
|
|
246
|
+
const httpService = () => {
|
|
247
|
+
if (rango) return rango;
|
|
248
|
+
rango = new rangoSdk.RangoClient(getConfig('API_KEY'));
|
|
249
|
+
return rango;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
253
|
+
const DEFAULT_SLIPPAGE = 1;
|
|
254
|
+
const HIGH_SLIPPAGE = 5;
|
|
255
|
+
const MAX_SLIPPAGE = 100;
|
|
256
|
+
const MIN_SLIPPGAE = 0;
|
|
257
|
+
|
|
258
|
+
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
|
|
259
|
+
meta: {
|
|
260
|
+
blockchains: [],
|
|
261
|
+
popularTokens: [],
|
|
262
|
+
swappers: [],
|
|
263
|
+
tokens: []
|
|
264
|
+
},
|
|
265
|
+
loadingStatus: 'loading',
|
|
266
|
+
fetchMeta: async () => {
|
|
267
|
+
try {
|
|
268
|
+
const response = await httpService().getAllMetadata();
|
|
269
|
+
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
270
|
+
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
271
|
+
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
272
|
+
set({
|
|
273
|
+
meta: response,
|
|
274
|
+
loadingStatus: 'success'
|
|
275
|
+
});
|
|
276
|
+
} catch (error) {
|
|
277
|
+
set({
|
|
278
|
+
loadingStatus: 'failed'
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
})));
|
|
283
|
+
|
|
284
|
+
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.persist( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
285
|
+
slippage: DEFAULT_SLIPPAGE,
|
|
286
|
+
customSlippage: null,
|
|
287
|
+
infiniteApprove: false,
|
|
288
|
+
affiliateRef: null,
|
|
289
|
+
disabledLiquiditySources: [],
|
|
290
|
+
theme: 'auto',
|
|
291
|
+
setSlippage: slippage => set(() => ({
|
|
292
|
+
slippage: slippage
|
|
293
|
+
})),
|
|
294
|
+
setCustomSlippage: customSlippage => set(() => ({
|
|
295
|
+
customSlippage: customSlippage
|
|
296
|
+
})),
|
|
297
|
+
setAffiliateRef: affiliateRef => set(() => ({
|
|
298
|
+
affiliateRef
|
|
299
|
+
})),
|
|
300
|
+
toggleAllLiquiditySources: () => set(state => {
|
|
301
|
+
const {
|
|
302
|
+
swappers
|
|
303
|
+
} = useMetaStore.getState().meta;
|
|
304
|
+
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
305
|
+
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
306
|
+
disabledLiquiditySources: []
|
|
307
|
+
};else {
|
|
308
|
+
return {
|
|
309
|
+
disabledLiquiditySources: swappersGroup
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
}),
|
|
313
|
+
toggleInfiniteApprove: () => set(state => ({
|
|
314
|
+
infiniteApprove: !state.infiniteApprove
|
|
315
|
+
})),
|
|
316
|
+
toggleLiquiditySource: name => set(state => {
|
|
317
|
+
if (state.disabledLiquiditySources.includes(name)) return {
|
|
318
|
+
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
319
|
+
};else return {
|
|
320
|
+
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
321
|
+
};
|
|
322
|
+
}),
|
|
323
|
+
setTheme: theme => set(() => ({
|
|
324
|
+
theme
|
|
325
|
+
}))
|
|
326
|
+
})), {
|
|
327
|
+
name: 'user-settings'
|
|
328
|
+
})));
|
|
129
329
|
|
|
130
330
|
function getStateWallet(state) {
|
|
131
331
|
switch (true) {
|
|
@@ -430,7 +630,7 @@ function LimitErrorMessage(bestRoute) {
|
|
|
430
630
|
recommendation
|
|
431
631
|
};
|
|
432
632
|
}
|
|
433
|
-
function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath,
|
|
633
|
+
function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount) {
|
|
434
634
|
if (loadingMetaStatus !== 'success') return {
|
|
435
635
|
title: 'Connect Wallet',
|
|
436
636
|
disabled: true
|
|
@@ -442,7 +642,7 @@ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, has
|
|
|
442
642
|
if (loading) return {
|
|
443
643
|
title: 'Finding Best Route...',
|
|
444
644
|
disabled: true
|
|
445
|
-
};else if (
|
|
645
|
+
};else if (!inputAmount || inputAmount === '0') return {
|
|
446
646
|
title: 'Enter an amount',
|
|
447
647
|
disabled: true
|
|
448
648
|
};else if (!bestRoute || !bestRoute.result) return {
|
|
@@ -511,7 +711,7 @@ function hasProperSlippage(userSlippage, minRequiredSlippage) {
|
|
|
511
711
|
if (!minRequiredSlippage) return true;
|
|
512
712
|
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
513
713
|
}
|
|
514
|
-
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage,
|
|
714
|
+
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, affiliateRef, initialRoute) {
|
|
515
715
|
const selectedWalletsMap = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = selectedWallet.address, selectedWalletsMap), {});
|
|
516
716
|
const connectedWallets = [];
|
|
517
717
|
wallets.forEach(wallet => {
|
|
@@ -521,7 +721,8 @@ function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, se
|
|
|
521
721
|
addresses: [wallet.address]
|
|
522
722
|
});
|
|
523
723
|
});
|
|
524
|
-
const
|
|
724
|
+
const checkPrerequisites = !!initialRoute;
|
|
725
|
+
const filteredBlockchains = removeDuplicateFrom((initialRoute?.result?.swaps || []).reduce((blockchains, swap) => (blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains), []));
|
|
525
726
|
const requestBody = {
|
|
526
727
|
amount: inputAmount.toString(),
|
|
527
728
|
affiliateRef,
|
|
@@ -645,155 +846,6 @@ function shouldRetrySwap(pendingSwap) {
|
|
|
645
846
|
return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
|
|
646
847
|
}
|
|
647
848
|
|
|
648
|
-
function searchParamsToToken(tokens, searchParams, chain) {
|
|
649
|
-
if (!chain) return null;
|
|
650
|
-
return tokens.find(token => {
|
|
651
|
-
const symbolAndAddress = searchParams?.split('--');
|
|
652
|
-
if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
|
|
653
|
-
return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
|
|
654
|
-
}) || null;
|
|
655
|
-
}
|
|
656
|
-
function getBestRouteToTokenUsdPrice(bestRoute) {
|
|
657
|
-
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
658
|
-
}
|
|
659
|
-
function isNumberOfSwapsChanged(route1, route2) {
|
|
660
|
-
const route1Swaps = route1.result?.swaps || [];
|
|
661
|
-
const route2Swaps = route2.result?.swaps || [];
|
|
662
|
-
return route1Swaps.length !== route2Swaps.length;
|
|
663
|
-
}
|
|
664
|
-
function isRouteSwappersUpdated(route1, route2) {
|
|
665
|
-
const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
|
|
666
|
-
const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
|
|
667
|
-
return !areEqual(route1Swappers, route2Swappers);
|
|
668
|
-
}
|
|
669
|
-
function isRouteInternalCoinsUpdated(route1, route2) {
|
|
670
|
-
const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
671
|
-
const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
672
|
-
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
673
|
-
}
|
|
674
|
-
function isRouteChanged(route1, route2) {
|
|
675
|
-
return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
|
|
676
|
-
}
|
|
677
|
-
function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
678
|
-
if (fee === null) return null;
|
|
679
|
-
const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
|
|
680
|
-
if (!relatedFeeStatus) return null;
|
|
681
|
-
return relatedFeeStatus.requiredAssets;
|
|
682
|
-
}
|
|
683
|
-
function isRouteParametersChanged(params) {
|
|
684
|
-
if (params.store === 'bestRoute') {
|
|
685
|
-
const {
|
|
686
|
-
prevState,
|
|
687
|
-
currentState
|
|
688
|
-
} = params;
|
|
689
|
-
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);
|
|
690
|
-
} else if (params.store === 'settings') {
|
|
691
|
-
const {
|
|
692
|
-
prevState,
|
|
693
|
-
currentState
|
|
694
|
-
} = params;
|
|
695
|
-
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
696
|
-
}
|
|
697
|
-
return false;
|
|
698
|
-
}
|
|
699
|
-
//todo: refactor bestRoute store and add loadingStatus
|
|
700
|
-
const getBestRouteStatus = (loading, error) => {
|
|
701
|
-
if (loading) return 'loading';
|
|
702
|
-
if (error) return 'failed';else return 'success';
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
const createSelectors = _store => {
|
|
706
|
-
let store = _store;
|
|
707
|
-
store.use = {};
|
|
708
|
-
for (let k of Object.keys(store.getState())) {
|
|
709
|
-
store.use[k] = () => store(s => s[k]);
|
|
710
|
-
}
|
|
711
|
-
return store;
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
// this API key is limited and
|
|
715
|
-
// it is only for test purpose
|
|
716
|
-
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
717
|
-
const httpService = /*#__PURE__*/new rangoSdk.RangoClient(process.env.REACT_APP_API_KEY || RANGO_PUBLIC_API_KEY);
|
|
718
|
-
|
|
719
|
-
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
720
|
-
const DEFAULT_SLIPPAGE = 1;
|
|
721
|
-
const HIGH_SLIPPAGE = 5;
|
|
722
|
-
const MAX_SLIPPAGE = 100;
|
|
723
|
-
const MIN_SLIPPGAE = 0;
|
|
724
|
-
|
|
725
|
-
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
|
|
726
|
-
meta: {
|
|
727
|
-
blockchains: [],
|
|
728
|
-
popularTokens: [],
|
|
729
|
-
swappers: [],
|
|
730
|
-
tokens: []
|
|
731
|
-
},
|
|
732
|
-
loadingStatus: 'loading',
|
|
733
|
-
fetchMeta: async () => {
|
|
734
|
-
try {
|
|
735
|
-
const response = await httpService.getAllMetadata();
|
|
736
|
-
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
737
|
-
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
738
|
-
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
739
|
-
set({
|
|
740
|
-
meta: response,
|
|
741
|
-
loadingStatus: 'success'
|
|
742
|
-
});
|
|
743
|
-
} catch (error) {
|
|
744
|
-
set({
|
|
745
|
-
loadingStatus: 'failed'
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
})));
|
|
750
|
-
|
|
751
|
-
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.persist( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
752
|
-
slippage: DEFAULT_SLIPPAGE,
|
|
753
|
-
customSlippage: null,
|
|
754
|
-
infiniteApprove: false,
|
|
755
|
-
affiliateRef: null,
|
|
756
|
-
disabledLiquiditySources: [],
|
|
757
|
-
theme: 'auto',
|
|
758
|
-
setSlippage: slippage => set(() => ({
|
|
759
|
-
slippage: slippage
|
|
760
|
-
})),
|
|
761
|
-
setCustomSlippage: customSlippage => set(() => ({
|
|
762
|
-
customSlippage: customSlippage
|
|
763
|
-
})),
|
|
764
|
-
setAffiliateRef: affiliateRef => set(() => ({
|
|
765
|
-
affiliateRef
|
|
766
|
-
})),
|
|
767
|
-
toggleAllLiquiditySources: () => set(state => {
|
|
768
|
-
const {
|
|
769
|
-
swappers
|
|
770
|
-
} = useMetaStore.getState().meta;
|
|
771
|
-
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
772
|
-
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
773
|
-
disabledLiquiditySources: []
|
|
774
|
-
};else {
|
|
775
|
-
return {
|
|
776
|
-
disabledLiquiditySources: swappersGroup
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
}),
|
|
780
|
-
toggleInfiniteApprove: () => set(state => ({
|
|
781
|
-
infiniteApprove: !state.infiniteApprove
|
|
782
|
-
})),
|
|
783
|
-
toggleLiquiditySource: name => set(state => {
|
|
784
|
-
if (state.disabledLiquiditySources.includes(name)) return {
|
|
785
|
-
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
786
|
-
};else return {
|
|
787
|
-
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
788
|
-
};
|
|
789
|
-
}),
|
|
790
|
-
setTheme: theme => set(() => ({
|
|
791
|
-
theme
|
|
792
|
-
}))
|
|
793
|
-
})), {
|
|
794
|
-
name: 'user-settings'
|
|
795
|
-
})));
|
|
796
|
-
|
|
797
849
|
const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
798
850
|
accounts: [],
|
|
799
851
|
balances: [],
|
|
@@ -814,7 +866,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.creat
|
|
|
814
866
|
}));
|
|
815
867
|
accounts.forEach(async account => {
|
|
816
868
|
try {
|
|
817
|
-
const response = await httpService.getWalletsDetails([{
|
|
869
|
+
const response = await httpService().getWalletsDetails([{
|
|
818
870
|
address: account.address,
|
|
819
871
|
blockchain: account.chain
|
|
820
872
|
}]);
|
|
@@ -858,7 +910,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.creat
|
|
|
858
910
|
}
|
|
859
911
|
});
|
|
860
912
|
return {
|
|
861
|
-
selectedWallets: selectedWallets
|
|
913
|
+
selectedWallets: state.selectedWallets.concat(selectedWallets)
|
|
862
914
|
};
|
|
863
915
|
}),
|
|
864
916
|
setSelectedWallet: wallet => set(state => ({
|
|
@@ -910,7 +962,7 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.cre
|
|
|
910
962
|
setBestRoute: bestRoute => set(state => {
|
|
911
963
|
let outputAmount = null;
|
|
912
964
|
let outputUsdValue = ZERO;
|
|
913
|
-
if (!state.inputAmount
|
|
965
|
+
if (!isPositiveNumber(state.inputAmount)) return {};
|
|
914
966
|
if (!!bestRoute) {
|
|
915
967
|
outputAmount = !!bestRoute.result?.outputAmount ? new BigNumber__default(bestRoute.result?.outputAmount) : null;
|
|
916
968
|
outputUsdValue = calcOutputUsdValue(bestRoute.result?.outputAmount, getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice);
|
|
@@ -1045,18 +1097,18 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1045
1097
|
disabledLiquiditySources,
|
|
1046
1098
|
affiliateRef
|
|
1047
1099
|
} = settingsStore.getState();
|
|
1048
|
-
if (!fromToken || !toToken || !inputAmount
|
|
1100
|
+
if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
|
|
1049
1101
|
abortController?.abort();
|
|
1050
1102
|
abortController = new AbortController();
|
|
1051
1103
|
const userSlippage = !!customSlippage ? customSlippage : slippage;
|
|
1052
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage,
|
|
1104
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
|
|
1053
1105
|
if (!bestRouteStore.getState().loading) bestRouteStore.setState({
|
|
1054
1106
|
loading: true,
|
|
1055
1107
|
bestRoute: null,
|
|
1056
1108
|
outputAmount: null,
|
|
1057
1109
|
outputUsdValue: new BigNumber__default(0)
|
|
1058
1110
|
});
|
|
1059
|
-
httpService.getBestRoute(requestBody, {
|
|
1111
|
+
httpService().getBestRoute(requestBody, {
|
|
1060
1112
|
signal: abortController.signal
|
|
1061
1113
|
}).then(res => {
|
|
1062
1114
|
const {
|
|
@@ -1083,7 +1135,9 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1083
1135
|
inputAmount,
|
|
1084
1136
|
inputUsdValue
|
|
1085
1137
|
} = useBestRouteStore.getState();
|
|
1086
|
-
if (!inputAmount ||
|
|
1138
|
+
if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0)) return bestRouteStore.setState({
|
|
1139
|
+
loading: false
|
|
1140
|
+
});
|
|
1087
1141
|
if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
|
|
1088
1142
|
loading: false,
|
|
1089
1143
|
bestRoute: null,
|
|
@@ -1396,6 +1450,7 @@ function TokenInfo(props) {
|
|
|
1396
1450
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
1397
1451
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
1398
1452
|
const balances = useWalletsStore.use.balances();
|
|
1453
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
1399
1454
|
const navigate = reactRouterDom.useNavigate();
|
|
1400
1455
|
const {
|
|
1401
1456
|
t
|
|
@@ -1499,12 +1554,13 @@ function TokenInfo(props) {
|
|
|
1499
1554
|
color: "neutrals800"
|
|
1500
1555
|
}, `$${numberToString(inputUsdValue)}`)),
|
|
1501
1556
|
value: props.inputAmount || '',
|
|
1557
|
+
min: 0,
|
|
1502
1558
|
onChange: props.type === 'From' ? event => {
|
|
1503
1559
|
props.onAmountChange(event.target.value);
|
|
1504
1560
|
} : undefined
|
|
1505
1561
|
}) : React__default.createElement(OutputContainer, null, React__default.createElement(ui.Typography, {
|
|
1506
1562
|
variant: "h4"
|
|
1507
|
-
},
|
|
1563
|
+
}, fetchingBestRoute && '?', !!bestRoute?.result && `≈ ${numberToString(props.outputAmount)}`, (!inputAmount || inputAmount === '0') && '0'))))));
|
|
1508
1564
|
}
|
|
1509
1565
|
|
|
1510
1566
|
const Container$1 = /*#__PURE__*/theme.styled('div', {
|
|
@@ -1688,8 +1744,7 @@ function Home() {
|
|
|
1688
1744
|
swap
|
|
1689
1745
|
} = LimitErrorMessage(bestRoute);
|
|
1690
1746
|
const priceImpactCanNotBeComputed = !canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue);
|
|
1691
|
-
const
|
|
1692
|
-
const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputIsZero);
|
|
1747
|
+
const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount);
|
|
1693
1748
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
1694
1749
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
1695
1750
|
React.useEffect(() => {
|
|
@@ -1726,7 +1781,7 @@ function Home() {
|
|
|
1726
1781
|
}), showBestRoute && React__default.createElement(BestRouteContainer, null, React__default.createElement(ui.BestRoute, {
|
|
1727
1782
|
error: bestRouteError,
|
|
1728
1783
|
loading: fetchingBestRoute,
|
|
1729
|
-
data: bestRoute,
|
|
1784
|
+
data: getFormatedBestRoute(bestRoute),
|
|
1730
1785
|
totalFee: numberToString(totalFeeInUsd, 0, 2),
|
|
1731
1786
|
feeWarning: highFee,
|
|
1732
1787
|
totalTime: secondsToString(totalArrivalTime(bestRoute))
|
|
@@ -1737,9 +1792,7 @@ function Home() {
|
|
|
1737
1792
|
title: `${swap?.swapperId} Limit`
|
|
1738
1793
|
}, React__default.createElement(React__default.Fragment, null, React__default.createElement(ui.Typography, {
|
|
1739
1794
|
variant: "body2"
|
|
1740
|
-
}, fromAmountRangeError
|
|
1741
|
-
variant: "body2"
|
|
1742
|
-
}, "Yours: ", numberToString(swap?.fromAmount || null), swap?.from.symbol), React__default.createElement("br", null), React__default.createElement(ui.Typography, {
|
|
1795
|
+
}, `${fromAmountRangeError}, Yours: ${numberToString(swap?.fromAmount || null)} ${swap?.from.symbol}`), React__default.createElement(ui.Typography, {
|
|
1743
1796
|
variant: "body2"
|
|
1744
1797
|
}, recommendation)))), React__default.createElement(Footer, null, React__default.createElement(ui.Button, {
|
|
1745
1798
|
type: "primary",
|
|
@@ -1994,6 +2047,7 @@ var ConfirmSwapErrorTypes;
|
|
|
1994
2047
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS"] = 1] = "ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS";
|
|
1995
2048
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["REQUEST_FAILED"] = 2] = "REQUEST_FAILED";
|
|
1996
2049
|
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_SLIPPAGE"] = 3] = "INSUFFICIENT_SLIPPAGE";
|
|
2050
|
+
ConfirmSwapErrorTypes[ConfirmSwapErrorTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
1997
2051
|
})(ConfirmSwapErrorTypes || (ConfirmSwapErrorTypes = {}));
|
|
1998
2052
|
var ConfirmSwapWarningTypes;
|
|
1999
2053
|
(function (ConfirmSwapWarningTypes) {
|
|
@@ -2001,7 +2055,6 @@ var ConfirmSwapWarningTypes;
|
|
|
2001
2055
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_SWAPPERS_UPDATED"] = 1] = "ROUTE_SWAPPERS_UPDATED";
|
|
2002
2056
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_COINS_UPDATED"] = 2] = "ROUTE_COINS_UPDATED";
|
|
2003
2057
|
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["ROUTE_AND_OUTPUT_AMOUNT_UPDATED"] = 3] = "ROUTE_AND_OUTPUT_AMOUNT_UPDATED";
|
|
2004
|
-
ConfirmSwapWarningTypes[ConfirmSwapWarningTypes["INSUFFICIENT_BALANCE"] = 4] = "INSUFFICIENT_BALANCE";
|
|
2005
2058
|
})(ConfirmSwapWarningTypes || (ConfirmSwapWarningTypes = {}));
|
|
2006
2059
|
|
|
2007
2060
|
function useConfirmSwap() {
|
|
@@ -2051,9 +2104,9 @@ function useConfirmSwap() {
|
|
|
2051
2104
|
}
|
|
2052
2105
|
abortControllerRef.current = new AbortController();
|
|
2053
2106
|
setLoading(true);
|
|
2054
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage,
|
|
2107
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, affiliateRef, initialRoute);
|
|
2055
2108
|
try {
|
|
2056
|
-
const confiremedRoute = await httpService.getBestRoute(requestBody, {
|
|
2109
|
+
const confiremedRoute = await httpService().getBestRoute(requestBody, {
|
|
2057
2110
|
signal: abortControllerRef.current?.signal
|
|
2058
2111
|
});
|
|
2059
2112
|
abortControllerRef.current = null;
|
|
@@ -2090,8 +2143,8 @@ function useConfirmSwap() {
|
|
|
2090
2143
|
}
|
|
2091
2144
|
const balanceWarnings = getBalanceWarnings(confiremedRoute, selectedWallets);
|
|
2092
2145
|
const enoughBalance = balanceWarnings.length === 0;
|
|
2093
|
-
if (!enoughBalance) confirmSwapState.
|
|
2094
|
-
type:
|
|
2146
|
+
if (!enoughBalance) confirmSwapState.errors.push({
|
|
2147
|
+
type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
|
|
2095
2148
|
messages: balanceWarnings
|
|
2096
2149
|
});
|
|
2097
2150
|
const minRequiredSlippage = getMinRequiredSlippage(initialRoute);
|
|
@@ -2161,31 +2214,6 @@ function MinRequiredSlippage(_ref) {
|
|
|
2161
2214
|
}), React__default.createElement(ChangeSlippageButton, null));
|
|
2162
2215
|
}
|
|
2163
2216
|
|
|
2164
|
-
function ConfirmSwapErrors(errors) {
|
|
2165
|
-
return errors.flatMap(error => {
|
|
2166
|
-
switch (error.type) {
|
|
2167
|
-
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
2168
|
-
return React__default.createElement(ui.Typography, {
|
|
2169
|
-
variant: "body2"
|
|
2170
|
-
}, "No routes found. Please try again later.");
|
|
2171
|
-
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
2172
|
-
return React__default.createElement(ui.Typography, {
|
|
2173
|
-
variant: "body2"
|
|
2174
|
-
}, `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`);
|
|
2175
|
-
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
2176
|
-
return React__default.createElement(ui.Typography, {
|
|
2177
|
-
variant: "body2"
|
|
2178
|
-
}, "Route updated and price impact is too high, try again later!");
|
|
2179
|
-
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
2180
|
-
return React__default.createElement(MinRequiredSlippage, {
|
|
2181
|
-
minRequiredSlippage: error.minRequiredSlippage
|
|
2182
|
-
});
|
|
2183
|
-
default:
|
|
2184
|
-
return [];
|
|
2185
|
-
}
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
2217
|
const List = /*#__PURE__*/ui.styled('ul', {
|
|
2190
2218
|
variants: {
|
|
2191
2219
|
showListStyle: {
|
|
@@ -2206,47 +2234,63 @@ const ListItem = /*#__PURE__*/ui.styled('li', {
|
|
|
2206
2234
|
}
|
|
2207
2235
|
});
|
|
2208
2236
|
const Message = /*#__PURE__*/ui.styled(ui.Typography, {
|
|
2209
|
-
display: 'block'
|
|
2210
|
-
color: '$warning500 !important'
|
|
2237
|
+
display: 'block'
|
|
2211
2238
|
});
|
|
2212
|
-
function
|
|
2239
|
+
function BalanceErrors(_ref) {
|
|
2213
2240
|
let {
|
|
2214
2241
|
messages
|
|
2215
2242
|
} = _ref;
|
|
2216
2243
|
const showListStyle = messages.length > 1;
|
|
2217
|
-
return React__default.createElement(
|
|
2244
|
+
return React__default.createElement(React__default.Fragment, null, React__default.createElement(ui.Typography, {
|
|
2245
|
+
className: "title",
|
|
2246
|
+
variant: "title",
|
|
2247
|
+
color: 'error'
|
|
2248
|
+
}, "Insufficent Balance:"), React__default.createElement(ui.Spacer, {
|
|
2249
|
+
size: 8,
|
|
2250
|
+
direction: "vertical"
|
|
2251
|
+
}), React__default.createElement(List, {
|
|
2218
2252
|
showListStyle: showListStyle
|
|
2219
2253
|
}, messages.map(warning => React__default.createElement(ListItem, {
|
|
2220
2254
|
showListStyle: showListStyle
|
|
2221
2255
|
}, React__default.createElement(Message, {
|
|
2222
2256
|
variant: "body2"
|
|
2223
|
-
}, warning))));
|
|
2257
|
+
}, warning)))));
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
function ConfirmSwapErrors(errors) {
|
|
2261
|
+
return errors.flatMap(error => {
|
|
2262
|
+
switch (error.type) {
|
|
2263
|
+
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
2264
|
+
return 'No routes found. Please try again later.';
|
|
2265
|
+
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
2266
|
+
return `Failed to confirm swap ${error.status ? `'status': ${error.status})` : ''}, please try again.`;
|
|
2267
|
+
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
2268
|
+
return 'Route updated and price impact is too high, try again later!';
|
|
2269
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
2270
|
+
return React__default.createElement(MinRequiredSlippage, {
|
|
2271
|
+
minRequiredSlippage: error.minRequiredSlippage
|
|
2272
|
+
});
|
|
2273
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
|
|
2274
|
+
return React__default.createElement(BalanceErrors, {
|
|
2275
|
+
messages: error.messages
|
|
2276
|
+
});
|
|
2277
|
+
default:
|
|
2278
|
+
return [];
|
|
2279
|
+
}
|
|
2280
|
+
});
|
|
2224
2281
|
}
|
|
2225
2282
|
|
|
2226
2283
|
function ConfirmSwapWarnings(warnings) {
|
|
2227
2284
|
return warnings.flatMap(warning => {
|
|
2228
2285
|
switch (warning.type) {
|
|
2229
2286
|
case ConfirmSwapWarningTypes.ROUTE_UPDATED:
|
|
2230
|
-
return
|
|
2231
|
-
variant: "body2"
|
|
2232
|
-
}, "Route has been updated.");
|
|
2287
|
+
return "Route has been updated.";
|
|
2233
2288
|
case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
2234
|
-
return
|
|
2235
|
-
variant: "body2"
|
|
2236
|
-
}, `Output amount changed to ${warning.newOutputAmount}
|
|
2237
|
-
(${warning.percentageChange}% change).`);
|
|
2289
|
+
return `Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`;
|
|
2238
2290
|
case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
|
|
2239
|
-
return
|
|
2240
|
-
variant: "body2"
|
|
2241
|
-
}, "Route swappers has been updated.");
|
|
2291
|
+
return "Route swappers has been updated.";
|
|
2242
2292
|
case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
|
|
2243
|
-
return
|
|
2244
|
-
variant: "body2"
|
|
2245
|
-
}, "Route internal coins has been updated.");
|
|
2246
|
-
case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
|
|
2247
|
-
return React__default.createElement(BalanceWarnings, {
|
|
2248
|
-
messages: warning.messages
|
|
2249
|
-
});
|
|
2293
|
+
return "Route internal coins has been updated.";
|
|
2250
2294
|
default:
|
|
2251
2295
|
return [];
|
|
2252
2296
|
}
|
|
@@ -2294,6 +2338,7 @@ function ConfirmSwapPage() {
|
|
|
2294
2338
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
2295
2339
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2296
2340
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
2341
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2297
2342
|
const bestRouteloadingStatus = getBestRouteStatus(fetchingBestRoute, !!fetchingBestRouteError);
|
|
2298
2343
|
const {
|
|
2299
2344
|
manager
|
|
@@ -2324,10 +2369,7 @@ function ConfirmSwapPage() {
|
|
|
2324
2369
|
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
|
|
2325
2370
|
};
|
|
2326
2371
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
2327
|
-
return React__default.createElement(ui.ConfirmSwap
|
|
2328
|
-
// @ts-ignore
|
|
2329
|
-
, {
|
|
2330
|
-
// @ts-ignore
|
|
2372
|
+
return React__default.createElement(ui.ConfirmSwap, {
|
|
2331
2373
|
requiredWallets: getRequiredChains(bestRoute),
|
|
2332
2374
|
selectableWallets: selectableWallets,
|
|
2333
2375
|
onBack: navigateBackFrom.bind(null, navigationRoutes.confirmSwap),
|
|
@@ -2336,15 +2378,16 @@ function ConfirmSwapPage() {
|
|
|
2336
2378
|
if (swap) {
|
|
2337
2379
|
manager?.create('swap', {
|
|
2338
2380
|
swapDetails: swap
|
|
2339
|
-
},
|
|
2340
|
-
// @ts-ignore
|
|
2341
|
-
{
|
|
2381
|
+
}, {
|
|
2342
2382
|
id: swap.requestId
|
|
2343
2383
|
});
|
|
2344
2384
|
setSelectedSwap(swap.requestId);
|
|
2345
2385
|
navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
2346
2386
|
replace: true
|
|
2347
2387
|
});
|
|
2388
|
+
setTimeout(() => {
|
|
2389
|
+
setInputAmount('');
|
|
2390
|
+
}, 0);
|
|
2348
2391
|
}
|
|
2349
2392
|
});
|
|
2350
2393
|
},
|
|
@@ -2454,9 +2497,11 @@ function HistoryPage() {
|
|
|
2454
2497
|
} = _ref;
|
|
2455
2498
|
return swap;
|
|
2456
2499
|
});
|
|
2500
|
+
const loading = !manager?.isLoaded();
|
|
2457
2501
|
return React__default.createElement(ui.History, {
|
|
2458
2502
|
list: pendingSwaps,
|
|
2459
2503
|
groupBy: groupSwapsByDate,
|
|
2504
|
+
loading: loading,
|
|
2460
2505
|
onSwapClick: requestId => {
|
|
2461
2506
|
setSelectedSwap(requestId);
|
|
2462
2507
|
navigate(navigationRoutes.swaps + `/${requestId}`, {
|
|
@@ -2695,8 +2740,9 @@ function WalletsPage(_ref) {
|
|
|
2695
2740
|
textField: false,
|
|
2696
2741
|
onBack: navigateBackFrom.bind(null, navigationRoutes.wallets)
|
|
2697
2742
|
}, React__default.createElement(React__default.Fragment, null, walletErrorMessage && React__default.createElement(AlertContainer, null, React__default.createElement(ui.Alert, {
|
|
2698
|
-
type: "error"
|
|
2699
|
-
|
|
2743
|
+
type: "error",
|
|
2744
|
+
title: walletErrorMessage
|
|
2745
|
+
})), loadingMetaStatus === 'loading' && React__default.createElement(LoaderContainer, {
|
|
2700
2746
|
className: "loader"
|
|
2701
2747
|
}, React__default.createElement(ui.Spinner, {
|
|
2702
2748
|
size: 24
|
|
@@ -2760,12 +2806,19 @@ function timeSince(timeMillis) {
|
|
|
2760
2806
|
return interval + ' ' + intervalType;
|
|
2761
2807
|
}
|
|
2762
2808
|
function getSwapDate(pendingSwap) {
|
|
2763
|
-
return pendingSwap.finishTime ?
|
|
2809
|
+
return pendingSwap.finishTime ? `${timeSince(parseInt(pendingSwap.finishTime))} ago` : `${timeSince(parseInt(pendingSwap.creationTime))} ago`;
|
|
2764
2810
|
}
|
|
2765
2811
|
|
|
2766
2812
|
const PlaceholderContainer = /*#__PURE__*/ui.styled('div', {
|
|
2767
2813
|
height: '450px'
|
|
2768
2814
|
});
|
|
2815
|
+
const LoaderContainer$1 = /*#__PURE__*/ui.styled('div', {
|
|
2816
|
+
display: 'flex',
|
|
2817
|
+
justifyContent: 'center',
|
|
2818
|
+
width: '100%',
|
|
2819
|
+
paddingTop: '33%',
|
|
2820
|
+
flex: 1
|
|
2821
|
+
});
|
|
2769
2822
|
function SwapDetailsPlaceholder(props) {
|
|
2770
2823
|
const {
|
|
2771
2824
|
requestId,
|
|
@@ -2776,7 +2829,7 @@ function SwapDetailsPlaceholder(props) {
|
|
|
2776
2829
|
title: "Swap Details",
|
|
2777
2830
|
textField: false,
|
|
2778
2831
|
onBack: onBack
|
|
2779
|
-
}, React__default.createElement(PlaceholderContainer, null, loading ? React__default.createElement(LoaderContainer, null, React__default.createElement(ui.Spinner, {
|
|
2832
|
+
}, React__default.createElement(PlaceholderContainer, null, loading ? React__default.createElement(LoaderContainer$1, null, React__default.createElement(ui.Spinner, {
|
|
2780
2833
|
size: 24
|
|
2781
2834
|
})) : React__default.createElement(ui.Alert, {
|
|
2782
2835
|
type: "secondary",
|
|
@@ -2799,12 +2852,6 @@ function SwapDetailsPage() {
|
|
|
2799
2852
|
const {
|
|
2800
2853
|
manager
|
|
2801
2854
|
} = queueManagerReact.useManager();
|
|
2802
|
-
const [loading, setLoading] = React.useState(true);
|
|
2803
|
-
React.useEffect(() => {
|
|
2804
|
-
setTimeout(() => {
|
|
2805
|
-
setLoading(false);
|
|
2806
|
-
}, 5000);
|
|
2807
|
-
}, []);
|
|
2808
2855
|
const pendingSwaps = getPendingSwaps(manager);
|
|
2809
2856
|
const selectedSwap = pendingSwaps.find(_ref => {
|
|
2810
2857
|
let {
|
|
@@ -2817,15 +2864,12 @@ function SwapDetailsPage() {
|
|
|
2817
2864
|
if (swap) queueManagerRangoPreset.cancelSwap(swap);
|
|
2818
2865
|
};
|
|
2819
2866
|
const swap = selectedSwap?.swap;
|
|
2867
|
+
const loading = !manager?.isLoaded();
|
|
2820
2868
|
if (!swap) return React__default.createElement(SwapDetailsPlaceholder, {
|
|
2821
2869
|
requestId: selectedSwapRequestId || '',
|
|
2822
2870
|
loading: loading,
|
|
2823
2871
|
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails)
|
|
2824
2872
|
});
|
|
2825
|
-
const firstStep = swap.steps[0];
|
|
2826
|
-
const lastStep = swap.steps[swap.steps.length - 1];
|
|
2827
|
-
const fromAmount = numberToString(swap.inputAmount);
|
|
2828
|
-
const toAmount = numberToString(swap.simulationResult.outputAmount);
|
|
2829
2873
|
const currentStep = queueManagerRangoPreset.getCurrentStep(swap);
|
|
2830
2874
|
const currentStepBlockchain = currentStep ? queueManagerRangoPreset.getCurrentBlockchainOfOrNull(swap, currentStep) : null;
|
|
2831
2875
|
const currentStepWallet = currentStep ? queueManagerRangoPreset.getRelatedWalletOrNull(swap, currentStep) : null;
|
|
@@ -2838,38 +2882,41 @@ function SwapDetailsPage() {
|
|
|
2838
2882
|
const lastConvertedTokenInFailedSwap = getLastConvertedTokenInFailedSwap(swap);
|
|
2839
2883
|
return React__default.createElement(ui.SwapHistory, Object.assign({
|
|
2840
2884
|
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails),
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2885
|
+
/* TODO: It was temporarily removed to find a better solution*/
|
|
2886
|
+
/*
|
|
2887
|
+
previewInputs={
|
|
2888
|
+
<>
|
|
2889
|
+
<TokenPreview
|
|
2890
|
+
chain={{
|
|
2891
|
+
displayName: firstStep?.fromBlockchain || '',
|
|
2892
|
+
logo: firstStep?.fromBlockchainLogo || '',
|
|
2893
|
+
}}
|
|
2894
|
+
token={{
|
|
2895
|
+
symbol: firstStep?.fromSymbol || '',
|
|
2896
|
+
image: firstStep?.fromLogo || '',
|
|
2897
|
+
}}
|
|
2898
|
+
amount={fromAmount}
|
|
2899
|
+
label={t('From')}
|
|
2900
|
+
loadingStatus={'success'}
|
|
2901
|
+
/>
|
|
2902
|
+
<Spacer size={12} direction="vertical" />
|
|
2903
|
+
<TokenPreview
|
|
2904
|
+
chain={{
|
|
2905
|
+
displayName: lastStep?.toBlockchain || '',
|
|
2906
|
+
logo: lastStep?.toBlockchainLogo || '',
|
|
2907
|
+
}}
|
|
2908
|
+
token={{
|
|
2909
|
+
symbol: lastStep?.toSymbol || '',
|
|
2910
|
+
image: lastStep?.toLogo || '',
|
|
2911
|
+
}}
|
|
2912
|
+
amount={toAmount}
|
|
2913
|
+
label={t('To')}
|
|
2914
|
+
loadingStatus={'success'}
|
|
2915
|
+
/>
|
|
2916
|
+
</>
|
|
2917
|
+
}
|
|
2918
|
+
*/
|
|
2919
|
+
pendingSwap: getFormatedPendingSwap(swap),
|
|
2873
2920
|
onCopy: handleCopy,
|
|
2874
2921
|
isCopied: isCopied,
|
|
2875
2922
|
onCancel: onCancel,
|
|
@@ -3045,6 +3092,10 @@ function Layout(_ref) {
|
|
|
3045
3092
|
|
|
3046
3093
|
const globalStyles = /*#__PURE__*/ui.globalCss({
|
|
3047
3094
|
'*': {
|
|
3095
|
+
boxSizing: 'border-box',
|
|
3096
|
+
margin: 0,
|
|
3097
|
+
padding: 0,
|
|
3098
|
+
listStyleType: 'none',
|
|
3048
3099
|
'&::-webkit-scrollbar': {
|
|
3049
3100
|
width: '$8',
|
|
3050
3101
|
height: '$8'
|
|
@@ -3286,6 +3337,11 @@ function QueueManager(props) {
|
|
|
3286
3337
|
canSwitchNetworkTo,
|
|
3287
3338
|
getWalletInfo
|
|
3288
3339
|
} = walletsCore.useWallets();
|
|
3340
|
+
const swapQueueDef = React.useMemo(() => {
|
|
3341
|
+
return queueManagerRangoPreset.makeQueueDefinition({
|
|
3342
|
+
API_KEY: getConfig('API_KEY')
|
|
3343
|
+
});
|
|
3344
|
+
}, []);
|
|
3289
3345
|
const {
|
|
3290
3346
|
blockchains
|
|
3291
3347
|
} = useMetaStore.use.meta();
|
|
@@ -3335,7 +3391,7 @@ function QueueManager(props) {
|
|
|
3335
3391
|
//@ts-ignore
|
|
3336
3392
|
, {
|
|
3337
3393
|
//@ts-ignore
|
|
3338
|
-
queuesDefs: [
|
|
3394
|
+
queuesDefs: [swapQueueDef],
|
|
3339
3395
|
context: context,
|
|
3340
3396
|
onPersistedDataLoaded: manager => {
|
|
3341
3397
|
queueManagerRangoPreset.checkWaitingForNetworkChange(manager);
|
|
@@ -3344,7 +3400,7 @@ function QueueManager(props) {
|
|
|
3344
3400
|
}, props.children);
|
|
3345
3401
|
}
|
|
3346
3402
|
|
|
3347
|
-
const
|
|
3403
|
+
const Widget = _ref => {
|
|
3348
3404
|
let {
|
|
3349
3405
|
config
|
|
3350
3406
|
} = _ref;
|
|
@@ -3368,6 +3424,13 @@ const SwapBox = _ref => {
|
|
|
3368
3424
|
const [disconnectedWallet, setDisconnectedWallet] = React.useState();
|
|
3369
3425
|
const currentPage = useUiStore.use.currentPage();
|
|
3370
3426
|
const evmBasedChainNames = blockchains.filter(rangoSdk.isEvmBlockchain).map(chain => chain.name);
|
|
3427
|
+
React.useMemo(() => {
|
|
3428
|
+
if (config?.apiKey) {
|
|
3429
|
+
initConfig({
|
|
3430
|
+
API_KEY: config?.apiKey
|
|
3431
|
+
});
|
|
3432
|
+
}
|
|
3433
|
+
}, [config]);
|
|
3371
3434
|
const onUpdateState = (type, event, value, state, supportedChains) => {
|
|
3372
3435
|
if (event === walletsCore.Events.ACCOUNTS) {
|
|
3373
3436
|
if (value) {
|
|
@@ -3421,5 +3484,11 @@ const SwapBox = _ref => {
|
|
|
3421
3484
|
}))))));
|
|
3422
3485
|
};
|
|
3423
3486
|
|
|
3424
|
-
exports
|
|
3487
|
+
Object.defineProperty(exports, 'WalletType', {
|
|
3488
|
+
enumerable: true,
|
|
3489
|
+
get: function () {
|
|
3490
|
+
return walletsShared.WalletType;
|
|
3491
|
+
}
|
|
3492
|
+
});
|
|
3493
|
+
exports.Widget = Widget;
|
|
3425
3494
|
//# sourceMappingURL=widget-embedded.cjs.development.js.map
|