@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.
@@ -6,10 +6,10 @@ 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
+ import { readAccountAddress, useWallets, Provider as Provider$1, Events } from '@rango-dev/wallets-core';
13
13
  import { shallow } from 'zustand/shallow';
14
14
  import { useTranslation, initReactI18next } from 'react-i18next';
15
15
  import { styled as styled$1 } from '@rango-dev/ui/src/theme';
@@ -118,6 +118,195 @@ const decimalNumber = function (number, toFixed) {
118
118
  return parseFloat(number).toFixed(toFixed);
119
119
  };
120
120
 
121
+ function searchParamsToToken(tokens, searchParams, chain) {
122
+ if (!chain) return null;
123
+ return tokens.find(token => {
124
+ const symbolAndAddress = searchParams?.split('--');
125
+ if (symbolAndAddress?.length === 1) return token.symbol === symbolAndAddress[0] && token.address === null && token.blockchain === chain.name;
126
+ return token.symbol === symbolAndAddress?.[0] && token.address === symbolAndAddress?.[1] && token.blockchain === chain.name;
127
+ }) || null;
128
+ }
129
+ function getBestRouteToTokenUsdPrice(bestRoute) {
130
+ return bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to.usdPrice;
131
+ }
132
+ function isNumberOfSwapsChanged(route1, route2) {
133
+ const route1Swaps = route1.result?.swaps || [];
134
+ const route2Swaps = route2.result?.swaps || [];
135
+ return route1Swaps.length !== route2Swaps.length;
136
+ }
137
+ function isRouteSwappersUpdated(route1, route2) {
138
+ const route1Swappers = route1.result?.swaps.map(swap => swap.swapperId) || [];
139
+ const route2Swappers = route2.result?.swaps.map(swap => swap.swapperId) || [];
140
+ return !areEqual(route1Swappers, route2Swappers);
141
+ }
142
+ function isRouteInternalCoinsUpdated(route1, route2) {
143
+ const route1InternalCoins = route1.result?.swaps.map(swap => swap.to.symbol) || [];
144
+ const route2InternalCoins = route2.result?.swaps.map(swap => swap.to.symbol) || [];
145
+ return !areEqual(route1InternalCoins, route2InternalCoins);
146
+ }
147
+ function isRouteChanged(route1, route2) {
148
+ return isNumberOfSwapsChanged(route1, route2) || isRouteSwappersUpdated(route1, route2) || isRouteInternalCoinsUpdated(route1, route2);
149
+ }
150
+ function getRequiredBalanceOfWallet(selectedWallet, fee) {
151
+ if (fee === null) return null;
152
+ const relatedFeeStatus = fee?.find(item => item.blockchain === selectedWallet.chain)?.wallets.find(wallet => wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase());
153
+ if (!relatedFeeStatus) return null;
154
+ return relatedFeeStatus.requiredAssets;
155
+ }
156
+ function isRouteParametersChanged(params) {
157
+ if (params.store === 'bestRoute') {
158
+ const {
159
+ prevState,
160
+ currentState
161
+ } = params;
162
+ 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);
163
+ } else if (params.store === 'settings') {
164
+ const {
165
+ prevState,
166
+ currentState
167
+ } = params;
168
+ return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
169
+ }
170
+ return false;
171
+ }
172
+ function getFormatedBestRoute(bestRoute) {
173
+ if (!bestRoute) return null;
174
+ const formatedSwaps = (bestRoute.result?.swaps || []).map(swap => ({
175
+ ...swap,
176
+ fromAmount: numberToString(swap.fromAmount, 6, 6),
177
+ toAmount: numberToString(swap.toAmount, 6, 6)
178
+ }));
179
+ return {
180
+ ...bestRoute,
181
+ ...(bestRoute.result && {
182
+ result: {
183
+ ...bestRoute.result,
184
+ swaps: formatedSwaps
185
+ }
186
+ })
187
+ };
188
+ }
189
+ function getFormatedPendingSwap(pendingSwap) {
190
+ const formatedSteps = pendingSwap.steps.map(step => ({
191
+ ...step,
192
+ feeInUsd: numberToString(step.feeInUsd, 4, 4),
193
+ outputAmount: numberToString(step.outputAmount, 6, 6),
194
+ expectedOutputAmountHumanReadable: numberToString(step.expectedOutputAmountHumanReadable, 6, 6)
195
+ }));
196
+ return {
197
+ ...pendingSwap,
198
+ inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
199
+ steps: formatedSteps
200
+ };
201
+ }
202
+ //todo: refactor bestRoute store and add loadingStatus
203
+ const getBestRouteStatus = (loading, error) => {
204
+ if (loading) return 'loading';
205
+ if (error) return 'failed';else return 'success';
206
+ };
207
+
208
+ const createSelectors = _store => {
209
+ let store = _store;
210
+ store.use = {};
211
+ for (let k of Object.keys(store.getState())) {
212
+ store.use[k] = () => store(s => s[k]);
213
+ }
214
+ return store;
215
+ };
216
+
217
+ const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
218
+ let configs = {
219
+ API_KEY: RANGO_PUBLIC_API_KEY
220
+ };
221
+ function getConfig(name) {
222
+ return configs[name];
223
+ }
224
+
225
+ let rango = undefined;
226
+ const httpService = () => {
227
+ if (rango) return rango;
228
+ rango = new RangoClient(getConfig('API_KEY'));
229
+ return rango;
230
+ };
231
+
232
+ const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
233
+ const DEFAULT_SLIPPAGE = 1;
234
+ const HIGH_SLIPPAGE = 5;
235
+ const MAX_SLIPPAGE = 100;
236
+ const MIN_SLIPPGAE = 0;
237
+
238
+ const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()(set => ({
239
+ meta: {
240
+ blockchains: [],
241
+ popularTokens: [],
242
+ swappers: [],
243
+ tokens: []
244
+ },
245
+ loadingStatus: 'loading',
246
+ fetchMeta: async () => {
247
+ try {
248
+ const response = await httpService().getAllMetadata();
249
+ const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
250
+ const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
251
+ response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
252
+ set({
253
+ meta: response,
254
+ loadingStatus: 'success'
255
+ });
256
+ } catch (error) {
257
+ set({
258
+ loadingStatus: 'failed'
259
+ });
260
+ }
261
+ }
262
+ })));
263
+
264
+ const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/persist( /*#__PURE__*/subscribeWithSelector(set => ({
265
+ slippage: DEFAULT_SLIPPAGE,
266
+ customSlippage: null,
267
+ infiniteApprove: false,
268
+ affiliateRef: null,
269
+ disabledLiquiditySources: [],
270
+ theme: 'auto',
271
+ setSlippage: slippage => set(() => ({
272
+ slippage: slippage
273
+ })),
274
+ setCustomSlippage: customSlippage => set(() => ({
275
+ customSlippage: customSlippage
276
+ })),
277
+ setAffiliateRef: affiliateRef => set(() => ({
278
+ affiliateRef
279
+ })),
280
+ toggleAllLiquiditySources: () => set(state => {
281
+ const {
282
+ swappers
283
+ } = useMetaStore.getState().meta;
284
+ const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
285
+ if (swappersGroup.length === state.disabledLiquiditySources.length) return {
286
+ disabledLiquiditySources: []
287
+ };else {
288
+ return {
289
+ disabledLiquiditySources: swappersGroup
290
+ };
291
+ }
292
+ }),
293
+ toggleInfiniteApprove: () => set(state => ({
294
+ infiniteApprove: !state.infiniteApprove
295
+ })),
296
+ toggleLiquiditySource: name => set(state => {
297
+ if (state.disabledLiquiditySources.includes(name)) return {
298
+ disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
299
+ };else return {
300
+ disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
301
+ };
302
+ }),
303
+ setTheme: theme => set(() => ({
304
+ theme
305
+ }))
306
+ })), {
307
+ name: 'user-settings'
308
+ })));
309
+
121
310
  function getStateWallet(state) {
122
311
  switch (true) {
123
312
  case state.connected:
@@ -421,7 +610,7 @@ function LimitErrorMessage(bestRoute) {
421
610
  recommendation
422
611
  };
423
612
  }
424
- function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputIsZero) {
613
+ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount) {
425
614
  if (loadingMetaStatus !== 'success') return {
426
615
  title: 'Connect Wallet',
427
616
  disabled: true
@@ -433,7 +622,7 @@ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, has
433
622
  if (loading) return {
434
623
  title: 'Finding Best Route...',
435
624
  disabled: true
436
- };else if (inputIsZero) return {
625
+ };else if (!inputAmount || inputAmount === '0') return {
437
626
  title: 'Enter an amount',
438
627
  disabled: true
439
628
  };else if (!bestRoute || !bestRoute.result) return {
@@ -502,7 +691,7 @@ function hasProperSlippage(userSlippage, minRequiredSlippage) {
502
691
  if (!minRequiredSlippage) return true;
503
692
  return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
504
693
  }
505
- function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, checkPrerequisites, affiliateRef) {
694
+ function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, affiliateRef, initialRoute) {
506
695
  const selectedWalletsMap = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = selectedWallet.address, selectedWalletsMap), {});
507
696
  const connectedWallets = [];
508
697
  wallets.forEach(wallet => {
@@ -512,7 +701,8 @@ function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, se
512
701
  addresses: [wallet.address]
513
702
  });
514
703
  });
