@rango-dev/widget-embedded 0.12.1-next.11 → 0.12.1-next.12

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 (60) hide show
  1. package/dist/components/BlockchainList/BlockchainList.d.ts.map +1 -1
  2. package/dist/components/BlockchainList/BlockchainList.styles.d.ts +2 -2
  3. package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
  5. package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -1
  6. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
  7. package/dist/components/RouteErrors/RouteErrors.types.d.ts +3 -1
  8. package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -1
  9. package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -1
  10. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  11. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts +1 -8
  12. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
  13. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +0 -148
  14. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  15. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
  16. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  17. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  18. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +1 -0
  19. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  20. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  21. package/dist/components/TokenList/TokenList.styles.d.ts +148 -0
  22. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  23. package/dist/constants/errors.d.ts +2 -2
  24. package/dist/constants/routing.d.ts +12 -2
  25. package/dist/constants/routing.d.ts.map +1 -1
  26. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/index.js.map +3 -3
  29. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  30. package/dist/pages/Home.d.ts.map +1 -1
  31. package/dist/utils/routing.d.ts +4 -2
  32. package/dist/utils/routing.d.ts.map +1 -1
  33. package/dist/utils/swap.d.ts +1 -1
  34. package/dist/utils/swap.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/src/components/BlockchainList/BlockchainList.styles.ts +6 -5
  37. package/src/components/BlockchainList/BlockchainList.tsx +5 -8
  38. package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +26 -4
  39. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +1 -1
  40. package/src/components/Layout/Layout.tsx +2 -2
  41. package/src/components/RouteErrors/RouteErrors.styles.ts +2 -1
  42. package/src/components/RouteErrors/RouteErrors.tsx +37 -26
  43. package/src/components/RouteErrors/RouteErrors.types.ts +3 -1
  44. package/src/components/RouteErrors/RouteErrorsModal.tsx +38 -11
  45. package/src/components/SwapDetails/SwapDetails.helpers.tsx +9 -26
  46. package/src/components/SwapDetails/SwapDetails.styles.ts +1 -9
  47. package/src/components/SwapDetails/SwapDetails.tsx +99 -73
  48. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +3 -7
  49. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -0
  50. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +1 -0
  51. package/src/components/TokenList/TokenList.styles.ts +7 -1
  52. package/src/components/TokenList/TokenList.tsx +3 -2
  53. package/src/constants/errors.ts +2 -2
  54. package/src/constants/routing.ts +17 -2
  55. package/src/hooks/useFetchBestRoute.ts +2 -2
  56. package/src/hooks/useSwapInput.ts +10 -1
  57. package/src/pages/ConfirmSwapPage.tsx +47 -19
  58. package/src/pages/Home.tsx +90 -42
  59. package/src/utils/routing.ts +56 -13
  60. package/src/utils/swap.ts +35 -19
@@ -14,20 +14,33 @@ import {
14
14
  Divider,
15
15
  IconButton,
16
16
  RouteCost,
17
+ RouteSummary,
17
18
  StepDetails,
18
- TokenAmount,
19
+ theme,
19
20
  Typography,
20
21
  useCopyToClipboard,
22
+ usePaddingRight,
21
23
  } from '@rango-dev/ui';
22
24
  import { useWallets } from '@rango-dev/wallets-react';
23
25
  import React, { useEffect, useRef, useState } from 'react';
24
26
  import { useNavigate } from 'react-router-dom';
25
27
 
26
28
  import { navigationRoutes } from '../../constants/navigationRoutes';
29
+ import {
30
+ GAS_FEE_MAX_DECIMALS,
31
+ GAS_FEE_MIN_DECIMALS,
32
+ PERCENTAGE_CHANGE_MAX_DECIMALS,
33
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
34
+ TOKEN_AMOUNT_MAX_DECIMALS,
35
+ TOKEN_AMOUNT_MIN_DECIMALS,
36
+ USD_VALUE_MAX_DECIMALS,
37
+ USD_VALUE_MIN_DECIMALS,
38
+ } from '../../constants/routing';
27
39
  import { useNavigateBack } from '../../hooks/useNavigateBack';
