@rango-dev/widget-embedded 0.37.1-next.2 → 0.38.0

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 (156) hide show
  1. package/dist/QueueManager.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  4. package/dist/components/Layout/Layout.d.ts.map +1 -1
  5. package/dist/components/Quote/Quote.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.styles.d.ts +1 -1
  7. package/dist/components/Quote/Quote.types.d.ts +0 -2
  8. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  9. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  10. package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
  11. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  12. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  13. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
  14. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  15. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
  16. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  17. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  18. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  19. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +1 -2
  20. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  21. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  22. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
  23. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  24. package/dist/constants/quote.d.ts +0 -10
  25. package/dist/constants/quote.d.ts.map +1 -1
  26. package/dist/constants/warnings.d.ts +3 -0
  27. package/dist/constants/warnings.d.ts.map +1 -0
  28. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  29. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  30. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  31. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  32. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  33. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  34. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
  35. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  36. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  37. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +4 -6
  38. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  39. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
  40. package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
  41. package/dist/hooks/useObserveBalanceChanges/index.d.ts +2 -0
  42. package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +1 -0
  43. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +4 -0
  44. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +1 -0
  45. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -2
  46. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  47. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -3
  48. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  49. package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
  50. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  51. package/dist/hooks/useWalletList.d.ts.map +1 -1
  52. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +3 -2
  53. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  54. package/dist/index.d.ts +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +2 -2
  57. package/dist/index.js.map +4 -4
  58. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  59. package/dist/pages/Home.d.ts.map +1 -1
  60. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  61. package/dist/store/app.d.ts +4 -2
  62. package/dist/store/app.d.ts.map +1 -1
  63. package/dist/store/quote.d.ts.map +1 -1
  64. package/dist/store/slices/config.d.ts +0 -4
  65. package/dist/store/slices/config.d.ts.map +1 -1
  66. package/dist/store/slices/data.d.ts.map +1 -1
  67. package/dist/store/ui.d.ts +0 -4
  68. package/dist/store/ui.d.ts.map +1 -1
  69. package/dist/store/wallets.d.ts +66 -0
  70. package/dist/store/wallets.d.ts.map +1 -0
  71. package/dist/types/config.d.ts +9 -7
  72. package/dist/types/config.d.ts.map +1 -1
  73. package/dist/types/quote.d.ts +17 -8
  74. package/dist/types/quote.d.ts.map +1 -1
  75. package/dist/types/wallets.d.ts +7 -3
  76. package/dist/types/wallets.d.ts.map +1 -1
  77. package/dist/utils/providers.d.ts +9 -8
  78. package/dist/utils/providers.d.ts.map +1 -1
  79. package/dist/utils/quote.d.ts +6 -5
  80. package/dist/utils/quote.d.ts.map +1 -1
  81. package/dist/utils/settings.d.ts +0 -1
  82. package/dist/utils/settings.d.ts.map +1 -1
  83. package/dist/utils/swap.d.ts +5 -5
  84. package/dist/utils/swap.d.ts.map +1 -1
  85. package/dist/utils/wallets.d.ts +14 -12
  86. package/dist/utils/wallets.d.ts.map +1 -1
  87. package/dist/widget-embedded.build.json +1 -1
  88. package/package.json +9 -9
  89. package/src/QueueManager.tsx +11 -17
  90. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +24 -5
  91. package/src/components/ConfirmWalletsModal/WalletList.tsx +7 -10
  92. package/src/components/Layout/Layout.tsx +3 -1
  93. package/src/components/Quote/Quote.tsx +3 -22
  94. package/src/components/Quote/Quote.types.ts +0 -2
  95. package/src/components/Quote/QuoteCostDetails.styles.ts +1 -0
  96. package/src/components/Quote/QuoteCostDetails.tsx +4 -23
  97. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +22 -42
  98. package/src/components/Quotes/Quotes.tsx +3 -2
  99. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
  100. package/src/components/SwapDetails/SwapDetails.tsx +6 -14
  101. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  102. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +13 -26
  103. package/src/components/TokenList/TokenList.tsx +27 -4
  104. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +1 -2
  105. package/src/components/WalletStatefulConnect/Namespaces.tsx +38 -31
  106. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
  107. package/src/constants/quote.ts +0 -25
  108. package/src/constants/warnings.ts +26 -0
  109. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +0 -1
  110. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
  111. package/src/containers/Inputs/Inputs.tsx +7 -20
  112. package/src/containers/QuoteInfo/QuoteInfo.tsx +9 -3
  113. package/src/containers/Wallets/Wallets.tsx +16 -82
  114. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  115. package/src/containers/WidgetInfo/WidgetInfo.tsx +8 -10
  116. package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
  117. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +66 -29
  118. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +15 -10
  119. package/src/hooks/useFetchApiConfig.ts +1 -5
  120. package/src/hooks/useFetchCustomToken.ts +0 -5
  121. package/src/hooks/useObserveBalanceChanges/index.ts +1 -0
  122. package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +68 -0
  123. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +17 -50
  124. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +5 -3
  125. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +6 -7
  126. package/src/hooks/useSwapInput.ts +11 -3
  127. package/src/hooks/useWalletList.ts +8 -6
  128. package/src/hooks/useWalletProviders/useWalletProviders.ts +12 -8
  129. package/src/index.ts +1 -1
  130. package/src/pages/ConfirmSwapPage.tsx +15 -7
  131. package/src/pages/Home.tsx +3 -5
  132. package/src/pages/SelectSwapItemsPage.tsx +2 -1
  133. package/src/store/app.ts +4 -4
  134. package/src/store/quote.ts +13 -3
  135. package/src/store/slices/config.ts +0 -76
  136. package/src/store/slices/data.test.ts +1 -23
  137. package/src/store/slices/data.ts +2 -3
  138. package/src/store/ui.ts +0 -6
  139. package/src/store/wallets.ts +268 -0
  140. package/src/types/config.ts +9 -8
  141. package/src/types/quote.ts +24 -10
  142. package/src/types/wallets.ts +7 -3
  143. package/src/utils/providers.ts +36 -88
  144. package/src/utils/quote.ts +45 -57
  145. package/src/utils/settings.ts +0 -4
  146. package/src/utils/swap.ts +37 -56
  147. package/src/utils/wallets.ts +141 -79
  148. package/dist/store/slices/types.d.ts +0 -6
  149. package/dist/store/slices/types.d.ts.map +0 -1
  150. package/dist/store/slices/wallets.d.ts +0 -80
  151. package/dist/store/slices/wallets.d.ts.map +0 -1
  152. package/dist/store/utils/wallets.d.ts +0 -17
  153. package/dist/store/utils/wallets.d.ts.map +0 -1
  154. package/src/store/slices/types.ts +0 -9
  155. package/src/store/slices/wallets.ts +0 -577
  156. package/src/store/utils/wallets.ts +0 -111
