@rango-dev/widget-embedded 0.1.10-next.77 → 0.1.10-next.80

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.
@@ -1,12 +1,2 @@
1
- import { BestRouteResponse } from 'rango-sdk';
2
- export declare function useConfirmSwap(): {
3
- loading: boolean;
4
- error: string;
5
- data: BestRouteResponse;
6
- warning: string;
7
- feeStatus: import("rango-sdk").BlockchainValidationStatus[];
8
- bestRouteChanged: boolean;
9
- enoughBalance: boolean;
10
- swap: () => void;
11
- };
1
+ export declare function useConfirmSwap(): any;
12
2
  //# sourceMappingURL=useConfirmSwap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useConfirmSwap.d.ts","sourceRoot":"","sources":["../src/hooks/useConfirmSwap.ts"],"names":[],"mappings":"AAQA,OAAO,EAAoB,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAkBhE,wBAAgB,cAAc;;;;;;;;;EA+M7B"}
1
+ {"version":3,"file":"useConfirmSwap.d.ts","sourceRoot":"","sources":["../src/hooks/useConfirmSwap.ts"],"names":[],"mappings":"AA2BA,wBAAgB,cAAc,QAgP7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"WalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/WalletsPage.tsx"],"names":[],"mappings":"AAkBA,wBAAgB,WAAW,gBA0C1B"}
1
+ {"version":3,"file":"WalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/WalletsPage.tsx"],"names":[],"mappings":"AAmBA,wBAAgB,WAAW,gBA8C1B"}
@@ -614,111 +614,7 @@ const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.crea
614
614
  name: 'user-settings'
615
615
  })));
616
616
 