515
- const filteredBlockchains = selectedWallets.map(wallet => wallet.chain);
704
+ const checkPrerequisites = !!initialRoute;
705
+ const filteredBlockchains = removeDuplicateFrom((initialRoute?.result?.swaps || []).reduce((blockchains, swap) => (blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains), []));
516
706
  const requestBody = {
517
707
  amount: inputAmount.toString(),
518
708
  affiliateRef,
@@ -636,165 +826,6 @@ function shouldRetrySwap(pendingSwap) {
636
826
  return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
637
827
  }
638
828
 
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
- const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
706
- let configs = {
707
- API_KEY: RANGO_PUBLIC_API_KEY
708
- };
709
- function getConfig(name) {
710
- return configs[name];
711
- }
712
-
713
- let rango = undefined;
714
- const httpService = () => {
715
- if (rango) return rango;
716
- rango = new RangoClient(getConfig('API_KEY'));
717
- return rango;
718
- };
719
-
720
- const SLIPPAGES = [0.5, 1, 3, 5, 8, 13, 20];
721
- const DEFAULT_SLIPPAGE = 1;
722
- const HIGH_SLIPPAGE = 5;
723
- const MAX_SLIPPAGE = 100;
724
- const MIN_SLIPPGAE = 0;
725
-
726
- const useMetaStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()(set => ({
727
- meta: {
728
- blockchains: [],
729
- popularTokens: [],
730
- swappers: [],
731
- tokens: []
732
- },
733
- loadingStatus: 'loading',
734
- fetchMeta: async () => {
735
- try {
736
- const response = await httpService().getAllMetadata();
737
- const chainThatHasTokenInMetaResponse = removeDuplicateFrom(response.tokens.map(t => t.blockchain));
738
- const enabledChains = response.blockchains.filter(chain => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name));
739
- response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
740
- set({
741
- meta: response,
742
- loadingStatus: 'success'
743
- });
744
- } catch (error) {
745
- set({
746
- loadingStatus: 'failed'
747
- });
748
- }
749
- }
750
- })));
751
-
752
- const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/persist( /*#__PURE__*/subscribeWithSelector(set => ({
753
- slippage: DEFAULT_SLIPPAGE,
754
- customSlippage: null,
755
- infiniteApprove: false,
756
- affiliateRef: null,
757
- disabledLiquiditySources: [],
758
- theme: 'auto',
759
- setSlippage: slippage => set(() => ({
760
- slippage: slippage
761
- })),
762
- setCustomSlippage: customSlippage => set(() => ({
763
- customSlippage: customSlippage
764
- })),
765
- setAffiliateRef: affiliateRef => set(() => ({
766
- affiliateRef
767
- })),
768
- toggleAllLiquiditySources: () => set(state => {
769
- const {
770
- swappers
771
- } = useMetaStore.getState().meta;
772
- const swappersGroup = removeDuplicateFrom(swappers.map(swapper => swapper.swapperGroup));
773
- if (swappersGroup.length === state.disabledLiquiditySources.length) return {
774
- disabledLiquiditySources: []
775
- };else {
776
- return {
777
- disabledLiquiditySources: swappersGroup
778
- };
779
- }
780
- }),
781
- toggleInfiniteApprove: () => set(state => ({
782
- infiniteApprove: !state.infiniteApprove
783
- })),
784
- toggleLiquiditySource: name => set(state => {
785
- if (state.disabledLiquiditySources.includes(name)) return {
786
- disabledLiquiditySources: state.disabledLiquiditySources.filter(liquiditySource => liquiditySource != name)
787
- };else return {
788
- disabledLiquiditySources: state.disabledLiquiditySources.concat(name)
789
- };
790
- }),
791
- setTheme: theme => set(() => ({
792
- theme
793
- }))
794
- })), {
795
- name: 'user-settings'
796
- })));
797
-
798
829
  const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/subscribeWithSelector(set => ({
799
830
  accounts: [],
800
831
  balances: [],
@@ -859,7 +890,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#
859
890
  }
860
891
  });
