@rango-dev/widget-embedded 0.36.1-next.11 → 0.36.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 (61) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  2. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  3. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  4. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  5. package/dist/constants/quote.d.ts +8 -0
  6. package/dist/constants/quote.d.ts.map +1 -1
  7. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  8. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  9. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  10. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +6 -4
  11. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  12. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  13. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +2 -4
  14. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  15. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  16. package/dist/index.js +2 -2
  17. package/dist/index.js.map +4 -4
  18. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  19. package/dist/store/quote.d.ts.map +1 -1
  20. package/dist/store/slices/wallets.d.ts +3 -1
  21. package/dist/store/slices/wallets.d.ts.map +1 -1
  22. package/dist/types/quote.d.ts +8 -17
  23. package/dist/types/quote.d.ts.map +1 -1
  24. package/dist/types/wallets.d.ts +1 -6
  25. package/dist/types/wallets.d.ts.map +1 -1
  26. package/dist/utils/providers.d.ts.map +1 -1
  27. package/dist/utils/quote.d.ts +5 -6
  28. package/dist/utils/quote.d.ts.map +1 -1
  29. package/dist/utils/swap.d.ts +4 -4
  30. package/dist/utils/swap.d.ts.map +1 -1
  31. package/dist/utils/wallets.d.ts.map +1 -1
  32. package/dist/widget-embedded.build.json +1 -1
  33. package/package.json +3 -3
  34. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +2 -19
  35. package/src/components/ConfirmWalletsModal/WalletList.tsx +1 -1
  36. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
  37. package/src/components/Quotes/Quotes.tsx +2 -3
  38. package/src/components/WalletStatefulConnect/Namespaces.tsx +30 -37
  39. package/src/constants/quote.ts +23 -0
  40. package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
  41. package/src/containers/Wallets/Wallets.tsx +63 -3
  42. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
  43. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
  44. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +20 -22
  45. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +2 -4
  46. package/src/hooks/useSwapInput.ts +2 -9
  47. package/src/pages/ConfirmSwapPage.tsx +7 -15
  48. package/src/store/quote.ts +3 -13
  49. package/src/store/slices/wallets.ts +13 -2
  50. package/src/types/quote.ts +10 -24
  51. package/src/types/wallets.ts +1 -6
  52. package/src/utils/providers.ts +43 -36
  53. package/src/utils/quote.ts +57 -45
  54. package/src/utils/swap.ts +55 -36
  55. package/src/utils/wallets.ts +2 -4
  56. package/dist/constants/warnings.d.ts +0 -3
  57. package/dist/constants/warnings.d.ts.map +0 -1
  58. package/dist/utils/hub.d.ts +0 -4
  59. package/dist/utils/hub.d.ts.map +0 -1
  60. package/src/constants/warnings.ts +0 -26
  61. package/src/utils/hub.ts +0 -21
package/src/utils/swap.ts CHANGED
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-magic-numbers */
2
- import type { FeesGroup, NameOfFees } from '../constants/quote';
3
1
  import type { FetchStatus, FindToken } from '../store/slices/data';
4
2
  import type { ConnectedWallet } from '../store/slices/wallets';