28
40
  import { useBestRouteStore } from '../../store/bestRoute';
29
41
  import { useMetaStore } from '../../store/meta';
30
42
  import { numberToString } from '../../utils/numbers';
43
+ import { getPriceImpactLevel } from '../../utils/routing';
31
44
  import {
32
45
  getLastConvertedTokenInFailedSwap,
33
46
  getPercentageChange,
@@ -44,21 +57,14 @@ import {
44
57
  } from '../SwapDetailsModal';
45
58
 
46
59
  import {
47
- AMOUNT_DECIMALS,
48
- getPriceImpactWarningLevel,
49
60
  getSteps,
50
61
  getStepState,
51
- MIN_DECIMALS,
52
- PERCENT_DECIMALS,
53
62
  RESET_INTERVAL,
54
63
  SECONDS,
55
64
  } from './SwapDetails.helpers';
56
- import {
57
- Container,
58
- HeaderDetails,
59
- Separator,
60
- StepsList,
61
- } from './SwapDetails.styles';
65
+ import { Container, HeaderDetails, StepsList } from './SwapDetails.styles';
66
+
67
+ const DEFAULT_CONTENT_PADDING = 20;
62
68
 
63
69
  export function SwapDetails(props: SwapDetailsProps) {
64
70
  const { swap, requestId, onDelete, onCancel: onCancelProps } = props;
@@ -67,13 +73,18 @@ export function SwapDetails(props: SwapDetailsProps) {
67
73
  const retry = useBestRouteStore.use.retry();
68
74
  const navigate = useNavigate();
69
75
  const { navigateBackFrom } = useNavigateBack();
70
- const listRef = useRef(null);
76
+ const listRef = useRef<HTMLDivElement | null>(null);
71
77
  const [_, handleCopy] = useCopyToClipboard(RESET_INTERVAL);
72
78
  const [modalState, setModalState] = useState<ModalState>(null);
73
79
  const [showCompletedModal, setShowCompletedModal] = useState<
74
80
  'success' | 'failed' | null
75
81
  >(null);
76
82
 
83
+ usePaddingRight({
84
+ elementRef: listRef,
85
+ paddingRight: theme.sizes[DEFAULT_CONTENT_PADDING],
86
+ });
87
+
77
88
  const onCancel = () => {
78
89
  onCancelProps();
79
90
  setModalState(null);
@@ -142,10 +153,6 @@ export function SwapDetails(props: SwapDetailsProps) {
142
153
  const [firstStep, lastStep] = [swap.steps[0], swap.steps[numberOfSteps - 1]];
143
154
  const outputAmount =
144
155
  lastStep.outputAmount || lastStep.expectedOutputAmountHumanReadable;
145
- const percentageChange =
146
- swap.inputAmount && outputAmount
147
- ? getPercentageChange(swap.inputAmount, outputAmount)
148
- : null;
149
156
 
150
157
  const totalFee = swap.steps.reduce(
151
158
  (totalFee, steps) => totalFee + parseFloat(steps.feeInUsd || ''),
@@ -165,7 +172,13 @@ export function SwapDetails(props: SwapDetailsProps) {
165
172
 
166
173
  const outputUsdValue = numberToString(
167
174
  String(
168
- parseFloat(numberToString(outputAmount, MIN_DECIMALS, AMOUNT_DECIMALS)) *
175
+ parseFloat(
176
+ numberToString(
177
+ outputAmount,
178
+ TOKEN_AMOUNT_MIN_DECIMALS,
179
+ TOKEN_AMOUNT_MAX_DECIMALS
180
+ )
181
+ ) *
169
182
  (getUsdPrice(
170
183
  lastStep.toBlockchain,
171
184
  lastStep.toSymbol,
@@ -173,16 +186,32 @@ export function SwapDetails(props: SwapDetailsProps) {
173
186
  tokens
174
187
  ) || 0)
175
188
  ),
176
- MIN_DECIMALS,
177
- AMOUNT_DECIMALS
189
+ USD_VALUE_MIN_DECIMALS,
190
+ USD_VALUE_MAX_DECIMALS
191
+ );
192
+
193
+ const inputUsdValue = numberToString(
194
+ String(
195
+ parseFloat(swap.inputAmount) *
196
+ (getUsdPrice(
197
+ firstStep.fromBlockchain,
198
+ firstStep.fromSymbol,
199
+ firstStep.fromSymbolAddress,
200
+ tokens
201
+ ) || 0)
202
+ ),
203
+ USD_VALUE_MIN_DECIMALS,
204
+ USD_VALUE_MAX_DECIMALS
178
205
  );
179
206
 
207
+ const percentageChange = getPercentageChange(inputUsdValue, outputUsdValue);
208
+
180
209
  const completeModalDesc =
181
210
  showCompletedModal === 'success'
182
- ? `You have recieved ${numberToString(
211
+ ? `You have received ${numberToString(
183
212
  outputAmount,
184
- MIN_DECIMALS,
185
- AMOUNT_DECIMALS
213
+ TOKEN_AMOUNT_MIN_DECIMALS,
214
+ TOKEN_AMOUNT_MAX_DECIMALS
186
215
  )} ${
187
216
  steps[numberOfSteps - 1].to.token.displayName
188
217
  } in ${getConciseAddress(
@@ -265,64 +294,57 @@ export function SwapDetails(props: SwapDetailsProps) {
265
294
  <RouteCost
266
295
  fee={numberToString(
267
296
  String(totalFee),
268
- AMOUNT_DECIMALS,
269
- AMOUNT_DECIMALS
297
+ GAS_FEE_MIN_DECIMALS,
298
+ GAS_FEE_MAX_DECIMALS
270
299
  )}
271
300
  time={minutes}
272
301
  steps={numberOfSteps}
273
302
  />
274
- <TokenAmount
275
- direction="horizontal"
276
- type="input"
277
- price={{
278
- value: numberToString(
279
- swap.inputAmount,
280
- AMOUNT_DECIMALS,
281
- AMOUNT_DECIMALS
282
- ),
283
- usdValue: numberToString(
284
- String(
285
- parseFloat(swap.inputAmount) *
286
- (getUsdPrice(
287
- firstStep.fromBlockchain,
288
- firstStep.fromSymbol,
289
- firstStep.fromSymbolAddress,
290
- tokens
291
- ) || 0)
303
+ <RouteSummary
304
+ from={{
305
+ price: {
306
+ value: numberToString(
307
+ swap.inputAmount,
308
+ TOKEN_AMOUNT_MIN_DECIMALS,
309
+ TOKEN_AMOUNT_MAX_DECIMALS
292
310
  ),
293
- MIN_DECIMALS,
294
- AMOUNT_DECIMALS
295
- ),
296
- }}
297
- token={{
298
- displayName: steps[0].from.token.displayName,
299
- image: steps[0].from.token.image,
311
+ usdValue: inputUsdValue,
312
+ },
313
+ token: {
314
+ displayName: steps[0].from.token.displayName,
315
+ image: steps[0].from.token.image,
316
+ },
317
+ chain: {
318
+ image: steps[0].from.chain.image,
319
+ displayName: steps[0].from.chain.displayName,
320
+ },
300
321
  }}
301
- chain={{ image: steps[0].from.chain.image }}
302
- />
303
- <Separator />
304
- <TokenAmount
305
- direction="horizontal"
306
- type="output"
307
- price={{
308
- value: numberToString(
309
- outputAmount,
310
- MIN_DECIMALS,
311
- AMOUNT_DECIMALS
312
- ),
313
- usdValue: outputUsdValue,
314
- }}
315
- token={{
316
- displayName: steps[numberOfSteps - 1].to.token.displayName,
317
- image: steps[numberOfSteps - 1].to.token.image,
322
+ to={{
323
+ price: {
324
+ value: numberToString(
325
+ outputAmount,
326
+ TOKEN_AMOUNT_MIN_DECIMALS,
327
+ TOKEN_AMOUNT_MAX_DECIMALS
328
+ ),
329
+ usdValue: outputUsdValue,
330
+ },
331
+ token: {
332
+ displayName: steps[numberOfSteps - 1].to.token.displayName,
333
+ image: steps[numberOfSteps - 1].to.token.image,
334
+ },
335
+ chain: {
336
+ image: steps[numberOfSteps - 1].to.chain.image,
337
+ displayName: steps[numberOfSteps - 1].to.chain.displayName,
338
+ },
318
339
  }}
319
- chain={{ image: steps[numberOfSteps - 1].to.chain.image }}
320
340
  percentageChange={numberToString(
321
341
  percentageChange,
322
- PERCENT_DECIMALS,
323
- PERCENT_DECIMALS
342
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
343
+ PERCENTAGE_CHANGE_MAX_DECIMALS
344
+ )}
345
+ warningLevel={getPriceImpactLevel(
346
+ percentageChange?.toNumber() ?? 0
324
347
  )}
325
- warningLevel={getPriceImpactWarningLevel(percentageChange)}
326
348
  />
327
349
  </div>
328
350
  <div className="title-steps">
@@ -368,12 +390,16 @@ export function SwapDetails(props: SwapDetailsProps) {
368
390
  diagnosisUrl={diagnosisUrl}
369
391
  onClose={() => setShowCompletedModal(null)}
370
392
  status={showCompletedModal}
371
- priceValue={numberToString(outputAmount, MIN_DECIMALS, AMOUNT_DECIMALS)}
393
+ priceValue={numberToString(
394
+ outputAmount,
395
+ TOKEN_AMOUNT_MIN_DECIMALS,
396
+ TOKEN_AMOUNT_MAX_DECIMALS
397
+ )}
372
398
  usdValue={outputUsdValue}
373
399
  percentageChange={numberToString(
374
400
  percentageChange,
375
- PERCENT_DECIMALS,
376
- PERCENT_DECIMALS
401
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
402
+ PERCENTAGE_CHANGE_MAX_DECIMALS
377
403
  )}
378
404
  token={{
379
405
  displayName: steps[numberOfSteps - 1].to.token.displayName,
@@ -6,12 +6,8 @@ import React from 'react';
6
6
 
7
7
  import { WalletContainer } from './SwapDetailsModal.styles';
8
8
 
9
- export const WalletStateContent = ({
10
- type,
11
- title,
12
- currentStepWallet,
13
- message,
14
- }: WalletStateContentProps) => {
9
+ export const WalletStateContent = (props: WalletStateContentProps) => {
10
+ const { type, title, currentStepWallet, message, showWalletButton } = props;
15
11
  const { connect, getWalletInfo, state: walletState } = useWallets();
16
12
  const walletType = currentStepWallet?.walletType;
17
13
  const isConnected = walletType && walletState(walletType).connected;
@@ -19,7 +15,7 @@ export const WalletStateContent = ({
19
15
  return (
20
16
  <>
21
17
  <MessageBox type={type} title={title} description={message} />
22
- {walletType && (
18
+ {showWalletButton && walletType && (
23
19
  <WalletContainer>
24
20
  <Wallet
25
21
  title={getWalletInfo(walletType).name}
@@ -29,6 +29,9 @@ export function SwapDetailsModal(props: ModalPropTypes) {
29
29
  title={modalNetworkValues[state].title}
30
30
  currentStepWallet={currentStepWallet}
31
31
  message={message}
32
+ showWalletButton={
33
+ state !== PendingSwapNetworkStatus.WaitingForNetworkChange
34
+ }
32
35
  />
33
36
  )}
34
37
  {state === 'delete' && (
@@ -46,6 +46,7 @@ export interface ModalNetworkValueTypes {
46
46
  export interface WalletStateContentProps extends ModalNetworkValueTypes {
47
47
  currentStepWallet: WalletTypeAndAddress | null;
48
48
  message: string;
49
+ showWalletButton: boolean;
49
50
  }
50
51
 
51
52
  export type CancelContentProps = Pick<ModalPropTypes, 'onClose' | 'onCancel'>;
@@ -1,5 +1,11 @@
1
1
  import { styled, Typography } from '@rango-dev/ui';
2
2
 
3
+ export const Container = styled('div', {
4
+ display: 'flex',
5
+ flexDirection: 'column',
6
+ flexGrow: 1,
7
+ });
8
+
3
9
  export const Title = styled('div', {
4
10
  display: 'flex',
5
11
  alignItems: 'center',
@@ -11,7 +17,7 @@ export const Title = styled('div', {
11
17
  },
12
18
  });
13
19
  export const List = styled('ul', {
14
- minHeight: 280,
20
+ flexGrow: 1,
15
21
  padding: 0,
16
22
  margin: 0,
17
23
  listStyle: 'none',
@@ -28,6 +28,7 @@ import { generateRangeColors } from '../../utils/common';
28
28
  import { LoadingTokenList } from './LoadingTokenList';
29
29
  import {
30
30
  BalanceContainer,
31
+ Container,
31
32
  End,
32
33
  ImageSection,
33
34
  List,
@@ -257,13 +258,13 @@ export function TokenList(props: PropTypes) {
257
258
  };
258
259
 
259
260
  return (
260
- <div>
261
+ <Container>
261
262
  <Typography variant="label" size="large">
262
263
  {i18n.t('Select Token')}
263
264
  </Typography>
264
265
  <Divider size={4} />
265
266
  {loadingStatus === 'loading' && <LoadingTokenList size={PAGE_SIZE} />}
266
267
  {loadingStatus === 'success' && <List>{renderList()}</List>}
267
- </div>
268
+ </Container>
268
269
  );
269
270
  }
@@ -22,7 +22,7 @@ export const errorMessages = {
22
22
  decreaseAmount: i18n.t('Bridge Limit Error: Please decrease your amount'),
23
23
  },
24
24
  highValueLossError: {
25
- impacTitle: i18n.t('High Price Impact'),
25
+ impactTitle: i18n.t('High Price Impact'),
26
26
  title: i18n.t('Price impact is too high!'),
27
27
  description: i18n.t(
28
28
  'The price impact is significantly higher than the allowed amount. If you are sure, continue, otherwise, change the swap.'
@@ -35,7 +35,7 @@ export const errorMessages = {
35
35
  ),
36
36
  },
37
37
  unknownPriceError: {
38
- impacTitle: i18n.t('USD Price Unknown'),
38
+ impactTitle: i18n.t('USD Price Unknown'),
39
39
  title: i18n.t('USD Price Unknown, Cannot calculate Price Impact.'),
40
40
  description: i18n.t(
41
41
  'USD Price Unknown, Cannot calculate Price Impact. The price impact may be higher than usual. Are you sure to continue the Swap?'
@@ -1,2 +1,17 @@
1
- export const LOW_PRICE_IMPACT = 3;
2
- export const HIGHT_PRICE_IMPACT = 10;
1
+ export const LOW_PRICE_IMPACT = -3;
2
+ export const HIGHT_PRICE_IMPACT = -10;
3
+
4
+ export const TOKEN_AMOUNT_MIN_DECIMALS = 6;
5
+ export const TOKEN_AMOUNT_MAX_DECIMALS = 6;
6
+
7
+ export const USD_VALUE_MIN_DECIMALS = 4;
8
+ export const USD_VALUE_MAX_DECIMALS = 4;
9
+
10
+ export const GAS_FEE_MIN_DECIMALS = 2;
11
+ export const GAS_FEE_MAX_DECIMALS = 2;
12
+
13
+ export const PERCENTAGE_CHANGE_MIN_DECIMALS = 2;
14
+ export const PERCENTAGE_CHANGE_MAX_DECIMALS = 2;
15
+
16
+ export const BALANCE_MIN_DECIMALS = 8;
17
+ export const BALANCE_MAX_DECIMALS = 8;
@@ -12,11 +12,11 @@ interface UseFetchBestRoute {
12
12
 
13
13
  export function useFetchBestRoute(): UseFetchBestRoute {
14
14
  const [loading, setLoading] = useState(false);
15
- const cancel = () => abortController.current?.abort();
16
15
  const abortController = useRef<AbortController | null>(null);
16
+ const cancel = () => abortController.current?.abort();
17
17
 
18
18
  const fetch: UseFetchBestRoute['fetch'] = async (requestBody) => {
19
- abortController.current?.abort();
19
+ cancel();
20
20
  abortController.current = new AbortController();
21
21
 
22
22
  setLoading(true);
@@ -53,6 +53,7 @@ export function useSwapInput(): UseSwapInput {
53
53
  setLoading(true);
54
54
  }
55
55
  if (!shouldSkipRequest) {
56
+ resetRoute();
56
57
  const requestBody = createBestRouteRequestBody({
57
58
  fromToken,
58
59
  toToken,
@@ -87,7 +88,8 @@ export function useSwapInput(): UseSwapInput {
87
88
  useEffect(() => {
88
89
  if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
89
90
  setLoading(false);
90
- return cancelFetch();
91
+ cancelFetch();
92
+ return;
91
93
  }
92
94
  if (shouldSkipRequest) {
93
95
  return;
@@ -98,5 +100,12 @@ export function useSwapInput(): UseSwapInput {
98
100
  return cancelFetch;
99
101
  }, [inputAmount]);
100
102
 
103
+ useEffect(() => {
104
+ if (!shouldSkipRequest) {
105
+ fetch();
106
+ }
107
+ return cancelFetch;
108
+ }, [disabledLiquiditySources.length]);
109
+
101
110
  return { fetch, loading, error };
102
111
  }
@@ -4,7 +4,6 @@ import type {
4
4
  ConfirmSwapFetchResult,
5
5
  } from '../hooks/useConfirmSwap';
6
6
  import type { WidgetConfig } from '../types';
7
- import type { PriceImpactWarningLevel } from '@rango-dev/ui/dist/widget/ui/src/components/PriceImpact/PriceImpact.types';
8
7
 
9
8
  import { i18n } from '@lingui/core';
10
9
  import { useManager } from '@rango-dev/queue-manager-react';
@@ -38,7 +37,16 @@ import { Layout } from '../components/Layout';
38
37
  import { NoRoutes } from '../components/NoRoutes';
39
38
  import { getConfirmSwapErrorMessage } from '../constants/errors';
40
39
  import { navigationRoutes } from '../constants/navigationRoutes';
41
- import { HIGHT_PRICE_IMPACT, LOW_PRICE_IMPACT } from '../constants/routing';
40
+ import {
41
+ GAS_FEE_MAX_DECIMALS,
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';
42
50
  import { getRouteWarningMessage } from '../constants/warnings';
43
51
  import { useConfirmSwap } from '../hooks/useConfirmSwap';
44
52
  import { useBestRouteStore } from '../store/bestRoute';
@@ -56,6 +64,7 @@ import {
56
64
  secondsToString,
57
65
  totalArrivalTime,
58
66
  } from '../utils/numbers';
67
+ import { getPriceImpactLevel } from '../utils/routing';
59
68
  import { getPercentageChange, getTotalFeeInUsd } from '../utils/swap';
60
69
 
61
70
  const Container = styled('div', {
@@ -117,7 +126,10 @@ export function ConfirmSwapPage(props: PropTypes) {
117
126
  const showWalletsOnInit = !routeWalletsConfirmed;
118
127
  const [showWallets, setShowWallets] = useState(false);
119
128
  const setSelectedSwap = useUiStore.use.setSelectedSwap();
120
- const { tokens } = useMetaStore.use.meta();
129
+ const {
130
+ meta: { tokens },
131
+ loadingStatus: loadingMetaStatus,
132
+ } = useMetaStore();
121
133
  const slippage = useSettingsStore.use.slippage();
122
134
  const customSlippage = useSettingsStore.use.customSlippage();
123
135
  const { manager } = useManager();
@@ -133,6 +145,8 @@ export function ConfirmSwapPage(props: PropTypes) {
133
145
  error: null,
134
146
  warnings: null,
135
147
  });
148
+ const showSkeleton =
149
+ fetchingConfirmationRoute || loadingMetaStatus === 'loading';
136
150
  const showNoRouteFound =
137
151
  !fetchingConfirmationRoute &&
138
152
  confirmSwapResult.error &&
@@ -152,15 +166,11 @@ export function ConfirmSwapPage(props: PropTypes) {
152
166
  inputUsdValue?.toNumber() ?? 0,
153
167
  outputUsdValue?.toNumber() ?? 0
154
168
  ),
155
- 2,
156
- 2
169
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
170
+ PERCENTAGE_CHANGE_MAX_DECIMALS
157
171
  );
158
- let warningLevel: PriceImpactWarningLevel = undefined;
159
- if (parseFloat(percentageChange) >= HIGHT_PRICE_IMPACT) {
160
- warningLevel = 'high';
161
- } else if (parseFloat(percentageChange) >= LOW_PRICE_IMPACT) {
162
- warningLevel = 'low';
163
- }
172
+
173
+ const warningLevel = getPriceImpactLevel(parseFloat(percentageChange));
164
174
 
165
175
  const onConfirmSwap: ConfirmSwap['fetch'] = async ({
166
176
  selectedWallets,
@@ -450,22 +460,40 @@ export function ConfirmSwapPage(props: PropTypes) {
450
460
  <Divider size={12} />
451
461
  </>
452
462
  )}
453
- {fetchingConfirmationRoute && (
454
- <BestRouteSkeleton type="swap-preview" expanded />
455
- )}
463
+ {showSkeleton && <BestRouteSkeleton type="swap-preview" expanded />}
456
464
  {showBestRoute && (
457
465
  <BestRoute
458
466
  expanded={true}
459
467
  steps={formatBestRoute(bestRoute) ?? []}
460
468
  input={{
461
- value: numberToString(inputAmount, 6, 6),
462
- usdValue: numberToString(inputUsdValue, 6, 6),
469
+ value: numberToString(
470
+ inputAmount,
471
+ TOKEN_AMOUNT_MIN_DECIMALS,
472
+ TOKEN_AMOUNT_MAX_DECIMALS
473
+ ),
474
+ usdValue: numberToString(
475
+ inputUsdValue,
476
+ USD_VALUE_MIN_DECIMALS,
477
+ USD_VALUE_MAX_DECIMALS
478
+ ),
463
479
  }}
464
480
  output={{
465
- value: numberToString(outputAmount, 6, 6),
466
- usdValue: numberToString(outputUsdValue, 6, 6),
481
+ value: numberToString(
482
+ outputAmount,
483
+ TOKEN_AMOUNT_MIN_DECIMALS,
484
+ TOKEN_AMOUNT_MAX_DECIMALS
485
+ ),
486
+ usdValue: numberToString(
487
+ outputUsdValue,
488
+ USD_VALUE_MIN_DECIMALS,
489
+ USD_VALUE_MAX_DECIMALS
490
+ ),
467
491
  }}
468
- totalFee={numberToString(totalFeeInUsd, 0, 2)}
492
+ totalFee={numberToString(
493
+ totalFeeInUsd,
494
+ GAS_FEE_MIN_DECIMALS,
495
+ GAS_FEE_MAX_DECIMALS
496
+ )}
469
497
  totalTime={secondsToString(totalArrivalTime(bestRoute))}
470
498
  recommended={true}
471
499
  type="swap-preview"