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

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 (110) hide show
  1. package/dist/Widget.d.ts.map +1 -1
  2. package/dist/components/BlockchainList/BlockchainList.d.ts.map +1 -1
  3. package/dist/components/BlockchainList/BlockchainList.styles.d.ts +14 -4
  4. package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
  5. package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts +6 -1
  6. package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts.map +1 -1
  7. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +6 -1
  8. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
  9. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
  10. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +90 -15
  11. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  12. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +18 -3
  13. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
  14. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +24 -4
  15. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  16. package/dist/components/Layout/Layout.styles.d.ts +18 -3
  17. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  18. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +6 -1
  19. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  20. package/dist/components/NoRoutes/NoRoutes.styles.d.ts +18 -3
  21. package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
  22. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +24 -4
  23. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  24. package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -1
  25. package/dist/components/RouteErrors/RouteErrors.styles.d.ts +24 -4
  26. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
  27. package/dist/components/RouteErrors/RouteErrors.types.d.ts +3 -1
  28. package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -1
  29. package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -1
  30. package/dist/components/SearchInput/SearchInput.styles.d.ts +6 -1
  31. package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
  32. package/dist/components/SelectableCategoryList/SelectableCategoryList.styles.d.ts +18 -3
  33. package/dist/components/SelectableCategoryList/SelectableCategoryList.styles.d.ts.map +1 -1
  34. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +30 -5
  35. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
  36. package/dist/components/Slippage/Slippage.styles.d.ts +24 -4
  37. package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
  38. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  39. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts +1 -8
  40. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
  41. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +35 -153
  42. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  43. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +6 -1
  44. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
  45. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
  46. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  47. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  48. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +6 -1
  49. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
  50. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +1 -0
  51. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  52. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +24 -4
  53. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
  54. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  55. package/dist/components/TokenList/TokenList.styles.d.ts +207 -9
  56. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  57. package/dist/components/WalletModal/WalletModalContent.styles.d.ts +24 -4
  58. package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
  59. package/dist/constants/errors.d.ts +2 -2
  60. package/dist/constants/routing.d.ts +12 -2
  61. package/dist/constants/routing.d.ts.map +1 -1
  62. package/dist/globalStyles.d.ts +1 -1
  63. package/dist/globalStyles.d.ts.map +1 -1
  64. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  65. package/dist/hooks/useTheme.d.ts +3 -6
  66. package/dist/hooks/useTheme.d.ts.map +1 -1
  67. package/dist/index.js +1 -1
  68. package/dist/index.js.map +4 -4
  69. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  70. package/dist/pages/Home.d.ts.map +1 -1
  71. package/dist/types/config.d.ts +3 -0
  72. package/dist/types/config.d.ts.map +1 -1
  73. package/dist/utils/configs.d.ts +2 -0
  74. package/dist/utils/configs.d.ts.map +1 -1
  75. package/dist/utils/routing.d.ts +4 -2
  76. package/dist/utils/routing.d.ts.map +1 -1
  77. package/dist/utils/swap.d.ts +1 -1
  78. package/dist/utils/swap.d.ts.map +1 -1
  79. package/package.json +2 -2
  80. package/src/Widget.tsx +2 -1
  81. package/src/components/BlockchainList/BlockchainList.styles.ts +6 -5
  82. package/src/components/BlockchainList/BlockchainList.tsx +5 -8
  83. package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +26 -4
  84. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +1 -1
  85. package/src/components/Layout/Layout.styles.ts +1 -2
  86. package/src/components/Layout/Layout.tsx +2 -2
  87. package/src/components/RouteErrors/RouteErrors.styles.ts +2 -1
  88. package/src/components/RouteErrors/RouteErrors.tsx +37 -26
  89. package/src/components/RouteErrors/RouteErrors.types.ts +3 -1
  90. package/src/components/RouteErrors/RouteErrorsModal.tsx +38 -11
  91. package/src/components/SwapDetails/SwapDetails.helpers.tsx +9 -26
  92. package/src/components/SwapDetails/SwapDetails.styles.ts +1 -9
  93. package/src/components/SwapDetails/SwapDetails.tsx +99 -73
  94. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +3 -7
  95. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -0
  96. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +1 -0
  97. package/src/components/TokenList/TokenList.styles.ts +7 -1
  98. package/src/components/TokenList/TokenList.tsx +3 -2
  99. package/src/constants/errors.ts +2 -2
  100. package/src/constants/routing.ts +17 -2
  101. package/src/globalStyles.ts +1 -4
  102. package/src/hooks/useFetchBestRoute.ts +2 -2
  103. package/src/hooks/useSwapInput.ts +10 -1
  104. package/src/hooks/useTheme.ts +37 -75
  105. package/src/pages/ConfirmSwapPage.tsx +47 -19
  106. package/src/pages/Home.tsx +90 -42
  107. package/src/types/config.ts +3 -0
  108. package/src/utils/configs.ts +3 -0
  109. package/src/utils/routing.ts +56 -13
  110. package/src/utils/swap.ts +35 -19
