@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
|
@@ -1,37 +1,49 @@
|
|
|
1
|
+
import type { QuoteError, QuoteWarning } from '../types';
|
|
2
|
+
|
|
1
3
|
import { useEffect, useRef, useState } from 'react';
|
|
2
4
|
|
|
3
|
-
import {
|
|
5
|
+
import { useMetaStore } from '../store/meta';
|
|
6
|
+
import { useQuoteStore } from '../store/quote';
|
|
4
7
|
import { useSettingsStore } from '../store/settings';
|
|
8
|
+
import { QuoteErrorType } from '../types';
|
|
5
9
|
import { debounce } from '../utils/common';
|
|
6
10
|
import { isPositiveNumber } from '../utils/numbers';
|
|
7
|
-
import {
|
|
11
|
+
import { generateQuoteWarnings } from '../utils/quote';
|
|
12
|
+
import { createQuoteRequestBody } from '../utils/swap';
|
|
8
13
|
import { tokensAreEqual } from '../utils/wallets';
|
|
9
14
|
|
|
10
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
handleQuoteErrors,
|
|
17
|
+
throwErrorIfResponseIsNotValid,
|
|
18
|
+
} from './useConfirmSwap/useConfirmSwap.helpers';
|
|
19
|
+
import { useFetchQuote } from './useFetchQuote';
|
|
11
20
|
|
|
12
21
|
const DEBOUNCE_DELAY = 600;
|
|
13
22
|
|
|
14
23
|
type UseSwapInput = {
|
|
15
24
|
fetch: () => void;
|
|
16
25
|
loading: boolean;
|
|
17
|
-
error:
|
|
26
|
+
error: QuoteError | null;
|
|
27
|
+
warning: QuoteWarning | null;
|
|
18
28
|
};
|
|
19
29
|
|
|
20
30
|
/**
|
|
21
|
-
* a hook for fetching
|
|
31
|
+
* a hook for fetching quote based on from and to input values
|
|
22
32
|
* we use this hook in home page
|
|
23
33
|
*/
|
|
24
34
|
export function useSwapInput(): UseSwapInput {
|
|
25
|
-
const { fetch:
|
|
26
|
-
const [loading, setLoading] = useState(false);
|
|
35
|
+
const { fetch: fetchQuote, cancelFetch } = useFetchQuote();
|
|
27
36
|
const {
|
|
28
37
|
fromToken,
|
|
29
38
|
toToken,
|
|
30
39
|
inputAmount,
|
|
31
40
|
inputUsdValue,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} =
|
|
41
|
+
resetQuote,
|
|
42
|
+
setQuote,
|
|
43
|
+
} = useQuoteStore();
|
|
44
|
+
const {
|
|
45
|
+
meta: { tokens },
|
|
46
|
+
} = useMetaStore();
|
|
35
47
|
const {
|
|
36
48
|
slippage,
|
|
37
49
|
customSlippage,
|
|
@@ -40,7 +52,9 @@ export function useSwapInput(): UseSwapInput {
|
|
|
40
52
|
affiliateWallets,
|
|
41
53
|
disabledLiquiditySources,
|
|
42
54
|
} = useSettingsStore();
|
|
43
|
-
const [
|
|
55
|
+
const [loading, setLoading] = useState(false);
|
|
56
|
+
const [error, setError] = useState<QuoteError | null>(null);
|
|
57
|
+
const [warning, setWarning] = useState<QuoteWarning | null>(null);
|
|
44
58
|
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
45
59
|
const userSlippage = customSlippage ?? slippage;
|
|
46
60
|
const hasTokensValue = !fromToken || !toToken;
|
|
@@ -49,13 +63,19 @@ export function useSwapInput(): UseSwapInput {
|
|
|
49
63
|
tokensAreEqual(fromToken, toToken) ||
|
|
50
64
|
!isPositiveNumber(inputAmount);
|
|
51
65
|
|
|
66
|
+
const resetState = (loading: boolean) => {
|
|
67
|
+
setLoading(loading);
|
|
68
|
+
setError(null);
|
|
69
|
+
setWarning(null);
|
|
70
|
+
};
|
|
71
|
+
|
|
52
72
|
const fetch: UseSwapInput['fetch'] = () => {
|
|
53
73
|
if (!loading) {
|
|
54
|
-
|
|
74
|
+
resetState(true);
|
|
55
75
|
}
|
|
56
76
|
if (!shouldSkipRequest) {
|
|
57
|
-
|
|
58
|
-
const requestBody =
|
|
77
|
+
resetQuote();
|
|
78
|
+
const requestBody = createQuoteRequestBody({
|
|
59
79
|
fromToken,
|
|
60
80
|
toToken,
|
|
61
81
|
inputAmount,
|
|
@@ -65,15 +85,29 @@ export function useSwapInput(): UseSwapInput {
|
|
|
65
85
|
affiliatePercent,
|
|
66
86
|
affiliateWallets,
|
|
67
87
|
});
|
|
68
|
-
|
|
88
|
+
fetchQuote(requestBody)
|
|
69
89
|
.then((res) => {
|
|
70
90
|
setLoading(false);
|
|
71
|
-
|
|
91
|
+
setQuote(res);
|
|
92
|
+
throwErrorIfResponseIsNotValid(res);
|
|
93
|
+
const quoteWarning = generateQuoteWarnings(res, {
|
|
94
|
+
fromToken,
|
|
95
|
+
toToken,
|
|
96
|
+
userSlippage,
|
|
97
|
+
tokens,
|
|
98
|
+
});
|
|
99
|
+
setWarning(quoteWarning);
|
|
72
100
|
})
|
|
73
101
|
.catch((error) => {
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
102
|
+
const { error: quoteError } = handleQuoteErrors(error);
|
|
103
|
+
if (
|
|
104
|
+
quoteError?.type === QuoteErrorType.NO_RESULT ||
|
|
105
|
+
quoteError?.type === QuoteErrorType.REQUEST_FAILED
|
|
106
|
+
) {
|
|
107
|
+
resetQuote();
|
|
108
|
+
}
|
|
109
|
+
if (quoteError?.type !== QuoteErrorType.REQUEST_CANCELED) {
|
|
110
|
+
setError(quoteError);
|
|
77
111
|
setLoading(false);
|
|
78
112
|
}
|
|
79
113
|
});
|
|
@@ -88,15 +122,15 @@ export function useSwapInput(): UseSwapInput {
|
|
|
88
122
|
|
|
89
123
|
useEffect(() => {
|
|
90
124
|
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
|
|
91
|
-
|
|
125
|
+
resetState(false);
|
|
92
126
|
cancelFetch();
|
|
93
127
|
return;
|
|
94
128
|
}
|
|
95
129
|
if (shouldSkipRequest) {
|
|
96
130
|
return;
|
|
97
131
|
}
|
|
98
|
-
|
|
99
|
-
|
|
132
|
+
resetQuote();
|
|
133
|
+
resetState(true);
|
|
100
134
|
debouncedFetch();
|
|
101
135
|
return cancelFetch;
|
|
102
136
|
}, [inputAmount, shouldSkipRequest]);
|
|
@@ -112,5 +146,5 @@ export function useSwapInput(): UseSwapInput {
|
|
|
112
146
|
return cancelFetch;
|
|
113
147
|
}, [disabledLiquiditySources.length]);
|
|
114
148
|
|
|
115
|
-
return { fetch, loading, error };
|
|
149
|
+
return { fetch, loading, error, warning };
|
|
116
150
|
}
|
|
@@ -3,8 +3,8 @@ import type { Asset } from 'rango-sdk';
|
|
|
3
3
|
|
|
4
4
|
import { useEffect, useMemo, useRef } from 'react';
|
|
5
5
|
|
|
6
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
7
6
|
import { useMetaStore } from '../store/meta';
|
|
7
|
+
import { useQuoteStore } from '../store/quote';
|
|
8
8
|
import { useSettingsStore } from '../store/settings';
|
|
9
9
|
import { tokensAreEqual } from '../utils/wallets';
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ export function useSyncStoresWithConfig(config: WidgetConfig | undefined) {
|
|
|
19
19
|
toToken,
|
|
20
20
|
fromBlockchain,
|
|
21
21
|
toBlockchain,
|
|
22
|
-
} =
|
|
22
|
+
} = useQuoteStore();
|
|
23
23
|
|
|
24
24
|
const {
|
|
25
25
|
meta: { tokens, blockchains },
|
|
@@ -2,20 +2,16 @@
|
|
|
2
2
|
import type {
|
|
3
3
|
ConfirmSwap,
|
|
4
4
|
ConfirmSwapFetchResult,
|
|
5
|
-
} from '../hooks/useConfirmSwap';
|
|
5
|
+
} from '../hooks/useConfirmSwap/useConfirmSwap.types';
|
|
6
6
|
import type { WidgetConfig } from '../types';
|
|
7
7
|
|
|
8
8
|
import { i18n } from '@lingui/core';
|
|
9
9
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
10
10
|
import {
|
|
11
11
|
Alert,
|
|
12
|
-
BestRoute,
|
|
13
|
-
BestRouteSkeleton,
|
|
14
12
|
Button,
|
|
15
13
|
Divider,
|
|
16
14
|
IconButton,
|
|
17
|
-
MessageBox,
|
|
18
|
-
Modal,
|
|
19
15
|
RefreshIcon,
|
|
20
16
|
SettingsIcon,
|
|
21
17
|
styled,
|
|
@@ -27,46 +23,19 @@ import React, { useEffect, useState } from 'react';
|
|
|
27
23
|
import { flushSync } from 'react-dom';
|
|
28
24
|
import { useNavigate } from 'react-router-dom';
|
|
29
25
|
|
|
30
|
-
import {
|
|
31
|
-
formatBestRoute,
|
|
32
|
-
getRequiredWallets,
|
|
33
|
-
} from '../components/ConfirmWalletsModal/ConfirmWallets.helpers';
|
|
26
|
+
import { getRequiredWallets } from '../components/ConfirmWalletsModal/ConfirmWallets.helpers';
|
|
34
27
|
import { ConfirmWalletsModal } from '../components/ConfirmWalletsModal/ConfirmWalletsModal';
|
|
35
28
|
import { HeaderButton } from '../components/HeaderButtons/HeaderButtons.styles';
|
|
36
29
|
import { Layout } from '../components/Layout';
|
|
37
|
-
import { NoRoutes } from '../components/NoRoutes';
|
|
38
|
-
import { getConfirmSwapErrorMessage } from '../constants/errors';
|
|
39
30
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
40
|
-
import {
|
|
41
|
-
|
|
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';
|
|
31
|
+
import { getQuoteUpdateWarningMessage } from '../constants/warnings';
|
|
32
|
+
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
51
33
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
52
|
-
import {
|
|
53
|
-
import { useMetaStore } from '../store/meta';
|
|
54
|
-
import { useSettingsStore } from '../store/settings';
|
|
34
|
+
import { useQuoteStore } from '../store/quote';
|
|
55
35
|
import { useUiStore } from '../store/ui';
|
|
56
36
|
import { useWalletsStore } from '../store/wallets';
|
|
57
|
-
import {
|
|
58
|
-
ConfirmSwapErrorTypes,
|
|
59
|
-
RouteWarningType,
|
|
60
|
-
SlippageWarningType,
|
|
61
|
-
} from '../types';
|
|
37
|
+
import { QuoteWarningType } from '../types';
|
|
62
38
|
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';
|
|
70
39
|
|
|
71
40
|
const Container = styled('div', {
|
|
72
41
|
position: 'relative',
|
|
@@ -108,36 +77,26 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
108
77
|
//TODO: move component's logics to a custom hook
|
|
109
78
|
const { config } = props;
|
|
110
79
|
const {
|
|
111
|
-
|
|
112
|
-
inputAmount,
|
|
113
|
-
outputAmount,
|
|
114
|
-
inputUsdValue,
|
|
115
|
-
outputUsdValue,
|
|
80
|
+
quote,
|
|
116
81
|
setInputAmount,
|
|
117
82
|
selectedWallets,
|
|
118
|
-
|
|
119
|
-
|
|
83
|
+
quoteWalletsConfirmed,
|
|
84
|
+
setQuoteWalletConfirmed,
|
|
120
85
|
customDestination,
|
|
121
|
-
|
|
86
|
+
quoteWarningsConfirmed,
|
|
87
|
+
} = useQuoteStore();
|
|
122
88
|
const navigate = useNavigate();
|
|
123
89
|
const [dbErrorMessage, setDbErrorMessage] = useState<string>('');
|
|
124
|
-
const [showSlippageWarning, setShowSlippageWarning] = useState(false);
|
|
125
90
|
|
|
126
91
|
const { connectedWallets } = useWalletsStore();
|
|
127
|
-
const showWalletsOnInit = !
|
|
92
|
+
const showWalletsOnInit = !quoteWalletsConfirmed;
|
|
128
93
|
const [showWallets, setShowWallets] = useState(false);
|
|
129
94
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
130
|
-
|
|
131
|
-
meta: { tokens, blockchains },
|
|
132
|
-
loadingStatus: loadingMetaStatus,
|
|
133
|
-
} = useMetaStore();
|
|
134
|
-
const slippage = useSettingsStore.use.slippage();
|
|
135
|
-
const customSlippage = useSettingsStore.use.customSlippage();
|
|
95
|
+
|
|
136
96
|
const { manager } = useManager();
|
|
137
|
-
const selectedSlippage = customSlippage || slippage;
|
|
138
97
|
const {
|
|
139
98
|
fetch: confirmSwap,
|
|
140
|
-
loading:
|
|
99
|
+
loading: fetchingConfirmationQuote,
|
|
141
100
|
cancelFetch,
|
|
142
101
|
} = useConfirmSwap();
|
|
143
102
|
const [confirmSwapResult, setConfirmSwapResult] =
|
|
@@ -146,32 +105,8 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
146
105
|
error: null,
|
|
147
106
|
warnings: null,
|
|
148
107
|
});
|
|
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
|
-
);
|
|
173
108
|
|
|
174
|
-
const
|
|
109
|
+
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
175
110
|
|
|
176
111
|
const onConfirmSwap: ConfirmSwap['fetch'] = async ({
|
|
177
112
|
selectedWallets,
|
|
@@ -183,7 +118,7 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
183
118
|
};
|
|
184
119
|
|
|
185
120
|
const addNewSwap = async () => {
|
|
186
|
-
if (confirmSwapResult.swap &&
|
|
121
|
+
if (confirmSwapResult.swap && quoteWalletsConfirmed) {
|
|
187
122
|
try {
|
|
188
123
|
await manager?.create(
|
|
189
124
|
'swap',
|
|
@@ -211,8 +146,8 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
211
146
|
};
|
|
212
147
|
|
|
213
148
|
const onStartConfirmSwap = async () => {
|
|
214
|
-
if (confirmSwapResult?.warnings?.
|
|
215
|
-
|
|
149
|
+
if (confirmSwapResult?.warnings?.quote && !quoteWarningsConfirmed) {
|
|
150
|
+
setShowQuoteWarningModal(true);
|
|
216
151
|
} else {
|
|
217
152
|
await onConfirm();
|
|
218
153
|
}
|
|
@@ -252,10 +187,10 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
252
187
|
}, []);
|
|
253
188
|
|
|
254
189
|
useEffect(() => {
|
|
255
|
-
const
|
|
256
|
-
confirmSwapResult.warnings?.
|
|
257
|
-
Object.values(
|
|
258
|
-
confirmSwapResult.warnings?.
|
|
190
|
+
const quoteChanged =
|
|
191
|
+
confirmSwapResult.warnings?.quote?.type &&
|
|
192
|
+
Object.values(QuoteWarningType).includes(
|
|
193
|
+
confirmSwapResult.warnings?.quote?.type
|
|
259
194
|
);
|
|
260
195
|
|
|
261
196
|
const selectedWalletDisconnected =
|
|
@@ -269,16 +204,15 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
269
204
|
)
|
|
270
205
|
);
|
|
271
206
|
|
|
272
|
-
let
|
|
207
|
+
let quoteWalletsChanged = false;
|
|
273
208
|
|
|
274
|
-
if (
|
|
275
|
-
let requiredWallets = getRequiredWallets(
|
|
209
|
+
if (quoteChanged) {
|
|
210
|
+
let requiredWallets = getRequiredWallets(quote);
|
|
276
211
|
|
|
277
212
|
const lastStepToBlockchain =
|
|
278
|
-
|
|
279
|
-
.blockchain;
|
|
213
|
+
quote?.result?.swaps[quote.result.swaps.length - 1].to.blockchain;
|
|
280
214
|
|
|
281
|
-
const isLastWalletRequired = !!
|
|
215
|
+
const isLastWalletRequired = !!quote?.result?.swaps.find(
|
|
282
216
|
(swap) => swap.from.blockchain === lastStepToBlockchain
|
|
283
217
|
);
|
|
284
218
|
|
|
@@ -297,16 +231,16 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
297
231
|
);
|
|
298
232
|
|
|
299
233
|
if (!allRequiredWalletsSelected) {
|
|
300
|
-
|
|
234
|
+
quoteWalletsChanged = true;
|
|
301
235
|
}
|
|
302
236
|
}
|
|
303
237
|
|
|
304
|
-
if (
|
|
238
|
+
if (quote && (selectedWalletDisconnected || quoteWalletsChanged)) {
|
|
305
239
|
queueMicrotask(() => flushSync(setShowWallets.bind(null, true)));
|
|
306
|
-
|
|
240
|
+
setQuoteWalletConfirmed(false);
|
|
307
241
|
}
|
|
308
242
|
}, [
|
|
309
|
-
confirmSwapResult.warnings?.
|
|
243
|
+
confirmSwapResult.warnings?.quote,
|
|
310
244
|
selectedWallets.length,
|
|
311
245
|
connectedWallets.length,
|
|
312
246
|
]);
|
|
@@ -315,7 +249,7 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
315
249
|
<Layout
|
|
316
250
|
header={{
|
|
317
251
|
title: i18n.t('Confirm Swap'),
|
|
318
|
-
onBack: navigate
|
|
252
|
+
onBack: () => navigate(-1),
|
|
319
253
|
hasConnectWallet: true,
|
|
320
254
|
suffix: (
|
|
321
255
|
<Tooltip
|
|
@@ -339,7 +273,7 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
339
273
|
type="primary"
|
|
340
274
|
size="large"
|
|
341
275
|
fullWidth
|
|
342
|
-
loading={
|
|
276
|
+
loading={fetchingConfirmationQuote}
|
|
343
277
|
disabled={!!confirmSwapResult.error}
|
|
344
278
|
onClick={onStartConfirmSwap}>
|
|
345
279
|
{i18n.t('Start Swap')}
|
|
@@ -349,70 +283,18 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
349
283
|
variant="contained"
|
|
350
284
|
type="primary"
|
|
351
285
|
size="large"
|
|
352
|
-
loading={
|
|
286
|
+
loading={fetchingConfirmationQuote}
|
|
353
287
|
onClick={setShowWallets.bind(null, true)}>
|
|
354
288
|
<WalletIcon size={24} />
|
|
355
289
|
</IconButton>
|
|
356
290
|
</Buttons>
|
|
357
291
|
}>
|
|
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>
|
|
410
292
|
{showWallets && (
|
|
411
293
|
<ConfirmWalletsModal
|
|
412
294
|
open={showWallets}
|
|
413
295
|
onClose={() => setShowWallets(false)}
|
|
414
296
|
onCancel={cancelFetch}
|
|
415
|
-
loading={
|
|
297
|
+
loading={fetchingConfirmationQuote}
|
|
416
298
|
onCheckBalance={onConfirmSwap}
|
|
417
299
|
config={config}
|
|
418
300
|
/>
|
|
@@ -426,7 +308,7 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
426
308
|
<Button
|
|
427
309
|
style={{ padding: '0' }}
|
|
428
310
|
variant="ghost"
|
|
429
|
-
disabled={
|
|
311
|
+
disabled={fetchingConfirmationQuote}
|
|
430
312
|
onClick={onRefresh}>
|
|
431
313
|
<div className="icon">
|
|
432
314
|
<RefreshIcon size={16} />
|
|
@@ -439,88 +321,37 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
439
321
|
<Divider size={12} />
|
|
440
322
|
</>
|
|
441
323
|
)}
|
|
442
|
-
{confirmSwapResult.warnings?.
|
|
324
|
+
{confirmSwapResult.warnings?.quoteUpdate && (
|
|
443
325
|
<>
|
|
444
326
|
<Alert
|
|
445
327
|
variant="alarm"
|
|
446
328
|
type="warning"
|
|
447
|
-
title={
|
|
448
|
-
|
|
449
|
-
|
|
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
|
|
329
|
+
title={
|
|
330
|
+
confirmSwapResult.warnings.quoteUpdate &&
|
|
331
|
+
getQuoteUpdateWarningMessage(
|
|
332
|
+
confirmSwapResult.warnings.quoteUpdate
|
|
333
|
+
)
|
|
504
334
|
}
|
|
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)}
|
|
520
335
|
/>
|
|
521
336
|
<Divider size={12} />
|
|
522
337
|
</>
|
|
523
338
|
)}
|
|
339
|
+
<QuoteInfo
|
|
340
|
+
quote={quote}
|
|
341
|
+
type="swap-preview"
|
|
342
|
+
expanded={true}
|
|
343
|
+
error={confirmSwapResult.error}
|
|
344
|
+
loading={fetchingConfirmationQuote}
|
|
345
|
+
warning={confirmSwapResult.warnings?.quote ?? null}
|
|
346
|
+
refetchQuote={onRefresh}
|
|
347
|
+
showWarningModal={showQuoteWarningModal}
|
|
348
|
+
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
349
|
+
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
350
|
+
onConfirmWarningModal={async () => {
|
|
351
|
+
setShowQuoteWarningModal(false);
|
|
352
|
+
await addNewSwap();
|
|
353
|
+
}}
|
|
354
|
+
/>
|
|
524
355
|
</Container>
|
|
525
356
|
</Layout>
|
|
526
357
|
);
|