5
3
  import type {
@@ -34,6 +32,14 @@ import { PendingSwapNetworkStatus } from 'rango-types';
34
32
  import { errorMessages } from '../constants/errors';
35
33
  import { swapButtonTitles } from '../constants/messages';
36
34
  import { ZERO } from '../constants/numbers';
35
+ import {
36
+ type FeesGroup,
37
+ HIGH_FEE_THRESHOLD_USD,
38
+ HIGH_VALUE_LOSS_CRITERIA,
39
+ type NameOfFees,
40
+ OUTPUT_CHANGE_WARNING_CRITERIA,
41
+ PERCENT_MULTIPLIER,
42
+ } from '../constants/quote';
37
43
  import {
38
44
  BALANCE_MAX_DECIMALS,
39
45
  BALANCE_MIN_DECIMALS,
@@ -43,7 +49,7 @@ import {
43
49
 
44
50
  import { getBlockchainShortNameFor, isValidTokenAddress } from './meta';
45
51
  import { numberToString } from './numbers';
46
- import { getPriceImpact, getRequiredBalanceOfWallet } from './quote';
52
+ import { getRequiredBalanceOfWallet } from './quote';
47
53
  import { getQuoteWallets } from './wallets';
48
54
 
49
55
  export function getOutputRatio(
@@ -61,7 +67,7 @@ export function getOutputRatio(
61
67
  return outputUsdValue
62
68
  .div(inputUsdValue)
63
69
  .minus(1)
64
- .multipliedBy(100)
70
+ .multipliedBy(PERCENT_MULTIPLIER)
65
71
  .toNumber();
66
72
  }
67
73
 
@@ -69,12 +75,16 @@ export function hasHighValueLoss(
69
75
  inputUsdValue: BigNumber | null,
70
76
  priceImpact: number
71
77
  ): boolean {
72
- return (
73
- ((parseInt(priceImpact.toFixed(2) || '0') <= -10 &&
74
- inputUsdValue?.gte(new BigNumber(400))) ||
75
- (parseInt(priceImpact.toFixed(2) || '0') <= -5 &&
76
- inputUsdValue?.gte(new BigNumber(1000)))) ??
77
- false
78
+ if (!inputUsdValue) {
79
+ return false;
80
+ }
81
+
82
+ const formattedPriceImpact = parseInt(priceImpact.toFixed(2) || '0');
83
+
84
+ return HIGH_VALUE_LOSS_CRITERIA.some(
85
+ ({ threshold, minInput }) =>
86
+ formattedPriceImpact <= threshold &&
87
+ inputUsdValue.gte(new BigNumber(minInput))
78
88
  );
79
89
  }
80
90
 
@@ -328,7 +338,7 @@ export function hasHighFee(totalFeeInUsd: BigNumber | null) {
328
338
  if (!totalFeeInUsd) {
329
339
  return false;
330
340
  }
331
- return !totalFeeInUsd.lt(new BigNumber(30));
341
+ return !totalFeeInUsd.lt(new BigNumber(HIGH_FEE_THRESHOLD_USD));
332
342
  }
333
343
 
334
344
  export function hasSlippageError(
@@ -480,8 +490,7 @@ export function createQuoteRequestBody(params: {
480
490
  addresses: [wallet.address],
481
491
  });
482
492
  });
483
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
484
- // @ts-ignore
493
+
485
494
  const requestBody: BestRouteRequest = {
486
495
  amount: inputAmount.toString(),
487
496
  affiliateRef: affiliateRef ?? undefined,
@@ -535,33 +544,52 @@ export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
535
544
  return wallets;
536
545
  }
537
546
 
538
- export function getQuoteOutputAmount(quote: SelectedQuote) {
539
- return quote?.outputAmount || null;
547
+ export function getUsdInputFrom(quote: SelectedQuote): BigNumber | undefined {
548
+ const inputAmount = quote.requestAmount;
549
+ const inputTokenUsdPrice = quote.swaps[0].from.usdPrice;
550
+ if (!inputAmount || !inputTokenUsdPrice) {
551
+ return;
552
+ }
553
+ return new BigNumber(inputAmount).multipliedBy(inputTokenUsdPrice);
554
+ }
555
+
556
+ export function getUsdOutputFrom(quote: SelectedQuote): BigNumber | undefined {
557
+ const outputAmount = quote?.outputAmount || null;
558
+ const outputTokenUsdPrice = quote.swaps[quote.swaps.length - 1].to.usdPrice;
559
+ if (!outputAmount || !outputTokenUsdPrice) {
560
+ return;
561
+ }
562
+ return new BigNumber(outputAmount).multipliedBy(outputTokenUsdPrice);
540
563
  }
541
564
 
542
565
  export function getPercentageChange(input: string, output: string) {
543
566
  return new BigNumber(output)
544
567
  .div(new BigNumber(input))
545
568
  .minus(1)
546
- .multipliedBy(100)
569
+ .multipliedBy(PERCENT_MULTIPLIER)
547
570
  .toNumber();
548
571
  }
549
572
 
550
- export function isOutputAmountChangedALot(
551
- oldQuote: SelectedQuote,
552
- newQuote: SelectedQuote
573
+ export function isOutputAmountChangedExcessively(
574
+ previousQuote: SelectedQuote,
575
+ currentQuote: SelectedQuote
553
576
  ) {
554
- const oldOutputAmount = getQuoteOutputAmount(oldQuote);
555
- const newOutputAmount = getQuoteOutputAmount(newQuote);
556
- if (!oldOutputAmount || !newOutputAmount) {
577
+ const usdInput = getUsdInputFrom(previousQuote);
578
+ const previousUsdOutput = getUsdOutputFrom(previousQuote);
579
+ const currentUsdOutput = getUsdOutputFrom(currentQuote);
580
+ if (!usdInput || !previousUsdOutput || !currentUsdOutput) {
557
581
  return false;
558
582
  }
559
- const percentageChange = getPriceImpact(oldOutputAmount, newOutputAmount);
560
- if (!percentageChange) {
561
- return true;
562
- }
563
583
 
564
- return percentageChange <= -1;
584
+ const percentageChange = getPercentageChange(
585
+ previousUsdOutput.toString(),
586
+ currentUsdOutput.toString()
587
+ );
588
+
589
+ return OUTPUT_CHANGE_WARNING_CRITERIA.some(
590
+ ({ threshold, minInput }) =>
591
+ percentageChange <= threshold && usdInput.isGreaterThanOrEqualTo(minInput)
592
+ );
565
593
  }
566
594
 
567
595
  export function generateBalanceWarnings(
@@ -623,15 +651,6 @@ export function generateBalanceWarnings(
623
651
  });
624
652
  }
625
653
 
626
- export function calcOutputUsdValue(
627
- outputAmount?: string,
628
- tokenPrice?: number | null
629
- ) {
630
- const amount = !!outputAmount ? new BigNumber(outputAmount) : ZERO;
631
-
632
- return amount.multipliedBy(tokenPrice || 0);
633
- }
634
-
635
654
  export function isNetworkStatusInWarningState(
636
655
  pendingSwapStep: PendingSwapStep | null
637
656
  ): boolean {
@@ -87,8 +87,7 @@ export function mapWalletTypesToWalletInfo(
87
87
  img: image,
88
88
  installLink,
89
89
  showOnMobile,
90
- namespaces,
91
- singleNamespace,
90
+ needsNamespace,
92
91
  supportedChains,
93
92
  needsDerivationPath,
94
93
  properties,
@@ -106,8 +105,7 @@ export function mapWalletTypesToWalletInfo(
106
105
  state,
107
106
  type,
108
107
  showOnMobile,
109
- namespaces,
110
- singleNamespace,
108
+ needsNamespace,
111
109
  blockchainTypes,
112
110
  needsDerivationPath,
113
111
  properties,
@@ -1,3 +0,0 @@
1
- import type { QuoteUpdateWarning } from '../types';
2
- export declare function getQuoteUpdateWarningMessage(warning: QuoteUpdateWarning): string;
3
- //# sourceMappingURL=warnings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../src/constants/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,UAmBvE"}
@@ -1,4 +0,0 @@
1
- import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
- export declare function convertCommonNamespacesKeysToLegacyNamespace(namespaces: CommonNamespaceKeys[]): Namespace[];
4
- //# sourceMappingURL=hub.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/utils/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAE3E,wBAAgB,4CAA4C,CAC1D,UAAU,EAAE,mBAAmB,EAAE,GAChC,SAAS,EAAE,CAeb"}
@@ -1,26 +0,0 @@
1
- import type { QuoteUpdateWarning } from '../types';
2
-
3
- import { i18n } from '@lingui/core';
4
-
5
- import { QuoteUpdateType } from '../types';
6
-
7
- export function getQuoteUpdateWarningMessage(warning: QuoteUpdateWarning) {
8
- switch (warning.type) {
9
- case QuoteUpdateType.QUOTE_UPDATED:
10
- return i18n.t('Route has been updated.');
11
- case QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED:
12
- return i18n.t(
13
- 'Output amount changed to {newOutputAmount} ({percentageChange}% change).',
14
- {
15
- newOutputAmount: warning.newOutputAmount,
16
- percentageChange: warning.percentageChange,
17
- }
18
- );
19
- case QuoteUpdateType.QUOTE_SWAPPERS_UPDATED:
20
- return i18n.t('Route swappers has been updated.');
21
- case QuoteUpdateType.QUOTE_COINS_UPDATED:
22
- return i18n.t('Route internal coins has been updated.');
23
- default:
24
- return '';
25
- }
26
- }
package/src/utils/hub.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
-
4
- export function convertCommonNamespacesKeysToLegacyNamespace(
5
- namespaces: CommonNamespaceKeys[]
6
- ): Namespace[] {
7
- return namespaces.map((namespace) => {
8
- switch (namespace) {
9
- case 'evm':
10
- return 'EVM';
11
- case 'solana':
12
- return 'Solana';
13
- case 'cosmos':
14
- return 'Cosmos';
15
- default:
16
- throw new Error(
17
- 'Can not convert this common namespace key to a proper legacy key.'
18
- );
19
- }
20
- });
21
- }