@@ -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"
@@ -22,6 +22,18 @@ import { RouteErrors } from '../components/RouteErrors';
22
22
  import { SwitchFromAndToButton } from '../components/SwitchFromAndTo';
23
23
  import { errorMessages } from '../constants/errors';
24
24
  import { navigationRoutes } from '../constants/navigationRoutes';
25
+ import {
26
+ BALANCE_MAX_DECIMALS,
27
+ BALANCE_MIN_DECIMALS,
28
+ GAS_FEE_MAX_DECIMALS,
29
+ GAS_FEE_MIN_DECIMALS,
30
+ PERCENTAGE_CHANGE_MAX_DECIMALS,
31
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
32
+ TOKEN_AMOUNT_MAX_DECIMALS,
33
+ TOKEN_AMOUNT_MIN_DECIMALS,
34
+ USD_VALUE_MAX_DECIMALS,
35
+ USD_VALUE_MIN_DECIMALS,
36
+ } from '../constants/routing';
25
37
  import { useSwapInput } from '../hooks/useSwapInput';
26
38
  import { useBestRouteStore } from '../store/bestRoute';
27
39
  import { useMetaStore } from '../store/meta';
@@ -33,7 +45,7 @@ import {
33
45
  secondsToString,
34
46
  totalArrivalTime,
35
47
  } from '../utils/numbers';
