@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.
- package/dist/hooks/useConfirmSwap.d.ts +1 -11
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +73 -123
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +73 -123
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +73 -123
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useConfirmSwap.ts +94 -60
- package/src/pages/WalletsPage.tsx +6 -1
|
@@ -606,111 +606,7 @@ const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*
|
|
|
606
606
|
name: 'user-settings'
|
|
607
607
|
})));
|
|
608
608
|
|
|
609
|
-
|
|
610
|
-
if (inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) return 0;
|
|
611
|
-
return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
|
|
612
|
-
}
|
|
613
|
-
function outputRatioHasWarning(inputUsdValue, outputRatio) {
|
|
614
|
-
return parseInt(outputRatio.toFixed(2) || '0') <= -10 && inputUsdValue.gte(new BigNumber(400)) || parseInt(outputRatio.toFixed(2) || '0') <= -5 && inputUsdValue.gte(new BigNumber(1000));
|
|
615
|
-
}
|
|
616
|
-
function hasLimitError(bestRoute) {
|
|
617
|
-
return (bestRoute?.result?.swaps || []).filter(swap => {
|
|
618
|
-
const minimum = !!swap.fromAmountMinValue ? new BigNumber(swap.fromAmountMinValue) : null;
|
|
619
|
-
const maximum = !!swap.fromAmountMaxValue ? new BigNumber(swap.fromAmountMaxValue) : null;
|
|
620
|
-
const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
|
|
621
|
-
if (isExclusive) {
|
|
622
|
-
return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
|
|
623
|
-
} else {
|
|
624
|
-
return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
|
|
625
|
-
}
|
|
626
|
-
}).length > 0;
|
|
627
|
-
}
|
|
628
|
-
function getSwapButtonTitle(accounts, loading, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath) {
|
|
629
|
-
if (loading) return 'Finding Best Route...';
|
|
630
|
-
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';
|
|
631
|
-
}
|
|
632
|
-
function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
|
|
633
|
-
return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0);
|
|
634
|
-
}
|
|
635
|
-
function calculatePendingSwap(inputAmount, bestRoute, wallets, settings, validateBalanceOrFee) {
|
|
636
|
-
const simulationResult = bestRoute.result;
|
|
637
|
-
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
638
|
-
return {
|
|
639
|
-
creationTime: new Date().getTime().toString(),
|
|
640
|
-
finishTime: null,
|
|
641
|
-
requestId: bestRoute.requestId || '',
|
|
642
|
-
inputAmount: inputAmount,
|
|
643
|
-
wallets,
|
|
644
|
-
status: 'running',
|
|
645
|
-
isPaused: false,
|
|
646
|
-
extraMessage: null,
|
|
647
|
-
extraMessageSeverity: null,
|
|
648
|
-
extraMessageDetail: null,
|
|
649
|
-
extraMessageErrorCode: null,
|
|
650
|
-
networkStatusExtraMessage: null,
|
|
651
|
-
networkStatusExtraMessageDetail: null,
|
|
652
|
-
lastNotificationTime: null,
|
|
653
|
-
settings: settings,
|
|
654
|
-
simulationResult: simulationResult,
|
|
655
|
-
validateBalanceOrFee,
|
|
656
|
-
//TODO: finalize PendingSwap type and remove ts-ignore
|
|
657
|
-
//@ts-ignore
|
|
658
|
-
steps: bestRoute.result?.swaps?.map((s, i) => ({
|
|
659
|
-
id: i + 1,
|
|
660
|
-
fromBlockchain: s.from.blockchain,
|
|
661
|
-
fromSymbol: s.from.symbol,
|
|
662
|
-
fromSymbolAddress: s.from.address,
|
|
663
|
-
fromDecimals: s.from.decimals,
|
|
664
|
-
fromAmountPrecision: s.fromAmountPrecision,
|
|
665
|
-
fromAmountMinValue: s.fromAmountMinValue,
|
|
666
|
-
fromAmountMaxValue: s.fromAmountMaxValue,
|
|
667
|
-
toBlockchain: s.to.blockchain,
|
|
668
|
-
fromLogo: s.from.logo,
|
|
669
|
-
toSymbol: s.to.symbol,
|
|
670
|
-
toSymbolAddress: s.to.address,
|
|
671
|
-
toDecimals: s.to.decimals,
|
|
672
|
-
toLogo: s.to.logo,
|
|
673
|
-
startTransactionTime: new Date().getTime(),
|
|
674
|
-
swapperId: s.swapperId,
|
|
675
|
-
expectedOutputAmountHumanReadable: s.toAmount,
|
|
676
|
-
outputAmount: null,
|
|
677
|
-
status: 'created',
|
|
678
|
-
networkStatus: null,
|
|
679
|
-
executedTransactionId: null,
|
|
680
|
-
externalTransactionId: null,
|
|
681
|
-
explorerUrl: null,
|
|
682
|
-
trackingCode: null,
|
|
683
|
-
cosmosTransaction: null,
|
|
684
|
-
solanaTransaction: null,
|
|
685
|
-
starknetTransaction: null,
|
|
686
|
-
starknetApprovalTransaction: null,
|
|
687
|
-
tronTransaction: null,
|
|
688
|
-
tronApprovalTransaction: null,
|
|
689
|
-
evmTransaction: null,
|
|
690
|
-
evmApprovalTransaction: null,
|
|
691
|
-
transferTransaction: null,
|
|
692
|
-
diagnosisUrl: null,
|
|
693
|
-
internalSteps: null,
|
|
694
|
-
fromBlockchainLogo: '',
|
|
695
|
-
toBlockchainLogo: '',
|
|
696
|
-
swapperLogo: '',
|
|
697
|
-
swapperType: ''
|
|
698
|
-
})) || []
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
function requiredWallets(route) {
|
|
702
|
-
const wallets = [];
|
|
703
|
-
route?.result?.swaps.forEach(swap => {
|
|
704
|
-
const currentStepFromBlockchain = swap.from.blockchain;
|
|
705
|
-
const currentStepToBlockchain = swap.to.blockchain;
|
|
706
|
-
let lastAddedWallet = wallets[wallets.length - 1];
|
|
707
|
-
if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
|
|
708
|
-
lastAddedWallet = wallets[wallets.length - 1];
|
|
709
|
-
if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
|
|
710
|
-
});
|
|
711
|
-
return wallets;
|
|
712
|
-
}
|
|
713
|
-
|
|
609
|
+
// import { WalletType } from '@rango-dev/wallets-shared';
|
|
714
610
|
function useConfirmSwap() {
|
|
715
611
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
716
612
|
const toToken = useBestRouteStore.use.toToken();
|
|
@@ -812,6 +708,7 @@ function useConfirmSwap() {
|
|
|
812
708
|
const routeChangeStatus = compareRoutes(bestRoute, r, inputAmount.toString(), fromToken.usdPrice, toToken.usdPrice);
|
|
813
709
|
setBestRoute(r);
|
|
814
710
|
const isChanged = routeChangeStatus.isChanged;
|
|
711
|
+
// const changeWarningMessage = routeChangeStatus.warningMessage;
|
|
815
712
|
setBestRouteChanged(isChanged);
|
|
816
713
|
setWarning('Best route changed');
|
|
817
714
|
setData(r);
|
|
@@ -823,19 +720,34 @@ function useConfirmSwap() {
|
|
|
823
720
|
const swap = () => {
|
|
824
721
|
if (!bestRoute) return;
|
|
825
722
|
if (inputAmount.toString() === '') return;
|
|
826
|
-
const wallets = selectedWallets.reduce(
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
723
|
+
// const wallets = selectedWallets.reduce(
|
|
724
|
+
// (
|
|
725
|
+
// selectedWalletsMap: { [p: string]: { address: string; walletType: WalletType } },
|
|
726
|
+
// selectedWallet,
|
|
727
|
+
// ) => (
|
|
728
|
+
// (selectedWalletsMap[selectedWallet.chain] = {
|
|
729
|
+
// address: selectedWallet.address,
|
|
730
|
+
// walletType: selectedWallet.walletType,
|
|
731
|
+
// }),
|
|
732
|
+
// selectedWalletsMap
|
|
733
|
+
// ),
|
|
734
|
+
// {},
|
|
735
|
+
// );
|
|
830
736
|
const proceedAnyway = enoughBalance !== null;
|
|
831
|
-
const settings = {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
};
|
|
836
|
-
if (proceedAnyway) {
|
|
837
|
-
|
|
838
|
-
|
|
737
|
+
// const settings: SwapSavedSettings = {
|
|
738
|
+
// slippage: slippage.toString(),
|
|
739
|
+
// disabledSwappersGroups: ['Osmosis'],
|
|
740
|
+
// disabledSwappersIds: [],
|
|
741
|
+
// };
|
|
742
|
+
// if (proceedAnyway) {
|
|
743
|
+
// const newSwap: PendingSwap = calculatePendingSwap(
|
|
744
|
+
// inputAmount!.toString(),
|
|
745
|
+
// bestRoute,
|
|
746
|
+
// wallets,
|
|
747
|
+
// settings,
|
|
748
|
+
// false,
|
|
749
|
+
// );
|
|
750
|
+
// }
|
|
839
751
|
!proceedAnyway && checkFeeAndBalance(selectedWallets).then(data => {
|
|
840
752
|
if (!data) {
|
|
841
753
|
setError('confirm swap error');
|
|
@@ -845,17 +757,15 @@ function useConfirmSwap() {
|
|
|
845
757
|
setError('confirm swap error');
|
|
846
758
|
return;
|
|
847
759
|
} else {
|
|
760
|
+
// @ts-ignore
|
|
848
761
|
const {
|
|
849
|
-
hasEnoughBalanceOrSlippage
|
|
850
|
-
bestRoute: newBestRoute
|
|
762
|
+
hasEnoughBalanceOrSlippage
|
|
851
763
|
} = data;
|
|
852
764
|
if (!hasEnoughBalanceOrSlippage) {
|
|
853
765
|
return;
|
|
854
766
|
}
|
|
855
767
|
setEnoughBalance(hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage);
|
|
856
|
-
if (hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage && !hasEnoughBalanceOrSlippage.routeChanged) {
|
|
857
|
-
const newSwap = calculatePendingSwap(inputAmount.toString(), newBestRoute, wallets, settings, true);
|
|
858
|
-
} else if (!hasEnoughBalanceOrSlippage.balance) {
|
|
768
|
+
if (hasEnoughBalanceOrSlippage.balance && hasEnoughBalanceOrSlippage.slippage && !hasEnoughBalanceOrSlippage.routeChanged) ; else if (!hasEnoughBalanceOrSlippage.balance) {
|
|
859
769
|
setError('not enough balance');
|
|
860
770
|
}
|
|
861
771
|
}
|
|
@@ -1885,6 +1795,45 @@ const errorMessages = {
|
|
|
1885
1795
|
genericServerError: 'Error connecting server, please reload the app and try again'
|
|
1886
1796
|
};
|
|
1887
1797
|
|
|
1798
|
+
function getOutputRatio(inputUsdValue, outputUsdValue) {
|
|
1799
|
+
if (inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) return 0;
|
|
1800
|
+
return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
|
|
1801
|
+
}
|
|
1802
|
+
function outputRatioHasWarning(inputUsdValue, outputRatio) {
|
|
1803
|
+
return parseInt(outputRatio.toFixed(2) || '0') <= -10 && inputUsdValue.gte(new BigNumber(400)) || parseInt(outputRatio.toFixed(2) || '0') <= -5 && inputUsdValue.gte(new BigNumber(1000));
|
|
1804
|
+
}
|
|
1805
|
+
function hasLimitError(bestRoute) {
|
|
1806
|
+
return (bestRoute?.result?.swaps || []).filter(swap => {
|
|
1807
|
+
const minimum = !!swap.fromAmountMinValue ? new BigNumber(swap.fromAmountMinValue) : null;
|
|
1808
|
+
const maximum = !!swap.fromAmountMaxValue ? new BigNumber(swap.fromAmountMaxValue) : null;
|
|
1809
|
+
const isExclusive = swap.fromAmountRestrictionType === 'EXCLUSIVE';
|
|
1810
|
+
if (isExclusive) {
|
|
1811
|
+
return minimum?.gte(swap.fromAmount) || maximum?.lte(swap.fromAmount);
|
|
1812
|
+
} else {
|
|
1813
|
+
return minimum?.gt(swap.fromAmount) || maximum?.lt(swap.fromAmount);
|
|
1814
|
+
}
|
|
1815
|
+
}).length > 0;
|
|
1816
|
+
}
|
|
1817
|
+
function getSwapButtonTitle(accounts, loading, hasLimitError, highValueLoss, priceImpactCanNotBeComputed, needsToWarnEthOnPath) {
|
|
1818
|
+
if (loading) return 'Finding Best Route...';
|
|
1819
|
+
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';
|
|
1820
|
+
}
|
|
1821
|
+
function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
|
|
1822
|
+
return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0);
|
|
1823
|
+
}
|
|
1824
|
+
function requiredWallets(route) {
|
|
1825
|
+
const wallets = [];
|
|
1826
|
+
route?.result?.swaps.forEach(swap => {
|
|
1827
|
+
const currentStepFromBlockchain = swap.from.blockchain;
|
|
1828
|
+
const currentStepToBlockchain = swap.to.blockchain;
|
|
1829
|
+
let lastAddedWallet = wallets[wallets.length - 1];
|
|
1830
|
+
if (currentStepFromBlockchain != lastAddedWallet) wallets.push(currentStepFromBlockchain);
|
|
1831
|
+
lastAddedWallet = wallets[wallets.length - 1];
|
|
1832
|
+
if (currentStepToBlockchain != lastAddedWallet) wallets.push(currentStepToBlockchain);
|
|
1833
|
+
});
|
|
1834
|
+
return wallets;
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1888
1837
|
const Container$2 = /*#__PURE__*/styled('div', {
|
|
1889
1838
|
display: 'flex',
|
|
1890
1839
|
flexDirection: 'column',
|
|
@@ -2163,7 +2112,8 @@ const ListContainer = /*#__PURE__*/styled('div', {
|
|
|
2163
2112
|
gap: '.5rem',
|
|
2164
2113
|
gridTemplateColumns: ' repeat(2, minmax(0, 1fr))',
|
|
2165
2114
|
height: '450px',
|
|
2166
|
-
alignContent: 'baseline'
|
|
2115
|
+
alignContent: 'baseline',
|
|
2116
|
+
padding: '0 0.5rem'
|
|
2167
2117
|
});
|
|
2168
2118
|
const AlertContainer = /*#__PURE__*/styled('div', {
|
|
2169
2119
|
paddingBottom: '$16'
|