@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.
Files changed (101) hide show
  1. package/dist/components/Layout/Layout.styles.d.ts +162 -0
  2. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  3. package/dist/components/NoResult/NoResult.d.ts.map +1 -1
  4. package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
  5. package/dist/components/Quote/Quote.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.types.d.ts +2 -0
  7. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  8. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  9. package/dist/components/Quote/{QuoteTrigger .d.ts → QuoteTrigger.d.ts} +1 -1
  10. package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -0
  11. package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -1
  12. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +0 -1
  13. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -1
  14. package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -1
  15. package/dist/components/Quotes/Quotes.d.ts +4 -0
  16. package/dist/components/Quotes/Quotes.d.ts.map +1 -0
  17. package/dist/components/Quotes/Quotes.styles.d.ts +487 -0
  18. package/dist/components/Quotes/Quotes.styles.d.ts.map +1 -0
  19. package/dist/components/Quotes/Quotes.types.d.ts +9 -0
  20. package/dist/components/Quotes/Quotes.types.d.ts.map +1 -0
  21. package/dist/components/Quotes/SelectStrategy.d.ts +5 -0
  22. package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -0
  23. package/dist/components/Quotes/index.d.ts +2 -0
  24. package/dist/components/Quotes/index.d.ts.map +1 -0
  25. package/dist/constants/index.d.ts +1 -0
  26. package/dist/constants/index.d.ts.map +1 -1
  27. package/dist/constants/quote.d.ts +4 -3
  28. package/dist/constants/quote.d.ts.map +1 -1
  29. package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts +5 -0
  30. package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts.map +1 -0
  31. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +325 -0
  32. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -0
  33. package/dist/containers/ExpandedQuotes/ExpandedQuotes.types.d.ts +9 -0
  34. package/dist/containers/ExpandedQuotes/ExpandedQuotes.types.d.ts.map +1 -0
  35. package/dist/containers/ExpandedQuotes/index.d.ts +2 -0
  36. package/dist/containers/ExpandedQuotes/index.d.ts.map +1 -0
  37. package/dist/containers/Inputs/Inputs.d.ts +4 -0
  38. package/dist/containers/Inputs/Inputs.d.ts.map +1 -0
  39. package/dist/containers/Inputs/Inputs.styles.d.ts +325 -0
  40. package/dist/containers/Inputs/Inputs.styles.d.ts.map +1 -0
  41. package/dist/containers/Inputs/Inputs.types.d.ts +7 -0
  42. package/dist/containers/Inputs/Inputs.types.d.ts.map +1 -0
  43. package/dist/containers/Inputs/index.d.ts +2 -0
  44. package/dist/containers/Inputs/index.d.ts.map +1 -0
  45. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  46. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +1 -0
  47. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
  48. package/dist/hooks/useMobileDetect.d.ts +3 -0
  49. package/dist/hooks/useMobileDetect.d.ts.map +1 -0
  50. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  51. package/dist/index.d.ts +2 -2
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +2 -2
  54. package/dist/index.js.map +4 -4
  55. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  56. package/dist/pages/Home.d.ts +1 -0
  57. package/dist/pages/Home.d.ts.map +1 -1
  58. package/dist/pages/Routes.d.ts.map +1 -1
  59. package/dist/types/config.d.ts +5 -0
  60. package/dist/types/config.d.ts.map +1 -1
  61. package/dist/utils/common.d.ts +1 -0
  62. package/dist/utils/common.d.ts.map +1 -1
  63. package/package.json +3 -3
  64. package/src/components/Layout/Layout.styles.ts +9 -7
  65. package/src/components/Layout/Layout.tsx +2 -2
  66. package/src/components/NoResult/NoResult.styles.ts +0 -2
  67. package/src/components/NoResult/NoResult.tsx +1 -0
  68. package/src/components/Quote/Quote.styles.ts +1 -1
  69. package/src/components/Quote/Quote.tsx +4 -2
  70. package/src/components/Quote/Quote.types.ts +2 -0
  71. package/src/components/Quote/QuoteCostDetails.tsx +10 -6
  72. package/src/components/Quote/{QuoteTrigger .tsx → QuoteTrigger.tsx} +3 -16
  73. package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +15 -12
  74. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +0 -1
  75. package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +16 -13
  76. package/src/components/Quotes/Quotes.styles.ts +18 -0
  77. package/src/components/Quotes/Quotes.tsx +134 -0
  78. package/src/components/Quotes/Quotes.types.ts +9 -0
  79. package/src/components/Quotes/SelectStrategy.tsx +33 -0
  80. package/src/components/Quotes/index.ts +1 -0
  81. package/src/constants/index.ts +1 -0
  82. package/src/constants/quote.ts +22 -7
  83. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +30 -0
  84. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +71 -0
  85. package/src/containers/ExpandedQuotes/ExpandedQuotes.types.ts +9 -0
  86. package/src/containers/ExpandedQuotes/index.ts +1 -0
  87. package/src/containers/Inputs/Inputs.styles.ts +12 -0
  88. package/src/containers/Inputs/Inputs.tsx +165 -0
  89. package/src/containers/Inputs/Inputs.types.ts +7 -0
  90. package/src/containers/Inputs/index.ts +1 -0
  91. package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
  92. package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
  93. package/src/hooks/useMobileDetect.ts +21 -0
  94. package/src/hooks/useSwapInput.ts +3 -1
  95. package/src/index.ts +2 -0
  96. package/src/pages/ConfirmSwapPage.tsx +0 -1
  97. package/src/pages/Home.tsx +142 -229
  98. package/src/pages/Routes.tsx +6 -69
  99. package/src/types/config.ts +6 -0
  100. package/src/utils/common.ts +3 -0
  101. package/dist/components/Quote/QuoteTrigger .d.ts.map +0 -1
