@rango-dev/widget-embedded 0.17.1-next.9 → 0.19.0
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/CHANGELOG.md +4 -0
- package/dist/QueueManager.d.ts +1 -2
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/Wallets.d.ts +0 -1
- package/dist/Wallets.d.ts.map +1 -1
- package/dist/Widget.d.ts +1 -1
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +2 -0
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +6 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +3 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +3 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts +4 -1
- package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.d.ts +4 -0
- package/dist/components/NoRoutes/NoRoutes.d.ts.map +1 -0
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts +3 -0
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +1 -0
- package/dist/components/{NoResult/NoResult.styles.d.ts → NoRoutes/NoRoutes.styles.d.ts} +1 -1
- package/dist/components/{NoResult/NoResult.styles.d.ts.map → NoRoutes/NoRoutes.styles.d.ts.map} +1 -1
- package/dist/components/{NoResult/NoResult.types.d.ts → NoRoutes/NoRoutes.types.d.ts} +3 -3
- package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +1 -0
- package/dist/components/NoRoutes/index.d.ts +2 -0
- package/dist/components/NoRoutes/index.d.ts.map +1 -0
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -0
- package/dist/components/{QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts → RouteErrors/RouteErrors.styles.d.ts} +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -0
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +24 -0
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -0
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -0
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +1 -0
- package/dist/components/RouteErrors/index.d.ts +2 -0
- package/dist/components/RouteErrors/index.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts +6 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +4 -4
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/constants/messages.d.ts +1 -1
- package/dist/constants/searchParams.d.ts +1 -2
- package/dist/constants/searchParams.d.ts.map +1 -1
- package/dist/constants/warnings.d.ts +2 -2
- package/dist/constants/warnings.d.ts.map +1 -1
- package/dist/hooks/{useConfirmSwap/useConfirmSwap.types.d.ts → useConfirmSwap.d.ts} +7 -5
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/{useFetchQuote.d.ts → useFetchBestRoute.d.ts} +3 -3
- package/dist/hooks/useFetchBestRoute.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useSwapInput.d.ts +2 -4
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts +2 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts +6 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts +2 -1
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +6 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +8 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +23 -5
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/{quote.d.ts → bestRoute.d.ts} +27 -39
- package/dist/store/bestRoute.d.ts.map +1 -0
- package/dist/store/meta.d.ts +23 -0
- package/dist/store/meta.d.ts.map +1 -0
- package/dist/store/settings.d.ts +2 -3
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +2 -3
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +0 -3
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +4 -5
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +5 -5
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/routing.d.ts +65 -0
- package/dist/types/routing.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/{quote.d.ts → routing.d.ts} +12 -16
- package/dist/utils/routing.d.ts.map +1 -0
- package/dist/utils/settings.d.ts +2 -3
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +22 -25
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -2
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/QueueManager.tsx +14 -14
- package/src/Wallets.tsx +15 -35
- package/src/Widget.tsx +24 -11
- package/src/components/AppRouter.tsx +5 -6
- package/src/components/AppRoutes.tsx +39 -6
- package/src/components/BlockchainList/BlockchainList.tsx +4 -4
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +7 -7
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +64 -2
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +40 -28
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +3 -1
- package/src/components/ConfirmWalletsModal/WalletList.tsx +5 -6
- package/src/components/ConfirmWalletsModal/WalletList.type.ts +4 -1
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
- package/src/components/{NoResult/NoResult.helpers.ts → NoRoutes/NoRoutes.helper.ts} +9 -16
- package/src/components/{NoResult/NoResult.styles.ts → NoRoutes/NoRoutes.styles.ts} +0 -2
- package/src/components/{NoResult/NoResult.tsx → NoRoutes/NoRoutes.tsx} +12 -10
- package/src/components/{NoResult/NoResult.types.ts → NoRoutes/NoRoutes.types.ts} +2 -3
- package/src/components/NoRoutes/index.ts +1 -0
- package/src/components/NotificationContent/NotificationContent.tsx +2 -3
- package/src/components/RouteErrors/RouteErrors.tsx +79 -0
- package/src/components/RouteErrors/RouteErrors.types.ts +29 -0
- package/src/components/RouteErrors/RouteErrorsModal.tsx +129 -0
- package/src/components/{QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx → RouteErrors/RouteErrorsModalItem.tsx} +3 -3
- package/src/components/RouteErrors/index.ts +1 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +22 -18
- package/src/components/SwitchFromAndTo.tsx +2 -2
- package/src/components/TokenList/TokenList.tsx +6 -5
- package/src/components/UpdateUrl.tsx +26 -36
- package/src/components/WidgetEvents.tsx +2 -4
- package/src/constants/errors.ts +10 -8
- package/src/constants/messages.ts +1 -1
- package/src/constants/searchParams.ts +0 -1
- package/src/constants/warnings.ts +7 -7
- package/src/hooks/useConfirmSwap.ts +303 -0
- package/src/hooks/{useFetchQuote.ts → useFetchBestRoute.ts} +3 -3
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useSwapInput.ts +23 -58
- package/src/hooks/useSyncStoresWithConfig.ts +19 -22
- package/src/hooks/useWalletList.ts +5 -3
- package/src/pages/ConfirmSwapPage.tsx +235 -58
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +247 -58
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +32 -23
- package/src/pages/SelectBlockchainPage.tsx +7 -6
- package/src/pages/SelectSwapItemsPage.tsx +5 -5
- package/src/pages/SettingsPage.tsx +13 -9
- package/src/pages/SwapDetailsPage.tsx +3 -3
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +12 -5
- package/src/store/app.ts +6 -18
- package/src/store/{quote.ts → bestRoute.ts} +60 -68
- package/src/store/meta.ts +39 -0
- package/src/store/settings.ts +4 -7
- package/src/store/slices/config.ts +15 -25
- package/src/store/slices/data.ts +29 -64
- package/src/store/wallets.ts +8 -11
- package/src/types/config.ts +5 -5
- package/src/types/index.ts +1 -1
- package/src/types/routing.ts +77 -0
- package/src/utils/numbers.ts +1 -1
- package/src/utils/routing.ts +321 -0
- package/src/utils/settings.ts +7 -8
- package/src/utils/swap.ts +85 -113
- package/src/utils/wallets.ts +17 -29
- package/dist/components/NoResult/NoResult.d.ts +0 -4
- package/dist/components/NoResult/NoResult.d.ts.map +0 -1
- package/dist/components/NoResult/NoResult.helpers.d.ts +0 -4
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +0 -1
- package/dist/components/NoResult/NoResult.types.d.ts.map +0 -1
- package/dist/components/NoResult/index.d.ts +0 -2
- package/dist/components/NoResult/index.d.ts.map +0 -1
- package/dist/components/Quote/Quote.d.ts +0 -4
- package/dist/components/Quote/Quote.d.ts.map +0 -1
- package/dist/components/Quote/Quote.styles.d.ts +0 -1429
- package/dist/components/Quote/Quote.styles.d.ts.map +0 -1
- package/dist/components/Quote/Quote.types.d.ts +0 -22
- package/dist/components/Quote/Quote.types.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSkeleton.d.ts +0 -4
- package/dist/components/Quote/QuoteSkeleton.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts +0 -319
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSkeleton.types.d.ts +0 -6
- package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSummary.d.ts +0 -11
- package/dist/components/Quote/QuoteSummary.d.ts.map +0 -1
- package/dist/components/Quote/QuoteSummary.styles.d.ts +0 -158
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +0 -1
- package/dist/components/Quote/index.d.ts +0 -4
- package/dist/components/Quote/index.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +0 -11
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +0 -4
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +0 -4
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +0 -9
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +0 -22
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +0 -11
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +0 -11
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +0 -1
- package/dist/components/QuoteWarningsAndErrors/index.d.ts +0 -2
- package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts +0 -4
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +0 -472
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +0 -17
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +0 -1
- package/dist/containers/QuoteInfo/index.d.ts +0 -2
- package/dist/containers/QuoteInfo/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/index.d.ts +0 -2
- package/dist/hooks/useConfirmSwap/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +0 -3
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +0 -16
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +0 -1
- package/dist/hooks/useFetchQuote.d.ts.map +0 -1
- package/dist/hooks/useForceAutoConnect.d.ts +0 -2
- package/dist/hooks/useForceAutoConnect.d.ts.map +0 -1
- package/dist/store/AppStore.d.ts +0 -11
- package/dist/store/AppStore.d.ts.map +0 -1
- package/dist/store/quote.d.ts.map +0 -1
- package/dist/types/quote.d.ts +0 -82
- package/dist/types/quote.d.ts.map +0 -1
- package/dist/utils/quote.d.ts.map +0 -1
- package/src/components/NoResult/index.ts +0 -1
- package/src/components/Quote/Quote.styles.ts +0 -212
- package/src/components/Quote/Quote.tsx +0 -345
- package/src/components/Quote/Quote.types.ts +0 -16
- package/src/components/Quote/QuoteSkeleton.styles.ts +0 -110
- package/src/components/Quote/QuoteSkeleton.tsx +0 -108
- package/src/components/Quote/QuoteSkeleton.types.ts +0 -5
- package/src/components/Quote/QuoteSummary.styles.ts +0 -15
- package/src/components/Quote/QuoteSummary.tsx +0 -46
- package/src/components/Quote/index.ts +0 -3
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +0 -107
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +0 -67
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +0 -103
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +0 -24
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +0 -77
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +0 -38
- package/src/components/QuoteWarningsAndErrors/index.ts +0 -1
- package/src/containers/QuoteInfo/QuoteInfo.styles.ts +0 -15
- package/src/containers/QuoteInfo/QuoteInfo.tsx +0 -97
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +0 -17
- package/src/containers/QuoteInfo/index.ts +0 -1
- package/src/hooks/useConfirmSwap/index.ts +0 -1
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +0 -168
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +0 -136
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +0 -19
- package/src/hooks/useForceAutoConnect.ts +0 -27
- package/src/store/AppStore.tsx +0 -35
- package/src/types/quote.ts +0 -107
- package/src/utils/quote.ts +0 -338
- /package/src/components/{QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts → RouteErrors/RouteErrors.styles.ts} +0 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import type {
|
|
3
|
+
ConfirmSwapError,
|
|
4
|
+
ConfirmSwapWarnings,
|
|
5
|
+
PendingSwapSettings,
|
|
6
|
+
Wallet,
|
|
7
|
+
} from '../types';
|
|
8
|
+
import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
+
import type { BestRouteResponse } from 'rango-sdk';
|
|
10
|
+
|
|
11
|
+
import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
12
|
+
import BigNumber from 'bignumber.js';
|
|
13
|
+
import { useEffect } from 'react';
|
|
14
|
+
|
|
15
|
+
import { errorMessages } from '../constants/errors';
|
|
16
|
+
import { HIGH_SLIPPAGE } from '../constants/swapSettings';
|
|
17
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
18
|
+
import { useMetaStore } from '../store/meta';
|
|
19
|
+
import { useSettingsStore } from '../store/settings';
|
|
20
|
+
import { useWalletsStore } from '../store/wallets';
|
|
21
|
+
import {
|
|
22
|
+
ConfirmSwapErrorTypes,
|
|
23
|
+
RouteWarningType,
|
|
24
|
+
SlippageWarningType,
|
|
25
|
+
} from '../types';
|
|
26
|
+
import { numberToString } from '../utils/numbers';
|
|
27
|
+
import {
|
|
28
|
+
isNumberOfSwapsChanged,
|
|
29
|
+
isRouteChanged,
|
|
30
|
+
isRouteInternalCoinsUpdated,
|
|
31
|
+
isRouteSwappersUpdated,
|
|
32
|
+
} from '../utils/routing';
|
|
33
|
+
import {
|
|
34
|
+
createBestRouteRequestBody,
|
|
35
|
+
getBalanceWarnings,
|
|
36
|
+
getMinRequiredSlippage,
|
|
37
|
+
getOutputRatio,
|
|
38
|
+
getPercentageChange,
|
|
39
|
+
getRouteOutputAmount,
|
|
40
|
+
getWalletsForNewSwap,
|
|
41
|
+
hasProperSlippage,
|
|
42
|
+
isOutputAmountChangedALot,
|
|
43
|
+
outputRatioHasWarning,
|
|
44
|
+
} from '../utils/swap';
|
|
45
|
+
|
|
46
|
+
import { useFetchBestRoute } from './useFetchBestRoute';
|
|
47
|
+
|
|
48
|
+
export type ConfirmSwapFetchResult = {
|
|
49
|
+
swap: PendingSwap | null;
|
|
50
|
+
error: ConfirmSwapError | null;
|
|
51
|
+
warnings: ConfirmSwapWarnings | null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type ConfirmSwap = {
|
|
55
|
+
loading: boolean;
|
|
56
|
+
fetch: (params: Params) => Promise<ConfirmSwapFetchResult>;
|
|
57
|
+
cancelFetch: () => void;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type Params = {
|
|
61
|
+
selectedWallets: Wallet[];
|
|
62
|
+
customDestination?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A request can be successful but in body of the response, it can be some case which is considered as failed.
|
|
67
|
+
*/
|
|
68
|
+
function throwErrorIfResponseIsNotValid(
|
|
69
|
+
response: BestRouteResponse,
|
|
70
|
+
params: { inputUsdValue: BigNumber | null; outputUsdValue: number | null }
|
|
71
|
+
) {
|
|
72
|
+
if (!response.result) {
|
|
73
|
+
throw new Error(errorMessages().noRoutesError.title, {
|
|
74
|
+
cause: {
|
|
75
|
+
type: ConfirmSwapErrorTypes.NO_ROUTE,
|
|
76
|
+
diagnosisMessage: response.diagnosisMessages?.[0],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const newRouteOutputUsdValue = new BigNumber(
|
|
82
|
+
response.result?.outputAmount || '0'
|
|
83
|
+
).multipliedBy(params.outputUsdValue || 0);
|
|
84
|
+
|
|
85
|
+
const outputRatio = getOutputRatio(
|
|
86
|
+
params.inputUsdValue,
|
|
87
|
+
newRouteOutputUsdValue
|
|
88
|
+
);
|
|
89
|
+
const highValueLoss = outputRatioHasWarning(
|
|
90
|
+
params.inputUsdValue,
|
|
91
|
+
outputRatio
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (highValueLoss) {
|
|
95
|
+
throw new Error('High value loss for route', {
|
|
96
|
+
cause: {
|
|
97
|
+
type: ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function generateWarnings(
|
|
106
|
+
previousRoute: BestRouteResponse,
|
|
107
|
+
currentRoute: BestRouteResponse,
|
|
108
|
+
params: {
|
|
109
|
+
selectedWallets: Wallet[];
|
|
110
|
+
userSlippage: number;
|
|
111
|
+
}
|
|
112
|
+
): ConfirmSwapWarnings {
|
|
113
|
+
const routeChanged = isRouteChanged(previousRoute, currentRoute);
|
|
114
|
+
const output: ConfirmSwapWarnings = {
|
|
115
|
+
balance: null,
|
|
116
|
+
route: null,
|
|
117
|
+
slippage: null,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
if (routeChanged) {
|
|
121
|
+
if (isOutputAmountChangedALot(previousRoute, currentRoute)) {
|
|
122
|
+
output.route = {
|
|
123
|
+
type: RouteWarningType.ROUTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
124
|
+
newOutputAmount: numberToString(getRouteOutputAmount(currentRoute)),
|
|
125
|
+
percentageChange: numberToString(
|
|
126
|
+
getPercentageChange(
|
|
127
|
+
getRouteOutputAmount(previousRoute),
|
|
128
|
+
getRouteOutputAmount(currentRoute)
|
|
129
|
+
),
|
|
130
|
+
null,
|
|
131
|
+
2
|
|
132
|
+
),
|
|
133
|
+
};
|
|
134
|
+
} else if (isNumberOfSwapsChanged(previousRoute, currentRoute)) {
|
|
135
|
+
output.route = {
|
|
136
|
+
type: RouteWarningType.ROUTE_UPDATED,
|
|
137
|
+
};
|
|
138
|
+
} else if (isRouteSwappersUpdated(previousRoute, currentRoute)) {
|
|
139
|
+
output.route = {
|
|
140
|
+
type: RouteWarningType.ROUTE_SWAPPERS_UPDATED,
|
|
141
|
+
};
|
|
142
|
+
} else if (isRouteInternalCoinsUpdated(previousRoute, currentRoute)) {
|
|
143
|
+
output.route = {
|
|
144
|
+
type: RouteWarningType.ROUTE_COINS_UPDATED,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const balanceWarnings = getBalanceWarnings(
|
|
150
|
+
currentRoute,
|
|
151
|
+
params.selectedWallets
|
|
152
|
+
);
|
|
153
|
+
const enoughBalance = balanceWarnings.length === 0;
|
|
154
|
+
|
|
155
|
+
if (!enoughBalance) {
|
|
156
|
+
output.balance = {
|
|
157
|
+
messages: balanceWarnings,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const minRequiredSlippage = getMinRequiredSlippage(previousRoute);
|
|
162
|
+
const highSlippage = params.userSlippage > HIGH_SLIPPAGE;
|
|
163
|
+
|
|
164
|
+
if (!hasProperSlippage(params.userSlippage.toString(), minRequiredSlippage)) {
|
|
165
|
+
output.slippage = {
|
|
166
|
+
type: SlippageWarningType.INSUFFICIENT_SLIPPAGE,
|
|
167
|
+
slippage: minRequiredSlippage,
|
|
168
|
+
};
|
|
169
|
+
} else if (highSlippage) {
|
|
170
|
+
output.slippage = {
|
|
171
|
+
type: SlippageWarningType.HIGH_SLIPPAGE,
|
|
172
|
+
slippage: params.userSlippage.toString(),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return output;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function useConfirmSwap(): ConfirmSwap {
|
|
180
|
+
const {
|
|
181
|
+
fromToken,
|
|
182
|
+
toToken,
|
|
183
|
+
inputAmount,
|
|
184
|
+
inputUsdValue,
|
|
185
|
+
setRoute,
|
|
186
|
+
bestRoute: initialRoute,
|
|
187
|
+
customDestination: customDestinationFromStore,
|
|
188
|
+
} = useBestRouteStore();
|
|
189
|
+
|
|
190
|
+
const {
|
|
191
|
+
slippage,
|
|
192
|
+
customSlippage,
|
|
193
|
+
affiliatePercent,
|
|
194
|
+
affiliateRef,
|
|
195
|
+
affiliateWallets,
|
|
196
|
+
disabledLiquiditySources,
|
|
197
|
+
} = useSettingsStore();
|
|
198
|
+
const { connectedWallets } = useWalletsStore();
|
|
199
|
+
|
|
200
|
+
const { meta } = useMetaStore();
|
|
201
|
+
|
|
202
|
+
const userSlippage = customSlippage || slippage;
|
|
203
|
+
|
|
204
|
+
const { fetch: fetchBestRoute, cancelFetch, loading } = useFetchBestRoute();
|
|
205
|
+
|
|
206
|
+
useEffect(() => cancelFetch, []);
|
|
207
|
+
|
|
208
|
+
const fetch: ConfirmSwap['fetch'] = async (params: Params) => {
|
|
209
|
+
const selectedWallets = params.selectedWallets;
|
|
210
|
+
const customDestination =
|
|
211
|
+
params?.customDestination ?? customDestinationFromStore;
|
|
212
|
+
|
|
213
|
+
if (!fromToken || !toToken || !inputAmount || !initialRoute) {
|
|
214
|
+
return {
|
|
215
|
+
route: null,
|
|
216
|
+
swap: null,
|
|
217
|
+
error: null,
|
|
218
|
+
warnings: null,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const requestBody = createBestRouteRequestBody({
|
|
223
|
+
fromToken,
|
|
224
|
+
toToken,
|
|
225
|
+
inputAmount,
|
|
226
|
+
wallets: connectedWallets,
|
|
227
|
+
selectedWallets,
|
|
228
|
+
disabledLiquiditySources,
|
|
229
|
+
slippage: userSlippage,
|
|
230
|
+
affiliateRef,
|
|
231
|
+
affiliatePercent,
|
|
232
|
+
affiliateWallets,
|
|
233
|
+
initialRoute,
|
|
234
|
+
destination: customDestination,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
let currentRoute: BestRouteResponse;
|
|
238
|
+
try {
|
|
239
|
+
currentRoute = await fetchBestRoute(requestBody).then((response) =>
|
|
240
|
+
throwErrorIfResponseIsNotValid(response, {
|
|
241
|
+
outputUsdValue: toToken.usdPrice,
|
|
242
|
+
inputUsdValue,
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
setRoute(currentRoute);
|
|
246
|
+
} catch (error: any) {
|
|
247
|
+
if (error?.code === 'ERR_CANCELED') {
|
|
248
|
+
return {
|
|
249
|
+
swap: null,
|
|
250
|
+
error: {
|
|
251
|
+
type: ConfirmSwapErrorTypes.REQUEST_CANCELED,
|
|
252
|
+
},
|
|
253
|
+
warnings: null,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (error.cause) {
|
|
258
|
+
return {
|
|
259
|
+
swap: null,
|
|
260
|
+
error: error.cause,
|
|
261
|
+
warnings: null,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
swap: null,
|
|
267
|
+
error: {
|
|
268
|
+
type: ConfirmSwapErrorTypes.REQUEST_FAILED,
|
|
269
|
+
},
|
|
270
|
+
warnings: null,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const swapSettings: PendingSwapSettings = {
|
|
275
|
+
slippage: userSlippage.toString(),
|
|
276
|
+
disabledSwappersGroups: disabledLiquiditySources,
|
|
277
|
+
};
|
|
278
|
+
const swap = calculatePendingSwap(
|
|
279
|
+
inputAmount.toString(),
|
|
280
|
+
currentRoute,
|
|
281
|
+
getWalletsForNewSwap(selectedWallets),
|
|
282
|
+
swapSettings,
|
|
283
|
+
false,
|
|
284
|
+
meta
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
route: currentRoute,
|
|
289
|
+
swap,
|
|
290
|
+
error: null,
|
|
291
|
+
warnings: generateWarnings(initialRoute, currentRoute, {
|
|
292
|
+
selectedWallets,
|
|
293
|
+
userSlippage,
|
|
294
|
+
}),
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
loading,
|
|
300
|
+
fetch,
|
|
301
|
+
cancelFetch,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
@@ -4,18 +4,18 @@ import { useRef, useState } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { httpService } from '../services/httpService';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface UseFetchBestRoute {
|
|
8
8
|
fetch: (requestBody: BestRouteRequest) => Promise<BestRouteResponse>;
|
|
9
9
|
cancelFetch: () => void;
|
|
10
10
|
loading: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function
|
|
13
|
+
export function useFetchBestRoute(): UseFetchBestRoute {
|
|
14
14
|
const [loading, setLoading] = useState(false);
|
|
15
15
|
const abortController = useRef<AbortController | null>(null);
|
|
16
16
|
const cancel = () => abortController.current?.abort();
|
|
17
17
|
|
|
18
|
-
const fetch:
|
|
18
|
+
const fetch: UseFetchBestRoute['fetch'] = async (requestBody) => {
|
|
19
19
|
cancel();
|
|
20
20
|
abortController.current = new AbortController();
|
|
21
21
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
2
2
|
|
|
3
3
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
4
|
-
import {
|
|
4
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
5
|
|
|
6
6
|
export function useNavigateBack() {
|
|
7
7
|
const isRouterInContext = useInRouterContext();
|
|
8
8
|
const navigate = useNavigate();
|
|
9
|
-
const
|
|
9
|
+
const routeWalletsConfirmed = useBestRouteStore.use.routeWalletsConfirmed();
|
|
10
10
|
|
|
11
11
|
navigationRoutes;
|
|
12
12
|
|
|
@@ -26,7 +26,7 @@ export function useNavigateBack() {
|
|
|
26
26
|
[navigationRoutes.settings, navigationRoutes.wallets].includes(
|
|
27
27
|
currentRoute
|
|
28
28
|
) &&
|
|
29
|
-
|
|
29
|
+
routeWalletsConfirmed
|
|
30
30
|
) {
|
|
31
31
|
return navigate('/' + navigationRoutes.confirmSwap, { replace: true });
|
|
32
32
|
}
|
|
@@ -1,48 +1,37 @@
|
|
|
1
|
-
import type { QuoteError, QuoteWarning } from '../types';
|
|
2
|
-
|
|
3
1
|
import { useEffect, useRef, useState } from 'react';
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
import { useQuoteStore } from '../store/quote';
|
|
3
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
7
4
|
import { useSettingsStore } from '../store/settings';
|
|
8
|
-
import { QuoteErrorType } from '../types';
|
|
9
5
|
import { debounce } from '../utils/common';
|
|
10
6
|
import { isPositiveNumber } from '../utils/numbers';
|
|
11
|
-
import {
|
|
12
|
-
import { createQuoteRequestBody } from '../utils/swap';
|
|
7
|
+
import { createBestRouteRequestBody } from '../utils/swap';
|
|
13
8
|
import { tokensAreEqual } from '../utils/wallets';
|
|
14
9
|
|
|
15
|
-
import {
|
|
16
|
-
handleQuoteErrors,
|
|
17
|
-
throwErrorIfResponseIsNotValid,
|
|
18
|
-
} from './useConfirmSwap/useConfirmSwap.helpers';
|
|
19
|
-
import { useFetchQuote } from './useFetchQuote';
|
|
10
|
+
import { useFetchBestRoute } from './useFetchBestRoute';
|
|
20
11
|
|
|
21
12
|
const DEBOUNCE_DELAY = 600;
|
|
22
13
|
|
|
23
14
|
type UseSwapInput = {
|
|
24
15
|
fetch: () => void;
|
|
25
16
|
loading: boolean;
|
|
26
|
-
error:
|
|
27
|
-
warning: QuoteWarning | null;
|
|
17
|
+
error: string;
|
|
28
18
|
};
|
|
29
19
|
|
|
30
20
|
/**
|
|
31
|
-
* a hook for fetching
|
|
21
|
+
* a hook for fetching best route based on from and to input values
|
|
32
22
|
* we use this hook in home page
|
|
33
23
|
*/
|
|
34
24
|
export function useSwapInput(): UseSwapInput {
|
|
35
|
-
const { fetch:
|
|
36
|
-
const
|
|
37
|
-
const tokens = useAppStore().tokens();
|
|
25
|
+
const { fetch: fetchBestRoute, cancelFetch } = useFetchBestRoute();
|
|
26
|
+
const [loading, setLoading] = useState(false);
|
|
38
27
|
const {
|
|
39
28
|
fromToken,
|
|
40
29
|
toToken,
|
|
41
30
|
inputAmount,
|
|
42
31
|
inputUsdValue,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} =
|
|
32
|
+
resetRoute,
|
|
33
|
+
setRoute,
|
|
34
|
+
} = useBestRouteStore();
|
|
46
35
|
const {
|
|
47
36
|
slippage,
|
|
48
37
|
customSlippage,
|
|
@@ -51,9 +40,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
51
40
|
affiliateWallets,
|
|
52
41
|
disabledLiquiditySources,
|
|
53
42
|
} = useSettingsStore();
|
|
54
|
-
const [
|
|
55
|
-
const [error, setError] = useState<QuoteError | null>(null);
|
|
56
|
-
const [warning, setWarning] = useState<QuoteWarning | null>(null);
|
|
43
|
+
const [error, setError] = useState('');
|
|
57
44
|
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
58
45
|
const userSlippage = customSlippage ?? slippage;
|
|
59
46
|
const hasTokensValue = !fromToken || !toToken;
|
|
@@ -62,53 +49,31 @@ export function useSwapInput(): UseSwapInput {
|
|
|
62
49
|
tokensAreEqual(fromToken, toToken) ||
|
|
63
50
|
!isPositiveNumber(inputAmount);
|
|
64
51
|
|
|
65
|
-
const resetState = (loading: boolean) => {
|
|
66
|
-
setLoading(loading);
|
|
67
|
-
setError(null);
|
|
68
|
-
setWarning(null);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
52
|
const fetch: UseSwapInput['fetch'] = () => {
|
|
72
53
|
if (!loading) {
|
|
73
|
-
|
|
54
|
+
setLoading(true);
|
|
74
55
|
}
|
|
75
56
|
if (!shouldSkipRequest) {
|
|
76
|
-
|
|
77
|
-
const requestBody =
|
|
57
|
+
resetRoute();
|
|
58
|
+
const requestBody = createBestRouteRequestBody({
|
|
78
59
|
fromToken,
|
|
79
60
|
toToken,
|
|
80
61
|
inputAmount,
|
|
81
|
-
liquiditySources,
|
|
82
|
-
excludeLiquiditySources: enableNewLiquiditySources,
|
|
83
62
|
disabledLiquiditySources,
|
|
84
63
|
slippage: userSlippage,
|
|
85
64
|
affiliateRef,
|
|
86
65
|
affiliatePercent,
|
|
87
66
|
affiliateWallets,
|
|
88
67
|
});
|
|
89
|
-
|
|
68
|
+
fetchBestRoute(requestBody)
|
|
90
69
|
.then((res) => {
|
|
91
70
|
setLoading(false);
|
|
92
|
-
|
|
93
|
-
throwErrorIfResponseIsNotValid(res);
|
|
94
|
-
const quoteWarning = generateQuoteWarnings(res, {
|
|
95
|
-
fromToken,
|
|
96
|
-
toToken,
|
|
97
|
-
userSlippage,
|
|
98
|
-
tokens,
|
|
99
|
-
});
|
|
100
|
-
setWarning(quoteWarning);
|
|
71
|
+
setRoute(res);
|
|
101
72
|
})
|
|
102
73
|
.catch((error) => {
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
quoteError?.type === QuoteErrorType.REQUEST_FAILED
|
|
107
|
-
) {
|
|
108
|
-
resetQuote();
|
|
109
|
-
}
|
|
110
|
-
if (quoteError?.type !== QuoteErrorType.REQUEST_CANCELED) {
|
|
111
|
-
setError(quoteError);
|
|
74
|
+
resetRoute();
|
|
75
|
+
if (error?.code !== 'ERR_CANCELED') {
|
|
76
|
+
setError(error.message);
|
|
112
77
|
setLoading(false);
|
|
113
78
|
}
|
|
114
79
|
});
|
|
@@ -123,15 +88,15 @@ export function useSwapInput(): UseSwapInput {
|
|
|
123
88
|
|
|
124
89
|
useEffect(() => {
|
|
125
90
|
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
|
|
126
|
-
|
|
91
|
+
setLoading(false);
|
|
127
92
|
cancelFetch();
|
|
128
93
|
return;
|
|
129
94
|
}
|
|
130
95
|
if (shouldSkipRequest) {
|
|
131
96
|
return;
|
|
132
97
|
}
|
|
133
|
-
|
|
134
|
-
|
|
98
|
+
resetRoute();
|
|
99
|
+
setLoading(true);
|
|
135
100
|
debouncedFetch();
|
|
136
101
|
return cancelFetch;
|
|
137
102
|
}, [inputAmount, shouldSkipRequest]);
|
|
@@ -147,5 +112,5 @@ export function useSwapInput(): UseSwapInput {
|
|
|
147
112
|
return cancelFetch;
|
|
148
113
|
}, [disabledLiquiditySources.length]);
|
|
149
114
|
|
|
150
|
-
return { fetch, loading, error
|
|
115
|
+
return { fetch, loading, error };
|
|
151
116
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { WidgetConfig } from '../types';
|
|
1
2
|
import type { Asset } from 'rango-sdk';
|
|
2
3
|
|
|
3
4
|
import { useEffect, useMemo, useRef } from 'react';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
7
|
+
import { useMetaStore } from '../store/meta';
|
|
7
8
|
import { useSettingsStore } from '../store/settings';
|
|
8
9
|
import { tokensAreEqual } from '../utils/wallets';
|
|
9
10
|
|
|
10
|
-
export function useSyncStoresWithConfig() {
|
|
11
|
+
export function useSyncStoresWithConfig(config: WidgetConfig | undefined) {
|
|
11
12
|
const {
|
|
12
13
|
setInputAmount,
|
|
13
14
|
setToToken,
|
|
@@ -18,12 +19,12 @@ export function useSyncStoresWithConfig() {
|
|
|
18
19
|
toToken,
|
|
19
20
|
fromBlockchain,
|
|
20
21
|
toBlockchain,
|
|
21
|
-
} =
|
|
22
|
+
} = useBestRouteStore();
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const {
|
|
25
|
+
meta: { tokens, blockchains },
|
|
26
|
+
loadingStatus: loadingMetaStatus,
|
|
27
|
+
} = useMetaStore();
|
|
27
28
|
|
|
28
29
|
const { setAffiliateRef, setAffiliatePercent, setAffiliateWallets } =
|
|
29
30
|
useSettingsStore();
|
|
@@ -54,7 +55,7 @@ export function useSyncStoresWithConfig() {
|
|
|
54
55
|
}, [config?.amount]);
|
|
55
56
|
|
|
56
57
|
useEffect(() => {
|
|
57
|
-
if (
|
|
58
|
+
if (loadingMetaStatus === 'success') {
|
|
58
59
|
const chain = blockchains.find(
|
|
59
60
|
(chain) => chain.name === config?.from?.blockchain
|
|
60
61
|
);
|
|
@@ -66,10 +67,8 @@ export function useSyncStoresWithConfig() {
|
|
|
66
67
|
setFromBlockchain(chain ?? null);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
if (token) {
|
|
70
|
-
setFromToken(
|
|
71
|
-
} else if (!token && prevConfigFromToken.current) {
|
|
72
|
-
setFromToken({ token: null });
|
|
70
|
+
if (token || (!token && prevConfigFromToken.current)) {
|
|
71
|
+
setFromToken(token ?? null);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
prevConfigFromBlockchain.current = config?.from?.blockchain;
|
|
@@ -80,13 +79,13 @@ export function useSyncStoresWithConfig() {
|
|
|
80
79
|
config?.from?.token?.address,
|
|
81
80
|
config?.from?.token?.blockchain,
|
|
82
81
|
config?.from?.blockchain,
|
|
83
|
-
|
|
82
|
+
loadingMetaStatus,
|
|
84
83
|
]);
|
|
85
84
|
|
|
86
85
|
useEffect(() => {
|
|
87
86
|
if (fromToken && fromTokensConfig) {
|
|
88
87
|
if (!fromTokensConfig.some((token) => tokensAreEqual(token, fromToken))) {
|
|
89
|
-
setFromToken(
|
|
88
|
+
setFromToken(null);
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
|
@@ -100,7 +99,7 @@ export function useSyncStoresWithConfig() {
|
|
|
100
99
|
useEffect(() => {
|
|
101
100
|
if (toToken && toTokensConfig) {
|
|
102
101
|
if (!toTokensConfig.some((token) => tokensAreEqual(token, toToken))) {
|
|
103
|
-
setToToken(
|
|
102
|
+
setToToken(null);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
|
|
@@ -112,7 +111,7 @@ export function useSyncStoresWithConfig() {
|
|
|
112
111
|
}, [toTokensConfig, toBlockchainsConfig]);
|
|
113
112
|
|
|
114
113
|
useEffect(() => {
|
|
115
|
-
if (
|
|
114
|
+
if (loadingMetaStatus === 'success') {
|
|
116
115
|
const chain = blockchains.find(
|
|
117
116
|
(chain) => chain.name === config?.to?.blockchain
|
|
118
117
|
);
|
|
@@ -124,10 +123,8 @@ export function useSyncStoresWithConfig() {
|
|
|
124
123
|
setToBlockchain(chain ?? null);
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
if (token) {
|
|
128
|
-
setToToken(
|
|
129
|
-
} else if (!token && prevConfigToToken.current) {
|
|
130
|
-
setToToken({ token: null });
|
|
126
|
+
if (token || (!token && prevConfigToToken.current)) {
|
|
127
|
+
setToToken(token ?? null);
|
|
131
128
|
}
|
|
132
129
|
|
|
133
130
|
prevConfigToBlockchain.current = config?.to?.blockchain;
|
|
@@ -138,7 +135,7 @@ export function useSyncStoresWithConfig() {
|
|
|
138
135
|
config?.to?.token?.address,
|
|
139
136
|
config?.to?.token?.blockchain,
|
|
140
137
|
config?.to?.blockchain,
|
|
141
|
-
|
|
138
|
+
loadingMetaStatus,
|
|
142
139
|
]);
|
|
143
140
|
|
|
144
141
|
useEffect(() => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@rango-dev/wallets-shared';
|
|
11
11
|
import { useEffect, useState } from 'react';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { useMetaStore } from '../store/meta';
|
|
14
14
|
import { useWalletsStore } from '../store/wallets';
|
|
15
15
|
import { configWalletsToWalletName } from '../utils/providers';
|
|
16
16
|
import {
|
|
@@ -37,7 +37,9 @@ export function useWalletList(params: Params) {
|
|
|
37
37
|
const { config, chain, onBeforeConnect, onConnect } = params;
|
|
38
38
|
const { state, disconnect, getWalletInfo, connect } = useWallets();
|
|
39
39
|
const { connectedWallets } = useWalletsStore();
|
|
40
|
-
const blockchains =
|
|
40
|
+
const { blockchains } = useMetaStore().meta;
|
|
41
|
+
const multiWallets =
|
|
42
|
+
typeof config?.multiWallets === 'undefined' ? true : config.multiWallets;
|
|
41
43
|
|
|
42
44
|
/** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
|
|
43
45
|
const listAvailableWalletTypes =
|
|
@@ -74,7 +76,7 @@ export function useWalletList(params: Params) {
|
|
|
74
76
|
const atLeastOneWalletIsConnected = !!wallets.find(
|
|
75
77
|
(w) => w.state === WalletState.CONNECTED
|
|
76
78
|
);
|
|
77
|
-
if (!
|
|
79
|
+
if (!multiWallets && atLeastOneWalletIsConnected) {
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
82
|
onBeforeConnect?.(type);
|