@@ -1,12 +1,7 @@
1
1
  import type { WidgetConfig } from '../types';
2
- import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
2
+ import type { ProviderInterface } from '@rango-dev/wallets-react';
3
3
 
4
- import {
5
- defineVersions,
6
- pickVersion,
7
- Provider,
8
- type VersionedProviders,
9
- } from '@rango-dev/wallets-core';
4
+ import { allProviders } from '@rango-dev/provider-all';
10
5
 
11
6
  export interface ProvidersOptions {
12
7
  walletConnectProjectId?: WidgetConfig['walletConnectProjectId'];
@@ -15,118 +10,71 @@ export interface ProvidersOptions {
15
10
  >['walletConnectListedDesktopWalletLink'];
16
11
  trezorManifest: WidgetConfig['trezorManifest'];
17
12
  tonConnect: WidgetConfig['tonConnect'];
18
- experimentalWallet?: 'enabled' | 'disabled';
19
13
  }
20
14
 
21
15
  /**
22
16
  *
23
17
  * Generate a list of providers by passing a provider name (e.g. metamask) or a custom provider which implemented ProviderInterface.
24
- * @returns BothProvidersInterface[] a list of BothProvidersInterface
18
+ * @returns ProviderInterface[] a list of ProviderInterface
25
19
  *
26
20
  */
27
- type BothProvidersInterface = LegacyProviderInterface | Provider;
28
- export function matchAndGenerateProviders({
29
- allProviders,
30
- configWallets,
31
- options,
32
- }: {
33
- allProviders: VersionedProviders[];
34
- configWallets: WidgetConfig['wallets'];
35
- options?: ProvidersOptions;
36
- }): VersionedProviders[] {
37
- if (configWallets) {
38
- /*
39
- * If `wallets` is included in widget config,
40
- * allProviders should be filtered based on wallets list
41
- */
42
- const selectedProviders: VersionedProviders[] = [];
21
+ export function matchAndGenerateProviders(
22
+ providers: WidgetConfig['wallets'],
23
+ options?: ProvidersOptions
24
+ ): ProviderInterface[] {
25
+ const all = allProviders({
26
+ walletconnect2: {
27
+ WC_PROJECT_ID: options?.walletConnectProjectId || '',
28
+ DISABLE_MODAL_AND_OPEN_LINK:
29
+ options?.walletConnectListedDesktopWalletLink,
30
+ },
31
+ selectedProviders: providers,
32
+ trezor: options?.trezorManifest
33
+ ? { manifest: options.trezorManifest }
34
+ : undefined,
35
+ tonConnect: options?.tonConnect?.manifestUrl
36
+ ? { manifestUrl: options?.tonConnect.manifestUrl }
37
+ : undefined,
38
+ });
39
+
40
+ if (providers) {
41
+ const selectedProviders: ProviderInterface[] = [];
43
42
 
44
- configWallets.forEach((requestedWallet) => {
43
+ providers.forEach((requestedProvider) => {
45
44
  /*
46
45
  * There are two types of provider we get, the first one is only passing the wallet name
47
46
  * then we will match the wallet name with our providers (@rango-dev/provider-*).
48
47
  * The second way is passing a custom provider which implemented ProviderInterface.
49
48
  */
50
- if (typeof requestedWallet === 'string') {
51
- const result = allProviders.find((provider) => {
52
- /*
53
- * To find a provider in allProviders,
54
- * a version of each provider should be picked
55
- * and validated based on that version scheme.
56
- * If the corresponding provider to a wallet was found in allProvider,
57
- * it will be add to selected providers.
58
- */
59
- const versionedProvider = pickProviderVersionWithFallbackToLegacy(
60
- provider,
61
- options
62
- );
63
- if (versionedProvider instanceof Provider) {
64
- return versionedProvider.id === requestedWallet;
65
- }
66
- return versionedProvider.config.type === requestedWallet;
49
+ if (typeof requestedProvider === 'string') {
50
+ const result: ProviderInterface | undefined = all.find((provider) => {
51
+ return provider.config.type === requestedProvider;
67
52
  });
68
-
69
- /*
70
- * A provider may have multiple versions
71
- * (e.g., 0.0, also known as legacy, and 1.0, also known as hub).
72
- * We should ensure that all existing versions of a provider are added to selectedProviders.
73
- */
74
53
  if (result) {
75
54
  selectedProviders.push(result);
76
55
  } else {
77
56
  console.warn(
78
- // A provider name is included in config but was not found in allProviders
79
- `Couldn't find ${requestedWallet} provider. Please make sure you are passing the correct name.`
57
+ `Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
80
58
  );
81
59
  }
82
60
  } else {
83
61
  // It's a custom provider so we directly push it to the list.
84
- if (requestedWallet instanceof Provider) {
85
- selectedProviders.push(
86
- defineVersions().version('1.0.0', requestedWallet).build()
87
- );
88
- } else {
89
- selectedProviders.push(
90
- defineVersions().version('0.0.0', requestedWallet).build()
91
- );
92
- }
62
+ selectedProviders.push(requestedProvider);
93
63
  }
94
64
  });
95
-
96
65
  return selectedProviders;
97
66
  }
98
67
 
99
- return allProviders;
100
- }
101
-
102
- function pickProviderVersionWithFallbackToLegacy(
103
- provider: VersionedProviders,
104
- options?: ProvidersOptions
105
- ): BothProvidersInterface {
106
- const { experimentalWallet = 'enabled' } = options || {};
107
- const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';
108
-
109
- try {
110
- return pickVersion(provider, version)[1];
111
- } catch {
112
- // Fallback to legacy version, if target version doesn't exists.
113
- return pickVersion(provider, '0.0.0')[1];
114
- }
68
+ return all;
115
69
  }
116
70
 
117
71
  export function configWalletsToWalletName(
118
- providers: VersionedProviders[],
72
+ config: WidgetConfig['wallets'],
119
73
  options?: ProvidersOptions
120
74
  ): string[] {
121
- const names = providers
122
- .map((provider) =>
123
- pickProviderVersionWithFallbackToLegacy(provider, options)
124
- )
125
- .map((provider) => {
126
- if (provider instanceof Provider) {
127
- return provider.id;
128
- }
129
- return provider.config.type;
130
- });
75
+ const providers = matchAndGenerateProviders(config, options);
76
+ const names = providers.map((provider) => {
77
+ return provider.config.type;
78
+ });
131
79
  return names;
132
80
  }
@@ -15,6 +15,7 @@ import type {
15
15
  MultiRouteSimulationResult,
16
16
  PreferenceType,
17
17
  RouteTag,
18
+ Token,
18
19
  } from 'rango-sdk';
19
20
  import type { PendingSwap } from 'rango-types';
20
21
 
@@ -28,19 +29,30 @@ import { QuoteWarningType } from '../types';
28
29
 
29
30
  import { areEqual } from './common';
30
31
  import { createTokenHash, findBlockchain } from './meta';
31
- import { numberToString } from './numbers';
32
32
  import {
33
+ calcOutputUsdValue,
33
34
  checkSlippageWarnings,
34
35
  getMinRequiredSlippage,
35
36
  getPercentageChange,
36
37
  getTotalFeeInUsd,
37
- getUsdInputFrom,
38
- getUsdOutputFrom,
39
38
  hasHighValueLoss,
40
39
  hasProperSlippage,
41
- isOutputAmountChangedExcessively,
42
40
  } from './swap';
43
41
 
42
+ export function getQuoteToTokenUsdPrice(
43
+ quote: SelectedQuote | null
44
+ ): number | null | undefined {
45
+ const swaps = quote?.swaps || [];
46
+ return swaps[swaps.length - 1].to.usdPrice;
47
+ }
48
+
49
+ export function getQuoteFromTokenUsdPrice(
50
+ quote: SelectedQuote | null
51
+ ): number | null | undefined {
52
+ const swaps = quote?.swaps || [];
53
+ return swaps[0].from.usdPrice;
54
+ }
55
+
44
56
  export function isNumberOfSwapsChanged(
45
57
  quoteA: SelectedQuote,
46
58
  quoteB: SelectedQuote
@@ -183,73 +195,56 @@ export function createRetryQuote(
183
195
  };
184
196
  }
185
197
 
186
- export function generateQuoteWarnings(params: {
187
- previousQuote?: SelectedQuote;
188
- currentQuote: SelectedQuote;
189
- findToken: FindToken;
190
- userSlippage: number;
191
- }): QuoteWarning | null {
192
- const { previousQuote, currentQuote, findToken, userSlippage } = params;
193
- const usdInput = getUsdInputFrom(currentQuote);
194
- const usdOutput = getUsdOutputFrom(currentQuote);
195
-
196
- if (!!currentQuote && usdInput && usdOutput) {
198
+ export function generateQuoteWarnings(
199
+ quote: SelectedQuote,
200
+ params: {
201
+ fromToken: Token;
202
+ toToken: Token;
203
+ findToken: FindToken;
204
+ userSlippage: number;
205
+ }
206
+ ): QuoteWarning | null {
207
+ const { fromToken, toToken, findToken, userSlippage } = params;
208
+ const inputUsdValue = calcOutputUsdValue(
209
+ quote.requestAmount,
210
+ getQuoteFromTokenUsdPrice(quote) || fromToken?.usdPrice
211
+ );
212
+ const outputUsdValue = calcOutputUsdValue(
213
+ quote.outputAmount,
214
+ getQuoteToTokenUsdPrice(quote) || toToken?.usdPrice
215
+ );
216
+
217
+ if (!!quote && inputUsdValue && outputUsdValue) {
197
218
  const priceImpact = getPriceImpact(
198
- usdInput.toString(),
199
- usdOutput.toString()
219
+ inputUsdValue.toString(),
220
+ outputUsdValue.toString()
200
221
  );
201
222
  const highValueLoss =
202
- !!priceImpact && hasHighValueLoss(usdInput, priceImpact);
223
+ !!priceImpact && hasHighValueLoss(inputUsdValue, priceImpact);
203
224
 
204
225
  if (highValueLoss) {
205
- const totalFee = getTotalFeeInUsd(currentQuote?.swaps, findToken);
226
+ const totalFee = getTotalFeeInUsd(quote?.swaps, findToken);
206
227
  const warningLevel = getPriceImpactLevel(priceImpact);
207
228
  return {
208
229
  type: QuoteWarningType.HIGH_VALUE_LOSS,
209
- inputUsdValue: usdInput,
210
- outputUsdValue: usdOutput,
230
+ inputUsdValue,
231
+ outputUsdValue,
211
232
  priceImpact,
212
233
  totalFee,
213
234
  warningLevel,
214
235
  };
215
236
  }
216
- }
217
-
218
- if (
219
- previousQuote &&
220
- isOutputAmountChangedExcessively(previousQuote, currentQuote)
221
- ) {
222
- return {
223
- type: QuoteWarningType.EXCESSIVE_OUTPUT_AMOUNT_CHANGE,
224
- usdValueChange: numberToString(
225
- getUsdOutputFrom(currentQuote)
226
- ?.minus(getUsdOutputFrom(previousQuote) ?? 0)
227
- .toString() ?? '0',
228
- null,
229
- 2
230
- ),
231
- percentageChange: numberToString(
232
- getPriceImpact(
233
- getUsdOutputFrom(previousQuote) ?? '1',
234
- getUsdOutputFrom(currentQuote) ?? '1'
235
- ),
236
- null,
237
- 2
238
- ),
239
- };
240
- }
241
-
242
- if (currentQuote && (!usdInput || !usdOutput)) {
237
+ } else if (quote && (!inputUsdValue || !outputUsdValue)) {
243
238
  return { type: QuoteWarningType.UNKNOWN_PRICE };
244
239
  }
245
240
 
246
- const minRequiredSlippage = getMinRequiredSlippage(currentQuote.swaps);
241
+ const minRequiredSlippage = getMinRequiredSlippage(quote.swaps);
247
242
  const highSlippage = userSlippage > HIGH_SLIPPAGE;
248
243
 
249
244
  if (!hasProperSlippage(params.userSlippage.toString(), minRequiredSlippage)) {
250
245
  return {
251
246
  type: QuoteWarningType.INSUFFICIENT_SLIPPAGE,
252
- recommendedSlippages: checkSlippageWarnings(currentQuote, userSlippage),
247
+ recommendedSlippages: checkSlippageWarnings(quote, userSlippage),
253
248
  minRequiredSlippage: minRequiredSlippage,
254
249
  };
255
250
  } else if (
@@ -265,13 +260,6 @@ export function generateQuoteWarnings(params: {
265
260
  return null;
266
261
  }
267
262
 
268
- export function isQuoteWarningConfirmationRequired(warning: QuoteWarning) {
269
- const WARNINGS_NOT_REQUIRING_CONFIRMATION = [
270
- QuoteWarningType.EXCESSIVE_OUTPUT_AMOUNT_CHANGE,
271
- ];
272
- return !WARNINGS_NOT_REQUIRING_CONFIRMATION.includes(warning.type);
273
- }
274
-
275
263
  export function getPriceImpact(
276
264
  inputUsdValue: BigNumber | string | null,
277
265
  outputUsdValue: BigNumber | string | null
@@ -72,10 +72,6 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) {
72
72
  return features?.[feature] === 'hidden';
73
73
  }
74
74
 
75
- export function isFeatureEnabled(feature: keyof Features, features?: Features) {
76
- return features?.[feature] === 'enabled';
77
- }
78
-
79
75
  export function isRoutingEnabled(item: keyof Routing, routing?: Routing) {
80
76
  return routing?.[item] === 'enabled';
81
77
  }
package/src/utils/swap.ts CHANGED
@@ -1,5 +1,7 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+ import type { FeesGroup, NameOfFees } from '../constants/quote';
1
3
  import type { FetchStatus, FindToken } from '../store/slices/data';
2
- import type { ConnectedWallet } from '../store/slices/wallets';
4
+ import type { ConnectedWallet } from '../store/wallets';
3
5
  import type {
4
6
  ConvertedToken,
5
7
  QuoteError,
@@ -32,14 +34,6 @@ import { PendingSwapNetworkStatus } from 'rango-types';
32
34
  import { errorMessages } from '../constants/errors';
33
35
  import { swapButtonTitles } from '../constants/messages';
34
36
  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';
43
37
  import {
44
38
  BALANCE_MAX_DECIMALS,
45
39
  BALANCE_MIN_DECIMALS,
@@ -49,7 +43,7 @@ import {
49
43
 
50
44
  import { getBlockchainShortNameFor, isValidTokenAddress } from './meta';
51
45
  import { numberToString } from './numbers';
52
- import { getRequiredBalanceOfWallet } from './quote';
46
+ import { getPriceImpact, getRequiredBalanceOfWallet } from './quote';
53
47
  import { getQuoteWallets } from './wallets';
54
48
 
55
49
  export function getOutputRatio(
@@ -67,7 +61,7 @@ export function getOutputRatio(
67
61
  return outputUsdValue
68
62
  .div(inputUsdValue)
69
63
  .minus(1)
70
- .multipliedBy(PERCENT_MULTIPLIER)
64
+ .multipliedBy(100)
71
65
  .toNumber();
72
66
  }
73
67
 
@@ -75,16 +69,12 @@ export function hasHighValueLoss(
75
69
  inputUsdValue: BigNumber | null,
76
70
  priceImpact: number
77
71
  ): boolean {
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))
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
88
78
  );
89
79
  }
90
80
 
@@ -338,7 +328,7 @@ export function hasHighFee(totalFeeInUsd: BigNumber | null) {
338
328
  if (!totalFeeInUsd) {
339
329
  return false;
340
330
  }
341
- return !totalFeeInUsd.lt(new BigNumber(HIGH_FEE_THRESHOLD_USD));
331
+ return !totalFeeInUsd.lt(new BigNumber(30));
342
332
  }
343
333
 
344
334
  export function hasSlippageError(
@@ -490,7 +480,8 @@ export function createQuoteRequestBody(params: {
490
480
  addresses: [wallet.address],
491
481
  });
492
482
  });
493
-
483
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
484
+ // @ts-ignore
494
485
  const requestBody: BestRouteRequest = {
495
486
  amount: inputAmount.toString(),
496
487
  affiliateRef: affiliateRef ?? undefined,
@@ -544,52 +535,33 @@ export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
544
535
  return wallets;
545
536
  }
546
537
 
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);
538
+ export function getQuoteOutputAmount(quote: SelectedQuote) {
539
+ return quote?.outputAmount || null;
563
540
  }
564
541
 
565
542
  export function getPercentageChange(input: string, output: string) {
566
543
  return new BigNumber(output)
567
544
  .div(new BigNumber(input))
568
545
  .minus(1)
569
- .multipliedBy(PERCENT_MULTIPLIER)
546
+ .multipliedBy(100)
570
547
  .toNumber();
571
548
  }
572
549
 
573
- export function isOutputAmountChangedExcessively(
574
- previousQuote: SelectedQuote,
575
- currentQuote: SelectedQuote
550
+ export function isOutputAmountChangedALot(
551
+ oldQuote: SelectedQuote,
552
+ newQuote: SelectedQuote
576
553
  ) {
577
- const usdInput = getUsdInputFrom(previousQuote);
578
- const previousUsdOutput = getUsdOutputFrom(previousQuote);
579
- const currentUsdOutput = getUsdOutputFrom(currentQuote);
580
- if (!usdInput || !previousUsdOutput || !currentUsdOutput) {
554
+ const oldOutputAmount = getQuoteOutputAmount(oldQuote);
555
+ const newOutputAmount = getQuoteOutputAmount(newQuote);
556
+ if (!oldOutputAmount || !newOutputAmount) {
581
557
  return false;
582
558
  }
559
+ const percentageChange = getPriceImpact(oldOutputAmount, newOutputAmount);
560
+ if (!percentageChange) {
561
+ return true;
562
+ }
583
563
 
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
- );
564
+ return percentageChange <= -1;
593
565
  }
594
566
 
595
567
  export function generateBalanceWarnings(
@@ -651,6 +623,15 @@ export function generateBalanceWarnings(
651
623
  });
652
624
  }
653
625
 
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
+
654
635
  export function isNetworkStatusInWarningState(
655
636
  pendingSwapStep: PendingSwapStep | null
656
637
  ): boolean {