@rango-dev/widget-embedded 0.22.4-next.1 → 0.22.4-next.11
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/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +3 -0
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +1 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +2 -2
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +15 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +3 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts +4 -0
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.d.ts +4 -0
- package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +5 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +3 -2
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
- package/dist/components/HeaderButtons/index.d.ts +1 -1
- package/dist/components/HeaderButtons/index.d.ts.map +1 -1
- package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts +6 -0
- package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +3 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.types.d.ts +1 -0
- package/dist/components/Layout/Layout.types.d.ts.map +1 -1
- package/dist/components/Layout/PageContainer.d.ts +1 -0
- package/dist/components/Layout/PageContainer.d.ts.map +1 -1
- package/dist/components/Layout/ScrollableArea.d.ts +1 -0
- package/dist/components/Layout/ScrollableArea.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +14 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts +3 -0
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +4 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1136 -25
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +12 -7
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts +5 -0
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteSummary.styles.d.ts +2 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteTrigger .d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +4 -0
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.types.d.ts +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.types.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts +20 -10
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.types.d.ts +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.types.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +5 -0
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +1 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +3 -0
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +5 -0
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +13 -0
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +1 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +2 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.Cancel.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.Delete.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/index.d.ts +1 -1
- package/dist/components/SwapDetailsModal/index.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +17 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +4 -0
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/constants/languages.d.ts.map +1 -1
- package/dist/constants/navigationRoutes.d.ts +1 -0
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +5 -1
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/containers/App/App.styles.d.ts +1 -0
- package/dist/containers/App/App.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +3 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +6 -3
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +5 -4
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -1
- package/dist/hooks/useFetch.d.ts +12 -0
- package/dist/hooks/useFetch.d.ts.map +1 -0
- package/dist/hooks/useFetchAllQuotes.d.ts +4 -0
- package/dist/hooks/useFetchAllQuotes.d.ts.map +1 -0
- package/dist/hooks/useFetchConfirmQuote.d.ts +4 -0
- package/dist/hooks/useFetchConfirmQuote.d.ts.map +1 -0
- package/dist/hooks/useSwapInput.d.ts +5 -5
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts +1 -0
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/Routes.d.ts +3 -0
- package/dist/pages/Routes.d.ts.map +1 -0
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/AppStore.d.ts +2 -2
- package/dist/store/app.d.ts +2 -2
- package/dist/store/quote.d.ts +32 -10
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +0 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/quote.d.ts +19 -1
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +12 -9
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +2 -3
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +18 -18
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +4 -3
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/QueueManager.tsx +0 -3
- package/src/components/AppRoutes.tsx +5 -0
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +3 -3
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +29 -21
- package/src/components/ConfirmWalletsModal/WalletList.tsx +24 -18
- package/src/components/HeaderButtons/{HomeButtons.tsx → HeaderButtons.tsx} +39 -26
- package/src/components/HeaderButtons/HeaderButtons.types.ts +3 -2
- package/src/components/HeaderButtons/index.ts +1 -1
- package/src/components/Layout/Layout.tsx +13 -1
- package/src/components/Layout/Layout.types.ts +1 -0
- package/src/components/Quote/Quote.styles.ts +133 -38
- package/src/components/Quote/Quote.tsx +77 -18
- package/src/components/Quote/Quote.types.ts +13 -7
- package/src/components/Quote/QuoteCostDetails.tsx +9 -4
- package/src/components/Quote/QuoteTrigger .tsx +7 -3
- package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
- package/src/components/QuoteSkeleton/QuoteSkeleton.types.ts +1 -1
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +10 -12
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +28 -9
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.types.ts +1 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +19 -19
- package/src/components/SwapDetails/SwapDetails.tsx +1 -1
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +1 -3
- package/src/components/SwapDetailsModal/SwapDetailsModal.Cancel.tsx +3 -7
- package/src/components/SwapDetailsModal/SwapDetailsModal.Delete.tsx +1 -3
- package/src/components/SwapDetailsModal/index.ts +1 -1
- package/src/constants/languages.ts +2 -1
- package/src/constants/navigationRoutes.ts +1 -0
- package/src/constants/quote.ts +17 -1
- package/src/containers/QuoteInfo/QuoteInfo.tsx +32 -7
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +6 -3
- package/src/containers/Wallets/Wallets.tsx +5 -11
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +36 -20
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +76 -78
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +1 -1
- package/src/hooks/useFetch.ts +48 -0
- package/src/hooks/useFetchAllQuotes.ts +21 -0
- package/src/hooks/useFetchConfirmQuote.ts +21 -0
- package/src/hooks/useSwapInput.ts +59 -31
- package/src/hooks/useWalletList.ts +5 -3
- package/src/pages/ConfirmSwapPage.tsx +12 -9
- package/src/pages/Home.tsx +27 -19
- package/src/pages/LiquiditySourcePage.tsx +3 -5
- package/src/pages/Routes.tsx +131 -0
- package/src/pages/SettingsPage.tsx +11 -13
- package/src/pages/WalletsPage.tsx +24 -18
- package/src/store/quote.ts +60 -22
- package/src/store/wallets.ts +0 -2
- package/src/types/quote.ts +27 -1
- package/src/utils/quote.ts +129 -67
- package/src/utils/settings.ts +2 -4
- package/src/utils/swap.ts +37 -77
- package/src/utils/wallets.ts +14 -9
- package/dist/components/HeaderButtons/HomeButtons.d.ts +0 -4
- package/dist/components/HeaderButtons/HomeButtons.d.ts.map +0 -1
- package/dist/hooks/useFetchQuote.d.ts +0 -9
- package/dist/hooks/useFetchQuote.d.ts.map +0 -1
- package/src/hooks/useFetchQuote.ts +0 -38
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import type { QuoteError, QuoteWarning } from '../types';
|
|
2
1
|
import type { Token } from 'rango-sdk';
|
|
3
2
|
|
|
4
3
|
import { useCallback, useEffect, useState } from 'react';
|
|
5
4
|
|
|
6
5
|
import { useAppStore } from '../store/AppStore';
|
|
7
6
|
import { useQuoteStore } from '../store/quote';
|
|
7
|
+
import { useWalletsStore } from '../store/wallets';
|
|
8
8
|
import { QuoteErrorType } from '../types';
|
|
9
9
|
import { debounce } from '../utils/common';
|
|
10
10
|
import { isPositiveNumber } from '../utils/numbers';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
generateQuoteWarnings,
|
|
13
|
+
getDefaultQuote,
|
|
14
|
+
sortQuotesBy,
|
|
15
|
+
} from '../utils/quote';
|
|
12
16
|
import { isFeatureEnabled } from '../utils/settings';
|
|
13
17
|
import { createQuoteRequestBody } from '../utils/swap';
|
|
14
18
|
import { areTokensEqual } from '../utils/wallets';
|
|
@@ -17,7 +21,7 @@ import {
|
|
|
17
21
|
handleQuoteErrors,
|
|
18
22
|
throwErrorIfResponseIsNotValid,
|
|
19
23
|
} from './useConfirmSwap/useConfirmSwap.helpers';
|
|
20
|
-
import {
|
|
24
|
+
import { useFetchAllQuotes } from './useFetchAllQuotes';
|
|
21
25
|
|
|
22
26
|
const DEBOUNCE_DELAY = 600;
|
|
23
27
|
const FIRST_INDEX = 0;
|
|
@@ -28,28 +32,34 @@ type FetchQuoteParams = Omit<
|
|
|
28
32
|
> & { fromToken: Token | null; toToken: Token | null };
|
|
29
33
|
|
|
30
34
|
type UseSwapInput = {
|
|
31
|
-
fetch: () => void;
|
|
35
|
+
fetch: (shouldChangeSelectedQuote?: boolean) => void;
|
|
32
36
|
loading: boolean;
|
|
33
|
-
error: QuoteError | null;
|
|
34
|
-
warning: QuoteWarning | null;
|
|
35
37
|
};
|
|
36
|
-
|
|
38
|
+
type UseSwapInputProps = {
|
|
39
|
+
refetchQuote: boolean;
|
|
40
|
+
};
|
|
37
41
|
/**
|
|
38
42
|
* a hook for fetching quote based on from and to input values
|
|
39
43
|
* we use this hook in home page
|
|
40
44
|
*/
|
|
41
|
-
export function useSwapInput(
|
|
42
|
-
|
|
45
|
+
export function useSwapInput({
|
|
46
|
+
refetchQuote,
|
|
47
|
+
}: UseSwapInputProps): UseSwapInput {
|
|
48
|
+
const { fetch: fetchQuote, cancelFetch } = useFetchAllQuotes();
|
|
43
49
|
const { enableNewLiquiditySources, features } = useAppStore().config;
|
|
50
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
51
|
+
|
|
44
52
|
const tokens = useAppStore().tokens();
|
|
45
53
|
const {
|
|
46
54
|
fromToken,
|
|
47
55
|
toToken,
|
|
48
56
|
inputAmount,
|
|
49
57
|
inputUsdValue,
|
|
50
|
-
|
|
58
|
+
selectedQuote,
|
|
59
|
+
sortStrategy,
|
|
51
60
|
resetQuote,
|
|
52
|
-
|
|
61
|
+
setSelectedQuote,
|
|
62
|
+
updateQuotePartialState,
|
|
53
63
|
} = useQuoteStore();
|
|
54
64
|
const {
|
|
55
65
|
slippage,
|
|
@@ -64,8 +74,6 @@ export function useSwapInput(): UseSwapInput {
|
|
|
64
74
|
const excludeLiquiditySources = useAppStore().excludeLiquiditySources();
|
|
65
75
|
|
|
66
76
|
const [loading, setLoading] = useState(true);
|
|
67
|
-
const [error, setError] = useState<QuoteError | null>(null);
|
|
68
|
-
const [warning, setWarning] = useState<QuoteWarning | null>(null);
|
|
69
77
|
const userSlippage = customSlippage ?? slippage;
|
|
70
78
|
const tokensValueInvalid = !fromToken || !toToken;
|
|
71
79
|
const shouldSkipRequest =
|
|
@@ -75,8 +83,6 @@ export function useSwapInput(): UseSwapInput {
|
|
|
75
83
|
|
|
76
84
|
const resetState = (loading: boolean) => {
|
|
77
85
|
setLoading(loading);
|
|
78
|
-
setError(null);
|
|
79
|
-
setWarning(null);
|
|
80
86
|
};
|
|
81
87
|
|
|
82
88
|
const fetch = (params: FetchQuoteParams) => {
|
|
@@ -92,6 +98,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
92
98
|
affiliatePercent,
|
|
93
99
|
affiliateWallets,
|
|
94
100
|
} = params;
|
|
101
|
+
|
|
95
102
|
if (!loading) {
|
|
96
103
|
resetState(true);
|
|
97
104
|
}
|
|
@@ -104,6 +111,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
104
111
|
liquiditySources: liquiditySources,
|
|
105
112
|
excludeLiquiditySources,
|
|
106
113
|
disabledLiquiditySources,
|
|
114
|
+
wallets: connectedWallets,
|
|
107
115
|
slippage,
|
|
108
116
|
affiliateRef,
|
|
109
117
|
affiliatePercent,
|
|
@@ -114,16 +122,32 @@ export function useSwapInput(): UseSwapInput {
|
|
|
114
122
|
}
|
|
115
123
|
fetchQuote(requestBody)
|
|
116
124
|
.then((res) => {
|
|
125
|
+
const sortQuotes = sortQuotesBy(sortStrategy, res.results);
|
|
126
|
+
const quote = getDefaultQuote(
|
|
127
|
+
selectedQuote,
|
|
128
|
+
sortQuotes,
|
|
129
|
+
res.requestAmount
|
|
130
|
+
);
|
|
131
|
+
|
|
117
132
|
setLoading(false);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
updateQuotePartialState('quotes', res);
|
|
134
|
+
setSelectedQuote(quote);
|
|
135
|
+
|
|
136
|
+
throwErrorIfResponseIsNotValid({
|
|
137
|
+
diagnosisMessages: res.diagnosisMessages,
|
|
138
|
+
requestId: quote?.requestId || '',
|
|
139
|
+
swaps: quote?.swaps,
|
|
125
140
|
});
|
|
126
|
-
|
|
141
|
+
|
|
142
|
+
const quoteWarning =
|
|
143
|
+
quote &&
|
|
144
|
+
generateQuoteWarnings(quote, {
|
|
145
|
+
fromToken,
|
|
146
|
+
toToken,
|
|
147
|
+
userSlippage,
|
|
148
|
+
tokens,
|
|
149
|
+
});
|
|
150
|
+
updateQuotePartialState('warning', quoteWarning);
|
|
127
151
|
})
|
|
128
152
|
.catch((error) => {
|
|
129
153
|
const { error: quoteError } = handleQuoteErrors(error);
|
|
@@ -134,7 +158,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
134
158
|
resetQuote();
|
|
135
159
|
}
|
|
136
160
|
if (quoteError?.type !== QuoteErrorType.REQUEST_CANCELED) {
|
|
137
|
-
|
|
161
|
+
updateQuotePartialState('error', quoteError);
|
|
138
162
|
setLoading(false);
|
|
139
163
|
}
|
|
140
164
|
});
|
|
@@ -151,20 +175,26 @@ export function useSwapInput(): UseSwapInput {
|
|
|
151
175
|
);
|
|
152
176
|
|
|
153
177
|
useEffect(() => {
|
|
154
|
-
if (
|
|
178
|
+
if (!refetchQuote) {
|
|
179
|
+
setLoading(false);
|
|
155
180
|
return;
|
|
156
181
|
}
|
|
157
|
-
if (
|
|
158
|
-
resetState(false);
|
|
159
|
-
cancelFetch();
|
|
182
|
+
if (fetchStatus !== 'success') {
|
|
160
183
|
return;
|
|
161
184
|
}
|
|
162
185
|
if (shouldSkipRequest) {
|
|
163
|
-
|
|
186
|
+
setLoading(false);
|
|
187
|
+
if (selectedQuote) {
|
|
164
188
|
resetQuote();
|
|
165
189
|
}
|
|
166
190
|
return;
|
|
167
191
|
}
|
|
192
|
+
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
|
|
193
|
+
resetState(false);
|
|
194
|
+
cancelFetch();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
168
198
|
resetQuote();
|
|
169
199
|
resetState(true);
|
|
170
200
|
debouncedFetch({
|
|
@@ -214,7 +244,5 @@ export function useSwapInput(): UseSwapInput {
|
|
|
214
244
|
affiliateWallets,
|
|
215
245
|
}),
|
|
216
246
|
loading,
|
|
217
|
-
error,
|
|
218
|
-
warning,
|
|
219
247
|
};
|
|
220
248
|
}
|
|
@@ -9,12 +9,13 @@ import {
|
|
|
9
9
|
type WalletType,
|
|
10
10
|
WalletTypes,
|
|
11
11
|
} from '@rango-dev/wallets-shared';
|
|
12
|
-
import { useEffect, useState } from 'react';
|
|
12
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
13
13
|
|
|
14
14
|
import { useAppStore } from '../store/AppStore';
|
|
15
15
|
import { useWalletsStore } from '../store/wallets';
|
|
16
16
|
import { configWalletsToWalletName } from '../utils/providers';
|
|
17
17
|
import {
|
|
18
|
+
hashWalletsState,
|
|
18
19
|
isExperimentalChain,
|
|
19
20
|
mapWalletTypesToWalletInfo,
|
|
20
21
|
sortWalletsBasedOnConnectionState,
|
|
@@ -87,14 +88,14 @@ export function useWalletList(params: Params) {
|
|
|
87
88
|
}
|
|
88
89
|
};
|
|
89
90
|
|
|
90
|
-
const disconnectConnectingWallets = () => {
|
|
91
|
+
const disconnectConnectingWallets = useCallback(() => {
|
|
91
92
|
const connectingWallets =
|
|
92
93
|
wallets?.filter((wallet) => wallet.state === WalletState.CONNECTING) ||
|
|
93
94
|
[];
|
|
94
95
|
for (const wallet of connectingWallets) {
|
|
95
96
|
void disconnect(wallet.type);
|
|
96
97
|
}
|
|
97
|
-
};
|
|
98
|
+
}, [hashWalletsState(wallets)]);
|
|
98
99
|
|
|
99
100
|
useEffect(() => {
|
|
100
101
|
return () => {
|
|
@@ -141,5 +142,6 @@ export function useWalletList(params: Params) {
|
|
|
141
142
|
),
|
|
142
143
|
error,
|
|
143
144
|
handleClick,
|
|
145
|
+
disconnectConnectingWallets,
|
|
144
146
|
};
|
|
145
147
|
}
|
|
@@ -72,7 +72,7 @@ const descriptionStyles = css({
|
|
|
72
72
|
export function ConfirmSwapPage() {
|
|
73
73
|
//TODO: move component's logics to a custom hook
|
|
74
74
|
const {
|
|
75
|
-
|
|
75
|
+
selectedQuote,
|
|
76
76
|
setInputAmount,
|
|
77
77
|
selectedWallets,
|
|
78
78
|
quoteWalletsConfirmed,
|
|
@@ -102,7 +102,6 @@ export function ConfirmSwapPage() {
|
|
|
102
102
|
error: null,
|
|
103
103
|
warnings: null,
|
|
104
104
|
});
|
|
105
|
-
|
|
106
105
|
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
107
106
|
|
|
108
107
|
const onConfirmSwap: ConfirmSwap['fetch'] = async ({
|
|
@@ -110,6 +109,7 @@ export function ConfirmSwapPage() {
|
|
|
110
109
|
customDestination,
|
|
111
110
|
}) => {
|
|
112
111
|
const result = await confirmSwap?.({ selectedWallets, customDestination });
|
|
112
|
+
|
|
113
113
|
setConfirmSwapResult(result);
|
|
114
114
|
return result;
|
|
115
115
|
};
|
|
@@ -212,12 +212,12 @@ export function ConfirmSwapPage() {
|
|
|
212
212
|
let quoteWalletsChanged = false;
|
|
213
213
|
|
|
214
214
|
if (quoteChanged) {
|
|
215
|
-
let requiredWallets = getRequiredWallets(
|
|
215
|
+
let requiredWallets = getRequiredWallets(selectedQuote?.swaps || null);
|
|
216
216
|
|
|
217
217
|
const lastStepToBlockchain =
|
|
218
|
-
|
|
218
|
+
selectedQuote?.swaps[selectedQuote.swaps.length - 1].to.blockchain;
|
|
219
219
|
|
|
220
|
-
const isLastWalletRequired = !!
|
|
220
|
+
const isLastWalletRequired = !!selectedQuote?.swaps.find(
|
|
221
221
|
(swap) => swap.from.blockchain === lastStepToBlockchain
|
|
222
222
|
);
|
|
223
223
|
|
|
@@ -240,7 +240,7 @@ export function ConfirmSwapPage() {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
if (
|
|
243
|
+
if (selectedQuote && (selectedWalletDisconnected || quoteWalletsChanged)) {
|
|
244
244
|
queueMicrotask(() => flushSync(setShowWallets.bind(null, true)));
|
|
245
245
|
setQuoteWalletConfirmed(false);
|
|
246
246
|
}
|
|
@@ -251,7 +251,7 @@ export function ConfirmSwapPage() {
|
|
|
251
251
|
]);
|
|
252
252
|
|
|
253
253
|
useLayoutEffect(() => {
|
|
254
|
-
if (!
|
|
254
|
+
if (!selectedQuote) {
|
|
255
255
|
navigate(`../${location.search}`);
|
|
256
256
|
}
|
|
257
257
|
}, []);
|
|
@@ -277,6 +277,7 @@ export function ConfirmSwapPage() {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
if (quoteWarning || quoteError) {
|
|
280
|
+
const settings_url = `../${navigationRoutes.settings}`;
|
|
280
281
|
alerts.push(
|
|
281
282
|
<QuoteWarningsAndErrors
|
|
282
283
|
warning={quoteWarning}
|
|
@@ -291,7 +292,7 @@ export function ConfirmSwapPage() {
|
|
|
291
292
|
setShowQuoteWarningModal(false);
|
|
292
293
|
await addNewSwap();
|
|
293
294
|
}}
|
|
294
|
-
onChangeSettings={() => navigate(
|
|
295
|
+
onChangeSettings={() => navigate(settings_url)}
|
|
295
296
|
/>
|
|
296
297
|
);
|
|
297
298
|
}
|
|
@@ -375,9 +376,11 @@ export function ConfirmSwapPage() {
|
|
|
375
376
|
{alerts.length > 0 ? <Divider size={10} /> : null}
|
|
376
377
|
|
|
377
378
|
<QuoteInfo
|
|
378
|
-
quote={
|
|
379
|
+
quote={selectedQuote}
|
|
379
380
|
type="swap-preview"
|
|
380
381
|
expanded={true}
|
|
382
|
+
selected
|
|
383
|
+
tagHidden
|
|
381
384
|
error={confirmSwapResult.error}
|
|
382
385
|
loading={fetchingConfirmationQuote}
|
|
383
386
|
warning={confirmSwapResult.warnings?.quote ?? null}
|
package/src/pages/Home.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { Button, Divider, styled, SwapInput, WarningIcon } from '@rango-dev/ui';
|
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { HeaderButtons } from '../components/HeaderButtons';
|
|
7
7
|
import { Layout, PageContainer } from '../components/Layout';
|
|
8
8
|
import { QuoteWarningsAndErrors } from '../components/QuoteWarningsAndErrors';
|
|
9
9
|
import { SwitchFromAndToButton } from '../components/SwitchFromAndTo';
|
|
@@ -41,12 +41,6 @@ const InputsContainer = styled('div', {
|
|
|
41
41
|
});
|
|
42
42
|
export function Home() {
|
|
43
43
|
const navigate = useNavigate();
|
|
44
|
-
const {
|
|
45
|
-
fetch: fetchQuote,
|
|
46
|
-
loading,
|
|
47
|
-
error: quoteError,
|
|
48
|
-
warning: quoteWarning,
|
|
49
|
-
} = useSwapInput();
|
|
50
44
|
const {
|
|
51
45
|
fromToken,
|
|
52
46
|
fromBlockchain,
|
|
@@ -57,10 +51,16 @@ export function Home() {
|
|
|
57
51
|
inputUsdValue,
|
|
58
52
|
outputAmount,
|
|
59
53
|
outputUsdValue,
|
|
60
|
-
|
|
54
|
+
selectedQuote,
|
|
55
|
+
refetchQuote,
|
|
56
|
+
error: quoteError,
|
|
57
|
+
warning: quoteWarning,
|
|
58
|
+
quotes,
|
|
61
59
|
resetQuoteWallets,
|
|
62
60
|
setQuoteWarningsConfirmed,
|
|
61
|
+
updateQuotePartialState,
|
|
63
62
|
} = useQuoteStore();
|
|
63
|
+
const { fetch: fetchQuote, loading } = useSwapInput({ refetchQuote });
|
|
64
64
|
|
|
65
65
|
const { config, fetchStatus: fetchMetaStatus } = useAppStore();
|
|
66
66
|
|
|
@@ -74,13 +74,13 @@ export function Home() {
|
|
|
74
74
|
const needsToWarnEthOnPath = false;
|
|
75
75
|
|
|
76
76
|
const priceImpactInputCanNotBeComputed = !canComputePriceImpact(
|
|
77
|
-
|
|
77
|
+
selectedQuote,
|
|
78
78
|
inputAmount,
|
|
79
79
|
inputUsdValue
|
|
80
80
|
);
|
|
81
81
|
|
|
82
82
|
const priceImpactOutputCanNotBeComputed = !canComputePriceImpact(
|
|
83
|
-
|
|
83
|
+
selectedQuote,
|
|
84
84
|
inputAmount,
|
|
85
85
|
outputUsdValue
|
|
86
86
|
);
|
|
@@ -89,7 +89,7 @@ export function Home() {
|
|
|
89
89
|
fetchMetaStatus,
|
|
90
90
|
fetchingQuote: loading,
|
|
91
91
|
inputAmount,
|
|
92
|
-
quote,
|
|
92
|
+
quote: selectedQuote,
|
|
93
93
|
anyWalletConnected: connectedWallets.length > 0,
|
|
94
94
|
error: quoteError,
|
|
95
95
|
warning: quoteWarning,
|
|
@@ -102,7 +102,7 @@ export function Home() {
|
|
|
102
102
|
formatBalance(fromTokenBalance)?.amount ?? '0';
|
|
103
103
|
|
|
104
104
|
const tokenBalanceReal =
|
|
105
|
-
!!fromBlockchain && !!fromToken
|
|
105
|
+
!!fromBlockchain && !!fromToken && fromTokenBalance?.amount
|
|
106
106
|
? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
|
|
107
107
|
: '0';
|
|
108
108
|
|
|
@@ -115,6 +115,7 @@ export function Home() {
|
|
|
115
115
|
|
|
116
116
|
useEffect(() => {
|
|
117
117
|
resetQuoteWallets();
|
|
118
|
+
updateQuotePartialState('refetchQuote', true);
|
|
118
119
|
}, []);
|
|
119
120
|
|
|
120
121
|
const percentageChange =
|
|
@@ -153,9 +154,9 @@ export function Home() {
|
|
|
153
154
|
hasBackButton: false,
|
|
154
155
|
title: config.title || i18n.t('Swap'),
|
|
155
156
|
suffix: (
|
|
156
|
-
<
|
|
157
|
+
<HeaderButtons
|
|
157
158
|
onClickRefresh={
|
|
158
|
-
(!!
|
|
159
|
+
(!!selectedQuote || quoteError) && !showQuoteWarningModal
|
|
159
160
|
? fetchQuote
|
|
160
161
|
: undefined
|
|
161
162
|
}
|
|
@@ -202,15 +203,13 @@ export function Home() {
|
|
|
202
203
|
loadingBalance={fetchingBalance}
|
|
203
204
|
tooltipContainer={getContainer()}
|
|
204
205
|
onSelectMaxBalance={() => {
|
|
205
|
-
|
|
206
|
-
setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
207
|
-
}
|
|
206
|
+
setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
208
207
|
}}
|
|
209
208
|
/>
|
|
210
209
|
<SwitchFromAndToButton />
|
|
211
210
|
</FromContainer>
|
|
212
211
|
<SwapInput
|
|
213
|
-
sharpBottomStyle={!!
|
|
212
|
+
sharpBottomStyle={!!selectedQuote || fetchingQuote}
|
|
214
213
|
label={i18n.t('To')}
|
|
215
214
|
mode="To"
|
|
216
215
|
fetchingQuote={fetchingQuote}
|
|
@@ -257,11 +256,20 @@ export function Home() {
|
|
|
257
256
|
</InputsContainer>
|
|
258
257
|
<Divider size="2" />
|
|
259
258
|
<QuoteInfo
|
|
260
|
-
quote={
|
|
259
|
+
quote={selectedQuote}
|
|
261
260
|
loading={fetchingQuote}
|
|
262
261
|
error={quoteError}
|
|
262
|
+
tagHidden={false}
|
|
263
263
|
warning={quoteWarning}
|
|
264
264
|
type="basic"
|
|
265
|
+
onClickAllRoutes={
|
|
266
|
+
!!quotes && quotes.results.length > 1
|
|
267
|
+
? () => {
|
|
268
|
+
updateQuotePartialState('refetchQuote', false);
|
|
269
|
+
navigate(navigationRoutes.routes);
|
|
270
|
+
}
|
|
271
|
+
: undefined
|
|
272
|
+
}
|
|
265
273
|
/>
|
|
266
274
|
{quoteWarning || quoteError ? (
|
|
267
275
|
<>
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
UniqueSwappersGroupType,
|
|
4
|
-
} from '../utils/settings';
|
|
1
|
+
import type { UniqueSwappersGroupType } from '../utils/settings';
|
|
2
|
+
import type { SwapperType } from 'rango-sdk';
|
|
5
3
|
|
|
6
4
|
import { i18n } from '@lingui/core';
|
|
7
5
|
import {
|
|
@@ -41,7 +39,7 @@ export function LiquiditySourcePage({ sourceType }: PropTypes) {
|
|
|
41
39
|
getUniqueSwappersGroups(swappers, disabledLiquiditySources);
|
|
42
40
|
|
|
43
41
|
const types = { Exchanges: i18n.t('Exchanges'), Bridges: i18n.t('Bridges') };
|
|
44
|
-
const validTypes: Array<
|
|
42
|
+
const validTypes: Array<SwapperType> = [];
|
|
45
43
|
if (sourceType === 'Exchanges') {
|
|
46
44
|
validTypes.push('DEX');
|
|
47
45
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { SelectedQuote } from '../types';
|
|
2
|
+
import type { MultiRouteSimulationResult } from 'rango-sdk';
|
|
3
|
+
|
|
4
|
+
import { i18n } from '@lingui/core';
|
|
5
|
+
import { Divider } from '@rango-dev/ui';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { useNavigate } from 'react-router-dom';
|
|
8
|
+
|
|
9
|
+
import { HeaderButtons } from '../components/HeaderButtons';
|
|
10
|
+
import { Layout, PageContainer } from '../components/Layout';
|
|
11
|
+
import { QuoteSkeleton } from '../components/QuoteSkeleton';
|
|
12
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
13
|
+
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
14
|
+
import { getQuoteError } from '../hooks/useConfirmSwap/useConfirmSwap.helpers';
|
|
15
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
16
|
+
import { useSwapInput } from '../hooks/useSwapInput';
|
|
17
|
+
import { useAppStore } from '../store/AppStore';
|
|
18
|
+
import { useQuoteStore } from '../store/quote';
|
|
19
|
+
import { generateQuoteWarnings } from '../utils/quote';
|
|
20
|
+
|
|
21
|
+
const ITEM_SKELETON_COUNT = 3;
|
|
22
|
+
export function RoutesPage() {
|
|
23
|
+
const navigate = useNavigate();
|
|
24
|
+
const navigateBack = useNavigateBack();
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
selectedQuote,
|
|
28
|
+
quotes,
|
|
29
|
+
refetchQuote,
|
|
30
|
+
setSelectedQuote,
|
|
31
|
+
updateQuotePartialState,
|
|
32
|
+
fromToken,
|
|
33
|
+
toToken,
|
|
34
|
+
error: quoteError,
|
|
35
|
+
} = useQuoteStore();
|
|
36
|
+
const { slippage, customSlippage } = useAppStore();
|
|
37
|
+
const tokens = useAppStore().tokens();
|
|
38
|
+
|
|
39
|
+
const userSlippage = customSlippage ?? slippage;
|
|
40
|
+
|
|
41
|
+
const { fetch: fetchQuote, loading: fetchingQuote } = useSwapInput({
|
|
42
|
+
refetchQuote,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const onClickOnQuote = (quote: SelectedQuote) => {
|
|
46
|
+
setSelectedQuote(quote);
|
|
47
|
+
updateQuotePartialState('refetchQuote', false);
|
|
48
|
+
navigateBack();
|
|
49
|
+
};
|
|
50
|
+
const getQuoteWarning = (quote: MultiRouteSimulationResult) => {
|
|
51
|
+
if (!fromToken || !toToken || !quotes) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const mergedQuote: SelectedQuote = {
|
|
55
|
+
requestAmount: quotes.requestAmount, // Assuming quotes is an array
|
|
56
|
+
...quote,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return generateQuoteWarnings(mergedQuote, {
|
|
60
|
+
fromToken,
|
|
61
|
+
toToken,
|
|
62
|
+
userSlippage,
|
|
63
|
+
tokens,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const settings_url = `../${navigationRoutes.settings}`;
|
|
67
|
+
const wallets_url = `../${navigationRoutes.wallets}`;
|
|
68
|
+
return (
|
|
69
|
+
<Layout
|
|
70
|
+
header={{
|
|
71
|
+
onWallet: () => {
|
|
72
|
+
navigate(wallets_url);
|
|
73
|
+
},
|
|
74
|
+
onBack: () => {
|
|
75
|
+
updateQuotePartialState('refetchQuote', false);
|
|
76
|
+
},
|
|
77
|
+
title: i18n.t('Routes'),
|
|
78
|
+
suffix: (
|
|
79
|
+
<HeaderButtons
|
|
80
|
+
onClickRefresh={
|
|
81
|
+
!!selectedQuote || quoteError ? fetchQuote : undefined
|
|
82
|
+
}
|
|
83
|
+
hidden={['notifications', 'history']}
|
|
84
|
+
onClickSettings={() => navigate(settings_url)}
|
|
85
|
+
/>
|
|
86
|
+
),
|
|
87
|
+
}}>
|
|
88
|
+
<PageContainer>
|
|
89
|
+
{fetchingQuote
|
|
90
|
+
? Array.from({ length: ITEM_SKELETON_COUNT }, (_, index) => (
|
|
91
|
+
<React.Fragment key={index}>
|
|
92
|
+
<QuoteSkeleton
|
|
93
|
+
tagHidden={false}
|
|
94
|
+
type="list-item"
|
|
95
|
+
expanded={false}
|
|
96
|
+
/>
|
|
97
|
+
<Divider size={16} />
|
|
98
|
+
</React.Fragment>
|
|
99
|
+
))
|
|
100
|
+
: !!quotes &&
|
|
101
|
+
quotes.results?.map((quote) => {
|
|
102
|
+
const quoteWarning = getQuoteWarning(quote);
|
|
103
|
+
const quoteError = getQuoteError(quote.swaps);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<React.Fragment key={quote.requestId}>
|
|
107
|
+
<QuoteInfo
|
|
108
|
+
selected={selectedQuote?.requestId === quote.requestId}
|
|
109
|
+
tagHidden={false}
|
|
110
|
+
quote={{ ...quote, requestAmount: quotes.requestAmount }}
|
|
111
|
+
loading={fetchingQuote}
|
|
112
|
+
error={quoteError?.options || null}
|
|
113
|
+
warning={quoteWarning}
|
|
114
|
+
onClick={(quote) => {
|
|
115
|
+
updateQuotePartialState('warning', quoteWarning);
|
|
116
|
+
updateQuotePartialState(
|
|
117
|
+
'error',
|
|
118
|
+
quoteError?.options || null
|
|
119
|
+
);
|
|
120
|
+
onClickOnQuote(quote);
|
|
121
|
+
}}
|
|
122
|
+
type="list-item"
|
|
123
|
+
/>
|
|
124
|
+
<Divider size={16} />
|
|
125
|
+
</React.Fragment>
|
|
126
|
+
);
|
|
127
|
+
})}
|
|
128
|
+
</PageContainer>
|
|
129
|
+
</Layout>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -129,18 +129,16 @@ export function SettingsPage() {
|
|
|
129
129
|
onClick: () => navigate(navigationRoutes.exchanges),
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
* };
|
|
143
|
-
*/
|
|
132
|
+
const languageItem = {
|
|
133
|
+
id: 'language-item',
|
|
134
|
+
title: (
|
|
135
|
+
<Typography variant="title" size="xmedium">
|
|
136
|
+
{i18n.t('Language')}
|
|
137
|
+
</Typography>
|
|
138
|
+
),
|
|
139
|
+
end: <ChevronRightIcon color="gray" />,
|
|
140
|
+
onClick: () => navigate(navigationRoutes.languages),
|
|
141
|
+
};
|
|
144
142
|
|
|
145
143
|
const themeItem = {
|
|
146
144
|
id: 'theme-item',
|
|
@@ -185,7 +183,7 @@ export function SettingsPage() {
|
|
|
185
183
|
const settingItems = isLiquidityHidden ? [] : [bridgeItem, exchangeItem];
|
|
186
184
|
|
|
187
185
|
if (!isLanguageHidden) {
|
|
188
|
-
|
|
186
|
+
settingItems.push(languageItem);
|
|
189
187
|
}
|
|
190
188
|
if (!theme?.singleTheme && !isThemeHidden) {
|
|
191
189
|
settingItems.push(themeItem);
|