@rango-dev/widget-embedded 0.1.10-next.76 → 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":"ConfirmWalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/ConfirmWalletsPage.tsx"],"names":[],"mappings":"AAOA,OAAO,EAA2C,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG3F,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,kBAAkB,gBAmCjC"}
1
+ {"version":3,"file":"ConfirmWalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/ConfirmWalletsPage.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAoG,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKpJ,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,kBAAkB,gBA+CjC"}
@@ -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"}
@@ -20,4 +20,6 @@ export declare function resetBalanceState(balance: Balance): Balance;
20
20
  export declare const calculateWalletUsdValue: (balance: Balance[]) => string;
21
21
  export declare const sortedTokens: (tokens: TokenWithBalance[], position: 'from' | 'to', balance: Balance[]) => TokenWithBalance[];
22
22
  export declare const getUsdPrice: (blockchain: string, symbol: string, address: string | null, allTokens: Token[]) => number | null;
23
+ export declare const isExperimentalChain: (blockchains: BlockchainMeta[], wallet: string) => boolean;
24
+ export declare const getKeplrCompatibleConnectedWallets: (selectableWallets: SelectableWallet[]) => WalletType[];
23
25
  //# sourceMappingURL=wallets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../src/utils/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,UAAU,EACV,WAAW,EACX,UAAU,EACX,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,WAAW,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG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B,MAAM,KACb,OAOF,CAAC;AAEF,eAAO,MAAM,kCAAkC,sBAC1B,gBAAgB,EAAE,KACpC,UAAU,EAQZ,CAAC"}
@@ -383,10 +383,11 @@ function getSelectableWallets(accounts, selectedWallets, getWalletInfo, required
383
383
  name: getWalletInfo(account.walletType).name,
384
384
  selected: !!selectedWallets.find(wallet => wallet.chain === account.chain && wallet.walletType === account.walletType)
385
385
  }));
386
- return requiredChains ? connectedWallets.filter(wallet => requiredChains.includes(wallet.chain)) : removeDuplicateWallets(connectedWallets, 'walletType');
386
+ return requiredChains ? connectedWallets.filter((wallet, index, array) => requiredChains.includes(wallet.chain) && array.findIndex(w => w.address === wallet.address) === index) : removeDuplicateWallets(connectedWallets, 'walletType');
387
387
  }
388
388
  const removeDuplicateWallets = (arr, key) => {
389
- return [...new Map(arr.map(item => [item[key], item])).values()];
389
+ const map = new Map(arr.map(item => [item[key], item]));
390
+ return Array.from(map.values());
390
391
  };
391
392
  function getBalanceFromWallet(balances, chain, symbol, address) {
392
393
  if (balances.length === 0) return null;
@@ -450,8 +451,6 @@ const calculateWalletUsdValue = balance => {
450
451
  return modifiedWalletBlockchain;
451
452
  });
452
453
  const total = numberToString(modifiedWalletBlockchains?.flatMap(b => b.accounts)?.flatMap(a => a?.balances)?.map(b => new BigNumber__default(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0))?.reduce((a, b) => a.plus(b), ZERO) || ZERO).toString();
453
- console.log('total');
454
- console.log(total);
455
454
  return numberWithThousandSeperator(total);
456
455
  };
457
456
  function numberWithThousandSeperator(number) {
@@ -476,6 +475,17 @@ const getUsdPrice = (blockchain, symbol, address, allTokens) => {
476
475
  const token = allTokens?.find(t => t.blockchain === blockchain && t.symbol?.toUpperCase() === symbol?.toUpperCase() && t.address === address);
477
476
  return token?.usdPrice || null;
478
477
  };
478
+ const isExperimentalChain = (blockchains, wallet) => {
479
+ const cosmosExperimentalChainInfo = walletsShared.getCosmosExperimentalChainInfo(Object.entries(blockchains).map(_ref => {
480
+ let [, blockchainMeta] = _ref;
481
+ return blockchainMeta;
482
+ }).filter(walletsShared.isCosmosBlockchain));
483
+ return cosmosExperimentalChainInfo && !!cosmosExperimentalChainInfo[wallet];
484
+ };
485
+ const getKeplrCompatibleConnectedWallets = selectableWallets => {
486
+ const connectedWalletTypes = new Set(selectableWallets.map(a => a.walletType.toString()));
487
+ return walletsShared.KEPLR_COMPATIBLE_WALLETS.filter(compatibleWallet => connectedWalletTypes.has(compatibleWallet));
488
+ };
479
489
 
480
490
  const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()(set => ({
481
491
  accounts: [],
@@ -604,111 +614,7 @@ const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.crea
604
614
  name: 'user-settings'
605
615
  })));
606
616
 
