@rango-dev/widget-embedded 0.1.11-next.10 → 0.1.11-next.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/pages/ConfirmSwapPage.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/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/widget-embedded.cjs.development.js +247 -216
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +247 -216
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +247 -216
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/TokenInfo.tsx +5 -5
- package/src/hooks/useConfirmSwap.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +4 -2
- package/src/pages/Home.tsx +3 -3
- package/src/pages/SwapDetailsPage.tsx +6 -12
- package/src/store/bestRoute.ts +2 -2
- package/src/store/wallets.ts +1 -1
- package/src/utils/routing.ts +31 -11
- package/src/utils/swap.ts +16 -5
|
@@ -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');
|
|
@@ -127,6 +127,195 @@ const decimalNumber = function (number, toFixed) {
|
|
|
127
127
|
return parseFloat(number).toFixed(toFixed);
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
function searchParamsToToken(tokens, searchParams, chain) {
|
|
131
|
+
if (!chain) return null;
|
|
132
|
+
return tokens.find(token => {
|
|
133
|
+
const symbolAndAddress = searchParams?.split('--');
|
|
134
|
+
if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
|
|
135
|
+
return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
|
|
136
|
+
}) || null;
|
|
137
|
+
}
|
|
138
|
+
function getBestRouteToTokenUsdPrice(bestRoute) {
|
|
139
|
+
return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
|
|
140
|
+
}
|
|
141
|
+
function isNumberOfSwapsChanged(route1, route2) {
|
|
142
|
+
const route1Swaps = route1.result?.swaps || [];
|
|
143
|
+
const route2Swaps = route2.result?.swaps || [];
|
|
144
|
+
return route1Swaps.length !== route2Swaps.length;
|
|
145
|
+
}
|
|
146
|
+
function isRouteSwappersUpdated(route1, route2) {
|
|
147
|
+
const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
|
|
148
|
+
const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
|
|
149
|
+
return !areEqual(route1Swappers, route2Swappers);
|
|
150
|
+
}
|
|
151
|
+
function isRouteInternalCoinsUpdated(route1, route2) {
|
|
152
|
+
const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
153
|
+
const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
|
|
154
|
+
return !areEqual(route1InternalCoins, route2InternalCoins);
|
|
155
|
+
}
|
|
156
|
+
function isRouteChanged(route1, route2) {
|
|
157
|
+
return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
|
|
158
|
+
}
|
|
159
|
+
function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
160
|
+
if (fee === null) return null;
|
|
161
|
+
const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
|
|
162
|
+
if (!relatedFeeStatus) return null;
|
|
163
|
+
return relatedFeeStatus.requiredAssets;
|
|
164
|
+
}
|
|
165
|
+
function isRouteParametersChanged(params) {
|
|
166
|
+
if (params.store === 'bestRoute') {
|
|
167
|
+
const {
|
|
168
|
+
prevState,
|
|
169
|
+
currentState
|
|
170
|
+
} = params;
|
|
171
|
+
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);
|
|
172
|
+
} else if (params.store === 'settings') {
|
|
173
|
+
const {
|
|
174
|
+
prevState,
|
|
175
|
+
currentState
|
|
176
|
+
} = params;
|
|
177
|
+
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
function getFormatedBestRoute(bestRoute) {
|
|
182
|
+
if (!bestRoute) return null;
|
|
183
|
+
const formatedSwaps = (bestRoute.result?.swaps || []).map(swap => ({
|
|
184
|
+
...swap,
|
|
185
|
+
fromAmount: numberToString(swap.fromAmount, 6, 6),
|
|
186
|
+
toAmount: numberToString(swap.toAmount, 6, 6)
|
|
187
|
+
}));
|
|
188
|
+
return {
|
|
189
|
+
...bestRoute,
|
|
190
|
+
...(bestRoute.result && {
|
|
191
|
+
result: {
|
|
192
|
+
...bestRoute.result,
|
|
193
|
+
swaps: formatedSwaps
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function getFormatedPendingSwap(pendingSwap) {
|
|
199
|
+
const formatedSteps = pendingSwap.steps.map(step => ({
|
|
200
|
+
...step,
|
|
201
|
+
feeInUsd: numberToString(step.feeInUsd, 4, 4),
|
|
202
|
+
outputAmount: numberToString(step.outputAmount, 6, 6),
|
|
203
|
+
expectedOutputAmountHumanReadable: numberToString(step.expectedOutputAmountHumanReadable, 6, 6)
|
|
204
|
+
}));
|
|
205
|
+
return {
|
|
206
|
+
...pendingSwap,
|
|
207
|
+
inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
|
|
208
|
+
steps: formatedSteps
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
//todo: refactor bestRoute store and add loadingStatus
|
|
212
|
+
const getBestRouteStatus = (loading, error) => {
|
|
213
|
+
if (loading) return 'loading';
|
|
214
|
+
if (error) return 'failed';else return 'success';
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const createSelectors = _store => {
|
|
218
|
+
let store = _store;
|
|
219
|
+
store.use = {};
|
|
220
|
+
for (let k of Object.keys(store.getState())) {
|
|
221
|
+
store.use[k] = () => store(s => s[k]);
|
|
222
|
+
}
|
|
223
|
+
return store;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
227
|
+
let configs = {
|
|
228
|
+
API_KEY: RANGO_PUBLIC_API_KEY
|
|
229
|
+
};
|
|
230
|
+
function getConfig(name) {
|
|
231
|
+
return configs[name];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
let rango = undefined;
|
|
235
|
+
const httpService = () => {
|
|
236
|
+
if (rango) return rango;
|
|
237
|
+
rango = new rangoSdk.RangoClient(getConfig('API_KEY'));
|
|
238
|
+
return rango;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
242
|
+
const DEFAULT_SLIPPAGE = 1;
|
|
243
|
+
const HIGH_SLIPPAGE = 5;
|
|
244
|
+
const MAX_SLIPPAGE = 100;
|
|
245
|
+
const MIN_SLIPPGAE = 0;
|
|
246
|
+
|
|
247
|
+
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
|
|
248
|
+
meta: {
|
|
249
|
+
blockchains: [],
|
|
250
|
+
popularTokens: [],
|
|
251
|
+
swappers: [],
|
|
252
|
+
tokens: []
|
|
253
|
+
},
|
|
254
|
+
loadingStatus: 'loading',
|
|
255
|
+
fetchMeta: async () => {
|
|
256
|
+
try {
|
|
257
|
+
const response = await httpService().getAllMetadata();
|
|
258
|
+
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
259
|
+
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
260
|
+
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
261
|
+
set({
|
|
262
|
+
meta: response,
|
|
263
|
+
loadingStatus: 'success'
|
|
264
|
+
});
|
|
265
|
+
} catch (error) {
|
|
266
|
+
set({
|
|
267
|
+
loadingStatus: 'failed'
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
})));
|
|
272
|
+
|
|
273
|
+
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.persist( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
274
|
+
slippage: DEFAULT_SLIPPAGE,
|
|
275
|
+
customSlippage: null,
|
|
276
|
+
infiniteApprove: false,
|
|
277
|
+
affiliateRef: null,
|
|
278
|
+
disabledLiquiditySources: [],
|
|
279
|
+
theme: 'auto',
|
|
280
|
+
setSlippage: slippage => set(() => ({
|
|
281
|
+
slippage: slippage
|
|
282
|
+
})),
|
|
283
|
+
setCustomSlippage: customSlippage => set(() => ({
|
|
284
|
+
customSlippage: customSlippage
|
|
285
|
+
})),
|
|
286
|
+
setAffiliateRef: affiliateRef => set(() => ({
|
|
287
|
+
affiliateRef
|
|
288
|
+
})),
|
|
289
|
+
toggleAllLiquiditySources: () => set(state => {
|
|
290
|
+
const {
|
|
291
|
+
swappers
|
|
292
|
+
} = useMetaStore.getState().meta;
|
|
293
|
+
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
294
|
+
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
295
|
+
disabledLiquiditySources: []
|
|
296
|
+
};else {
|
|
297
|
+
return {
|
|
298
|
+
disabledLiquiditySources: swappersGroup
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}),
|
|
302
|
+
toggleInfiniteApprove: () => set(state => ({
|
|
303
|
+
infiniteApprove: !state.infiniteApprove
|
|
304
|
+
})),
|
|
305
|
+
toggleLiquiditySource: name => set(state => {
|
|
306
|
+
if (state.disabledLiquiditySources.includes(name)) return {
|
|
307
|
+
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
308
|
+
};else return {
|
|
309
|
+
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
310
|
+
};
|
|
311
|
+
}),
|
|
312
|
+
setTheme: theme => set(() => ({
|
|
313
|
+
theme
|
|
314
|
+
}))
|
|
315
|
+
})), {
|
|
316
|
+
name: 'user-settings'
|
|
317
|
+
})));
|
|
318
|
+
|
|
130
319
|
function getStateWallet(state) {
|
|
131
320
|
switch (true) {
|
|
132
321
|
case state.connected:
|
|
@@ -430,7 +619,7 @@ function LimitErrorMessage(bestRoute) {
|
|
|
430
619
|
recommendation
|
|
431
620
|
};
|
|
432
621
|
}
|
|
433
|
-
function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath,
|
|
622
|
+
function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount) {
|
|
434
623
|
if (loadingMetaStatus !== 'success') return {
|
|
435
624
|
title: 'Connect Wallet',
|
|
436
625
|
disabled: true
|
|
@@ -442,7 +631,7 @@ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, has
|
|
|
442
631
|
if (loading) return {
|
|
443
632
|
title: 'Finding Best Route...',
|
|
444
633
|
disabled: true
|
|
445
|
-
};else if (
|
|
634
|
+
};else if (!inputAmount || inputAmount === '0') return {
|
|
446
635
|
title: 'Enter an amount',
|
|
447
636
|
disabled: true
|
|
448
637
|
};else if (!bestRoute || !bestRoute.result) return {
|
|
@@ -511,7 +700,7 @@ function hasProperSlippage(userSlippage, minRequiredSlippage) {
|
|
|
511
700
|
if (!minRequiredSlippage) return true;
|
|
512
701
|
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
513
702
|
}
|
|
514
|
-
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage,
|
|
703
|
+
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, affiliateRef, initialRoute) {
|
|
515
704
|
const selectedWalletsMap = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = selectedWallet.address, selectedWalletsMap), {});
|
|
516
705
|
const connectedWallets = [];
|
|
517
706
|
wallets.forEach(wallet => {
|
|
@@ -521,7 +710,8 @@ function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, se
|
|
|
521
710
|
addresses: [wallet.address]
|
|
522
711
|
});
|
|
523
712
|
});
|
|
524
|
-
const
|
|
713
|
+
const checkPrerequisites = !!initialRoute;
|
|
714
|
+
const filteredBlockchains = removeDuplicateFrom((initialRoute?.result?.swaps || []).reduce((blockchains, swap) => (blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains), []));
|
|
525
715
|
const requestBody = {
|
|
526
716
|
amount: inputAmount.toString(),
|
|
527
717
|
affiliateRef,
|
|
@@ -645,165 +835,6 @@ function shouldRetrySwap(pendingSwap) {
|
|
|
645
835
|
return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
|
|
646
836
|
}
|
|
647
837
|
|
|
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
|
-
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
715
|
-
let configs = {
|
|
716
|
-
API_KEY: RANGO_PUBLIC_API_KEY
|
|
717
|
-
};
|
|
718
|
-
function getConfig(name) {
|
|
719
|
-
return configs[name];
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
let rango = undefined;
|
|
723
|
-
const httpService = () => {
|
|
724
|
-
if (rango) return rango;
|
|
725
|
-
rango = new rangoSdk.RangoClient(getConfig('API_KEY'));
|
|
726
|
-
return rango;
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
|
|
730
|
-
const DEFAULT_SLIPPAGE = 1;
|
|
731
|
-
const HIGH_SLIPPAGE = 5;
|
|
732
|
-
const MAX_SLIPPAGE = 100;
|
|
733
|
-
const MIN_SLIPPGAE = 0;
|
|
734
|
-
|
|
735
|
-
const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
|
|
736
|
-
meta: {
|
|
737
|
-
blockchains: [],
|
|
738
|
-
popularTokens: [],
|
|
739
|
-
swappers: [],
|
|
740
|
-
tokens: []
|
|
741
|
-
},
|
|
742
|
-
loadingStatus: 'loading',
|
|
743
|
-
fetchMeta: async () => {
|
|
744
|
-
try {
|
|
745
|
-
const response = await httpService().getAllMetadata();
|
|
746
|
-
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
|
|
747
|
-
const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
|
|
748
|
-
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
749
|
-
set({
|
|
750
|
-
meta: response,
|
|
751
|
-
loadingStatus: 'success'
|
|
752
|
-
});
|
|
753
|
-
} catch (error) {
|
|
754
|
-
set({
|
|
755
|
-
loadingStatus: 'failed'
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
})));
|
|
760
|
-
|
|
761
|
-
const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.persist( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
762
|
-
slippage: DEFAULT_SLIPPAGE,
|
|
763
|
-
customSlippage: null,
|
|
764
|
-
infiniteApprove: false,
|
|
765
|
-
affiliateRef: null,
|
|
766
|
-
disabledLiquiditySources: [],
|
|
767
|
-
theme: 'auto',
|
|
768
|
-
setSlippage: slippage => set(() => ({
|
|
769
|
-
slippage: slippage
|
|
770
|
-
})),
|
|
771
|
-
setCustomSlippage: customSlippage => set(() => ({
|
|
772
|
-
customSlippage: customSlippage
|
|
773
|
-
})),
|
|
774
|
-
setAffiliateRef: affiliateRef => set(() => ({
|
|
775
|
-
affiliateRef
|
|
776
|
-
})),
|
|
777
|
-
toggleAllLiquiditySources: () => set(state => {
|
|
778
|
-
const {
|
|
779
|
-
swappers
|
|
780
|
-
} = useMetaStore.getState().meta;
|
|
781
|
-
const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
|
|
782
|
-
if (swappersGroup.length === state.disabledLiquiditySources.length) return {
|
|
783
|
-
disabledLiquiditySources: []
|
|
784
|
-
};else {
|
|
785
|
-
return {
|
|
786
|
-
disabledLiquiditySources: swappersGroup
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
}),
|
|
790
|
-
toggleInfiniteApprove: () => set(state => ({
|
|
791
|
-
infiniteApprove: !state.infiniteApprove
|
|
792
|
-
})),
|
|
793
|
-
toggleLiquiditySource: name => set(state => {
|
|
794
|
-
if (state.disabledLiquiditySources.includes(name)) return {
|
|
795
|
-
disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
|
|
796
|
-
};else return {
|
|
797
|
-
disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
|
|
798
|
-
};
|
|
799
|
-
}),
|
|
800
|
-
setTheme: theme => set(() => ({
|
|
801
|
-
theme
|
|
802
|
-
}))
|
|
803
|
-
})), {
|
|
804
|
-
name: 'user-settings'
|
|
805
|
-
})));
|
|
806
|
-
|
|
807
838
|
const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
|
|
808
839
|
accounts: [],
|
|
809
840
|
balances: [],
|
|
@@ -868,7 +899,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.creat
|
|
|
868
899
|
}
|
|
869
900
|
});
|
|
870
901
|
return {
|
|
871
|
-
selectedWallets: selectedWallets
|
|
902
|
+
selectedWallets: state.selectedWallets.concat(selectedWallets)
|
|
872
903
|
};
|
|
873
904
|
}),
|
|
874
905
|
setSelectedWallet: wallet => set(state => ({
|
|
@@ -1059,7 +1090,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1059
1090
|
abortController?.abort();
|
|
1060
1091
|
abortController = new AbortController();
|
|
1061
1092
|
const userSlippage = !!customSlippage ? customSlippage : slippage;
|
|
1062
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage,
|
|
1093
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
|
|
1063
1094
|
if (!bestRouteStore.getState().loading) bestRouteStore.setState({
|
|
1064
1095
|
loading: true,
|
|
1065
1096
|
bestRoute: null,
|
|
@@ -1093,7 +1124,9 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1093
1124
|
inputAmount,
|
|
1094
1125
|
inputUsdValue
|
|
1095
1126
|
} = useBestRouteStore.getState();
|
|
1096
|
-
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return
|
|
1127
|
+
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return bestRouteStore.setState({
|
|
1128
|
+
loading: false
|
|
1129
|
+
});
|
|
1097
1130
|
if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
|
|
1098
1131
|
loading: false,
|
|
1099
1132
|
bestRoute: null,
|
|
@@ -1406,6 +1439,7 @@ function TokenInfo(props) {
|
|
|
1406
1439
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
1407
1440
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
1408
1441
|
const balances = useWalletsStore.use.balances();
|
|
1442
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
1409
1443
|
const navigate = reactRouterDom.useNavigate();
|
|
1410
1444
|
const {
|
|
1411
1445
|
t
|
|
@@ -1514,7 +1548,7 @@ function TokenInfo(props) {
|
|
|
1514
1548
|
} : undefined
|
|
1515
1549
|
}) : React__default.createElement(OutputContainer, null, React__default.createElement(ui.Typography, {
|
|
1516
1550
|
variant: "h4"
|
|
1517
|
-
},
|
|
1551
|
+
}, fetchingBestRoute && '?', !!bestRoute?.result && `≈ ${numberToString(props.outputAmount)}`, (!inputAmount || inputAmount === '0') && '0'))))));
|
|
1518
1552
|
}
|
|
1519
1553
|
|
|
1520
1554
|
const Container$1 = /*#__PURE__*/theme.styled('div', {
|
|
@@ -1698,8 +1732,7 @@ function Home() {
|
|
|
1698
1732
|
swap
|
|
1699
1733
|
} = LimitErrorMessage(bestRoute);
|
|
1700
1734
|
const priceImpactCanNotBeComputed = !canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue);
|
|
1701
|
-
const
|
|
1702
|
-
const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputIsZero);
|
|
1735
|
+
const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount);
|
|
1703
1736
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
1704
1737
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
1705
1738
|
React.useEffect(() => {
|
|
@@ -1736,7 +1769,7 @@ function Home() {
|
|
|
1736
1769
|
}), showBestRoute && React__default.createElement(BestRouteContainer, null, React__default.createElement(ui.BestRoute, {
|
|
1737
1770
|
error: bestRouteError,
|
|
1738
1771
|
loading: fetchingBestRoute,
|
|
1739
|
-
data: bestRoute,
|
|
1772
|
+
data: getFormatedBestRoute(bestRoute),
|
|
1740
1773
|
totalFee: numberToString(totalFeeInUsd, 0, 2),
|
|
1741
1774
|
feeWarning: highFee,
|
|
1742
1775
|
totalTime: secondsToString(totalArrivalTime(bestRoute))
|
|
@@ -2061,7 +2094,7 @@ function useConfirmSwap() {
|
|
|
2061
2094
|
}
|
|
2062
2095
|
abortControllerRef.current = new AbortController();
|
|
2063
2096
|
setLoading(true);
|
|
2064
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage,
|
|
2097
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, affiliateRef, initialRoute);
|
|
2065
2098
|
try {
|
|
2066
2099
|
const confiremedRoute = await httpService().getBestRoute(requestBody, {
|
|
2067
2100
|
signal: abortControllerRef.current?.signal
|
|
@@ -2304,6 +2337,7 @@ function ConfirmSwapPage() {
|
|
|
2304
2337
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
2305
2338
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2306
2339
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
2340
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2307
2341
|
const bestRouteloadingStatus = getBestRouteStatus(fetchingBestRoute, !!fetchingBestRouteError);
|
|
2308
2342
|
const {
|
|
2309
2343
|
manager
|
|
@@ -2334,10 +2368,7 @@ function ConfirmSwapPage() {
|
|
|
2334
2368
|
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
|
|
2335
2369
|
};
|
|
2336
2370
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
2337
|
-
return React__default.createElement(ui.ConfirmSwap
|
|
2338
|
-
// @ts-ignore
|
|
2339
|
-
, {
|
|
2340
|
-
// @ts-ignore
|
|
2371
|
+
return React__default.createElement(ui.ConfirmSwap, {
|
|
2341
2372
|
requiredWallets: getRequiredChains(bestRoute),
|
|
2342
2373
|
selectableWallets: selectableWallets,
|
|
2343
2374
|
onBack: navigateBackFrom.bind(null, navigationRoutes.confirmSwap),
|
|
@@ -2346,15 +2377,16 @@ function ConfirmSwapPage() {
|
|
|
2346
2377
|
if (swap) {
|
|
2347
2378
|
manager?.create('swap', {
|
|
2348
2379
|
swapDetails: swap
|
|
2349
|
-
},
|
|
2350
|
-
// @ts-ignore
|
|
2351
|
-
{
|
|
2380
|
+
}, {
|
|
2352
2381
|
id: swap.requestId
|
|
2353
2382
|
});
|
|
2354
2383
|
setSelectedSwap(swap.requestId);
|
|
2355
2384
|
navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
2356
2385
|
replace: true
|
|
2357
2386
|
});
|
|
2387
|
+
setTimeout(() => {
|
|
2388
|
+
setInputAmount('');
|
|
2389
|
+
}, 0);
|
|
2358
2390
|
}
|
|
2359
2391
|
});
|
|
2360
2392
|
},
|
|
@@ -2832,10 +2864,6 @@ function SwapDetailsPage() {
|
|
|
2832
2864
|
loading: loading,
|
|
2833
2865
|
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails)
|
|
2834
2866
|
});
|
|
2835
|
-
const firstStep = swap.steps[0];
|
|
2836
|
-
const lastStep = swap.steps[swap.steps.length - 1];
|
|
2837
|
-
const fromAmount = numberToString(swap.inputAmount);
|
|
2838
|
-
const toAmount = numberToString(swap.simulationResult.outputAmount);
|
|
2839
2867
|
const currentStep = queueManagerRangoPreset.getCurrentStep(swap);
|
|
2840
2868
|
const currentStepBlockchain = currentStep ? queueManagerRangoPreset.getCurrentBlockchainOfOrNull(swap, currentStep) : null;
|
|
2841
2869
|
const currentStepWallet = currentStep ? queueManagerRangoPreset.getRelatedWalletOrNull(swap, currentStep) : null;
|
|
@@ -2848,38 +2876,41 @@ function SwapDetailsPage() {
|
|
|
2848
2876
|
const lastConvertedTokenInFailedSwap = getLastConvertedTokenInFailedSwap(swap);
|
|
2849
2877
|
return React__default.createElement(ui.SwapHistory, Object.assign({
|
|
2850
2878
|
onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails),
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2879
|
+
/* TODO: It was temporarily removed to find a better solution*/
|
|
2880
|
+
/*
|
|
2881
|
+
previewInputs={
|
|
2882
|
+
<>
|
|
2883
|
+
<TokenPreview
|
|
2884
|
+
chain={{
|
|
2885
|
+
displayName: firstStep?.fromBlockchain || '',
|
|
2886
|
+
logo: firstStep?.fromBlockchainLogo || '',
|
|
2887
|
+
}}
|
|
2888
|
+
token={{
|
|
2889
|
+
symbol: firstStep?.fromSymbol || '',
|
|
2890
|
+
image: firstStep?.fromLogo || '',
|
|
2891
|
+
}}
|
|
2892
|
+
amount={fromAmount}
|
|
2893
|
+
label={t('From')}
|
|
2894
|
+
loadingStatus={'success'}
|
|
2895
|
+
/>
|
|
2896
|
+
<Spacer size={12} direction="vertical" />
|
|
2897
|
+
<TokenPreview
|
|
2898
|
+
chain={{
|
|
2899
|
+
displayName: lastStep?.toBlockchain || '',
|
|
2900
|
+
logo: lastStep?.toBlockchainLogo || '',
|
|
2901
|
+
}}
|
|
2902
|
+
token={{
|
|
2903
|
+
symbol: lastStep?.toSymbol || '',
|
|
2904
|
+
image: lastStep?.toLogo || '',
|
|
2905
|
+
}}
|
|
2906
|
+
amount={toAmount}
|
|
2907
|
+
label={t('To')}
|
|
2908
|
+
loadingStatus={'success'}
|
|
2909
|
+
/>
|
|
2910
|
+
</>
|
|
2911
|
+
}
|
|
2912
|
+
*/
|
|
2913
|
+
pendingSwap: getFormatedPendingSwap(swap),
|
|
2883
2914
|
onCopy: handleCopy,
|
|
2884
2915
|
isCopied: isCopied,
|
|
2885
2916
|
onCancel: onCancel,
|