@rango-dev/widget-embedded 0.17.1-next.2 → 0.17.1-next.4
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/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +1 -3
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts +4 -0
- package/dist/components/NoResult/NoResult.d.ts.map +1 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts +4 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -0
- package/dist/components/{NoRoutes/NoRoutes.styles.d.ts → NoResult/NoResult.styles.d.ts} +1 -1
- package/dist/components/{NoRoutes/NoRoutes.styles.d.ts.map → NoResult/NoResult.styles.d.ts.map} +1 -1
- package/dist/components/{NoRoutes/NoRoutes.types.d.ts → NoResult/NoResult.types.d.ts} +3 -3
- package/dist/components/NoResult/NoResult.types.d.ts.map +1 -0
- package/dist/components/NoResult/index.d.ts +2 -0
- package/dist/components/NoResult/index.d.ts.map +1 -0
- package/dist/components/Quote/Quote.d.ts +4 -0
- package/dist/components/Quote/Quote.d.ts.map +1 -0
- package/dist/components/Quote/Quote.styles.d.ts +1429 -0
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -0
- package/dist/components/Quote/Quote.types.d.ts +22 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.d.ts +4 -0
- package/dist/components/Quote/QuoteSkeleton.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts +319 -0
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.types.d.ts +6 -0
- package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.d.ts +11 -0
- package/dist/components/Quote/QuoteSummary.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts +158 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -0
- package/dist/components/Quote/index.d.ts +4 -0
- package/dist/components/Quote/index.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +9 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -0
- package/dist/components/{RouteErrors/RouteErrors.styles.d.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts} +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +22 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/index.d.ts +2 -0
- package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDetails.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/warnings.d.ts +2 -2
- package/dist/constants/warnings.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts +4 -0
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +472 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +17 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/index.d.ts +2 -0
- package/dist/containers/QuoteInfo/index.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/index.d.ts +2 -0
- package/dist/hooks/useConfirmSwap/index.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +3 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +16 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -0
- package/dist/hooks/{useConfirmSwap.d.ts → useConfirmSwap/useConfirmSwap.types.d.ts} +5 -7
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -0
- package/dist/hooks/{useFetchBestRoute.d.ts → useFetchQuote.d.ts} +3 -3
- package/dist/hooks/useFetchQuote.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useSwapInput.d.ts +4 -2
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -2
- package/dist/store/{bestRoute.d.ts → quote.d.ts} +25 -20
- package/dist/store/quote.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/quote.d.ts +82 -0
- package/dist/types/quote.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/{routing.d.ts → quote.d.ts} +16 -12
- package/dist/utils/quote.d.ts.map +1 -0
- package/dist/utils/settings.d.ts +1 -1
- package/dist/utils/swap.d.ts +22 -20
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/package.json +3 -3
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +3 -3
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +2 -64
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +23 -26
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +1 -1
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
- package/src/components/{NoRoutes/NoRoutes.helper.ts → NoResult/NoResult.helpers.ts} +16 -9
- package/src/components/{NoRoutes/NoRoutes.styles.ts → NoResult/NoResult.styles.ts} +2 -0
- package/src/components/{NoRoutes/NoRoutes.tsx → NoResult/NoResult.tsx} +7 -12
- package/src/components/{NoRoutes/NoRoutes.types.ts → NoResult/NoResult.types.ts} +3 -2
- package/src/components/NoResult/index.ts +1 -0
- package/src/components/Quote/Quote.styles.ts +212 -0
- package/src/components/Quote/Quote.tsx +347 -0
- package/src/components/Quote/Quote.types.ts +16 -0
- package/src/components/Quote/QuoteSkeleton.styles.ts +110 -0
- package/src/components/Quote/QuoteSkeleton.tsx +108 -0
- package/src/components/Quote/QuoteSkeleton.types.ts +5 -0
- package/src/components/Quote/QuoteSummary.styles.ts +15 -0
- package/src/components/Quote/QuoteSummary.tsx +46 -0
- package/src/components/Quote/index.ts +3 -0
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +107 -0
- package/src/components/{RouteErrors/RouteErrorsModalItem.tsx → QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx} +3 -3
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +67 -0
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +103 -0
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +24 -0
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +77 -0
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +38 -0
- package/src/components/QuoteWarningsAndErrors/index.ts +1 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +13 -16
- package/src/components/SwitchFromAndTo.tsx +2 -2
- package/src/components/UpdateUrl.tsx +12 -12
- package/src/components/WidgetEvents.tsx +2 -3
- package/src/constants/errors.ts +8 -10
- package/src/constants/messages.ts +1 -1
- package/src/constants/warnings.ts +7 -7
- package/src/containers/QuoteInfo/QuoteInfo.styles.ts +15 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +97 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +17 -0
- package/src/containers/QuoteInfo/index.ts +1 -0
- package/src/hooks/useConfirmSwap/index.ts +1 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +168 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +136 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +19 -0
- package/src/hooks/{useFetchBestRoute.ts → useFetchQuote.ts} +3 -3
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useSwapInput.ts +57 -23
- package/src/hooks/useSyncStoresWithConfig.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +58 -227
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +52 -241
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +1 -1
- package/src/pages/SelectBlockchainPage.tsx +3 -3
- package/src/pages/SelectSwapItemsPage.tsx +2 -2
- package/src/pages/SettingsPage.tsx +1 -1
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +1 -1
- package/src/store/{bestRoute.ts → quote.ts} +42 -38
- package/src/types/index.ts +1 -1
- package/src/types/quote.ts +107 -0
- package/src/utils/numbers.ts +1 -1
- package/src/utils/quote.ts +338 -0
- package/src/utils/swap.ts +99 -69
- package/src/utils/wallets.ts +2 -2
- package/dist/components/NoRoutes/NoRoutes.d.ts +0 -4
- package/dist/components/NoRoutes/NoRoutes.d.ts.map +0 -1
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts +0 -3
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +0 -1
- package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +0 -1
- package/dist/components/NoRoutes/index.d.ts +0 -2
- package/dist/components/NoRoutes/index.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +0 -24
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +0 -1
- package/dist/components/RouteErrors/index.d.ts +0 -2
- package/dist/components/RouteErrors/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +0 -1
- package/dist/hooks/useFetchBestRoute.d.ts.map +0 -1
- package/dist/store/bestRoute.d.ts.map +0 -1
- package/dist/types/routing.d.ts +0 -65
- package/dist/types/routing.d.ts.map +0 -1
- package/dist/utils/routing.d.ts.map +0 -1
- package/src/components/NoRoutes/index.ts +0 -1
- package/src/components/RouteErrors/RouteErrors.tsx +0 -79
- package/src/components/RouteErrors/RouteErrors.types.ts +0 -29
- package/src/components/RouteErrors/RouteErrorsModal.tsx +0 -129
- package/src/components/RouteErrors/index.ts +0 -1
- package/src/hooks/useConfirmSwap.ts +0 -303
- package/src/types/routing.ts +0 -77
- package/src/utils/routing.ts +0 -321
- /package/src/components/{RouteErrors/RouteErrors.styles.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts} +0 -0
package/src/pages/Home.tsx
CHANGED
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
import type { SwapResult } from 'rango-sdk';
|
|
2
|
-
|
|
3
1
|
import { i18n } from '@lingui/core';
|
|
4
|
-
import {
|
|
5
|
-
Alert,
|
|
6
|
-
BestRoute,
|
|
7
|
-
BestRouteSkeleton,
|
|
8
|
-
Button,
|
|
9
|
-
Divider,
|
|
10
|
-
styled,
|
|
11
|
-
SwapInput,
|
|
12
|
-
Typography,
|
|
13
|
-
WarningIcon,
|
|
14
|
-
} from '@rango-dev/ui';
|
|
2
|
+
import { Button, styled, SwapInput, WarningIcon } from '@rango-dev/ui';
|
|
15
3
|
import React, { useEffect, useRef, useState } from 'react';
|
|
16
4
|
import { useNavigate } from 'react-router-dom';
|
|
17
5
|
|
|
18
6
|
import { HomeButtons } from '../components/HeaderButtons';
|
|
19
7
|
import { Layout } from '../components/Layout';
|
|
20
|
-
import { NoRoutes } from '../components/NoRoutes';
|
|
21
|
-
import { RouteErrors } from '../components/RouteErrors';
|
|
22
8
|
import { SwitchFromAndToButton } from '../components/SwitchFromAndTo';
|
|
23
9
|
import { errorMessages } from '../constants/errors';
|
|
24
10
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
25
11
|
import {
|
|
26
12
|
BALANCE_MAX_DECIMALS,
|
|
27
13
|
BALANCE_MIN_DECIMALS,
|
|
28
|
-
GAS_FEE_MAX_DECIMALS,
|
|
29
|
-
GAS_FEE_MIN_DECIMALS,
|
|
30
14
|
PERCENTAGE_CHANGE_MAX_DECIMALS,
|
|
31
15
|
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
32
16
|
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
@@ -34,29 +18,22 @@ import {
|
|
|
34
18
|
USD_VALUE_MAX_DECIMALS,
|
|
35
19
|
USD_VALUE_MIN_DECIMALS,
|
|
36
20
|
} from '../constants/routing';
|
|
21
|
+
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
37
22
|
import { useSwapInput } from '../hooks/useSwapInput';
|
|
38
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
39
23
|
import { useMetaStore } from '../store/meta';
|
|
24
|
+
import { useQuoteStore } from '../store/quote';
|
|
40
25
|
import { useUiStore } from '../store/ui';
|
|
41
26
|
import { useWalletsStore } from '../store/wallets';
|
|
42
27
|
import { ButtonState } from '../types';
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
46
|
-
numberToString,
|
|
47
|
-
secondsToString,
|
|
48
|
-
totalArrivalTime,
|
|
49
|
-
} from '../utils/numbers';
|
|
50
|
-
import { getFormattedBestRoute, getPriceImpactLevel } from '../utils/routing';
|
|
28
|
+
import { numberToString } from '../utils/numbers';
|
|
29
|
+
import { getPriceImpact, getPriceImpactLevel } from '../utils/quote';
|
|
51
30
|
import {
|
|
52
31
|
canComputePriceImpact,
|
|
53
32
|
getOutputRatio,
|
|
54
33
|
getPercentageChange,
|
|
55
34
|
getSwapButtonState,
|
|
56
|
-
|
|
35
|
+
hasHighValueLoss,
|
|
57
36
|
hasLimitError,
|
|
58
|
-
LimitErrorMessage,
|
|
59
|
-
outputRatioHasWarning,
|
|
60
37
|
} from '../utils/swap';
|
|
61
38
|
import { getBalanceFromWallet } from '../utils/wallets';
|
|
62
39
|
|
|
@@ -76,27 +53,13 @@ const InputsContainer = styled('div', {
|
|
|
76
53
|
gap: 5,
|
|
77
54
|
alignSelf: 'stretch',
|
|
78
55
|
});
|
|
79
|
-
|
|
80
|
-
const BestRouteContainer = styled('div', {
|
|
81
|
-
width: '100%',
|
|
82
|
-
paddingTop: '$2',
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const FooterStepAlarm = styled('div', {
|
|
86
|
-
paddingBottom: '$15',
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const FooterAlert = styled('div', {
|
|
90
|
-
width: '100%',
|
|
91
|
-
display: 'flex',
|
|
92
|
-
});
|
|
93
|
-
|
|
94
56
|
export function Home() {
|
|
95
57
|
const navigate = useNavigate();
|
|
96
58
|
const {
|
|
97
|
-
fetch:
|
|
98
|
-
loading:
|
|
99
|
-
error:
|
|
59
|
+
fetch: fetchQuote,
|
|
60
|
+
loading: fetchingQuote,
|
|
61
|
+
error: quoteError,
|
|
62
|
+
warning: quoteWarning,
|
|
100
63
|
} = useSwapInput();
|
|
101
64
|
const {
|
|
102
65
|
fromToken,
|
|
@@ -108,51 +71,40 @@ export function Home() {
|
|
|
108
71
|
inputUsdValue,
|
|
109
72
|
outputAmount,
|
|
110
73
|
outputUsdValue,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
74
|
+
quote,
|
|
75
|
+
resetQuoteWallets,
|
|
76
|
+
setQuoteWarningsConfirmed,
|
|
77
|
+
} = useQuoteStore();
|
|
114
78
|
|
|
115
|
-
const {
|
|
116
|
-
meta: { tokens, blockchains },
|
|
117
|
-
loadingStatus: loadingMetaStatus,
|
|
118
|
-
} = useMetaStore();
|
|
79
|
+
const { loadingStatus: loadingMetaStatus } = useMetaStore();
|
|
119
80
|
|
|
120
81
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
121
82
|
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
122
|
-
const [
|
|
123
|
-
const {
|
|
124
|
-
fromAmountRangeError,
|
|
125
|
-
swap: swapHasError,
|
|
126
|
-
recommendation,
|
|
127
|
-
} = LimitErrorMessage(bestRoute);
|
|
83
|
+
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
128
84
|
const layoutRef = useRef<HTMLDivElement>(null);
|
|
129
85
|
|
|
130
|
-
const showBestRoute =
|
|
131
|
-
!!Number(inputAmount) &&
|
|
132
|
-
(!!bestRoute || fetchingBestRoute || !!bestRouteError);
|
|
133
|
-
|
|
134
86
|
const needsToWarnEthOnPath = false;
|
|
135
87
|
|
|
136
88
|
const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
|
|
137
|
-
const highValueLoss =
|
|
89
|
+
const highValueLoss = hasHighValueLoss(inputUsdValue, outToInRatio);
|
|
138
90
|
|
|
139
91
|
const priceImpactInputCanNotBeComputed = !canComputePriceImpact(
|
|
140
|
-
|
|
92
|
+
quote,
|
|
141
93
|
inputAmount,
|
|
142
94
|
inputUsdValue
|
|
143
95
|
);
|
|
144
96
|
|
|
145
97
|
const priceImpactOutputCanNotBeComputed = !canComputePriceImpact(
|
|
146
|
-
|
|
98
|
+
quote,
|
|
147
99
|
inputAmount,
|
|
148
100
|
outputUsdValue
|
|
149
101
|
);
|
|
150
102
|
const swapButtonState = getSwapButtonState(
|
|
151
103
|
loadingMetaStatus,
|
|
152
104
|
connectedWallets,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
hasLimitError(
|
|
105
|
+
fetchingQuote,
|
|
106
|
+
quote,
|
|
107
|
+
hasLimitError(quote),
|
|
156
108
|
highValueLoss,
|
|
157
109
|
priceImpactInputCanNotBeComputed || priceImpactOutputCanNotBeComputed,
|
|
158
110
|
needsToWarnEthOnPath,
|
|
@@ -193,7 +145,7 @@ export function Home() {
|
|
|
193
145
|
|
|
194
146
|
useEffect(() => {
|
|
195
147
|
setCurrentPage(navigationRoutes.home);
|
|
196
|
-
|
|
148
|
+
resetQuoteWallets();
|
|
197
149
|
return setCurrentPage.bind(null, '');
|
|
198
150
|
}, []);
|
|
199
151
|
|
|
@@ -201,83 +153,9 @@ export function Home() {
|
|
|
201
153
|
!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
|
|
202
154
|
? null
|
|
203
155
|
: getPercentageChange(
|
|
204
|
-
inputUsdValue.
|
|
205
|
-
outputUsdValue.
|
|
156
|
+
inputUsdValue.toString(),
|
|
157
|
+
outputUsdValue.toString()
|
|
206
158
|
);
|
|
207
|
-
|
|
208
|
-
const getBestRouteSteps = (swaps: SwapResult[]) => {
|
|
209
|
-
return swaps.map((swap, index) => ({
|
|
210
|
-
swapper: { displayName: swap.swapperId, image: swap.swapperLogo },
|
|
211
|
-
from: {
|
|
212
|
-
token: { displayName: swap.from.symbol, image: swap.from.logo },
|
|
213
|
-
chain: {
|
|
214
|
-
displayName:
|
|
215
|
-
getBlockchainShortNameFor(swap.from.blockchain, blockchains) ?? '',
|
|
216
|
-
image: swap.from.blockchainLogo,
|
|
217
|
-
},
|
|
218
|
-
price: {
|
|
219
|
-
value:
|
|
220
|
-
index === 0
|
|
221
|
-
? numberToString(
|
|
222
|
-
inputAmount,
|
|
223
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
224
|
-
TOKEN_AMOUNT_MAX_DECIMALS
|
|
225
|
-
)
|
|
226
|
-
: swap.fromAmount,
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
to: {
|
|
230
|
-
token: { displayName: swap.to.symbol, image: swap.to.logo },
|
|
231
|
-
chain: {
|
|
232
|
-
displayName:
|
|
233
|
-
getBlockchainShortNameFor(swap.to.blockchain, blockchains) ?? '',
|
|
234
|
-
image: swap.to.blockchainLogo,
|
|
235
|
-
},
|
|
236
|
-
price: {
|
|
237
|
-
value: swap.toAmount,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
alerts:
|
|
241
|
-
swap.swapperId === swapHasError?.swapperId ? (
|
|
242
|
-
<FooterStepAlarm>
|
|
243
|
-
<Alert
|
|
244
|
-
type="error"
|
|
245
|
-
title={recommendation}
|
|
246
|
-
footer={
|
|
247
|
-
<FooterAlert>
|
|
248
|
-
<Typography size="xsmall" variant="body" color="neutral700">
|
|
249
|
-
{fromAmountRangeError}
|
|
250
|
-
</Typography>
|
|
251
|
-
<Divider direction="horizontal" size={8} />
|
|
252
|
-
<Typography size="xsmall" variant="body" color="neutral700">
|
|
253
|
-
|
|
|
254
|
-
</Typography>
|
|
255
|
-
<Divider direction="horizontal" size={8} />
|
|
256
|
-
<Typography size="xsmall" variant="body" color="neutral700">
|
|
257
|
-
{i18n.t({
|
|
258
|
-
id: 'Yours: {amount} {symbol}',
|
|
259
|
-
values: {
|
|
260
|
-
amount: numberToString(
|
|
261
|
-
swapHasError?.fromAmount || null,
|
|
262
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
263
|
-
TOKEN_AMOUNT_MAX_DECIMALS
|
|
264
|
-
),
|
|
265
|
-
symbol: swap?.from.symbol,
|
|
266
|
-
},
|
|
267
|
-
})}
|
|
268
|
-
</Typography>
|
|
269
|
-
</FooterAlert>
|
|
270
|
-
}
|
|
271
|
-
/>
|
|
272
|
-
</FooterStepAlarm>
|
|
273
|
-
) : undefined,
|
|
274
|
-
}));
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
278
|
-
|
|
279
|
-
const bestRouteData = getFormattedBestRoute(bestRoute);
|
|
280
|
-
|
|
281
159
|
return (
|
|
282
160
|
<Layout
|
|
283
161
|
ref={layoutRef}
|
|
@@ -296,8 +174,8 @@ export function Home() {
|
|
|
296
174
|
onClick={() => {
|
|
297
175
|
if (swapButtonState.state === ButtonState.WAITFORCONNECTING) {
|
|
298
176
|
navigate(navigationRoutes.wallets);
|
|
299
|
-
} else if (
|
|
300
|
-
|
|
177
|
+
} else if (quoteWarning) {
|
|
178
|
+
setShowQuoteWarningModal(true);
|
|
301
179
|
} else {
|
|
302
180
|
navigate(navigationRoutes.confirmSwap);
|
|
303
181
|
}
|
|
@@ -311,9 +189,7 @@ export function Home() {
|
|
|
311
189
|
suffix: (
|
|
312
190
|
<HomeButtons
|
|
313
191
|
layoutRef={layoutRef.current}
|
|
314
|
-
onClickRefresh={
|
|
315
|
-
!!bestRoute || bestRouteError ? refetchBestRoute : undefined
|
|
316
|
-
}
|
|
192
|
+
onClickRefresh={!!quote || quoteError ? fetchQuote : undefined}
|
|
317
193
|
onClickHistory={() => navigate(navigationRoutes.swaps)}
|
|
318
194
|
onClickSettings={() => navigate(navigationRoutes.settings)}
|
|
319
195
|
/>
|
|
@@ -324,6 +200,8 @@ export function Home() {
|
|
|
324
200
|
<FromContainer>
|
|
325
201
|
<SwapInput
|
|
326
202
|
label={i18n.t('From')}
|
|
203
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
204
|
+
//@ts-ignore
|
|
327
205
|
mode="From"
|
|
328
206
|
onInputChange={setInputAmount}
|
|
329
207
|
balance={tokenBalance}
|
|
@@ -360,7 +238,7 @@ export function Home() {
|
|
|
360
238
|
<SwitchFromAndToButton />
|
|
361
239
|
</FromContainer>
|
|
362
240
|
<SwapInput
|
|
363
|
-
sharpBottomStyle={!!
|
|
241
|
+
sharpBottomStyle={!!quote?.result || fetchingQuote}
|
|
364
242
|
label={i18n.t('To')}
|
|
365
243
|
mode="To"
|
|
366
244
|
chain={{
|
|
@@ -371,18 +249,12 @@ export function Home() {
|
|
|
371
249
|
displayName: toToken?.symbol || '',
|
|
372
250
|
image: toToken?.image || '',
|
|
373
251
|
}}
|
|
374
|
-
percentageChange={
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
379
|
-
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
380
|
-
)
|
|
381
|
-
: null
|
|
382
|
-
}
|
|
383
|
-
warningLevel={getPriceImpactLevel(
|
|
384
|
-
percentageChange?.toNumber() ?? 0
|
|
252
|
+
percentageChange={numberToString(
|
|
253
|
+
getPriceImpact(inputUsdValue, outputUsdValue),
|
|
254
|
+
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
255
|
+
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
385
256
|
)}
|
|
257
|
+
warningLevel={getPriceImpactLevel(percentageChange ?? 0)}
|
|
386
258
|
price={{
|
|
387
259
|
value: numberToString(
|
|
388
260
|
outputAmount,
|
|
@@ -405,84 +277,23 @@ export function Home() {
|
|
|
405
277
|
loading={loadingMetaStatus === 'loading'}
|
|
406
278
|
/>
|
|
407
279
|
</InputsContainer>
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
425
|
-
TOKEN_AMOUNT_MAX_DECIMALS
|
|
426
|
-
),
|
|
427
|
-
usdValue: numberToString(
|
|
428
|
-
inputUsdValue,
|
|
429
|
-
USD_VALUE_MIN_DECIMALS,
|
|
430
|
-
USD_VALUE_MAX_DECIMALS
|
|
431
|
-
),
|
|
432
|
-
}}
|
|
433
|
-
output={{
|
|
434
|
-
value: numberToString(
|
|
435
|
-
outputAmount,
|
|
436
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
437
|
-
TOKEN_AMOUNT_MAX_DECIMALS
|
|
438
|
-
),
|
|
439
|
-
usdValue: numberToString(
|
|
440
|
-
outputUsdValue,
|
|
441
|
-
USD_VALUE_MIN_DECIMALS,
|
|
442
|
-
USD_VALUE_MAX_DECIMALS
|
|
443
|
-
),
|
|
444
|
-
}}
|
|
445
|
-
steps={getBestRouteSteps(bestRouteData.result.swaps)}
|
|
446
|
-
percentageChange={numberToString(
|
|
447
|
-
percentageChange,
|
|
448
|
-
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
449
|
-
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
450
|
-
)}
|
|
451
|
-
totalFee={numberToString(
|
|
452
|
-
totalFeeInUsd,
|
|
453
|
-
GAS_FEE_MIN_DECIMALS,
|
|
454
|
-
GAS_FEE_MAX_DECIMALS
|
|
455
|
-
)}
|
|
456
|
-
totalTime={secondsToString(
|
|
457
|
-
totalArrivalTime(bestRoute?.result?.swaps)
|
|
458
|
-
)}
|
|
459
|
-
/>
|
|
460
|
-
</BestRouteContainer>
|
|
461
|
-
) : showBestRoute && !fetchingBestRoute ? (
|
|
462
|
-
<>
|
|
463
|
-
<Divider size={20} />
|
|
464
|
-
<NoRoutes
|
|
465
|
-
diagnosisMessage={bestRouteData?.diagnosisMessages?.[0]}
|
|
466
|
-
fetch={refetchBestRoute}
|
|
467
|
-
error={!!bestRouteError}
|
|
468
|
-
/>
|
|
469
|
-
</>
|
|
470
|
-
) : null}
|
|
280
|
+
<QuoteInfo
|
|
281
|
+
quote={quote}
|
|
282
|
+
loading={fetchingQuote}
|
|
283
|
+
error={quoteError}
|
|
284
|
+
warning={quoteWarning}
|
|
285
|
+
type="basic"
|
|
286
|
+
refetchQuote={fetchQuote}
|
|
287
|
+
showWarningModal={showQuoteWarningModal}
|
|
288
|
+
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
289
|
+
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
290
|
+
onConfirmWarningModal={() => {
|
|
291
|
+
setShowQuoteWarningModal(false);
|
|
292
|
+
setQuoteWarningsConfirmed(true);
|
|
293
|
+
navigate(navigationRoutes.confirmSwap);
|
|
294
|
+
}}
|
|
295
|
+
/>
|
|
471
296
|
</Container>
|
|
472
|
-
<RouteErrors
|
|
473
|
-
openModal={openWarningModal}
|
|
474
|
-
onToggle={setOpenWarningModal}
|
|
475
|
-
totalFeeInUsd={totalFeeInUsd}
|
|
476
|
-
outputUsdValue={outputUsdValue}
|
|
477
|
-
inputUsdValue={inputUsdValue}
|
|
478
|
-
percentageChange={percentageChange}
|
|
479
|
-
highValueLoss={highValueLoss}
|
|
480
|
-
priceImpactCanNotBeComputed={
|
|
481
|
-
priceImpactInputCanNotBeComputed || priceImpactOutputCanNotBeComputed
|
|
482
|
-
}
|
|
483
|
-
loading={fetchingBestRoute || loadingMetaStatus === 'loading'}
|
|
484
|
-
extraSpace={!!bestRoute?.result || !bestRoute}
|
|
485
|
-
/>
|
|
486
297
|
</Layout>
|
|
487
298
|
);
|
|
488
299
|
}
|
|
@@ -111,7 +111,7 @@ export function LiquiditySourcePage({
|
|
|
111
111
|
return (
|
|
112
112
|
<Layout
|
|
113
113
|
header={{
|
|
114
|
-
onBack: navigateBackFrom
|
|
114
|
+
onBack: () => navigateBackFrom(navigationRoutes.settings),
|
|
115
115
|
title: i18n.t(sourceType),
|
|
116
116
|
suffix: (
|
|
117
117
|
<LiquiditySourceSuffix>
|
|
@@ -8,8 +8,8 @@ import { SearchInput } from '../components/SearchInput';
|
|
|
8
8
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
9
9
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
10
10
|
import { useAppStore } from '../store/app';
|
|
11
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
12
11
|
import { useMetaStore } from '../store/meta';
|
|
12
|
+
import { useQuoteStore } from '../store/quote';
|
|
13
13
|
|
|
14
14
|
interface PropTypes {
|
|
15
15
|
type: 'source' | 'destination';
|
|
@@ -20,8 +20,8 @@ export function SelectBlockchainPage(props: PropTypes) {
|
|
|
20
20
|
const { navigateBackFrom } = useNavigateBack();
|
|
21
21
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
22
22
|
const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
|
|
23
|
-
const setToBlockchain =
|
|
24
|
-
const setFromBlockchain =
|
|
23
|
+
const setToBlockchain = useQuoteStore.use.setToBlockchain();
|
|
24
|
+
const setFromBlockchain = useQuoteStore.use.setFromBlockchain();
|
|
25
25
|
const { loadingStatus } = useMetaStore();
|
|
26
26
|
|
|
27
27
|
const blockchains = useAppStore().blockchains({
|
|
@@ -12,7 +12,7 @@ import { TokenList } from '../components/TokenList/TokenList';
|
|
|
12
12
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
13
13
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
14
14
|
import { useAppStore } from '../store/app';
|
|
15
|
-
import {
|
|
15
|
+
import { useQuoteStore } from '../store/quote';
|
|
16
16
|
import { useWalletsStore } from '../store/wallets';
|
|
17
17
|
import { getTokensBalanceFromWalletAndSort } from '../utils/wallets';
|
|
18
18
|
|
|
@@ -31,7 +31,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
31
31
|
setToToken,
|
|
32
32
|
setFromBlockchain,
|
|
33
33
|
setToBlockchain,
|
|
34
|
-
} =
|
|
34
|
+
} = useQuoteStore();
|
|
35
35
|
const { connectedWallets } = useWalletsStore();
|
|
36
36
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
37
37
|
|
|
@@ -175,7 +175,7 @@ export function SettingsPage({ supportedSwappers, singleTheme }: PropTypes) {
|
|
|
175
175
|
return (
|
|
176
176
|
<Layout
|
|
177
177
|
header={{
|
|
178
|
-
onBack: navigateBackFrom
|
|
178
|
+
onBack: () => navigateBackFrom(navigationRoutes.settings),
|
|
179
179
|
title: i18n.t('Setting'),
|
|
180
180
|
}}>
|
|
181
181
|
<SettingsContainer>
|
package/src/pages/ThemePage.tsx
CHANGED
|
@@ -71,7 +71,7 @@ export function WalletsPage({ config }: PropTypes) {
|
|
|
71
71
|
<Layout
|
|
72
72
|
header={{
|
|
73
73
|
title: i18n.t('Connect Wallets'),
|
|
74
|
-
onBack: navigateBackFrom
|
|
74
|
+
onBack: () => navigateBackFrom(navigationRoutes.wallets),
|
|
75
75
|
}}>
|
|
76
76
|
<Container>
|
|
77
77
|
<Typography variant="title" size="xmedium" align="center">
|