@@ -1,90 +1,59 @@
1
1
  import { i18n } from '@lingui/core';
2
- import { Button, Divider, styled, SwapInput, WarningIcon } from '@rango-dev/ui';
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
- PERCENTAGE_CHANGE_MAX_DECIMALS,
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 { getContainer } from '../utils/common';
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 FromContainer = styled('div', {
33
- position: 'relative',
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 { fetch: fetchQuote, loading } = useSwapInput({ refetchQuote });
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, getBalanceFor } = useWalletsStore();
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 fromTokenBalance = fromToken ? getBalanceFor(fromToken) : null;
100
-
101
- const fromTokenFormattedBalance =
102
- formatBalance(fromTokenBalance)?.amount ?? '0';
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
- const percentageChange =
122
- !inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
123
- ? null
124
- : getPriceImpact(inputUsdValue.toString(), outputUsdValue.toString());
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
- <Layout
128
- height="auto"
129
- footer={
130
- <Button
131
- type="primary"
132
- size="large"
133
- disabled={swapButtonState.disabled || !isActiveTab}
134
- prefix={
135
- swapButtonState.action === 'confirm-warning' && <WarningIcon />
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
- {swapButtonState.title}
148
- </Button>
149
- }
150
- header={{
151
- onWallet: () => {
152
- navigate(navigationRoutes.wallets);
153
- },
154
- hasBackButton: false,
155
- title: config.title || i18n.t('Swap'),
156
- suffix: (
157
- <HeaderButtons
158
- onClickRefresh={
159
- (!!selectedQuote || quoteError) && !showQuoteWarningModal
160
- ? fetchQuote
161
- : undefined
162
- }
163
- onClickHistory={() => navigate(navigationRoutes.swaps)}
164
- onClickSettings={() => navigate(navigationRoutes.settings)}
165
- />
166
- ),
167
- }}>
168
- <PageContainer>
169
- <InputsContainer>
170
- <FromContainer>
171
- <SwapInput
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
- <SwitchFromAndToButton />
210
- </FromContainer>
211
- <SwapInput
212
- sharpBottomStyle={!!selectedQuote || fetchingQuote}
213
- label={i18n.t('To')}
214
- mode="To"
142
+ ),
143
+ }}>
144
+ <PageContainer>
145
+ <Inputs
215
146
  fetchingQuote={fetchingQuote}
216
- chain={{
217
- displayName: toBlockchain?.displayName || '',
218
- image: toBlockchain?.logo || '',
219
- }}
220
- token={{
221
- displayName: toToken?.symbol || '',
222
- image: toToken?.image || '',
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
- </InputsContainer>
257
- <Divider size="2" />
258
- <QuoteInfo
259
- quote={selectedQuote}
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
- refetchQuote={fetchQuote}
282
- showWarningModal={showQuoteWarningModal}
283
- confirmationDisabled={!isActiveTab}
284
- onOpenWarningModal={() => setShowQuoteWarningModal(true)}
285
- onCloseWarningModal={() => setShowQuoteWarningModal(false)}
286
- onConfirmWarningModal={() => {
287
- setShowQuoteWarningModal(false);
288
- setQuoteWarningsConfirmed(true);
289
- navigate(navigationRoutes.confirmSwap);
290
- }}
291
- onChangeSettings={() => navigate(navigationRoutes.settings)}
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
- ) : null}
295
- </PageContainer>
296
- </Layout>
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
  }
@@ -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 { QuoteSkeleton } from '../components/QuoteSkeleton';
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
- {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
- })}
60
+ <Quotes
61
+ fetch={fetchQuote}
62
+ loading={fetchingQuote}
63
+ onClickOnQuote={onClickOnQuote}
64
+ />
128
65
  </PageContainer>
129
66
  </Layout>
130
67
  );
@@ -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
  };
@@ -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"}