617
- function getOutputRatio(inputUsdValue, outputUsdValue) {
618
- if (inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) return 0;
619
- return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
620
- }
621
- function outputRatioHasWarning(inputUsdValue, outputRatio) {
622
- return parseInt(outputRatio.toFixed(2) || '0') <= -10 && inputUsdValue.gte(new BigNumber__default(400)) || parseInt(outputRatio.toFixed(2) || '0') <= -5 && inputUsdValue.gte(new BigNumber__default(1000));
623
- }
624
- function hasLimitError(bestRoute) {
625
- return (bestRoute?.result?.swaps || []).filter(swap => {
626
- const minimum = !!swap.fromAmountMinValue ? new BigNumber__default(swap.fromAmountMinValue) : null;
627
- const maximum = !!swap.fromAmountMaxValue ? new BigNumber__default(swap.fromAmountMaxValue) : null;
628
- const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
629
- if (isExclusive) {
630
- return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
631
- } else {
632
- return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
633
- }
634
- }).length > 0;
635
- }
636
- function getSwapButtonTitle(accounts, loading, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath) {
637
- if (loading) return 'Finding Best Route...';
638
- if (accounts.length == 0) return 'Connect Wallet';else if (hasLimitError) return 'Limit Error';else if (highValueLoss) return 'Price impact is too high!';else if (priceImpactCanNotBeComputed) return 'USD price is unknown, price impact might be high!';else if (needsToWarnEthOnPath) return 'The route goes through Ethereum. Continue?';else return 'Swap';
639
- }
640
- function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
641
- return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0);
642
- }
643
- function calculatePendingSwap(inputAmount, bestRoute, wallets, settings, validateBalanceOrFee) {
644
- const simulationResult = bestRoute.result;
645
- if (!simulationResult) throw Error('Simulation result should not be null');
646
- return {
647
- creationTime: new Date().getTime().toString(),
648
- finishTime: null,
649
- requestId: bestRoute.requestId || '',
650
- inputAmount: inputAmount,
651
- wallets,
652
- status: 'running',
653
- isPaused: false,
654
- extraMessage: null,
655
- extraMessageSeverity: null,
656
- extraMessageDetail: null,
657
- extraMessageErrorCode: null,
658
- networkStatusExtraMessage: null,
659
- networkStatusExtraMessageDetail: null,
660
- lastNotificationTime: null,
661
- settings: settings,
662
- simulationResult: simulationResult,
663
- validateBalanceOrFee,
664
- //TODO: finalize PendingSwap type and remove ts-ignore
665
- //@ts-ignore
666
- steps: bestRoute.result?.swaps?.map((s, i) => ({
667
- id: i + 1,
668
- fromBlockchain: s.from.blockchain,
669
- fromSymbol: s.from.symbol,
670
- fromSymbolAddress: s.from.address,
671
- fromDecimals: s.from.decimals,
672
- fromAmountPrecision: s.fromAmountPrecision,
673
- fromAmountMinValue: s.fromAmountMinValue,
674
- fromAmountMaxValue: s.fromAmountMaxValue,
675
- toBlockchain: s.to.blockchain,
676
- fromLogo: s.from.logo,
677
- toSymbol: s.to.symbol,
678
- toSymbolAddress: s.to.address,
679
- toDecimals: s.to.decimals,
680
- toLogo: s.to.logo,
681
- startTransactionTime: new Date().getTime(),
682
- swapperId: s.swapperId,
683
- expectedOutputAmountHumanReadable: s.toAmount,
684
- outputAmount: null,
685
- status: 'created',
686
- networkStatus: null,
687
- executedTransactionId: null,
688
- externalTransactionId: null,
689
- explorerUrl: null,
690
- trackingCode: null,
691
- cosmosTransaction: null,
692
- solanaTransaction: null,
693
- starknetTransaction: null,
694
- starknetApprovalTransaction: null,
695
- tronTransaction: null,
696
- tronApprovalTransaction: null,
697
- evmTransaction: null,
698
- evmApprovalTransaction: null,
699
- transferTransaction: null,
700
- diagnosisUrl: null,
701
- internalSteps: null,
702
- fromBlockchainLogo: '',
703
- toBlockchainLogo: '',
704
- swapperLogo: '',
705
- swapperType: ''
706
- })) || []
707
- };
708
- }
709
- function requiredWallets(route) {
710
- const wallets = [];
711
- route?.result?.swaps.forEach(swap => {
712
- const currentStepFromBlockchain = swap.from.blockchain;
713
- const currentStepToBlockchain = swap.to.blockchain;
714
- let lastAddedWallet = wallets[wallets.length - 1];
715
- if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
716
- lastAddedWallet = wallets[wallets.length - 1];
717
- if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
718
- });
719
- return wallets;
720
- }
721
-
617
+ // import { WalletType } from '@rango-dev/wallets-shared';
722
618
  function useConfirmSwap() {
723
619
  const fromToken = useBestRouteStore.use.fromToken();
724
620
  const toToken = useBestRouteStore.use.toToken();
@@ -820,6 +716,7 @@ function useConfirmSwap() {
820
716
  const routeChangeStatus = compareRoutes(bestRoute, r, inputAmount.toString(), fromToken.usdPrice, toToken.usdPrice);
821
717
  setBestRoute(r);
822
718
  const isChanged = routeChangeStatus.isChanged;
719
+ // const changeWarningMessage = routeChangeStatus.warningMessage;
823
720
  setBestRouteChanged(isChanged);
824
721
  setWarning('Best route changed');
825
722
  setData(r);
@@ -831,19 +728,34 @@ function useConfirmSwap() {
831
728
  const swap = () => {
832
729
  if (!bestRoute) return;
833
730
  if (inputAmount.toString() === '') return;
834
- const wallets = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = {
835
- address: selectedWallet.address,
836
- walletType: selectedWallet.walletType
837
- }, selectedWalletsMap), {});
731
+ // const wallets = selectedWallets.reduce(
732
+ // (
733
+ // selectedWalletsMap: { [p: string]: { address: string; walletType: WalletType } },
734
+ // selectedWallet,
735
+ // ) => (
736
+ // (selectedWalletsMap[selectedWallet.chain] = {
737
+ // address: selectedWallet.address,
738
+ // walletType: selectedWallet.walletType,
739
+ // }),
740
+ // selectedWalletsMap
741
+ // ),
742
+ // {},
743
+ // );
838
744
  const proceedAnyway = enoughBalance !== null;
839
- const settings = {
840
- slippage: slippage.toString(),
841
- disabledSwappersGroups: ['Osmosis'],
842
- disabledSwappersIds: []
843
- };
844
- if (proceedAnyway) {
845
- const newSwap = calculatePendingSwap(inputAmount.toString(), bestRoute, wallets, settings, false);
846
- }
745
+ // const settings: SwapSavedSettings = {
746
+ // slippage: slippage.toString(),
747
+ // disabledSwappersGroups: ['Osmosis'],
748
+ // disabledSwappersIds: [],
749
+ // };
750
+ // if (proceedAnyway) {
751
+ // const newSwap: PendingSwap = calculatePendingSwap(
752
+ // inputAmount!.toString(),
753
+ // bestRoute,
754
+ // wallets,
755
+ // settings,
756
+ // false,
757
+ // );
758
+ // }
847
759
  !proceedAnyway && checkFeeAndBalance(selectedWallets).then(data => {
848
760
  if (!data) {
849
761
  setError('confirm swap error');
@@ -853,17 +765,15 @@ function useConfirmSwap() {
853
765
  setError('confirm swap error');
854
766
  return;
855
767
  } else {
768
+ // @ts-ignore
856
769
  const {
857
- hasEnoughBalanceOrSlippage,
858
- bestRoute: newBestRoute
770
+ hasEnoughBalanceOrSlippage
859
771
  } = data;
860
772
  if (!hasEnoughBalanceOrSlippage) {
861
773
  return;
862
774
  }
863
775
  setEnoughBalance(hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage);
864
- if (hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage && !hasEnoughBalanceOrSlippage.routeChanged) {
865
- const newSwap = calculatePendingSwap(inputAmount.toString(), newBestRoute, wallets, settings, true);
866
- } else if (!hasEnoughBalanceOrSlippage.balance) {
776
+ if (hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage && !hasEnoughBalanceOrSlippage.routeChanged) ; else if (!hasEnoughBalanceOrSlippage.balance) {
867
777
  setError('not enough balance');
868
778
  }
869
779
  }
@@ -1893,6 +1803,45 @@ const errorMessages = {
1893
1803
  genericServerError: 'Error connecting server, please reload the app and try again'
1894
1804
  };
1895
1805
 
1806
+ function getOutputRatio(inputUsdValue, outputUsdValue) {
1807
+ if (inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) return 0;
1808
+ return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
1809
+ }
1810
+ function outputRatioHasWarning(inputUsdValue, outputRatio) {
1811
+ return parseInt(outputRatio.toFixed(2) || '0') <= -10 && inputUsdValue.gte(new BigNumber__default(400)) || parseInt(outputRatio.toFixed(2) || '0') <= -5 && inputUsdValue.gte(new BigNumber__default(1000));
1812
+ }
1813
+ function hasLimitError(bestRoute) {
1814
+ return (bestRoute?.result?.swaps || []).filter(swap => {
1815
+ const minimum = !!swap.fromAmountMinValue ? new BigNumber__default(swap.fromAmountMinValue) : null;
1816
+ const maximum = !!swap.fromAmountMaxValue ? new BigNumber__default(swap.fromAmountMaxValue) : null;
1817
+ const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
1818
+ if (isExclusive) {
1819
+ return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
1820
+ } else {
1821
+ return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
1822
+ }
1823
+ }).length > 0;
1824
+ }
1825
+ function getSwapButtonTitle(accounts, loading, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath) {
1826
+ if (loading) return 'Finding Best Route...';
1827
+ if (accounts.length == 0) return 'Connect Wallet';else if (hasLimitError) return 'Limit Error';else if (highValueLoss) return 'Price impact is too high!';else if (priceImpactCanNotBeComputed) return 'USD price is unknown, price impact might be high!';else if (needsToWarnEthOnPath) return 'The route goes through Ethereum. Continue?';else return 'Swap';
1828
+ }
1829
+ function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
1830
+ return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0);
1831
+ }
1832
+ function requiredWallets(route) {
1833
+ const wallets = [];
1834
+ route?.result?.swaps.forEach(swap => {
1835
+ const currentStepFromBlockchain = swap.from.blockchain;
1836
+ const currentStepToBlockchain = swap.to.blockchain;
1837
+ let lastAddedWallet = wallets[wallets.length - 1];
1838
+ if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
1839
+ lastAddedWallet = wallets[wallets.length - 1];
1840
+ if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
1841
+ });
1842
+ return wallets;
1843
+ }
1844
+
1896
1845
  const Container$2 = /*#__PURE__*/ui.styled('div', {
1897
1846
  display: 'flex',
1898
1847
  flexDirection: 'column',
@@ -2171,7 +2120,8 @@ const ListContainer = /*#__PURE__*/ui.styled('div', {
2171
2120
  gap: '.5rem',
2172
2121
  gridTemplateColumns: ' repeat(2, minmax(0, 1fr))',
2173
2122
  height: '450px',
2174
- alignContent: 'baseline'
2123
+ alignContent: 'baseline',
2124
+ padding: '0 0.5rem'
2175
2125
  });
2176
2126
  const AlertContainer = /*#__PURE__*/ui.styled('div', {
2177
2127
  paddingBottom: '$16'