861
892
  return {
862
- selectedWallets: selectedWallets
893
+ selectedWallets: state.selectedWallets.concat(selectedWallets)
863
894
  };
864
895
  }),
865
896
  setSelectedWallet: wallet => set(state => ({
@@ -1050,7 +1081,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1050
1081
  abortController?.abort();
1051
1082
  abortController = new AbortController();
1052
1083
  const userSlippage = !!customSlippage ? customSlippage : slippage;
1053
- const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, false, affiliateRef);
1084
+ const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
1054
1085
  if (!bestRouteStore.getState().loading) bestRouteStore.setState({
1055
1086
  loading: true,
1056
1087
  bestRoute: null,
@@ -1084,7 +1115,9 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1084
1115
  inputAmount,
1085
1116
  inputUsdValue
1086
1117
  } = useBestRouteStore.getState();
1087
- if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return;
1118
+ if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return bestRouteStore.setState({
1119
+ loading: false
1120
+ });
1088
1121
  if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
1089
1122
  loading: false,
1090
1123
  bestRoute: null,
@@ -1397,6 +1430,7 @@ function TokenInfo(props) {
1397
1430
  const bestRoute = useBestRouteStore.use.bestRoute();
1398
1431
  const inputAmount = useBestRouteStore.use.inputAmount();
1399
1432
  const balances = useWalletsStore.use.balances();
1433
+ const fetchingBestRoute = useBestRouteStore.use.loading();
1400
1434
  const navigate = useNavigate();
1401
1435
  const {
1402
1436
  t
@@ -1505,7 +1539,7 @@ function TokenInfo(props) {
1505
1539
  } : undefined
1506
1540
  }) : React.createElement(OutputContainer, null, React.createElement(Typography, {
1507
1541
  variant: "h4"
1508
- }, bestRoute ? `≈ ${numberToString(props.outputAmount)}` : inputAmount ? '?' : '0'))))));
1542
+ }, fetchingBestRoute && '?', !!bestRoute?.result && `≈ ${numberToString(props.outputAmount)}`, (!inputAmount || inputAmount === '0') && '0'))))));
1509
1543
  }
