@rango-dev/widget-embedded 0.23.1-next.0 → 0.23.1-next.2
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/Layout/Layout.styles.d.ts +162 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +2 -0
- 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/{QuoteTrigger .d.ts → QuoteTrigger.d.ts} +1 -1
- package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +0 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.d.ts +4 -0
- package/dist/components/Quotes/Quotes.d.ts.map +1 -0
- package/dist/components/Quotes/Quotes.styles.d.ts +487 -0
- package/dist/components/Quotes/Quotes.styles.d.ts.map +1 -0
- package/dist/components/Quotes/Quotes.types.d.ts +9 -0
- package/dist/components/Quotes/Quotes.types.d.ts.map +1 -0
- package/dist/components/Quotes/SelectStrategy.d.ts +5 -0
- package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -0
- package/dist/components/Quotes/index.d.ts +2 -0
- package/dist/components/Quotes/index.d.ts.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +4 -3
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts +5 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts.map +1 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +325 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.types.d.ts +9 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.types.d.ts.map +1 -0
- package/dist/containers/ExpandedQuotes/index.d.ts +2 -0
- package/dist/containers/ExpandedQuotes/index.d.ts.map +1 -0
- package/dist/containers/Inputs/Inputs.d.ts +4 -0
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -0
- package/dist/containers/Inputs/Inputs.styles.d.ts +325 -0
- package/dist/containers/Inputs/Inputs.styles.d.ts.map +1 -0
- package/dist/containers/Inputs/Inputs.types.d.ts +7 -0
- package/dist/containers/Inputs/Inputs.types.d.ts.map +1 -0
- package/dist/containers/Inputs/index.d.ts +2 -0
- package/dist/containers/Inputs/index.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
- package/dist/hooks/useMobileDetect.d.ts +3 -0
- package/dist/hooks/useMobileDetect.d.ts.map +1 -0
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.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 +1 -0
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/Routes.d.ts.map +1 -1
- package/dist/types/config.d.ts +5 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/Layout/Layout.styles.ts +9 -7
- package/src/components/Layout/Layout.tsx +2 -2
- package/src/components/NoResult/NoResult.styles.ts +0 -2
- package/src/components/NoResult/NoResult.tsx +1 -0
- package/src/components/Quote/Quote.styles.ts +1 -1
- package/src/components/Quote/Quote.tsx +4 -2
- package/src/components/Quote/Quote.types.ts +2 -0
- package/src/components/Quote/QuoteCostDetails.tsx +10 -6
- package/src/components/Quote/{QuoteTrigger .tsx → QuoteTrigger.tsx} +3 -16
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +15 -12
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +0 -1
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +16 -13
- package/src/components/Quotes/Quotes.styles.ts +18 -0
- package/src/components/Quotes/Quotes.tsx +134 -0
- package/src/components/Quotes/Quotes.types.ts +9 -0
- package/src/components/Quotes/SelectStrategy.tsx +33 -0
- package/src/components/Quotes/index.ts +1 -0
- package/src/constants/index.ts +1 -0
- package/src/constants/quote.ts +22 -7
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +30 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +71 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.types.ts +9 -0
- package/src/containers/ExpandedQuotes/index.ts +1 -0
- package/src/containers/Inputs/Inputs.styles.ts +12 -0
- package/src/containers/Inputs/Inputs.tsx +165 -0
- package/src/containers/Inputs/Inputs.types.ts +7 -0
- package/src/containers/Inputs/index.ts +1 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
- package/src/hooks/useMobileDetect.ts +21 -0
- package/src/hooks/useSwapInput.ts +3 -1
- package/src/index.ts +2 -0
- package/src/pages/ConfirmSwapPage.tsx +0 -1
- package/src/pages/Home.tsx +142 -229
- package/src/pages/Routes.tsx +6 -69
- package/src/types/config.ts +6 -0
- package/src/utils/common.ts +3 -0
- package/dist/components/Quote/QuoteTrigger .d.ts.map +0 -1
package/src/pages/Home.tsx
CHANGED
|
@@ -1,90 +1,59 @@
|
|
|
1
1
|
import { i18n } from '@lingui/core';
|
|
2
|
-
import { Button, Divider, styled,
|
|
2
|
+
import { Button, Divider, styled, WarningIcon } from '@rango-dev/ui';
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
|
|
6
6
|
import { HeaderButtons } from '../components/HeaderButtons';
|
|
7
7
|
import { Layout, PageContainer } from '../components/Layout';
|
|
8
8
|
import { QuoteWarningsAndErrors } from '../components/QuoteWarningsAndErrors';
|
|
9
|
-
import { SwitchFromAndToButton } from '../components/SwitchFromAndTo';
|
|
10
|
-
import { errorMessages } from '../constants/errors';
|
|
11
9
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
15
|
-
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
16
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
17
|
-
USD_VALUE_MAX_DECIMALS,
|
|
18
|
-
USD_VALUE_MIN_DECIMALS,
|
|
19
|
-
} from '../constants/routing';
|
|
10
|
+
import { ExpandedQuotes } from '../containers/ExpandedQuotes';
|
|
11
|
+
import { Inputs } from '../containers/Inputs';
|
|
20
12
|
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
13
|
+
import useMobileDetect from '../hooks/useMobileDetect';
|
|
21
14
|
import { useSwapInput } from '../hooks/useSwapInput';
|
|
22
15
|
import { useAppStore } from '../store/AppStore';
|
|
23
16
|
import { useQuoteStore } from '../store/quote';
|
|
24
17
|
import { useUiStore } from '../store/ui';
|
|
25
18
|
import { useWalletsStore } from '../store/wallets';
|
|
26
|
-
import {
|
|
27
|
-
import { formatTooltipNumbers, numberToString } from '../utils/numbers';
|
|
28
|
-
import { getPriceImpact, getPriceImpactLevel } from '../utils/quote';
|
|
29
|
-
import { canComputePriceImpact, getSwapButtonState } from '../utils/swap';
|
|
30
|
-
import { formatBalance, isFetchingBalance } from '../utils/wallets';
|
|
19
|
+
import { getSwapButtonState } from '../utils/swap';
|
|
31
20
|
|
|
32
|
-
const
|
|
33
|
-
|
|
21
|
+
const MainContainer = styled('div', {
|
|
22
|
+
display: 'grid',
|
|
23
|
+
gridTemplateColumns: 'auto auto',
|
|
24
|
+
alignItems: 'flex-start',
|
|
25
|
+
height: 700,
|
|
34
26
|
});
|
|
27
|
+
export const TIME_TO_NAVIGATE_ANOTHER_PAGE = 300;
|
|
35
28
|
|
|
36
|
-
const InputsContainer = styled('div', {
|
|
37
|
-
display: 'flex',
|
|
38
|
-
flexDirection: 'column',
|
|
39
|
-
gap: 5,
|
|
40
|
-
alignSelf: 'stretch',
|
|
41
|
-
});
|
|
42
29
|
export function Home() {
|
|
43
30
|
const navigate = useNavigate();
|
|
44
31
|
const {
|
|
45
32
|
fromToken,
|
|
46
|
-
fromBlockchain,
|
|
47
33
|
toToken,
|
|
48
|
-
toBlockchain,
|
|
49
|
-
setInputAmount,
|
|
50
34
|
inputAmount,
|
|
51
|
-
inputUsdValue,
|
|
52
|
-
outputAmount,
|
|
53
|
-
outputUsdValue,
|
|
54
35
|
selectedQuote,
|
|
55
36
|
refetchQuote,
|
|
56
37
|
error: quoteError,
|
|
57
38
|
warning: quoteWarning,
|
|
58
39
|
quotes,
|
|
40
|
+
setSelectedQuote,
|
|
59
41
|
resetQuoteWallets,
|
|
60
42
|
setQuoteWarningsConfirmed,
|
|
61
43
|
updateQuotePartialState,
|
|
62
44
|
} = useQuoteStore();
|
|
63
|
-
const
|
|
45
|
+
const [isVisibleExpanded, setIsVisibleExpanded] = useState<boolean>(false);
|
|
46
|
+
const isMobile = useMobileDetect();
|
|
64
47
|
|
|
48
|
+
const { fetch: fetchQuote, loading } = useSwapInput({ refetchQuote });
|
|
65
49
|
const { config, fetchStatus: fetchMetaStatus } = useAppStore();
|
|
66
50
|
|
|
67
|
-
const { connectedWallets
|
|
51
|
+
const { connectedWallets } = useWalletsStore();
|
|
68
52
|
const { isActiveTab } = useUiStore();
|
|
69
53
|
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
70
|
-
const fetchingBalance =
|
|
71
|
-
!!fromBlockchain &&
|
|
72
|
-
isFetchingBalance(connectedWallets, fromBlockchain.name);
|
|
73
54
|
|
|
74
55
|
const needsToWarnEthOnPath = false;
|
|
75
56
|
|
|
76
|
-
const priceImpactInputCanNotBeComputed = !canComputePriceImpact(
|
|
77
|
-
selectedQuote,
|
|
78
|
-
inputAmount,
|
|
79
|
-
inputUsdValue
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const priceImpactOutputCanNotBeComputed = !canComputePriceImpact(
|
|
83
|
-
selectedQuote,
|
|
84
|
-
inputAmount,
|
|
85
|
-
outputUsdValue
|
|
86
|
-
);
|
|
87
|
-
|
|
88
57
|
const swapButtonState = getSwapButtonState({
|
|
89
58
|
fetchMetaStatus,
|
|
90
59
|
fetchingQuote: loading,
|
|
@@ -95,204 +64,148 @@ export function Home() {
|
|
|
95
64
|
warning: quoteWarning,
|
|
96
65
|
needsToWarnEthOnPath,
|
|
97
66
|
});
|
|
67
|
+
const isExpandable = config?.variant === 'expandable' && !isMobile;
|
|
68
|
+
const hasInputs =
|
|
69
|
+
!!inputAmount && !!fromToken && !!toToken && inputAmount !== '0';
|
|
70
|
+
const fetchingQuote = hasInputs && fetchMetaStatus === 'success' && loading;
|
|
98
71
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const tokenBalanceReal =
|
|
105
|
-
!!fromBlockchain && !!fromToken && fromTokenBalance?.amount
|
|
106
|
-
? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
|
|
107
|
-
: '0';
|
|
108
|
-
|
|
109
|
-
const fetchingQuote =
|
|
110
|
-
fetchMetaStatus === 'success' &&
|
|
111
|
-
!!inputAmount &&
|
|
112
|
-
!!fromToken &&
|
|
113
|
-
!!toToken &&
|
|
114
|
-
loading;
|
|
72
|
+
const hasValidQuotes =
|
|
73
|
+
!isExpandable || (isExpandable && quotes?.results.length);
|
|
74
|
+
const hasWarningOrError = quoteWarning || quoteError;
|
|
75
|
+
const showMessages = hasValidQuotes && hasWarningOrError;
|
|
115
76
|
|
|
116
77
|
useEffect(() => {
|
|
117
78
|
resetQuoteWallets();
|
|
118
79
|
updateQuotePartialState('refetchQuote', true);
|
|
119
80
|
}, []);
|
|
120
81
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
setIsVisibleExpanded(hasInputs);
|
|
84
|
+
}, [hasInputs]);
|
|
85
|
+
|
|
86
|
+
const onClickRefresh =
|
|
87
|
+
(!!selectedQuote || quoteError) && !showQuoteWarningModal
|
|
88
|
+
? fetchQuote
|
|
89
|
+
: undefined;
|
|
90
|
+
|
|
91
|
+
const onHandleNavigation = (route: string) => {
|
|
92
|
+
if (isExpandable && isVisibleExpanded) {
|
|
93
|
+
setIsVisibleExpanded(false);
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
navigate(route);
|
|
96
|
+
}, TIME_TO_NAVIGATE_ANOTHER_PAGE);
|
|
97
|
+
} else {
|
|
98
|
+
navigate(route);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
125
101
|
|
|
126
102
|
return (
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
fullWidth
|
|
138
|
-
onClick={() => {
|
|
139
|
-
if (swapButtonState.action === 'connect-wallet') {
|
|
140
|
-
navigate(navigationRoutes.wallets);
|
|
141
|
-
} else if (swapButtonState.action === 'confirm-warning') {
|
|
142
|
-
setShowQuoteWarningModal(true);
|
|
143
|
-
} else {
|
|
144
|
-
navigate(navigationRoutes.confirmSwap);
|
|
103
|
+
<MainContainer>
|
|
104
|
+
<Layout
|
|
105
|
+
height="auto"
|
|
106
|
+
footer={
|
|
107
|
+
<Button
|
|
108
|
+
type="primary"
|
|
109
|
+
size="large"
|
|
110
|
+
disabled={swapButtonState.disabled || !isActiveTab}
|
|
111
|
+
prefix={
|
|
112
|
+
swapButtonState.action === 'confirm-warning' && <WarningIcon />
|
|
145
113
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
label={i18n.t('From')}
|
|
173
|
-
mode="From"
|
|
174
|
-
onInputChange={setInputAmount}
|
|
175
|
-
balance={fromTokenFormattedBalance}
|
|
176
|
-
chain={{
|
|
177
|
-
displayName: fromBlockchain?.displayName || '',
|
|
178
|
-
image: fromBlockchain?.logo || '',
|
|
179
|
-
}}
|
|
180
|
-
token={{
|
|
181
|
-
displayName: fromToken?.symbol || '',
|
|
182
|
-
image: fromToken?.image || '',
|
|
183
|
-
}}
|
|
184
|
-
onClickToken={() => navigate(navigationRoutes.fromSwap)}
|
|
185
|
-
price={{
|
|
186
|
-
value: inputAmount,
|
|
187
|
-
usdValue: priceImpactInputCanNotBeComputed
|
|
188
|
-
? undefined
|
|
189
|
-
: numberToString(
|
|
190
|
-
inputUsdValue,
|
|
191
|
-
USD_VALUE_MIN_DECIMALS,
|
|
192
|
-
USD_VALUE_MAX_DECIMALS
|
|
193
|
-
),
|
|
194
|
-
realUsdValue: priceImpactInputCanNotBeComputed
|
|
195
|
-
? undefined
|
|
196
|
-
: formatTooltipNumbers(inputUsdValue),
|
|
197
|
-
error: priceImpactInputCanNotBeComputed
|
|
198
|
-
? errorMessages().unknownPriceError.impactTitle
|
|
199
|
-
: undefined,
|
|
200
|
-
}}
|
|
201
|
-
disabled={fetchMetaStatus === 'failed'}
|
|
202
|
-
loading={fetchMetaStatus === 'loading'}
|
|
203
|
-
loadingBalance={fetchingBalance}
|
|
204
|
-
tooltipContainer={getContainer()}
|
|
205
|
-
onSelectMaxBalance={() => {
|
|
206
|
-
setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
114
|
+
fullWidth
|
|
115
|
+
onClick={() => {
|
|
116
|
+
if (swapButtonState.action === 'connect-wallet') {
|
|
117
|
+
onHandleNavigation(navigationRoutes.wallets);
|
|
118
|
+
} else if (swapButtonState.action === 'confirm-warning') {
|
|
119
|
+
setShowQuoteWarningModal(true);
|
|
120
|
+
} else {
|
|
121
|
+
onHandleNavigation(navigationRoutes.confirmSwap);
|
|
122
|
+
}
|
|
123
|
+
}}>
|
|
124
|
+
{swapButtonState.title}
|
|
125
|
+
</Button>
|
|
126
|
+
}
|
|
127
|
+
header={{
|
|
128
|
+
onWallet: () => {
|
|
129
|
+
onHandleNavigation(navigationRoutes.wallets);
|
|
130
|
+
},
|
|
131
|
+
hasBackButton: false,
|
|
132
|
+
title: config.title || i18n.t('Swap'),
|
|
133
|
+
suffix: (
|
|
134
|
+
<HeaderButtons
|
|
135
|
+
hidden={isExpandable ? ['refresh'] : undefined}
|
|
136
|
+
onClickRefresh={onClickRefresh}
|
|
137
|
+
onClickHistory={() => onHandleNavigation(navigationRoutes.swaps)}
|
|
138
|
+
onClickSettings={() => {
|
|
139
|
+
onHandleNavigation(navigationRoutes.settings);
|
|
207
140
|
}}
|
|
208
141
|
/>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
label={i18n.t('To')}
|
|
214
|
-
mode="To"
|
|
142
|
+
),
|
|
143
|
+
}}>
|
|
144
|
+
<PageContainer>
|
|
145
|
+
<Inputs
|
|
215
146
|
fetchingQuote={fetchingQuote}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
147
|
+
fetchMetaStatus={fetchMetaStatus}
|
|
148
|
+
onClickToken={(mode) => {
|
|
149
|
+
onHandleNavigation(
|
|
150
|
+
mode === 'from'
|
|
151
|
+
? navigationRoutes.fromSwap
|
|
152
|
+
: navigationRoutes.toSwap
|
|
153
|
+
);
|
|
223
154
|
}}
|
|
224
|
-
percentageChange={numberToString(
|
|
225
|
-
getPriceImpact(inputUsdValue, outputUsdValue),
|
|
226
|
-
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
227
|
-
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
228
|
-
)}
|
|
229
|
-
warningLevel={getPriceImpactLevel(percentageChange ?? 0)}
|
|
230
|
-
price={{
|
|
231
|
-
value: numberToString(
|
|
232
|
-
outputAmount,
|
|
233
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
234
|
-
TOKEN_AMOUNT_MAX_DECIMALS
|
|
235
|
-
),
|
|
236
|
-
usdValue: priceImpactOutputCanNotBeComputed
|
|
237
|
-
? undefined
|
|
238
|
-
: numberToString(
|
|
239
|
-
outputUsdValue,
|
|
240
|
-
USD_VALUE_MIN_DECIMALS,
|
|
241
|
-
USD_VALUE_MAX_DECIMALS
|
|
242
|
-
),
|
|
243
|
-
realValue: formatTooltipNumbers(outputAmount),
|
|
244
|
-
realUsdValue: priceImpactOutputCanNotBeComputed
|
|
245
|
-
? undefined
|
|
246
|
-
: formatTooltipNumbers(outputUsdValue),
|
|
247
|
-
error: priceImpactOutputCanNotBeComputed
|
|
248
|
-
? errorMessages().unknownPriceError.impactTitle
|
|
249
|
-
: undefined,
|
|
250
|
-
}}
|
|
251
|
-
onClickToken={() => navigate(navigationRoutes.toSwap)}
|
|
252
|
-
disabled={fetchMetaStatus === 'failed'}
|
|
253
|
-
loading={fetchMetaStatus === 'loading'}
|
|
254
|
-
tooltipContainer={getContainer()}
|
|
255
155
|
/>
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
loading={fetchingQuote}
|
|
261
|
-
error={quoteError}
|
|
262
|
-
tagHidden={false}
|
|
263
|
-
warning={quoteWarning}
|
|
264
|
-
type="basic"
|
|
265
|
-
onClickAllRoutes={
|
|
266
|
-
!!quotes && quotes.results.length > 1
|
|
267
|
-
? () => {
|
|
268
|
-
updateQuotePartialState('refetchQuote', false);
|
|
269
|
-
navigate(navigationRoutes.routes);
|
|
270
|
-
}
|
|
271
|
-
: undefined
|
|
272
|
-
}
|
|
273
|
-
/>
|
|
274
|
-
{quoteWarning || quoteError ? (
|
|
275
|
-
<>
|
|
276
|
-
<Divider size="10" />
|
|
277
|
-
<QuoteWarningsAndErrors
|
|
278
|
-
warning={quoteWarning}
|
|
279
|
-
error={quoteError}
|
|
156
|
+
<Divider size="2" />
|
|
157
|
+
{!isExpandable ? (
|
|
158
|
+
<QuoteInfo
|
|
159
|
+
quote={selectedQuote}
|
|
280
160
|
loading={fetchingQuote}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
161
|
+
error={quoteError}
|
|
162
|
+
tagHidden={false}
|
|
163
|
+
warning={quoteWarning}
|
|
164
|
+
type="basic"
|
|
165
|
+
onClickAllRoutes={
|
|
166
|
+
!!quotes && quotes.results.length > 1
|
|
167
|
+
? () => {
|
|
168
|
+
updateQuotePartialState('refetchQuote', false);
|
|
169
|
+
onHandleNavigation(navigationRoutes.routes);
|
|
170
|
+
}
|
|
171
|
+
: undefined
|
|
172
|
+
}
|
|
292
173
|
/>
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
174
|
+
) : null}
|
|
175
|
+
|
|
176
|
+
{showMessages ? (
|
|
177
|
+
<>
|
|
178
|
+
<Divider size="10" />
|
|
179
|
+
<QuoteWarningsAndErrors
|
|
180
|
+
warning={quoteWarning}
|
|
181
|
+
error={quoteError}
|
|
182
|
+
refetchQuote={fetchQuote}
|
|
183
|
+
showWarningModal={showQuoteWarningModal}
|
|
184
|
+
confirmationDisabled={!isActiveTab}
|
|
185
|
+
onOpenWarningModal={() => setShowQuoteWarningModal(true)}
|
|
186
|
+
onCloseWarningModal={() => setShowQuoteWarningModal(false)}
|
|
187
|
+
onConfirmWarningModal={() => {
|
|
188
|
+
setShowQuoteWarningModal(false);
|
|
189
|
+
setQuoteWarningsConfirmed(true);
|
|
190
|
+
onHandleNavigation(navigationRoutes.confirmSwap);
|
|
191
|
+
}}
|
|
192
|
+
onChangeSettings={() =>
|
|
193
|
+
onHandleNavigation(navigationRoutes.settings)
|
|
194
|
+
}
|
|
195
|
+
/>
|
|
196
|
+
</>
|
|
197
|
+
) : null}
|
|
198
|
+
</PageContainer>
|
|
199
|
+
</Layout>
|
|
200
|
+
{isExpandable ? (
|
|
201
|
+
<ExpandedQuotes
|
|
202
|
+
loading={fetchingQuote}
|
|
203
|
+
onClickOnQuote={(quote) => setSelectedQuote(quote)}
|
|
204
|
+
fetch={fetchQuote}
|
|
205
|
+
onClickRefresh={onClickRefresh}
|
|
206
|
+
isVisible={isVisibleExpanded}
|
|
207
|
+
/>
|
|
208
|
+
) : null}
|
|
209
|
+
</MainContainer>
|
|
297
210
|
);
|
|
298
211
|
}
|
package/src/pages/Routes.tsx
CHANGED
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
import type { SelectedQuote } from '../types';
|
|
2
|
-
import type { MultiRouteSimulationResult } from 'rango-sdk';
|
|
3
2
|
|
|
4
3
|
import { i18n } from '@lingui/core';
|
|
5
|
-
import { Divider } from '@rango-dev/ui';
|
|
6
4
|
import React from 'react';
|
|
7
5
|
import { useNavigate } from 'react-router-dom';
|
|
8
6
|
|
|
9
7
|
import { HeaderButtons } from '../components/HeaderButtons';
|
|
10
8
|
import { Layout, PageContainer } from '../components/Layout';
|
|
11
|
-
import {
|
|
9
|
+
import { Quotes } from '../components/Quotes';
|
|
12
10
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
13
|
-
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
14
|
-
import { getQuoteError } from '../hooks/useConfirmSwap/useConfirmSwap.helpers';
|
|
15
11
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
16
12
|
import { useSwapInput } from '../hooks/useSwapInput';
|
|
17
|
-
import { useAppStore } from '../store/AppStore';
|
|
18
13
|
import { useQuoteStore } from '../store/quote';
|
|
19
|
-
import { generateQuoteWarnings } from '../utils/quote';
|
|
20
14
|
|
|
21
|
-
const ITEM_SKELETON_COUNT = 3;
|
|
22
15
|
export function RoutesPage() {
|
|
23
16
|
const navigate = useNavigate();
|
|
24
17
|
const navigateBack = useNavigateBack();
|
|
25
18
|
|
|
26
19
|
const {
|
|
27
20
|
selectedQuote,
|
|
28
|
-
quotes,
|
|
29
21
|
refetchQuote,
|
|
30
22
|
setSelectedQuote,
|
|
31
23
|
updateQuotePartialState,
|
|
32
|
-
fromToken,
|
|
33
|
-
toToken,
|
|
34
24
|
error: quoteError,
|
|
35
25
|
} = useQuoteStore();
|
|
36
|
-
const { slippage, customSlippage } = useAppStore();
|
|
37
|
-
const tokens = useAppStore().tokens();
|
|
38
|
-
|
|
39
|
-
const userSlippage = customSlippage ?? slippage;
|
|
40
26
|
|
|
41
27
|
const { fetch: fetchQuote, loading: fetchingQuote } = useSwapInput({
|
|
42
28
|
refetchQuote,
|
|
@@ -47,22 +33,7 @@ export function RoutesPage() {
|
|
|
47
33
|
updateQuotePartialState('refetchQuote', false);
|
|
48
34
|
navigateBack();
|
|
49
35
|
};
|
|
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
36
|
|
|
59
|
-
return generateQuoteWarnings(mergedQuote, {
|
|
60
|
-
fromToken,
|
|
61
|
-
toToken,
|
|
62
|
-
userSlippage,
|
|
63
|
-
tokens,
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
37
|
const settings_url = `../${navigationRoutes.settings}`;
|
|
67
38
|
const wallets_url = `../${navigationRoutes.wallets}`;
|
|
68
39
|
return (
|
|
@@ -86,45 +57,11 @@ export function RoutesPage() {
|
|
|
86
57
|
),
|
|
87
58
|
}}>
|
|
88
59
|
<PageContainer>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
})}
|
|
60
|
+
<Quotes
|
|
61
|
+
fetch={fetchQuote}
|
|
62
|
+
loading={fetchingQuote}
|
|
63
|
+
onClickOnQuote={onClickOnQuote}
|
|
64
|
+
/>
|
|
128
65
|
</PageContainer>
|
|
129
66
|
</Layout>
|
|
130
67
|
);
|
package/src/types/config.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
|
3
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
import type { Asset } from 'rango-sdk';
|
|
5
5
|
|
|
6
|
+
export type WidgetVariant = 'default' | 'expandable';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* The above type defines a set of optional color properties for a widget.
|
|
8
10
|
* @property {string} background
|
|
@@ -179,6 +181,9 @@ export type Features = Partial<
|
|
|
179
181
|
* - 'connectWalletButton': Visibility state for the wallet connect icon.
|
|
180
182
|
* - 'language': Visibility state for the language.
|
|
181
183
|
* - 'experimentalRoute': Enablement state for the experimental route.
|
|
184
|
+
* @property {WidgetVariant} variant
|
|
185
|
+
* If it is expandable, multiple routes will show up on the home page;
|
|
186
|
+
* if not, you will need to go to a different page to see the suggested routes.
|
|
182
187
|
*/
|
|
183
188
|
|
|
184
189
|
export type WidgetConfig = {
|
|
@@ -199,4 +204,5 @@ export type WidgetConfig = {
|
|
|
199
204
|
externalWallets?: boolean;
|
|
200
205
|
enableNewLiquiditySources?: boolean;
|
|
201
206
|
features?: Features;
|
|
207
|
+
variant?: WidgetVariant;
|
|
202
208
|
};
|
package/src/utils/common.ts
CHANGED
|
@@ -34,3 +34,6 @@ export function containsText(text: string, searchText: string): boolean {
|
|
|
34
34
|
|
|
35
35
|
export const getContainer = () =>
|
|
36
36
|
document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) as HTMLElement;
|
|
37
|
+
|
|
38
|
+
export const getExpanded = () =>
|
|
39
|
+
document.getElementById(WIDGET_UI_ID.EXPANDED_BOX_ID) as HTMLElement;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteTrigger .d.ts","sourceRoot":"","sources":["../../../src/components/Quote/QuoteTrigger .tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAWhF,OAAO,KAA8B,MAAM,OAAO,CAAC;AAkCnD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,qBA6KpD"}
|