36
- import { getFormatedBestRoute } from '../utils/routing';
48
+ import { getFormattedBestRoute, getPriceImpactLevel } from '../utils/routing';
37
49
  import {
38
50
  canComputePriceImpact,
39
51
  getOutputRatio,
@@ -77,12 +89,6 @@ const FooterAlert = styled('div', {
77
89
  display: 'flex',
78
90
  });
79
91
 
80
- const BALANCE_PRECISION = 8;
81
- const TWO_DECIMAL = 2;
82
- const MAX_DECIMAL = 6;
83
- const MIN_DECIMAL = 0;
84
- const WARNING_LEVEL_LIMIT = -10;
85
-
86
92
  export function Home() {
87
93
  const navigate = useNavigate();
88
94
  const {
@@ -160,7 +166,8 @@ export function Home() {
160
166
  fromToken?.symbol,
161
167
  fromToken?.address
162
168
  )?.amount || '0',
163
- BALANCE_PRECISION
169
+ BALANCE_MIN_DECIMALS,
170
+ BALANCE_MAX_DECIMALS
164
171
  )
165
172
  : '0';
166
173
 
@@ -208,7 +215,11 @@ export function Home() {
208
215
  price: {
209
216
  value:
210
217
  index === 0
211
- ? numberToString(inputAmount, MIN_DECIMAL, TWO_DECIMAL)
218
+ ? numberToString(
219
+ inputAmount,
220
+ TOKEN_AMOUNT_MIN_DECIMALS,
221
+ TOKEN_AMOUNT_MAX_DECIMALS
222
+ )
212
223
  : swap.fromAmount,
213
224
  },
214
225
  },
@@ -240,7 +251,9 @@ export function Home() {
240
251
  <Divider direction="horizontal" size={8} />
241
252
  <Typography size="xsmall" variant="body" color="neutral900">
242
253
  {`Yours: ${numberToString(
243
- swapHasError?.fromAmount || null
254
+ swapHasError?.fromAmount || null,
255
+ TOKEN_AMOUNT_MIN_DECIMALS,
256
+ TOKEN_AMOUNT_MAX_DECIMALS
244
257
  )} ${swap?.from.symbol}`}
245
258
  </Typography>
246
259
  </FooterAlert>
@@ -253,7 +266,7 @@ export function Home() {
253
266
 
254
267
  const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
255
268
 
256
- const bestRouteData = getFormatedBestRoute(bestRoute);
269
+ const bestRouteData = getFormattedBestRoute(bestRoute);
257
270
 
258
271
  return (
259
272
  <Layout
@@ -316,9 +329,13 @@ export function Home() {
316
329
  value: inputAmount,
317
330
  usdValue: priceImpactInputCanNotBeComputed
318
331
  ? undefined
319
- : numberToString(inputUsdValue),
332
+ : numberToString(
333
+ inputUsdValue,
334
+ USD_VALUE_MIN_DECIMALS,
335
+ USD_VALUE_MAX_DECIMALS
336
+ ),
320
337
  error: priceImpactInputCanNotBeComputed
321
- ? errorMessages.unknownPriceError.impacTitle
338
+ ? errorMessages.unknownPriceError.impactTitle
322
339
  : undefined,
323
340
  }}
324
341
  disabled={loadingMetaStatus === 'failed'}
@@ -344,19 +361,31 @@ export function Home() {
344
361
  }}
345
362
  percentageChange={
346
363
  !!percentageChange?.lt(0)
347
- ? numberToString(percentageChange, MIN_DECIMAL, TWO_DECIMAL)
364
+ ? numberToString(
365
+ percentageChange,
366
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
367
+ PERCENTAGE_CHANGE_MAX_DECIMALS
368
+ )
348
369
  : null
349
370
  }
350
- warningLevel={
351
- !!percentageChange?.lt(WARNING_LEVEL_LIMIT) ? 'high' : 'low'
352
- }
371
+ warningLevel={getPriceImpactLevel(
372
+ percentageChange?.toNumber() ?? 0
373
+ )}
353
374
  price={{
354
- value: numberToString(outputAmount),
375
+ value: numberToString(
376
+ outputAmount,
377
+ TOKEN_AMOUNT_MIN_DECIMALS,
378
+ TOKEN_AMOUNT_MAX_DECIMALS
379
+ ),
355
380
  usdValue: priceImpactOutputCanNotBeComputed
356
381
  ? undefined
357
- : numberToString(outputUsdValue),
382
+ : numberToString(
383
+ outputUsdValue,
384
+ USD_VALUE_MIN_DECIMALS,
385
+ USD_VALUE_MAX_DECIMALS
386
+ ),
358
387
  error: priceImpactOutputCanNotBeComputed
359
- ? errorMessages.unknownPriceError.impacTitle
388
+ ? errorMessages.unknownPriceError.impactTitle
360
389
  : undefined,
361
390
  }}
362
391
  onClickToken={() => navigate('to-swap')}
@@ -377,20 +406,40 @@ export function Home() {
377
406
  type="basic"
378
407
  recommended={true}
379
408
  input={{
380
- value: numberToString(inputAmount, MIN_DECIMAL, MAX_DECIMAL),
381
- usdValue: numberToString(inputUsdValue),
409
+ value: numberToString(
410
+ inputAmount,
411
+ TOKEN_AMOUNT_MIN_DECIMALS,
412
+ TOKEN_AMOUNT_MAX_DECIMALS
413
+ ),
414
+ usdValue: numberToString(
415
+ inputUsdValue,
416
+ USD_VALUE_MIN_DECIMALS,
417
+ USD_VALUE_MAX_DECIMALS
418
+ ),
382
419
  }}
383
420
  output={{
384
- value: numberToString(outputAmount),
385
- usdValue: numberToString(outputUsdValue),
421
+ value: numberToString(
422
+ outputAmount,
423
+ TOKEN_AMOUNT_MIN_DECIMALS,
424
+ TOKEN_AMOUNT_MAX_DECIMALS
425
+ ),
426
+ usdValue: numberToString(
427
+ outputUsdValue,
428
+ USD_VALUE_MIN_DECIMALS,
429
+ USD_VALUE_MAX_DECIMALS
430
+ ),
386
431
  }}
387
432
  steps={getBestRouteSteps(bestRouteData.result.swaps)}
388
433
  percentageChange={numberToString(
389
434
  percentageChange,
390
- MIN_DECIMAL,
391
- TWO_DECIMAL
435
+ PERCENTAGE_CHANGE_MIN_DECIMALS,
436
+ PERCENTAGE_CHANGE_MAX_DECIMALS
437
+ )}
438
+ totalFee={numberToString(
439
+ totalFeeInUsd,
440
+ GAS_FEE_MIN_DECIMALS,
441
+ GAS_FEE_MAX_DECIMALS
392
442
  )}
393
- totalFee={numberToString(totalFeeInUsd, MIN_DECIMAL, TWO_DECIMAL)}
394
443
  totalTime={secondsToString(totalArrivalTime(bestRoute))}
395
444
  />
396
445
  </BestRouteContainer>
@@ -405,21 +454,20 @@ export function Home() {
405
454
  </>
406
455
  ) : null}
407
456
  </Container>
408
- {!fetchingBestRoute && (
409
- <RouteErrors
410
- openModal={openWarningModal}
411
- onToggle={setOpenWarningModal}
412
- totalFeeInUsd={totalFeeInUsd}
413
- outputUsdValue={outputUsdValue}
414
- inputUsdValue={inputUsdValue}
415
- percentageChange={percentageChange}
416
- highValueLoss={highValueLoss}
417
- priceImpactCanNotBeComputed={
418
- priceImpactInputCanNotBeComputed ||
419
- priceImpactOutputCanNotBeComputed
420
- }
421
- />
422
- )}
457
+ <RouteErrors
458
+ openModal={openWarningModal}
459
+ onToggle={setOpenWarningModal}
460
+ totalFeeInUsd={totalFeeInUsd}
461
+ outputUsdValue={outputUsdValue}
462
+ inputUsdValue={inputUsdValue}
463
+ percentageChange={percentageChange}
464
+ highValueLoss={highValueLoss}
465
+ priceImpactCanNotBeComputed={
466
+ priceImpactInputCanNotBeComputed || priceImpactOutputCanNotBeComputed
467
+ }
468
+ loading={fetchingBestRoute || loadingMetaStatus === 'loading'}
469
+ extraSpace={!!bestRoute?.result || !bestRoute}
470
+ />
423
471
  </Layout>
424
472
  );
425
473
  }
@@ -38,6 +38,8 @@ export type WidgetColors = {
38
38
  * border color
39
39
  * @property {number} borderRadius - `borderRadius` is a property of the `WidgetTheme` type that
40
40
  * specifies the radius of the corners of a widget.
41
+ * @property {number} secondaryBorderRadius - `secondaryBorderRadius` is a property of the `WidgetTheme` type that
42
+ * specifies the radius of the buttons of a widget.
41
43
  * @property {number} width - The `width` property is a number that represents the width of the widget.
42
44
  * @property {number} height - The `height` property is a number that specifies the height of the widget.
43
45
  * @property {boolean} singleTheme - The `singleTheme` property is a boolean that specifies the theme is support dark and light or only light.
@@ -47,6 +49,7 @@ export type WidgetTheme = {
47
49
  fontFamily?: string;
48
50
  colors?: { light: WidgetColors; dark: WidgetColors };
49
51
  borderRadius?: number;
52
+ secondaryBorderRadius?: number;
50
53
  width?: number;
51
54
  height?: number;
52
55
  singleTheme?: boolean;
@@ -28,3 +28,6 @@ export function initConfig(nextConfigs: Configs) {
28
28
  configs = clonedConfigs;
29
29
  return configs;
30
30
  }
31
+
32
+ export const DEFAULT_PRIMARY_RADIUS = 20;
33
+ export const DEFAULT_SECONDARY_RADIUS = 25;
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
2
  import type { BestRouteEqualityParams, Wallet } from '../types';
3
3
  import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
4
+ import type { PriceImpactWarningLevel } from '@rango-dev/ui';
4
5
  import type {
5
6
  SimulationAssetAndAmount,
6
7
  SimulationValidationStatus,
@@ -9,6 +10,15 @@ import type { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
9
10
 
10
11
  import BigNumber from 'bignumber.js';
11
12
 
13
+ import {
14
+ GAS_FEE_MAX_DECIMALS,
15
+ GAS_FEE_MIN_DECIMALS,
16
+ HIGHT_PRICE_IMPACT,
17
+ LOW_PRICE_IMPACT,
18
+ TOKEN_AMOUNT_MAX_DECIMALS,
19
+ TOKEN_AMOUNT_MIN_DECIMALS,
20
+ } from '../constants/routing';
21
+
12
22
  import { areEqual } from './common';
13
23
  import { numberToString } from './numbers';
14
24
 
@@ -149,43 +159,63 @@ export function isRouteParametersChanged(params: BestRouteEqualityParams) {
149
159
  return false;
150
160
  }
151
161
 
152
- export function getFormatedBestRoute(
162
+ export function getFormattedBestRoute(
153
163
  bestRoute: BestRouteResponse | null
154
164
  ): BestRouteResponse | null {
155
165
  if (!bestRoute) {
156
166
  return null;
157
167
  }
158
168
 
159
- const formatedSwaps = (bestRoute.result?.swaps || []).map((swap) => ({
169
+ const formattedSwaps = (bestRoute.result?.swaps || []).map((swap) => ({
160
170
  ...swap,
161
- fromAmount: numberToString(swap.fromAmount, 6, 6),
162
- toAmount: numberToString(swap.toAmount, 6, 6),
171
+ fromAmount: numberToString(
172
+ swap.fromAmount,
173
+ TOKEN_AMOUNT_MIN_DECIMALS,
174
+ TOKEN_AMOUNT_MAX_DECIMALS
175
+ ),
176
+ toAmount: numberToString(
177
+ swap.toAmount,
178
+ TOKEN_AMOUNT_MIN_DECIMALS,
179
+ TOKEN_AMOUNT_MAX_DECIMALS
180
+ ),
163
181
  }));
164
182
 
165
183
  return {
166
184
  ...bestRoute,
167
185
  ...(bestRoute.result && {
168
- result: { ...bestRoute.result, swaps: formatedSwaps },
186
+ result: { ...bestRoute.result, swaps: formattedSwaps },
169
187
  }),
170
188
  };
171
189
  }
172
190
 
173
- export function getFormatedPendingSwap(pendingSwap: PendingSwap): PendingSwap {
174
- const formatedSteps = pendingSwap.steps.map((step) => ({
191
+ export function getFormattedPendingSwap(pendingSwap: PendingSwap): PendingSwap {
192
+ const formattedSteps = pendingSwap.steps.map((step) => ({
175
193
  ...step,
176
- feeInUsd: numberToString(step.feeInUsd, 4, 4),
177
- outputAmount: numberToString(step.outputAmount, 6, 6),
194
+ feeInUsd: numberToString(
195
+ step.feeInUsd,
196
+ GAS_FEE_MIN_DECIMALS,
197
+ GAS_FEE_MAX_DECIMALS
198
+ ),
199
+ outputAmount: numberToString(
200
+ step.outputAmount,
201
+ TOKEN_AMOUNT_MIN_DECIMALS,
202
+ TOKEN_AMOUNT_MAX_DECIMALS
203
+ ),
178
204
  expectedOutputAmountHumanReadable: numberToString(
179
205
  step.expectedOutputAmountHumanReadable,
180
- 6,
181
- 6
206
+ TOKEN_AMOUNT_MIN_DECIMALS,
207
+ TOKEN_AMOUNT_MAX_DECIMALS
182
208
  ),
183
209
  }));
184
210
 
185
211
  return {
186
212
  ...pendingSwap,
187
- inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
188
- steps: formatedSteps,
213
+ inputAmount: numberToString(
214
+ pendingSwap.inputAmount,
215
+ TOKEN_AMOUNT_MIN_DECIMALS,
216
+ TOKEN_AMOUNT_MAX_DECIMALS
217
+ ),
218
+ steps: formattedSteps,
189
219
  };
190
220
  }
191
221
 
@@ -199,3 +229,16 @@ export const getBestRouteStatus = (loading: boolean, error: boolean) => {
199
229
  }
200
230
  return 'success';
201
231
  };
232
+
233
+ export function getPriceImpactLevel(
234
+ priceImpact: number
235
+ ): PriceImpactWarningLevel {
236
+ let warningLevel: PriceImpactWarningLevel = undefined;
237
+ if (priceImpact <= LOW_PRICE_IMPACT && priceImpact > HIGHT_PRICE_IMPACT) {
238
+ warningLevel = 'low';
239
+ } else if (priceImpact <= HIGHT_PRICE_IMPACT) {
240
+ warningLevel = 'high';
241
+ }
242
+
243
+ return warningLevel;
244
+ }
package/src/utils/swap.ts CHANGED
@@ -23,6 +23,12 @@ import { isValidAddress } from '../components/ConfirmWalletsModal/ConfirmWallets
23
23
  import { errorMessages } from '../constants/errors';
24
24
  import { swapButtonTitles } from '../constants/messages';
25
25
  import { ZERO } from '../constants/numbers';
26
+ import {
27
+ BALANCE_MAX_DECIMALS,
28
+ BALANCE_MIN_DECIMALS,
29
+ TOKEN_AMOUNT_MAX_DECIMALS,
30
+ TOKEN_AMOUNT_MIN_DECIMALS,
31
+ } from '../constants/routing';
26
32
  import { useMetaStore } from '../store/meta';
27
33
  import { ButtonState } from '../types';
28
34
 
@@ -112,26 +118,34 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
112
118
  let fromAmountRangeError = '';
113
119
  let recommendation = '';
114
120
  if (!isExclusive && !!minimum && minimum.gt(swap.fromAmount)) {
115
- fromAmountRangeError = `Required: >= ${numberToString(minimum)} ${
116
- swap.from.symbol
117
- }`;
121
+ fromAmountRangeError = `Required: >= ${numberToString(
122
+ minimum,
123
+ TOKEN_AMOUNT_MIN_DECIMALS,
124
+ TOKEN_AMOUNT_MAX_DECIMALS
125
+ )} ${swap.from.symbol}`;
118
126
  recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
119
127
  } else if (isExclusive && !!minimum && minimum.gte(swap.fromAmount)) {
120
- fromAmountRangeError = `Required: > ${numberToString(minimum)} ${
121
- swap.from.symbol
122
- }`;
128
+ fromAmountRangeError = `Required: > ${numberToString(
129
+ minimum,
130
+ TOKEN_AMOUNT_MIN_DECIMALS,
131
+ TOKEN_AMOUNT_MAX_DECIMALS
132
+ )} ${swap.from.symbol}`;
123
133
  recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
124
134
  }
125
135
 
126
136
  if (!isExclusive && !!maximum && maximum.lt(swap.fromAmount)) {
127
- fromAmountRangeError = `Required: <= ${numberToString(maximum)} ${
128
- swap.from.symbol
129
- }`;
137
+ fromAmountRangeError = `Required: <= ${numberToString(
138
+ maximum,
139
+ TOKEN_AMOUNT_MIN_DECIMALS,
140
+ TOKEN_AMOUNT_MAX_DECIMALS
141
+ )} ${swap.from.symbol}`;
130
142
  recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
131
143
  } else if (isExclusive && !!maximum && maximum.lte(swap.fromAmount)) {
132
- fromAmountRangeError = `Required: < ${numberToString(maximum)} ${
133
- swap.from.symbol
134
- }`;
144
+ fromAmountRangeError = `Required: < ${numberToString(
145
+ maximum,
146
+ TOKEN_AMOUNT_MIN_DECIMALS,
147
+ TOKEN_AMOUNT_MAX_DECIMALS
148
+ )} ${swap.from.symbol}`;
135
149
  recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
136
150
  }
137
151
 
@@ -492,14 +506,14 @@ export function getRouteOutputAmount(route: BestRouteResponse | null) {
492
506
  }
493
507
 
494
508
  export function getPercentageChange(
495
- oldValue: string | number | null,
496
- newValue: string | number | null
509
+ inputUsdValue: string | number | null,
510
+ outputUsdValue: string | number | null
497
511
  ) {
498
- if (!oldValue || !newValue) {
512
+ if (!inputUsdValue || !outputUsdValue) {
499
513
  return null;
500
514
  }
501
- return new BigNumber(newValue)
502
- .div(new BigNumber(oldValue))
515
+ return new BigNumber(outputUsdValue)
516
+ .div(new BigNumber(inputUsdValue))
503
517
  .minus(1)
504
518
  .multipliedBy(100);
505
519
  }
@@ -544,13 +558,15 @@ export function getBalanceWarnings(
544
558
  new BigNumber(asset.currentAmount.amount).shiftedBy(
545
559
  -asset.currentAmount.decimals
546
560
  ),
547
- 8
561
+ BALANCE_MIN_DECIMALS,
562
+ BALANCE_MAX_DECIMALS
548
563
  );
549
564
  const requiredAmount = numberToString(
550
565
  new BigNumber(asset.requiredAmount.amount).shiftedBy(
551
566
  -asset.requiredAmount.decimals
552
567
  ),
553
- 8
568
+ BALANCE_MIN_DECIMALS,
569
+ BALANCE_MAX_DECIMALS
554
570
  );
555
571
  let reason = '';
556
572
  if (asset.reason === 'FEE') {