1510
1544
 
1511
1545
  const Container$1 = /*#__PURE__*/styled$1('div', {
@@ -1689,8 +1723,7 @@ function Home() {
1689
1723
  swap
1690
1724
  } = LimitErrorMessage(bestRoute);
1691
1725
  const priceImpactCanNotBeComputed = !canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue);
1692
- const inputIsZero = inputAmount === '0';
1693
- const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputIsZero);
1726
+ const swapButtonState = getSwapButtonState(loadingMetaStatus, accounts, fetchingBestRoute, bestRoute, hasLimitError(bestRoute), highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath, inputAmount);
1694
1727
  const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
1695
1728
  const highFee = hasHighFee(totalFeeInUsd);
1696
1729
  useEffect(() => {
@@ -1727,7 +1760,7 @@ function Home() {
1727
1760
  }), showBestRoute && React.createElement(BestRouteContainer, null, React.createElement(BestRoute, {
1728
1761
  error: bestRouteError,
1729
1762
  loading: fetchingBestRoute,
1730
- data: bestRoute,
1763
+ data: getFormatedBestRoute(bestRoute),
1731
1764
  totalFee: numberToString(totalFeeInUsd, 0, 2),
1732
1765
  feeWarning: highFee,
1733
1766
  totalTime: secondsToString(totalArrivalTime(bestRoute))
@@ -2052,7 +2085,7 @@ function useConfirmSwap() {
2052
2085
  }
2053
2086
  abortControllerRef.current = new AbortController();
2054
2087
  setLoading(true);
2055
- const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, true, affiliateRef);
2088
+ const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, affiliateRef, initialRoute);
2056
2089
  try {
2057
2090
  const confiremedRoute = await httpService().getBestRoute(requestBody, {
2058
2091
  signal: abortControllerRef.current?.signal
@@ -2295,6 +2328,7 @@ function ConfirmSwapPage() {
2295
2328
  const customSlippage = useSettingsStore.use.customSlippage();
2296
2329
  const inputUsdValue = useBestRouteStore.use.inputUsdValue();
2297
2330
  const outputUsdValue = useBestRouteStore.use.outputUsdValue();
2331
+ const setInputAmount = useBestRouteStore.use.setInputAmount();
2298
2332
  const bestRouteloadingStatus = getBestRouteStatus(fetchingBestRoute, !!fetchingBestRouteError);
2299
2333
  const {
2300
2334
  manager
@@ -2325,10 +2359,7 @@ function ConfirmSwapPage() {
2325
2359
  getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
2326
2360
  };
2327
2361
  const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
2328
- return React.createElement(ConfirmSwap
2329
- // @ts-ignore
2330
- , {
2331
- // @ts-ignore
2362
+ return React.createElement(ConfirmSwap, {
2332
2363
  requiredWallets: getRequiredChains(bestRoute),
2333
2364
  selectableWallets: selectableWallets,
2334
2365
  onBack: navigateBackFrom.bind(null, navigationRoutes.confirmSwap),
@@ -2337,15 +2368,16 @@ function ConfirmSwapPage() {
2337
2368
  if (swap) {
2338
2369
  manager?.create('swap', {
2339
2370
  swapDetails: swap
2340
- },
2341
- // @ts-ignore
2342
- {
2371
+ }, {
2343
2372
  id: swap.requestId
2344
2373
  });
2345
2374
  setSelectedSwap(swap.requestId);
2346
2375
  navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
2347
2376
  replace: true
2348
2377
  });
2378
+ setTimeout(() => {
2379
+ setInputAmount('');
2380
+ }, 0);
2349
2381
  }
2350
2382
  });
2351
2383
  },
@@ -2823,10 +2855,6 @@ function SwapDetailsPage() {
2823
2855
  loading: loading,
2824
2856
  onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails)
2825
2857
  });
2826
- const firstStep = swap.steps[0];
2827
- const lastStep = swap.steps[swap.steps.length - 1];
2828
- const fromAmount = numberToString(swap.inputAmount);
2829
- const toAmount = numberToString(swap.simulationResult.outputAmount);
2830
2858
  const currentStep = getCurrentStep(swap);
2831
2859
  const currentStepBlockchain = currentStep ? getCurrentBlockchainOfOrNull(swap, currentStep) : null;
2832
2860
  const currentStepWallet = currentStep ? getRelatedWalletOrNull(swap, currentStep) : null;
@@ -2839,38 +2867,41 @@ function SwapDetailsPage() {
2839
2867
  const lastConvertedTokenInFailedSwap = getLastConvertedTokenInFailedSwap(swap);
2840
2868
  return React.createElement(SwapHistory, Object.assign({
2841
2869
  onBack: navigateBackFrom.bind(null, navigationRoutes.swapDetails),
2842
- previewInputs: React.createElement(React.Fragment, null, React.createElement(TokenPreview, {
2843
- chain: {
2844
- displayName: firstStep?.fromBlockchain || '',
2845
- // @ts-ignore
2846
- logo: firstStep?.fromBlockchainLogo || ''
2847
- },
2848
- token: {
2849
- symbol: firstStep?.fromSymbol || '',
2850
- image: firstStep?.fromLogo || ''
2851
- },
2852
- amount: fromAmount,
2853
- label: t('From'),
2854
- loadingStatus: 'success'
2855
- }), React.createElement(Spacer, {
2856
- size: 12,
2857
- direction: "vertical"
2858
- }), React.createElement(TokenPreview, {
2859
- chain: {
2860
- displayName: lastStep?.toBlockchain || '',
2861
- //@ts-ignore
2862
- logo: lastStep?.toBlockchainLogo || ''
2863
- },
2864
- token: {
2865
- symbol: lastStep?.toSymbol || '',
2866
- image: lastStep?.toLogo || ''
2867
- },
2868
- amount: toAmount,
2869
- label: t('To'),
2870
- loadingStatus: 'success'
2871
- })),
2872
- //todo: move PendingSwap type to rango-types
2873
- pendingSwap: swap,
2870
+ /* TODO: It was temporarily removed to find a better solution*/
2871
+ /*
2872
+ previewInputs={
2873
+ <>
2874
+ <TokenPreview
2875
+ chain={{
2876
+ displayName: firstStep?.fromBlockchain || '',
2877
+ logo: firstStep?.fromBlockchainLogo || '',
2878
+ }}
2879
+ token={{
2880
+ symbol: firstStep?.fromSymbol || '',
2881
+ image: firstStep?.fromLogo || '',
2882
+ }}
2883
+ amount={fromAmount}
2884
+ label={t('From')}
2885
+ loadingStatus={'success'}
2886
+ />
2887
+ <Spacer size={12} direction="vertical" />
2888
+ <TokenPreview
2889
+ chain={{
2890
+ displayName: lastStep?.toBlockchain || '',
2891
+ logo: lastStep?.toBlockchainLogo || '',
2892
+ }}
2893
+ token={{
2894
+ symbol: lastStep?.toSymbol || '',
2895
+ image: lastStep?.toLogo || '',
2896
+ }}
2897
+ amount={toAmount}
2898
+ label={t('To')}
2899
+ loadingStatus={'success'}
2900
+ />
2901
+ </>
2902
+ }
2903
+ */
2904
+ pendingSwap: getFormatedPendingSwap(swap),
2874
2905
  onCopy: handleCopy,
2875
2906
  isCopied: isCopied,
2876
2907
  onCancel: onCancel,