@rango-dev/widget-embedded 0.22.4-next.0 → 0.22.4-next.10

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 (197) hide show
  1. package/dist/QueueManager.d.ts.map +1 -1
  2. package/dist/components/AppRoutes.d.ts.map +1 -1
  3. package/dist/components/BlockchainList/BlockchainList.styles.d.ts +3 -0
  4. package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
  5. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +1 -0
  6. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
  7. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +2 -2
  8. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
  9. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +15 -0
  10. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  11. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  12. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  13. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +3 -0
  14. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
  15. package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts +4 -0
  16. package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts.map +1 -1
  17. package/dist/components/HeaderButtons/HeaderButtons.d.ts +4 -0
  18. package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -0
  19. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +5 -0
  20. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  21. package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +3 -2
  22. package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
  23. package/dist/components/HeaderButtons/index.d.ts +1 -1
  24. package/dist/components/HeaderButtons/index.d.ts.map +1 -1
  25. package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts +6 -0
  26. package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts.map +1 -1
  27. package/dist/components/Layout/Layout.d.ts.map +1 -1
  28. package/dist/components/Layout/Layout.styles.d.ts +3 -0
  29. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  30. package/dist/components/Layout/Layout.types.d.ts +1 -0
  31. package/dist/components/Layout/Layout.types.d.ts.map +1 -1
  32. package/dist/components/Layout/PageContainer.d.ts +1 -0
  33. package/dist/components/Layout/PageContainer.d.ts.map +1 -1
  34. package/dist/components/Layout/ScrollableArea.d.ts +1 -0
  35. package/dist/components/Layout/ScrollableArea.d.ts.map +1 -1
  36. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -0
  37. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  38. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +14 -0
  39. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
  40. package/dist/components/NoResult/NoResult.styles.d.ts +3 -0
  41. package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
  42. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +4 -0
  43. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  44. package/dist/components/Quote/Quote.d.ts.map +1 -1
  45. package/dist/components/Quote/Quote.styles.d.ts +1136 -25
  46. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  47. package/dist/components/Quote/Quote.types.d.ts +12 -7
  48. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  49. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  50. package/dist/components/Quote/QuoteCostDetails.styles.d.ts +5 -0
  51. package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
  52. package/dist/components/Quote/QuoteSummary.styles.d.ts +2 -0
  53. package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -1
  54. package/dist/components/Quote/QuoteTrigger .d.ts.map +1 -1
  55. package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +4 -0
  56. package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
  57. package/dist/components/QuoteSkeleton/QuoteSkeleton.types.d.ts +1 -1
  58. package/dist/components/QuoteSkeleton/QuoteSkeleton.types.d.ts.map +1 -1
  59. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
  60. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts +20 -10
  61. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts.map +1 -1
  62. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.types.d.ts +1 -1
  63. package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.types.d.ts.map +1 -1
  64. package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +5 -0
  65. package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
  66. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +4 -0
  67. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
  68. package/dist/components/SearchInput/SearchInput.styles.d.ts +1 -0
  69. package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
  70. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +3 -0
  71. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
  72. package/dist/components/Slippage/Slippage.styles.d.ts +5 -0
  73. package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
  74. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +13 -0
  75. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  76. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +1 -0
  77. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
  78. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +2 -1
  79. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  80. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +1 -0
  81. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
  82. package/dist/components/SwapDetailsModal/index.d.ts +1 -1
  83. package/dist/components/SwapDetailsModal/index.d.ts.map +1 -1
  84. package/dist/components/TokenList/TokenList.styles.d.ts +17 -0
  85. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  86. package/dist/components/WalletModal/WalletModalContent.styles.d.ts +4 -0
  87. package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
  88. package/dist/constants/languages.d.ts.map +1 -1
  89. package/dist/constants/navigationRoutes.d.ts +1 -0
  90. package/dist/constants/navigationRoutes.d.ts.map +1 -1
  91. package/dist/constants/quote.d.ts +5 -1
  92. package/dist/constants/quote.d.ts.map +1 -1
  93. package/dist/containers/App/App.styles.d.ts +1 -0
  94. package/dist/containers/App/App.styles.d.ts.map +1 -1
  95. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  96. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +3 -0
  97. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -1
  98. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +6 -3
  99. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
  100. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  101. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  102. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +5 -4
  103. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  104. package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts +1 -1
  105. package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -1
  106. package/dist/hooks/useFetch.d.ts +12 -0
  107. package/dist/hooks/useFetch.d.ts.map +1 -0
  108. package/dist/hooks/useFetchAllQuotes.d.ts +4 -0
  109. package/dist/hooks/useFetchAllQuotes.d.ts.map +1 -0
  110. package/dist/hooks/useFetchConfirmQuote.d.ts +4 -0
  111. package/dist/hooks/useFetchConfirmQuote.d.ts.map +1 -0
  112. package/dist/hooks/useSwapInput.d.ts +5 -5
  113. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  114. package/dist/hooks/useWalletList.d.ts +1 -0
  115. package/dist/hooks/useWalletList.d.ts.map +1 -1
  116. package/dist/index.js +2 -2
  117. package/dist/index.js.map +4 -4
  118. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  119. package/dist/pages/Home.d.ts.map +1 -1
  120. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  121. package/dist/pages/Routes.d.ts +3 -0
  122. package/dist/pages/Routes.d.ts.map +1 -0
  123. package/dist/pages/SettingsPage.d.ts.map +1 -1
  124. package/dist/pages/WalletsPage.d.ts.map +1 -1
  125. package/dist/store/AppStore.d.ts +2 -2
  126. package/dist/store/app.d.ts +2 -2
  127. package/dist/store/quote.d.ts +32 -10
  128. package/dist/store/quote.d.ts.map +1 -1
  129. package/dist/store/wallets.d.ts +0 -2
  130. package/dist/store/wallets.d.ts.map +1 -1
  131. package/dist/types/quote.d.ts +19 -1
  132. package/dist/types/quote.d.ts.map +1 -1
  133. package/dist/utils/quote.d.ts +12 -9
  134. package/dist/utils/quote.d.ts.map +1 -1
  135. package/dist/utils/settings.d.ts +2 -3
  136. package/dist/utils/settings.d.ts.map +1 -1
  137. package/dist/utils/swap.d.ts +18 -18
  138. package/dist/utils/swap.d.ts.map +1 -1
  139. package/dist/utils/wallets.d.ts +4 -3
  140. package/dist/utils/wallets.d.ts.map +1 -1
  141. package/package.json +10 -10
  142. package/src/QueueManager.tsx +0 -3
  143. package/src/components/AppRoutes.tsx +5 -0
  144. package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +3 -3
  145. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +22 -19
  146. package/src/components/ConfirmWalletsModal/WalletList.tsx +24 -18
  147. package/src/components/HeaderButtons/{HomeButtons.tsx → HeaderButtons.tsx} +39 -26
  148. package/src/components/HeaderButtons/HeaderButtons.types.ts +3 -2
  149. package/src/components/HeaderButtons/index.ts +1 -1
  150. package/src/components/Layout/Layout.tsx +13 -1
  151. package/src/components/Layout/Layout.types.ts +1 -0
  152. package/src/components/Quote/Quote.styles.ts +133 -38
  153. package/src/components/Quote/Quote.tsx +77 -18
  154. package/src/components/Quote/Quote.types.ts +13 -7
  155. package/src/components/Quote/QuoteCostDetails.tsx +9 -4
  156. package/src/components/Quote/QuoteTrigger .tsx +7 -3
  157. package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
  158. package/src/components/QuoteSkeleton/QuoteSkeleton.types.ts +1 -1
  159. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +10 -12
  160. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +28 -9
  161. package/src/components/QuoteSkeleton/QuoteSummarySkeleton.types.ts +1 -1
  162. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +19 -19
  163. package/src/components/SwapDetails/SwapDetails.tsx +1 -1
  164. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  165. package/src/components/SwapDetailsModal/index.ts +1 -1
  166. package/src/constants/languages.ts +2 -1
  167. package/src/constants/navigationRoutes.ts +1 -0
  168. package/src/constants/quote.ts +17 -1
  169. package/src/containers/QuoteInfo/QuoteInfo.tsx +32 -7
  170. package/src/containers/QuoteInfo/QuoteInfo.types.ts +6 -3
  171. package/src/containers/Wallets/Wallets.tsx +5 -11
  172. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +36 -20
  173. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +76 -78
  174. package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +1 -1
  175. package/src/hooks/useFetch.ts +48 -0
  176. package/src/hooks/useFetchAllQuotes.ts +21 -0
  177. package/src/hooks/useFetchConfirmQuote.ts +21 -0
  178. package/src/hooks/useSwapInput.ts +59 -31
  179. package/src/hooks/useWalletList.ts +5 -3
  180. package/src/pages/ConfirmSwapPage.tsx +12 -9
  181. package/src/pages/Home.tsx +25 -15
  182. package/src/pages/LiquiditySourcePage.tsx +3 -5
  183. package/src/pages/Routes.tsx +131 -0
  184. package/src/pages/SettingsPage.tsx +11 -13
  185. package/src/pages/WalletsPage.tsx +24 -18
  186. package/src/store/quote.ts +60 -22
  187. package/src/store/wallets.ts +0 -2
  188. package/src/types/quote.ts +27 -1
  189. package/src/utils/quote.ts +129 -67
  190. package/src/utils/settings.ts +2 -4
  191. package/src/utils/swap.ts +37 -77
  192. package/src/utils/wallets.ts +14 -9
  193. package/dist/components/HeaderButtons/HomeButtons.d.ts +0 -4
  194. package/dist/components/HeaderButtons/HomeButtons.d.ts.map +0 -1
  195. package/dist/hooks/useFetchQuote.d.ts +0 -9
  196. package/dist/hooks/useFetchQuote.d.ts.map +0 -1
  197. package/src/hooks/useFetchQuote.ts +0 -38
