@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
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
import type {
|
|
3
3
|
ConfirmSwap,
|
|
4
4
|
ConfirmSwapFetchResult,
|
|
5
|
-
} from '../hooks/useConfirmSwap
|
|
5
|
+
} from '../hooks/useConfirmSwap';
|
|
6
|
+
import type { WidgetConfig } from '../types';
|
|
6
7
|
|
|
7
8
|
import { i18n } from '@lingui/core';
|
|
8
9
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
9
10
|
import {
|
|
10
11
|
Alert,
|
|
12
|
+
BestRoute,
|
|
13
|
+
BestRouteSkeleton,
|
|
11
14
|
Button,
|
|
12
15
|
Divider,
|
|
13
16
|
IconButton,
|
|
17
|
+
MessageBox,
|
|
18
|
+
Modal,
|
|
14
19
|
RefreshIcon,
|
|
15
20
|
SettingsIcon,
|
|
16
21
|
styled,
|
|
@@ -22,19 +27,46 @@ import React, { useEffect, useState } from 'react';
|
|
|
22
27
|
import { flushSync } from 'react-dom';
|
|
23
28
|
import { useNavigate } from 'react-router-dom';
|
|
24
29
|
|
|
25
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
formatBestRoute,
|
|
32
|
+
getRequiredWallets,
|
|
33
|
+
} from '../components/ConfirmWalletsModal/ConfirmWallets.helpers';
|
|
26
34
|
import { ConfirmWalletsModal } from '../components/ConfirmWalletsModal/ConfirmWalletsModal';
|
|
27
35
|
import { HeaderButton } from '../components/HeaderButtons/HeaderButtons.styles';
|
|
28
36
|
import { Layout } from '../components/Layout';
|
|
37
|
+
import { NoRoutes } from '../components/NoRoutes';
|
|
38
|
+
import { getConfirmSwapErrorMessage } from '../constants/errors';
|
|
29
39
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
30
|
-
import {
|
|
31
|
-
|
|
40
|
+
import {
|
|
41
|
+
GAS_FEE_MAX_DECIMALS,
|
|
42
|
+
GAS_FEE_MIN_DECIMALS,
|
|
43
|
+
PERCENTAGE_CHANGE_MAX_DECIMALS,
|
|
44
|
+
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
45
|
+
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
46
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
47
|
+
USD_VALUE_MAX_DECIMALS,
|
|
48
|
+
USD_VALUE_MIN_DECIMALS,
|
|
49
|
+
} from '../constants/routing';
|
|
50
|
+
import { getRouteWarningMessage } from '../constants/warnings';
|
|
32
51
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
33
|
-
import {
|
|
52
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
53
|
+
import { useMetaStore } from '../store/meta';
|
|
54
|
+
import { useSettingsStore } from '../store/settings';
|
|
34
55
|
import { useUiStore } from '../store/ui';
|
|
35
56
|
import { useWalletsStore } from '../store/wallets';
|
|
36
|
-
import {
|
|
57
|
+
import {
|
|
58
|
+
ConfirmSwapErrorTypes,
|
|
59
|
+
RouteWarningType,
|
|
60
|
+
SlippageWarningType,
|
|
61
|
+
} from '../types';
|
|
37
62
|
import { getContainer } from '../utils/common';
|
|
63
|
+
import {
|
|
64
|
+
numberToString,
|
|
65
|
+
secondsToString,
|
|
66
|
+
totalArrivalTime,
|
|
67
|
+
} from '../utils/numbers';
|
|
68
|
+
import { getPriceImpactLevel } from '../utils/routing';
|
|
69
|
+
import { getPercentageChange, getTotalFeeInUsd } from '../utils/swap';
|
|
38
70
|
|
|
39
71
|
const Container = styled('div', {
|
|
40
72
|
position: 'relative',
|
|
@@ -68,28 +100,44 @@ const Buttons = styled('div', {
|
|
|
68
100
|
},
|
|
69
101
|
});
|
|
70
102
|
|
|
71
|
-
|
|
103
|
+
type PropTypes = {
|
|
104
|
+
config?: WidgetConfig;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export function ConfirmSwapPage(props: PropTypes) {
|
|
72
108
|
//TODO: move component's logics to a custom hook
|
|
109
|
+
const { config } = props;
|
|
73
110
|
const {
|
|
74
|
-
|
|
111
|
+
bestRoute,
|
|
112
|
+
inputAmount,
|
|
113
|
+
outputAmount,
|
|
114
|
+
inputUsdValue,
|
|
115
|
+
outputUsdValue,
|
|
75
116
|
setInputAmount,
|
|
76
117
|
selectedWallets,
|
|
77
|
-
|
|
78
|
-
|
|
118
|
+
routeWalletsConfirmed,
|
|
119
|
+
setRouteWalletConfirmed,
|
|
79
120
|
customDestination,
|
|
80
|
-
|
|
81
|
-
} = useQuoteStore();
|
|
121
|
+
} = useBestRouteStore();
|
|
82
122
|
const navigate = useNavigate();
|
|
83
123
|
const [dbErrorMessage, setDbErrorMessage] = useState<string>('');
|
|
124
|
+
const [showSlippageWarning, setShowSlippageWarning] = useState(false);
|
|
84
125
|
|
|
85
126
|
const { connectedWallets } = useWalletsStore();
|
|
86
|
-
const showWalletsOnInit = !
|
|
127
|
+
const showWalletsOnInit = !routeWalletsConfirmed;
|
|
87
128
|
const [showWallets, setShowWallets] = useState(false);
|
|
88
129
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
130
|
+
const {
|
|
131
|
+
meta: { tokens, blockchains },
|
|
132
|
+
loadingStatus: loadingMetaStatus,
|
|
133
|
+
} = useMetaStore();
|
|
134
|
+
const slippage = useSettingsStore.use.slippage();
|
|
135
|
+
const customSlippage = useSettingsStore.use.customSlippage();
|
|
89
136
|
const { manager } = useManager();
|
|
137
|
+
const selectedSlippage = customSlippage || slippage;
|
|
90
138
|
const {
|
|
91
139
|
fetch: confirmSwap,
|
|
92
|
-
loading:
|
|
140
|
+
loading: fetchingConfirmationRoute,
|
|
93
141
|
cancelFetch,
|
|
94
142
|
} = useConfirmSwap();
|
|
95
143
|
const [confirmSwapResult, setConfirmSwapResult] =
|
|
@@ -98,8 +146,32 @@ export function ConfirmSwapPage() {
|
|
|
98
146
|
error: null,
|
|
99
147
|
warnings: null,
|
|
100
148
|
});
|
|
149
|
+
const showSkeleton =
|
|
150
|
+
fetchingConfirmationRoute || loadingMetaStatus === 'loading';
|
|
151
|
+
const showNoRouteFound =
|
|
152
|
+
!fetchingConfirmationRoute &&
|
|
153
|
+
confirmSwapResult.error &&
|
|
154
|
+
[
|
|
155
|
+
ConfirmSwapErrorTypes.NO_ROUTE,
|
|
156
|
+
ConfirmSwapErrorTypes.REQUEST_FAILED,
|
|
157
|
+
].includes(confirmSwapResult.error.type);
|
|
158
|
+
const showBestRoute =
|
|
159
|
+
!showNoRouteFound &&
|
|
160
|
+
!fetchingConfirmationRoute &&
|
|
161
|
+
bestRoute &&
|
|
162
|
+
bestRoute.result;
|
|
163
|
+
|
|
164
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
165
|
+
const percentageChange = numberToString(
|
|
166
|
+
getPercentageChange(
|
|
167
|
+
inputUsdValue?.toNumber() ?? 0,
|
|
168
|
+
outputUsdValue?.toNumber() ?? 0
|
|
169
|
+
),
|
|
170
|
+
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
171
|
+
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
172
|
+
);
|
|
101
173
|
|
|
102
|
-
const
|
|
174
|
+
const warningLevel = getPriceImpactLevel(parseFloat(percentageChange));
|
|
103
175
|
|
|
104
176
|
const onConfirmSwap: ConfirmSwap['fetch'] = async ({
|
|
105
177
|
selectedWallets,
|
|
@@ -111,7 +183,7 @@ export function ConfirmSwapPage() {
|
|
|
111
183
|
};
|
|
112
184
|
|
|
113
185
|
const addNewSwap = async () => {
|
|
114
|
-
if (confirmSwapResult.swap &&
|
|
186
|
+
if (confirmSwapResult.swap && routeWalletsConfirmed) {
|
|
115
187
|
try {
|
|
116
188
|
await manager?.create(
|
|
117
189
|
'swap',
|
|
@@ -139,8 +211,8 @@ export function ConfirmSwapPage() {
|
|
|
139
211
|
};
|
|
140
212
|
|
|
141
213
|
const onStartConfirmSwap = async () => {
|
|
142
|
-
if (confirmSwapResult?.warnings?.
|
|
143
|
-
|
|
214
|
+
if (confirmSwapResult?.warnings?.slippage) {
|
|
215
|
+
setShowSlippageWarning(true);
|
|
144
216
|
} else {
|
|
145
217
|
await onConfirm();
|
|
146
218
|
}
|
|
@@ -180,10 +252,10 @@ export function ConfirmSwapPage() {
|
|
|
180
252
|
}, []);
|
|
181
253
|
|
|
182
254
|
useEffect(() => {
|
|
183
|
-
const
|
|
184
|
-
confirmSwapResult.warnings?.
|
|
185
|
-
Object.values(
|
|
186
|
-
confirmSwapResult.warnings?.
|
|
255
|
+
const routeChanged =
|
|
256
|
+
confirmSwapResult.warnings?.route?.type &&
|
|
257
|
+
Object.values(RouteWarningType).includes(
|
|
258
|
+
confirmSwapResult.warnings?.route?.type
|
|
187
259
|
);
|
|
188
260
|
|
|
189
261
|
const selectedWalletDisconnected =
|
|
@@ -197,15 +269,16 @@ export function ConfirmSwapPage() {
|
|
|
197
269
|
)
|
|
198
270
|
);
|
|
199
271
|
|
|
200
|
-
let
|
|
272
|
+
let routeWalletsChanged = false;
|
|
201
273
|
|
|
202
|
-
if (
|
|
203
|
-
let requiredWallets = getRequiredWallets(
|
|
274
|
+
if (routeChanged) {
|
|
275
|
+
let requiredWallets = getRequiredWallets(bestRoute);
|
|
204
276
|
|
|
205
277
|
const lastStepToBlockchain =
|
|
206
|
-
|
|
278
|
+
bestRoute?.result?.swaps[bestRoute.result.swaps.length - 1].to
|
|
279
|
+
.blockchain;
|
|
207
280
|
|
|
208
|
-
const isLastWalletRequired = !!
|
|
281
|
+
const isLastWalletRequired = !!bestRoute?.result?.swaps.find(
|
|
209
282
|
(swap) => swap.from.blockchain === lastStepToBlockchain
|
|
210
283
|
);
|
|
211
284
|
|
|
@@ -224,16 +297,16 @@ export function ConfirmSwapPage() {
|
|
|
224
297
|
);
|
|
225
298
|
|
|
226
299
|
if (!allRequiredWalletsSelected) {
|
|
227
|
-
|
|
300
|
+
routeWalletsChanged = true;
|
|
228
301
|
}
|
|
229
302
|
}
|
|
230
303
|
|
|
231
|
-
if (
|
|
304
|
+
if (bestRoute && (selectedWalletDisconnected || routeWalletsChanged)) {
|
|
232
305
|
queueMicrotask(() => flushSync(setShowWallets.bind(null, true)));
|
|
233
|
-
|
|
306
|
+
setRouteWalletConfirmed(false);
|
|
234
307
|
}
|
|
235
308
|
}, [
|
|
236
|
-
confirmSwapResult.warnings?.
|
|
309
|
+
confirmSwapResult.warnings?.route,
|
|
237
310
|
selectedWallets.length,
|
|
238
311
|
connectedWallets.length,
|
|
239
312
|
]);
|
|
@@ -242,7 +315,7 @@ export function ConfirmSwapPage() {
|
|
|
242
315
|
<Layout
|
|
243
316
|
header={{
|
|
244
317
|
title: i18n.t('Confirm Swap'),
|
|
245
|
-
onBack: (
|
|
318
|
+
onBack: navigate.bind(null, -1),
|
|
246
319
|
hasConnectWallet: true,
|
|
247
320
|
suffix: (
|
|
248
321
|
<Tooltip
|
|
@@ -266,7 +339,7 @@ export function ConfirmSwapPage() {
|
|
|
266
339
|
type="primary"
|
|
267
340
|
size="large"
|
|
268
341
|
fullWidth
|
|
269
|
-
loading={
|
|
342
|
+
loading={fetchingConfirmationRoute}
|
|
270
343
|
disabled={!!confirmSwapResult.error}
|
|
271
344
|
onClick={onStartConfirmSwap}>
|
|
272
345
|
{i18n.t('Start Swap')}
|
|
@@ -276,19 +349,72 @@ export function ConfirmSwapPage() {
|
|
|
276
349
|
variant="contained"
|
|
277
350
|
type="primary"
|
|
278
351
|
size="large"
|
|
279
|
-
loading={
|
|
352
|
+
loading={fetchingConfirmationRoute}
|
|
280
353
|
onClick={setShowWallets.bind(null, true)}>
|
|
281
354
|
<WalletIcon size={24} />
|
|
282
355
|
</IconButton>
|
|
283
356
|
</Buttons>
|
|
284
357
|
}>
|
|
358
|
+
<Modal
|
|
359
|
+
anchor="bottom"
|
|
360
|
+
open={showSlippageWarning}
|
|
361
|
+
prefix={
|
|
362
|
+
<Button
|
|
363
|
+
size="small"
|
|
364
|
+
variant="ghost"
|
|
365
|
+
onClick={() => navigate('/' + navigationRoutes.settings)}>
|
|
366
|
+
<Typography variant="label" size="medium" color="$neutral700">
|
|
367
|
+
{i18n.t('Change settings')}
|
|
368
|
+
</Typography>
|
|
369
|
+
</Button>
|
|
370
|
+
}
|
|
371
|
+
container={document.querySelector('#swap-box') as HTMLDivElement}
|
|
372
|
+
onClose={setShowSlippageWarning.bind(null, (prevState) => !prevState)}>
|
|
373
|
+
{confirmSwapResult.warnings?.slippage && (
|
|
374
|
+
<MessageBox
|
|
375
|
+
type="warning"
|
|
376
|
+
title={
|
|
377
|
+
confirmSwapResult.warnings.slippage.type ===
|
|
378
|
+
SlippageWarningType.HIGH_SLIPPAGE
|
|
379
|
+
? i18n.t('High slippage')
|
|
380
|
+
: i18n.t('Low slippage')
|
|
381
|
+
}
|
|
382
|
+
description={
|
|
383
|
+
confirmSwapResult.warnings.slippage.type ===
|
|
384
|
+
SlippageWarningType.HIGH_SLIPPAGE
|
|
385
|
+
? i18n.t({
|
|
386
|
+
id: ' Caution, your slippage is high (={selectedSlippage}). Your trade may be front run.',
|
|
387
|
+
values: { selectedSlippage },
|
|
388
|
+
})
|
|
389
|
+
: i18n.t({
|
|
390
|
+
id: 'We recommend you to increase slippage to at least {minRequiredSlippage} for this route.',
|
|
391
|
+
values: {
|
|
392
|
+
minRequiredSlippage:
|
|
393
|
+
confirmSwapResult.warnings.slippage.slippage,
|
|
394
|
+
},
|
|
395
|
+
})
|
|
396
|
+
}>
|
|
397
|
+
<Divider size={18} />
|
|
398
|
+
<Divider size={32} />
|
|
399
|
+
<Button
|
|
400
|
+
size="large"
|
|
401
|
+
type="primary"
|
|
402
|
+
variant="contained"
|
|
403
|
+
fullWidth
|
|
404
|
+
onClick={onConfirm}>
|
|
405
|
+
{i18n.t('Confirm anyway')}
|
|
406
|
+
</Button>
|
|
407
|
+
</MessageBox>
|
|
408
|
+
)}
|
|
409
|
+
</Modal>
|
|
285
410
|
{showWallets && (
|
|
286
411
|
<ConfirmWalletsModal
|
|
287
412
|
open={showWallets}
|
|
288
413
|
onClose={() => setShowWallets(false)}
|
|
289
414
|
onCancel={cancelFetch}
|
|
290
|
-
loading={
|
|
415
|
+
loading={fetchingConfirmationRoute}
|
|
291
416
|
onCheckBalance={onConfirmSwap}
|
|
417
|
+
config={config}
|
|
292
418
|
/>
|
|
293
419
|
)}
|
|
294
420
|
|
|
@@ -300,7 +426,7 @@ export function ConfirmSwapPage() {
|
|
|
300
426
|
<Button
|
|
301
427
|
style={{ padding: '0' }}
|
|
302
428
|
variant="ghost"
|
|
303
|
-
disabled={
|
|
429
|
+
disabled={fetchingConfirmationRoute}
|
|
304
430
|
onClick={onRefresh}>
|
|
305
431
|
<div className="icon">
|
|
306
432
|
<RefreshIcon size={16} />
|
|
@@ -313,37 +439,88 @@ export function ConfirmSwapPage() {
|
|
|
313
439
|
<Divider size={12} />
|
|
314
440
|
</>
|
|
315
441
|
)}
|
|
316
|
-
{confirmSwapResult.warnings?.
|
|
442
|
+
{confirmSwapResult.warnings?.route && (
|
|
317
443
|
<>
|
|
318
444
|
<Alert
|
|
319
445
|
variant="alarm"
|
|
320
446
|
type="warning"
|
|
321
|
-
title={
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
447
|
+
title={getRouteWarningMessage(confirmSwapResult.warnings.route)}
|
|
448
|
+
/>
|
|
449
|
+
<Divider size={12} />
|
|
450
|
+
</>
|
|
451
|
+
)}
|
|
452
|
+
{showSkeleton && <BestRouteSkeleton type="swap-preview" expanded />}
|
|
453
|
+
{showBestRoute && (
|
|
454
|
+
<BestRoute
|
|
455
|
+
expanded={true}
|
|
456
|
+
tooltipContainer={getContainer()}
|
|
457
|
+
steps={formatBestRoute(bestRoute, blockchains) ?? []}
|
|
458
|
+
input={{
|
|
459
|
+
value: numberToString(
|
|
460
|
+
inputAmount,
|
|
461
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
462
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
463
|
+
),
|
|
464
|
+
usdValue: numberToString(
|
|
465
|
+
inputUsdValue,
|
|
466
|
+
USD_VALUE_MIN_DECIMALS,
|
|
467
|
+
USD_VALUE_MAX_DECIMALS
|
|
468
|
+
),
|
|
469
|
+
}}
|
|
470
|
+
output={{
|
|
471
|
+
value: numberToString(
|
|
472
|
+
outputAmount,
|
|
473
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
474
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
475
|
+
),
|
|
476
|
+
usdValue: numberToString(
|
|
477
|
+
outputUsdValue,
|
|
478
|
+
USD_VALUE_MIN_DECIMALS,
|
|
479
|
+
USD_VALUE_MAX_DECIMALS
|
|
480
|
+
),
|
|
481
|
+
}}
|
|
482
|
+
totalFee={numberToString(
|
|
483
|
+
totalFeeInUsd,
|
|
484
|
+
GAS_FEE_MIN_DECIMALS,
|
|
485
|
+
GAS_FEE_MAX_DECIMALS
|
|
486
|
+
)}
|
|
487
|
+
totalTime={secondsToString(
|
|
488
|
+
totalArrivalTime(bestRoute.result?.swaps)
|
|
489
|
+
)}
|
|
490
|
+
recommended={true}
|
|
491
|
+
type="swap-preview"
|
|
492
|
+
percentageChange={percentageChange}
|
|
493
|
+
warningLevel={warningLevel}
|
|
494
|
+
/>
|
|
495
|
+
)}
|
|
496
|
+
{showNoRouteFound && (
|
|
497
|
+
<>
|
|
498
|
+
<Divider size={12} />
|
|
499
|
+
<NoRoutes
|
|
500
|
+
diagnosisMessage={
|
|
501
|
+
confirmSwapResult.error?.type === ConfirmSwapErrorTypes.NO_ROUTE
|
|
502
|
+
? confirmSwapResult.error.diagnosisMessage
|
|
503
|
+
: undefined
|
|
326
504
|
}
|
|
505
|
+
error={
|
|
506
|
+
confirmSwapResult.error?.type ===
|
|
507
|
+
ConfirmSwapErrorTypes.REQUEST_FAILED
|
|
508
|
+
}
|
|
509
|
+
fetch={onRefresh}
|
|
510
|
+
/>
|
|
511
|
+
</>
|
|
512
|
+
)}
|
|
513
|
+
{confirmSwapResult.error?.type ===
|
|
514
|
+
ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS && (
|
|
515
|
+
<>
|
|
516
|
+
<Alert
|
|
517
|
+
variant="alarm"
|
|
518
|
+
type="error"
|
|
519
|
+
title={getConfirmSwapErrorMessage(confirmSwapResult.error)}
|
|
327
520
|
/>
|
|
328
521
|
<Divider size={12} />
|
|
329
522
|
</>
|
|
330
523
|
)}
|
|
331
|
-
<QuoteInfo
|
|
332
|
-
quote={quote}
|
|
333
|
-
type="swap-preview"
|
|
334
|
-
expanded={true}
|
|
335
|
-
error={confirmSwapResult.error}
|
|
336
|
-
loading={fetchingConfirmationQuote}
|
|
337
|
-
warning={confirmSwapResult.warnings?.quote ?? null}
|
|
338
|
-
refetchQuote={onRefresh}
|
|
339
|
-
showWarningModal={showQuoteWarningModal}
|
|
340
|
-
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
341
|
-
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
342
|
-
onConfirmWarningModal={async () => {
|
|
343
|
-
setShowQuoteWarningModal(false);
|
|
344
|
-
await addNewSwap();
|
|
345
|
-
}}
|
|
346
|
-
/>
|
|
347
524
|
</Container>
|
|
348
525
|
</Layout>
|
|
349
526
|
);
|