607
- function getOutputRatio(inputUsdValue, outputUsdValue) {
608
- if (inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) return 0;
609
- return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
610
- }
611
- function outputRatioHasWarning(inputUsdValue, outputRatio) {
612
- 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));
613
- }
614
- function hasLimitError(bestRoute) {
615
- return (bestRoute?.result?.swaps || []).filter(swap => {
616
- const minimum = !!swap.fromAmountMinValue ? new BigNumber__default(swap.fromAmountMinValue) : null;
617
- const maximum = !!swap.fromAmountMaxValue ? new BigNumber__default(swap.fromAmountMaxValue) : null;
618
- const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
619
- if (isExclusive) {
620
- return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
621
- } else {
622
- return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
623
- }
624
- }).length > 0;
625
- }
626
- function getSwapButtonTitle(accounts, loading, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath) {
627
- if (loading) return 'Finding Best Route...';
628
- 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';
629
- }
630
- function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
631
- return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0);
632
- }
633
- function calculatePendingSwap(inputAmount, bestRoute, wallets, settings, validateBalanceOrFee) {
634
- const simulationResult = bestRoute.result;
635
- if (!simulationResult) throw Error('Simulation result should not be null');
636
- return {
637
- creationTime: new Date().getTime().toString(),
638
- finishTime: null,
639
- requestId: bestRoute.requestId || '',
640
- inputAmount: inputAmount,
641
- wallets,
642
- status: 'running',
643
- isPaused: false,
644
- extraMessage: null,
645
- extraMessageSeverity: null,
646
- extraMessageDetail: null,
647
- extraMessageErrorCode: null,
648
- networkStatusExtraMessage: null,
649
- networkStatusExtraMessageDetail: null,
650
- lastNotificationTime: null,
651
- settings: settings,
652
- simulationResult: simulationResult,
653
- validateBalanceOrFee,
654
- //TODO: finalize PendingSwap type and remove ts-ignore
655
- //@ts-ignore
656
- steps: bestRoute.result?.swaps?.map((s, i) => ({
657
- id: i + 1,
658
- fromBlockchain: s.from.blockchain,
659
- fromSymbol: s.from.symbol,
660
- fromSymbolAddress: s.from.address,
661
- fromDecimals: s.from.decimals,
662
- fromAmountPrecision: s.fromAmountPrecision,
663
- fromAmountMinValue: s.fromAmountMinValue,
664
- fromAmountMaxValue: s.fromAmountMaxValue,
665
- toBlockchain: s.to.blockchain,
666
- fromLogo: s.from.logo,
667
- toSymbol: s.to.symbol,
668
- toSymbolAddress: s.to.address,
669
- toDecimals: s.to.decimals,
670
- toLogo: s.to.logo,
671
- startTransactionTime: new Date().getTime(),
672
- swapperId: s.swapperId,
673
- expectedOutputAmountHumanReadable: s.toAmount,
674
- outputAmount: null,
675
- status: 'created',
676
- networkStatus: null,
677
- executedTransactionId: null,
678
- externalTransactionId: null,
679
- explorerUrl: null,
680
- trackingCode: null,
681
- cosmosTransaction: null,
682
- solanaTransaction: null,
683
- starknetTransaction: null,
684
- starknetApprovalTransaction: null,
685
- tronTransaction: null,
686
- tronApprovalTransaction: null,
687
- evmTransaction: null,
688
- evmApprovalTransaction: null,
689
- transferTransaction: null,
690
- diagnosisUrl: null,
691
- internalSteps: null,
692
- fromBlockchainLogo: '',
693
- toBlockchainLogo: '',
694
- swapperLogo: '',
695
- swapperType: ''
696
- })) || []
697
- };
698
- }
699
- function requiredWallets(route) {
700
- const wallets = [];
701
- route?.result?.swaps.forEach(swap => {
702
- const currentStepFromBlockchain = swap.from.blockchain;
703
- const currentStepToBlockchain = swap.to.blockchain;
704
- let lastAddedWallet = wallets[wallets.length - 1];
705
- if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
706
- lastAddedWallet = wallets[wallets.length - 1];
707
- if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
708
- });
709
- return wallets;
710
- }
711
-
617
+ // import { WalletType } from '@rango-dev/wallets-shared';
712
618
  function useConfirmSwap() {
713
619
  const fromToken = useBestRouteStore.use.fromToken();
714
620
  const toToken = useBestRouteStore.use.toToken();
@@ -810,6 +716,7 @@ function useConfirmSwap() {
810
716
  const routeChangeStatus = compareRoutes(bestRoute, r, inputAmount.toString(), fromToken.usdPrice, toToken.usdPrice);
811
717
  setBestRoute(r);
812
718
  const isChanged = routeChangeStatus.isChanged;
719
+ // const changeWarningMessage = routeChangeStatus.warningMessage;
813
720
  setBestRouteChanged(isChanged);
814
721
  setWarning('Best route changed');
815
722
  setData(r);
@@ -821,19 +728,34 @@ function useConfirmSwap() {
821
728
  const swap = () => {
822
729
  if (!bestRoute) return;
823
730
  if (inputAmount.toString() === '') return;
824
- const wallets = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = {
825
- address: selectedWallet.address,
826
- walletType: selectedWallet.walletType
827
- }, 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
+ // );
828
744
  const proceedAnyway = enoughBalance !== null;
829
- const settings = {
830
- slippage: slippage.toString(),
831
- disabledSwappersGroups: ['Osmosis'],
832
- disabledSwappersIds: []
833
- };
834
- if (proceedAnyway) {
835
- const newSwap = calculatePendingSwap(inputAmount.toString(), bestRoute, wallets, settings, false);
836
- }
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
+ // }
837
759
  !proceedAnyway && checkFeeAndBalance(selectedWallets).then(data => {
838
760
  if (!data) {
839
761
  setError('confirm swap error');
@@ -843,17 +765,15 @@ function useConfirmSwap() {
843
765
  setError('confirm swap error');
844
766
  return;
845
767
  } else {
768
+ // @ts-ignore
846
769
  const {
847
- hasEnoughBalanceOrSlippage,
848
- bestRoute: newBestRoute
770
+ hasEnoughBalanceOrSlippage
849
771
  } = data;
850
772
  if (!hasEnoughBalanceOrSlippage) {
851
773
  return;
852
774
  }
853
775
  setEnoughBalance(hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage);
854
- if (hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage && !hasEnoughBalanceOrSlippage.routeChanged) {
855
- const newSwap = calculatePendingSwap(inputAmount.toString(), newBestRoute, wallets, settings, true);
856
- } else if (!hasEnoughBalanceOrSlippage.balance) {
776
+ if (hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage && !hasEnoughBalanceOrSlippage.routeChanged) ; else if (!hasEnoughBalanceOrSlippage.balance) {
857
777
  setError('not enough balance');
858
778
  }
859
779
  }
@@ -1883,6 +1803,45 @@ const errorMessages = {
1883
1803
  genericServerError: 'Error connecting server, please reload the app and try again'
1884
1804
  };
1885
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
+
1886
1845
  const Container$2 = /*#__PURE__*/ui.styled('div', {
1887
1846
  display: 'flex',
1888
1847
  flexDirection: 'column',
@@ -2161,7 +2120,8 @@ const ListContainer = /*#__PURE__*/ui.styled('div', {
2161
2120
  gap: '.5rem',
2162
2121
  gridTemplateColumns: ' repeat(2, minmax(0, 1fr))',
2163
2122
  height: '450px',
2164
- alignContent: 'baseline'
2123
+ alignContent: 'baseline',
2124
+ padding: '0 0.5rem'
2165
2125
  });
2166
2126
  const AlertContainer = /*#__PURE__*/ui.styled('div', {
2167
2127
  paddingBottom: '$16'
@@ -2208,25 +2168,36 @@ function WalletsPage() {
2208
2168
  function ConfirmWalletsPage() {
2209
2169
  const navigate = reactRouterDom.useNavigate();
2210
2170
  const bestRoute = useBestRouteStore.use.bestRoute();
2171
+ const {
2172
+ blockchains
2173
+ } = useMetaStore.use.meta();
2211
2174
  const accounts = useWalletsStore.use.accounts();
2212
2175
  const selectedWallets = useWalletsStore.use.selectedWallets();
2213
2176
  const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
2214
2177
  const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
2215
2178
  const {
2216
- getWalletInfo
2179
+ getWalletInfo,
2180
+ connect
2217
2181
  } = walletsCore.useWallets();
2218
2182
  const confirmDisabled = !requiredWallets(bestRoute).every(chain => selectedWallets.map(wallet => wallet.chain).includes(chain));
2219
2183
  React.useEffect(() => {
2220
2184
  initSelectedWallets();
2221
2185
  }, []);
2186
+ const selectableWallets = getSelectableWallets(accounts, selectedWallets, getWalletInfo, getRequiredChains(bestRoute));
2187
+ const handleConnectChain = wallet => {
2188
+ const network = wallet;
2189
+ getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
2190
+ };
2222
2191
  return React__default.createElement(ui.ConfirmWallets, {
2223
2192
  requiredWallets: getRequiredChains(bestRoute),
2224
- selectableWallets: getSelectableWallets(accounts, selectedWallets, getWalletInfo, getRequiredChains(bestRoute)),
2193
+ selectableWallets: selectableWallets,
2225
2194
  onBack: () => navigate(-1),
2226
2195
  swap: bestRoute,
2227
2196
  onConfirm: () => navigate(navigationRoutes.confirmSwap),
2228
2197
  onChange: wallet => setSelectedWallet(wallet),
2229
- confirmDisabled: confirmDisabled
2198
+ confirmDisabled: confirmDisabled,
2199
+ handleConnectChain: wallet => handleConnectChain(wallet),
2200
+ isExperimentalChain: wallet => getKeplrCompatibleConnectedWallets(selectableWallets).length > 0 ? isExperimentalChain(blockchains, wallet) : false
2230
2201
  });
2231
2202
  }
2232
2203