@@ -38,7 +38,6 @@ export interface ConnectedWallet extends Wallet {
38
38
  interface WalletsStore {
39
39
  connectedWallets: ConnectedWallet[];
40
40
  balances: TokensBalance;
41
- customDestination: string;
42
41
  loading: boolean;
43
42
  connectWallet: (accounts: Wallet[], tokens: Token[]) => void;
44
43
  disconnectWallet: (walletType: WalletType) => void;
@@ -57,7 +56,6 @@ export const useWalletsStore = createSelectors(
57
56
  subscribeWithSelector((set, get) => ({
58
57
  connectedWallets: [],
59
58
  balances: {},
60
- customDestination: '',
61
59
  loading: false,
62
60
  connectWallet: (accounts, tokens) => {
63
61
  const getWalletsDetails = get().getWalletsDetails;
@@ -2,7 +2,12 @@
2
2
 
3
3
  import type { PriceImpactWarningLevel } from '@rango-dev/ui';
4
4
  import type BigNumber from 'bignumber.js';
5
- import type { SwapResult } from 'rango-sdk';
5
+ import type {
6
+ BlockchainValidationStatus,
7
+ RouteTag,
8
+ RoutingResultType,
9
+ SwapResult,
10
+ } from 'rango-sdk';
6
11
 
7
12
  export enum QuoteErrorType {
8
13
  NO_RESULT,
@@ -105,3 +110,24 @@ export type ConfirmSwapWarnings = {
105
110
  quoteUpdate: QuoteUpdateWarning | null;
106
111
  balance: { messages: string[] } | null;
107
112
  };
113
+
114
+ export type QuoteResponse = {
115
+ requestId: string;
116
+ swaps?: SwapResult[];
117
+ diagnosisMessages: string[] | null;
118
+ };
119
+
120
+ export type SelectedQuote = {
121
+ swaps: SwapResult[];
122
+ requestId: string;
123
+ outputAmount?: string;
124
+ resultType?: RoutingResultType;
125
+ tags?: RouteTag[];
126
+ validationStatus: BlockchainValidationStatus[] | null;
127
+ requestAmount: string;
128
+ };
129
+
130
+ export type QuoteErrorResponse = {
131
+ message: string;
132
+ options: QuoteError;
133
+ };
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
- import type { QuoteError, QuoteWarning, Wallet } from '../types';
2
+ import type { QuoteWarning, SelectedQuote, Wallet } from '../types';
3
3
  import type { PriceImpactWarningLevel, Step } from '@rango-dev/ui';
4
4
  import type {
5
5
  SimulationAssetAndAmount,
@@ -7,8 +7,12 @@ import type {
7
7
  } from '@rango-dev/ui/dist/widget/ui/src/types/swaps';
8
8
  import type {
9
9
  Asset,
10
- BestRouteResponse,
11
10
  BlockchainMeta,
11
+ MultiRouteResponse,
12
+ MultiRouteSimulationResult,
13
+ PreferenceType,
14
+ RouteTag,
15
+ TagValue,
12
16
  Token,
13
17
  } from 'rango-sdk';
14
18
  import type { PendingSwap } from 'rango-types';
@@ -16,65 +20,60 @@ import type { PendingSwap } from 'rango-types';
16
20
  import { getLastSuccessfulStep } from '@rango-dev/queue-manager-rango-preset';
17
21
  import BigNumber from 'bignumber.js';
18
22
 
23
+ import { HIGH_PRIORITY_TAGS } from '../constants/quote';
19
24
  import { HIGHT_PRICE_IMPACT, LOW_PRICE_IMPACT } from '../constants/routing';
20
25
  import { HIGH_SLIPPAGE } from '../constants/swapSettings';
21
26
  import { getUsdValue } from '../store/quote';
22
- import { QuoteErrorType, QuoteWarningType } from '../types';
27
+ import { QuoteWarningType } from '../types';
23
28
 
24
29
  import { areEqual } from './common';
25
30
  import { findBlockchain, findToken } from './meta';
26
31
  import {
27
- checkSlippageErrors,
28
32
  checkSlippageWarnings,
29
- getLimitErrorMessage,
30
33
  getMinRequiredSlippage,
31
34
  getPercentageChange,
32
35
  getTotalFeeInUsd,
33
36
  hasHighValueLoss,
34
- hasLimitError,
35
37
  hasProperSlippage,
36
38
  } from './swap';
37
39
 
38
40
  export function getQuoteToTokenUsdPrice(
39
- quote: BestRouteResponse | null
41
+ quote: SelectedQuote | null
40
42
  ): number | null | undefined {
41
- return quote?.result?.swaps[quote?.result?.swaps.length - 1].to.usdPrice;
43
+ const swaps = quote?.swaps || [];
44
+ return swaps[swaps.length - 1].to.usdPrice;
42
45
  }
43
46
 
44
47
  export function isNumberOfSwapsChanged(
45
- quoteA: BestRouteResponse,
46
- quoteB: BestRouteResponse
48
+ quoteA: SelectedQuote,
49
+ quoteB: SelectedQuote
47
50
  ) {
48
- const quoteASwaps = quoteA.result?.swaps || [];
49
- const quoteBSwaps = quoteB.result?.swaps || [];
51
+ const quoteASwaps = quoteA?.swaps || [];
52
+ const quoteBSwaps = quoteB?.swaps || [];
50
53
  return quoteASwaps.length !== quoteBSwaps.length;
51
54
  }
52
55
 
53
56
  export function isQuoteSwappersUpdated(
54
- quoteA: BestRouteResponse,
55
- quoteB: BestRouteResponse
57
+ quoteA: SelectedQuote,
58
+ quoteB: SelectedQuote
56
59
  ) {
57
- const quoteASwappers =
58
- quoteA.result?.swaps.map((swap) => swap.swapperId) || [];
59
- const quoteBSwappers =
60
- quoteB.result?.swaps.map((swap) => swap.swapperId) || [];
60
+ const quoteASwappers = quoteA?.swaps.map((swap) => swap.swapperId) || [];
61
+ const quoteBSwappers = quoteB?.swaps.map((swap) => swap.swapperId) || [];
61
62
  return !areEqual(quoteASwappers, quoteBSwappers);
62
63
  }
63
64
 
64
65
  export function isQuoteInternalCoinsUpdated(
65
- quoteA: BestRouteResponse,
66
- quoteB: BestRouteResponse
66
+ quoteA: SelectedQuote,
67
+ quoteB: SelectedQuote
67
68
  ) {
68
- const quoteAInternalCoins =
69
- quoteA.result?.swaps.map((swap) => swap.to.symbol) || [];
70
- const quoteBInternalCoins =
71
- quoteB.result?.swaps.map((swap) => swap.to.symbol) || [];
69
+ const quoteAInternalCoins = quoteA?.swaps.map((swap) => swap.to.symbol) || [];
70
+ const quoteBInternalCoins = quoteB?.swaps.map((swap) => swap.to.symbol) || [];
72
71
  return !areEqual(quoteAInternalCoins, quoteBInternalCoins);
73
72
  }
74
73
 
75
74
  export function isQuoteChanged(
76
- quoteA: BestRouteResponse,
77
- quoteB: BestRouteResponse
75
+ quoteA: SelectedQuote,
76
+ quoteB: SelectedQuote
78
77
  ): boolean {
79
78
  return (
80
79
  isNumberOfSwapsChanged(quoteA, quoteB) ||
@@ -198,7 +197,7 @@ export function createRetryQuote(
198
197
  }
199
198
 
200
199
  export function generateQuoteWarnings(
201
- quote: BestRouteResponse,
200
+ quote: SelectedQuote,
202
201
  params: {
203
202
  fromToken: Token;
204
203
  toToken: Token;
@@ -208,9 +207,9 @@ export function generateQuoteWarnings(
208
207
  ): QuoteWarning | null {
209
208
  const { fromToken, toToken, tokens, userSlippage } = params;
210
209
  const inputUsdValue = getUsdValue(fromToken, quote.requestAmount);
211
- const outputUsdValue = getUsdValue(toToken, quote.result?.outputAmount ?? '');
210
+ const outputUsdValue = getUsdValue(toToken, quote?.outputAmount ?? '');
212
211
 
213
- if (quote.result && inputUsdValue && outputUsdValue) {
212
+ if (!!quote && inputUsdValue && outputUsdValue) {
214
213
  const priceImpact = getPriceImpact(
215
214
  inputUsdValue.toString(),
216
215
  outputUsdValue.toString()
@@ -219,7 +218,7 @@ export function generateQuoteWarnings(
219
218
  !!priceImpact && hasHighValueLoss(inputUsdValue, priceImpact);
220
219
 
221
220
  if (highValueLoss) {
222
- const totalFee = getTotalFeeInUsd(quote.result.swaps, tokens);
221
+ const totalFee = getTotalFeeInUsd(quote?.swaps, tokens);
223
222
  const warningLevel = getPriceImpactLevel(priceImpact);
224
223
  return {
225
224
  type: QuoteWarningType.HIGH_VALUE_LOSS,
@@ -230,11 +229,11 @@ export function generateQuoteWarnings(
230
229
  warningLevel,
231
230
  };
232
231
  }
233
- } else if (quote.result && (!inputUsdValue || !outputUsdValue)) {
232
+ } else if (quote && (!inputUsdValue || !outputUsdValue)) {
234
233
  return { type: QuoteWarningType.UNKNOWN_PRICE };
235
234
  }
236
235
 
237
- const minRequiredSlippage = getMinRequiredSlippage(quote);
236
+ const minRequiredSlippage = getMinRequiredSlippage(quote.swaps);
238
237
  const highSlippage = userSlippage > HIGH_SLIPPAGE;
239
238
 
240
239
  if (!hasProperSlippage(params.userSlippage.toString(), minRequiredSlippage)) {
@@ -256,41 +255,6 @@ export function generateQuoteWarnings(
256
255
  return null;
257
256
  }
258
257
 
259
- export function generateQuoteErrors(
260
- quote: BestRouteResponse
261
- ): QuoteError | null {
262
- if (!quote.result) {
263
- return {
264
- type: QuoteErrorType.NO_RESULT,
265
- diagnosisMessage: quote.diagnosisMessages?.[0],
266
- };
267
- }
268
- const limitError = hasLimitError(quote);
269
- if (limitError) {
270
- const { swap, recommendation, fromAmountRangeError } =
271
- getLimitErrorMessage(quote);
272
- return {
273
- type: QuoteErrorType.BRIDGE_LIMIT,
274
- swap: swap,
275
- recommendation,
276
- fromAmountRangeError,
277
- };
278
- }
279
-
280
- const recommendedSlippages = checkSlippageErrors(quote);
281
-
282
- if (recommendedSlippages) {
283
- const minRequiredSlippage = getMinRequiredSlippage(quote);
284
- return {
285
- type: QuoteErrorType.INSUFFICIENT_SLIPPAGE,
286
- recommendedSlippages,
287
- minRequiredSlippage,
288
- };
289
- }
290
-
291
- return null;
292
- }
293
-
294
258
  export function getPriceImpact(
295
259
  inputUsdValue: BigNumber | string | null,
296
260
  outputUsdValue: BigNumber | string | null
@@ -326,3 +290,101 @@ export const getUniqueBlockchains = (steps: Step[]) => {
326
290
 
327
291
  return result;
328
292
  };
293
+
294
+ export const sortQuotesBy = (
295
+ strategy: PreferenceType,
296
+ quotes: MultiRouteResponse['results']
297
+ ): MultiRouteResponse['results'] => {
298
+ return quotes.sort((quote1, quote2) => {
299
+ const getScore = (route: MultiRouteSimulationResult) =>
300
+ route.scores?.find((score) => score.preferenceType === strategy)?.score ??
301
+ 0;
302
+
303
+ const quote1Score = getScore(quote1);
304
+ const quote2Score = getScore(quote2);
305
+
306
+ if (quote1Score !== quote2Score) {
307
+ return quote2Score - quote1Score;
308
+ }
309
+
310
+ const lowerQuoteId1 = quote1.requestId.toLowerCase();
311
+ const lowerQuoteId2 = quote2.requestId.toLowerCase();
312
+
313
+ return lowerQuoteId1.localeCompare(lowerQuoteId2);
314
+ });
315
+ };
316
+
317
+ export const getDefaultQuote = (
318
+ currentQuote: SelectedQuote | null,
319
+ quotes: MultiRouteSimulationResult[],
320
+ requestAmount: string
321
+ ): SelectedQuote | null => {
322
+ if (!quotes.length) {
323
+ return null;
324
+ }
325
+ if (!currentQuote) {
326
+ // Handle the case where currentQuote is null
327
+ return {
328
+ requestAmount: requestAmount,
329
+ ...quotes[0], // Return the first quote from the quotes array
330
+ };
331
+ }
332
+ // Create a set of swapperIds from the currentQuote swaps
333
+ const currentQuoteSwapperIds = new Set(
334
+ currentQuote.swaps.map((swap) => swap.swapperId)
335
+ );
336
+
337
+ // Find a quote that matches the currentQuote's swapperIds
338
+ const matchedQuote = quotes.find((quote) => {
339
+ // Create a set of swapperIds from the quote swaps
340
+ const quoteSwapperIds = new Set(quote.swaps.map((swap) => swap.swapperId));
341
+
342
+ // Check if all swapperIds from the currentQuote are present in the quoteSwapperIds
343
+ return Array.from(currentQuoteSwapperIds).every((swapperId) =>
344
+ quoteSwapperIds.has(swapperId)
345
+ );
346
+ });
347
+
348
+ // Return the matchedQuote if found, otherwise return the first quote from the quotes array
349
+ return {
350
+ requestAmount: requestAmount,
351
+ ...(matchedQuote || quotes[0]),
352
+ };
353
+ };
354
+
355
+ export const sortTags = (tags: RouteTag[]): RouteTag[] => {
356
+ const customSort = (a: RouteTag, b: RouteTag) => {
357
+ const indexA = HIGH_PRIORITY_TAGS.indexOf(a.value);
358
+ const indexB = HIGH_PRIORITY_TAGS.indexOf(b.value);
359
+
360
+ if (indexA !== -1 && indexB !== -1) {
361
+ return indexA - indexB;
362
+ }
363
+
364
+ if (indexA !== -1) {
365
+ return -1;
366
+ } else if (indexB !== -1) {
367
+ return 1;
368
+ }
369
+
370
+ return 0;
371
+ };
372
+
373
+ return tags.sort(customSort);
374
+ };
375
+
376
+ export const getRouteTagColor = (tag: TagValue): string => {
377
+ switch (tag) {
378
+ case 'FASTEST':
379
+ return '#06C270';
380
+ case 'RECOMMENDED':
381
+ return '#469BF5';
382
+ case 'LOWEST_FEE':
383
+ return '#FF4DAD';
384
+ case 'HIGH_IMPACT':
385
+ return '#FF3B3B';
386
+ case 'CENTRALIZED':
387
+ default:
388
+ return '#FFF1D4';
389
+ }
390
+ };
@@ -1,15 +1,13 @@
1
1
  import type { Features } from '../types';
2
- import type { SwapperMeta } from 'rango-sdk';
2
+ import type { SwapperMeta, SwapperType } from 'rango-sdk';
3
3
 
4
4
  import { removeDuplicateFrom } from './common';
5
5
 
6
- export type LiquiditySourceType = 'BRIDGE' | 'AGGREGATOR' | 'DEX';
7
-
8
6
  export type UniqueSwappersGroupType = {
9
7
  id: string;
10
8
  groupTitle: string;
11
9
  logo: string;
12
- type: LiquiditySourceType;
10
+ type: SwapperType;
13
11
  selected: boolean;
14
12
  };
15
13
 
package/src/utils/swap.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
2
  import type { FeesGroup, NameOfFees } from '../constants/quote';
3
3
  import type { FetchStatus } from '../store/slices/data';
4
+ import type { ConnectedWallet } from '../store/wallets';
4
5
  import type {
5
6
  ConvertedToken,
6
7
  QuoteError,
7
8
  QuoteWarning,
8
9
  RecommendedSlippages,
10
+ SelectedQuote,
9
11
  SwapButtonState,
10
12
  Wallet,
11
13
  } from '../types';
12
14
  import type { WalletType } from '@rango-dev/wallets-shared';
13
15
  import type {
14
16
  BestRouteRequest,
15
- BestRouteResponse,
16
17
  BlockchainMeta,
17
18
  RecommendedSlippage,
18
19
  SwapFee,
@@ -36,7 +37,6 @@ import {
36
37
  TOKEN_AMOUNT_MIN_DECIMALS,
37
38
  } from '../constants/routing';
38
39
 
39
- import { removeDuplicateFrom } from './common';
40
40
  import { getBlockchainShortNameFor } from './meta';
41
41
  import { numberToString } from './numbers';
42
42
  import { getPriceImpact, getRequiredBalanceOfWallet } from './quote';
@@ -74,9 +74,9 @@ export function hasHighValueLoss(
74
74
  );
75
75
  }
76
76
 
77
- export function hasLimitError(quote: BestRouteResponse | null): boolean {
77
+ export function hasLimitError(swaps: SwapResult[]): boolean {
78
78
  return (
79
- (quote?.result?.swaps || []).filter((swap) => {
79
+ (swaps || []).filter((swap) => {
80
80
  const minimum = !!swap.fromAmountMinValue
81
81
  ? new BigNumber(swap.fromAmountMinValue)
82
82
  : null;
@@ -91,12 +91,13 @@ export function hasLimitError(quote: BestRouteResponse | null): boolean {
91
91
  }).length > 0
92
92
  );
93
93
  }
94
- export function getLimitErrorMessage(quote: BestRouteResponse): {
94
+
95
+ export function getLimitErrorMessage(swaps: SwapResult[]): {
95
96
  swap: SwapResult;
96
97
  fromAmountRangeError: string;
97
98
  recommendation: string;
98
99
  } {
99
- const swap = (quote.result?.swaps || []).filter((swap) => {
100
+ const swap = (swaps || []).filter((swap) => {
100
101
  const minimum = !!swap.fromAmountMinValue
101
102
  ? new BigNumber(swap.fromAmountMinValue)
102
103
  : null;
@@ -184,7 +185,7 @@ export function getSwapButtonState(params: {
184
185
  anyWalletConnected: boolean;
185
186
  fetchingQuote: boolean;
186
187
  inputAmount: string;
187
- quote: BestRouteResponse | null;
188
+ quote: SelectedQuote | null;
188
189
  warning: QuoteWarning | null;
189
190
  error: QuoteError | null;
190
191
  needsToWarnEthOnPath: boolean;
@@ -213,14 +214,7 @@ export function getSwapButtonState(params: {
213
214
  disabled: false,
214
215
  };
215
216
  }
216
- if (
217
- fetchingQuote ||
218
- !quote ||
219
- !quote.result ||
220
- error ||
221
- !inputAmount ||
222
- inputAmount === '0'
223
- ) {
217
+ if (fetchingQuote || !quote || error || !inputAmount || inputAmount === '0') {
224
218
  return {
225
219
  title: swapButtonTitles().swap,
226
220
  action: 'confirm-swap',
@@ -247,24 +241,24 @@ export function getSwapButtonState(params: {
247
241
  }
248
242
 
249
243
  export function canComputePriceImpact(
250
- quote: BestRouteResponse | null,
244
+ quote: SelectedQuote | null,
251
245
  inputAmount: string,
252
246
  usdValue: BigNumber | null
253
247
  ) {
254
248
  return !(
255
249
  (!usdValue || usdValue.lte(ZERO)) &&
256
- !!quote?.result &&
250
+ !!quote &&
257
251
  !!inputAmount &&
258
252
  inputAmount !== '0' &&
259
253
  parseFloat(inputAmount || '0') !== 0 &&
260
- !!quote.result
254
+ !!quote
261
255
  );
262
256
  }
263
257
 
264
- export function requiredWallets(quote: BestRouteResponse | null) {
258
+ export function requiredWallets(quote: SelectedQuote | null) {
265
259
  const wallets: string[] = [];
266
260
 
267
- quote?.result?.swaps.forEach((swap) => {
261
+ quote?.swaps.forEach((swap) => {
268
262
  const currentStepFromBlockchain = swap.from.blockchain;
269
263
  const currentStepToBlockchain = swap.to.blockchain;
270
264
  let lastAddedWallet = wallets[wallets.length - 1];
@@ -377,10 +371,10 @@ export function hasSlippageError(
377
371
  }
378
372
 
379
373
  export function checkSlippageErrors(
380
- quote: BestRouteResponse
374
+ swaps: SwapResult[]
381
375
  ): RecommendedSlippages | null {
382
376
  const recommendedSlippages: RecommendedSlippages = new Map();
383
- quote.result?.swaps.forEach((swap, index) => {
377
+ swaps.forEach((swap, index) => {
384
378
  if (swap.recommendedSlippage?.error) {
385
379
  recommendedSlippages.set(index, swap.recommendedSlippage.slippage);
386
380
  }
@@ -392,11 +386,11 @@ export function checkSlippageErrors(
392
386
  }
393
387
 
394
388
  export function checkSlippageWarnings(
395
- quote: BestRouteResponse,
389
+ quote: SelectedQuote,
396
390
  userSlippage: number
397
391
  ): RecommendedSlippages | null {
398
392
  const recommendedSlippages: RecommendedSlippages = new Map();
399
- quote.result?.swaps.forEach((swap, index) => {
393
+ quote?.swaps.forEach((swap, index) => {
400
394
  if (
401
395
  swap.recommendedSlippage?.slippage &&
402
396
  parseFloat(swap.recommendedSlippage.slippage) > userSlippage
@@ -410,12 +404,8 @@ export function checkSlippageWarnings(
410
404
  return null;
411
405
  }
412
406
 
413
- export function getMinRequiredSlippage(
414
- quote: BestRouteResponse
415
- ): string | null {
416
- const slippages = quote.result?.swaps.map(
417
- (slippage) => slippage.recommendedSlippage
418
- );
407
+ export function getMinRequiredSlippage(swaps: SwapResult[]): string | null {
408
+ const slippages = swaps.map((slippage) => slippage.recommendedSlippage);
419
409
  return (
420
410
  slippages
421
411
  ?.map((s) => s?.slippage || '0')
@@ -436,7 +426,7 @@ export function hasProperSlippage(
436
426
  }
437
427
 
438
428
  export function hasEnoughBalance(
439
- quote: BestRouteResponse,
429
+ quote: SelectedQuote,
440
430
  selectedWallets: Wallet[]
441
431
  ) {
442
432
  const fee = quote.validationStatus;
@@ -463,7 +453,7 @@ export function hasEnoughBalance(
463
453
  }
464
454
 
465
455
  export function hasEnoughBalanceAndProperSlippage(
466
- quote: BestRouteResponse,
456
+ quote: SelectedQuote,
467
457
  selectedWallets: Wallet[],
468
458
  userSlippage: string,
469
459
  minRequiredSlippage: string | null
@@ -478,7 +468,7 @@ export function createQuoteRequestBody(params: {
478
468
  fromToken: Token;
479
469
  toToken: Token;
480
470
  inputAmount: string;
481
- wallets?: Wallet[];
471
+ wallets?: ConnectedWallet[];
482
472
  selectedWallets?: Wallet[];
483
473
  liquiditySources?: string[];
484
474
  excludeLiquiditySources?: boolean;
@@ -487,7 +477,6 @@ export function createQuoteRequestBody(params: {
487
477
  affiliateRef: string | null;
488
478
  affiliatePercent: number | null;
489
479
  affiliateWallets: { [key: string]: string } | null;
490
- initialQuote?: BestRouteResponse;
491
480
  destination?: string;
492
481
  }): BestRouteRequest {
493
482
  const {
@@ -503,7 +492,6 @@ export function createQuoteRequestBody(params: {
503
492
  affiliateRef,
504
493
  affiliatePercent,
505
494
  affiliateWallets,
506
- initialQuote,
507
495
  destination,
508
496
  } = params;
509
497
  const selectedWalletsMap = selectedWallets?.reduce(
@@ -520,46 +508,18 @@ export function createQuoteRequestBody(params: {
520
508
  const connectedWallets: BestRouteRequest['connectedWallets'] = [];
521
509
 
522
510
  wallets?.forEach((wallet) => {
523
- const chainAndAccounts = connectedWallets.find(
524
- (connectedWallet) => connectedWallet.blockchain === wallet.chain
525
- );
526
- if (!!chainAndAccounts) {
527
- chainAndAccounts.addresses.push(wallet.address);
528
- } else {
529
- connectedWallets.push({
530
- blockchain: wallet.chain,
531
- addresses: [wallet.address],
532
- });
533
- }
511
+ connectedWallets.push({
512
+ blockchain: wallet.chain,
513
+ addresses: [wallet.address],
514
+ });
534
515
  });
535
-
536
- const checkPrerequisites = !!initialQuote;
537
-
538
- const filteredBlockchains = removeDuplicateFrom(
539
- (initialQuote?.result?.swaps || []).reduce(
540
- (blockchains: string[], swap) => {
541
- blockchains.push(swap.from.blockchain, swap.to.blockchain);
542
- // Check if internalSwaps array exists
543
- if (swap.internalSwaps && Array.isArray(swap.internalSwaps)) {
544
- swap.internalSwaps.map((internalSwap) => {
545
- blockchains.push(
546
- internalSwap.from.blockchain,
547
- internalSwap.to.blockchain
548
- );
549
- });
550
- }
551
- return blockchains;
552
- },
553
- []
554
- )
555
- );
556
-
516
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
517
+ // @ts-ignore
557
518
  const requestBody: BestRouteRequest = {
558
519
  amount: inputAmount.toString(),
559
520
  affiliateRef: affiliateRef ?? undefined,
560
521
  affiliatePercent: affiliatePercent ?? undefined,
561
522
  affiliateWallets: affiliateWallets ?? undefined,
562
- checkPrerequisites,
563
523
  from: {
564
524
  address: fromToken.address,
565
525
  blockchain: fromToken.blockchain,
@@ -584,7 +544,6 @@ export function createQuoteRequestBody(params: {
584
544
  ),
585
545
  swappersGroupsExclude: false,
586
546
  }),
587
- ...(checkPrerequisites && { blockchains: filteredBlockchains }),
588
547
  };
589
548
  return requestBody;
590
549
  }
@@ -609,8 +568,8 @@ export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
609
568
  return wallets;
610
569
  }
611
570
 
612
- export function getQuoteOutputAmount(quote: BestRouteResponse) {
613
- return quote.result?.outputAmount || null;
571
+ export function getQuoteOutputAmount(quote: SelectedQuote) {
572
+ return quote?.outputAmount || null;
614
573
  }
615
574
 
616
575
  export function getPercentageChange(input: string, output: string) {
@@ -622,8 +581,8 @@ export function getPercentageChange(input: string, output: string) {
622
581
  }
623
582
 
624
583
  export function isOutputAmountChangedALot(
625
- oldQuote: BestRouteResponse,
626
- newQuote: BestRouteResponse
584
+ oldQuote: SelectedQuote,
585
+ newQuote: SelectedQuote
627
586
  ) {
628
587
  const oldOutputAmount = getQuoteOutputAmount(oldQuote);
629
588
  const newOutputAmount = getQuoteOutputAmount(newQuote);
@@ -639,7 +598,7 @@ export function isOutputAmountChangedALot(
639
598
  }
640
599
 
641
600
  export function generateBalanceWarnings(
642
- quote: BestRouteResponse,
601
+ quote: SelectedQuote,
643
602
  selectedWallets: Wallet[],
644
603
  blockchains: BlockchainMeta[]
645
604
  ) {
@@ -650,6 +609,7 @@ export function generateBalanceWarnings(
650
609
  requiredWallets.indexOf(selectedWallet1.chain) -
651
610
  requiredWallets.indexOf(selectedWallet2.chain)
652
611
  );
612
+
653
613
  return walletsSortedByRequiredWallets
654
614
  .flatMap((wallet) => getRequiredBalanceOfWallet(wallet, fee) || [])
655
615
  .filter((asset) => !asset.ok)
@@ -797,8 +757,8 @@ export function shouldRetrySwap(pendingSwap: PendingSwap) {
797
757
  export function confirmSwapDisabled(
798
758
  fetching: boolean,
799
759
  showCustomDestination: boolean,
800
- customDestination: string,
801
- quote: BestRouteResponse | null,
760
+ customDestination: string | null,
761
+ quote: SelectedQuote | null,
802
762
  selectedWallets: { walletType: string; chain: string }[],
803
763
  lastStepToBlockchain?: BlockchainMeta
804
764
  ) {