@rango-dev/widget-embedded 0.17.1-next.2 → 0.17.1-next.4

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/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +1 -3
  2. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +1 -1
  5. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
  6. package/dist/components/NoResult/NoResult.d.ts +4 -0
  7. package/dist/components/NoResult/NoResult.d.ts.map +1 -0
  8. package/dist/components/NoResult/NoResult.helpers.d.ts +4 -0
  9. package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -0
  10. package/dist/components/{NoRoutes/NoRoutes.styles.d.ts → NoResult/NoResult.styles.d.ts} +1 -1
  11. package/dist/components/{NoRoutes/NoRoutes.styles.d.ts.map → NoResult/NoResult.styles.d.ts.map} +1 -1
  12. package/dist/components/{NoRoutes/NoRoutes.types.d.ts → NoResult/NoResult.types.d.ts} +3 -3
  13. package/dist/components/NoResult/NoResult.types.d.ts.map +1 -0
  14. package/dist/components/NoResult/index.d.ts +2 -0
  15. package/dist/components/NoResult/index.d.ts.map +1 -0
  16. package/dist/components/Quote/Quote.d.ts +4 -0
  17. package/dist/components/Quote/Quote.d.ts.map +1 -0
  18. package/dist/components/Quote/Quote.styles.d.ts +1429 -0
  19. package/dist/components/Quote/Quote.styles.d.ts.map +1 -0
  20. package/dist/components/Quote/Quote.types.d.ts +22 -0
  21. package/dist/components/Quote/Quote.types.d.ts.map +1 -0
  22. package/dist/components/Quote/QuoteSkeleton.d.ts +4 -0
  23. package/dist/components/Quote/QuoteSkeleton.d.ts.map +1 -0
  24. package/dist/components/Quote/QuoteSkeleton.styles.d.ts +319 -0
  25. package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +1 -0
  26. package/dist/components/Quote/QuoteSkeleton.types.d.ts +6 -0
  27. package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +1 -0
  28. package/dist/components/Quote/QuoteSummary.d.ts +11 -0
  29. package/dist/components/Quote/QuoteSummary.d.ts.map +1 -0
  30. package/dist/components/Quote/QuoteSummary.styles.d.ts +158 -0
  31. package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -0
  32. package/dist/components/Quote/index.d.ts +4 -0
  33. package/dist/components/Quote/index.d.ts.map +1 -0
  34. package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +11 -0
  35. package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -0
  36. package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +4 -0
  37. package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +1 -0
  38. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +4 -0
  39. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -0
  40. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +9 -0
  41. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -0
  42. package/dist/components/{RouteErrors/RouteErrors.styles.d.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts} +1 -1
  43. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -0
  44. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +22 -0
  45. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -0
  46. package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +11 -0
  47. package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -0
  48. package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +11 -0
  49. package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -0
  50. package/dist/components/QuoteWarningsAndErrors/index.d.ts +2 -0
  51. package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +1 -0
  52. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  53. package/dist/components/WidgetEvents.d.ts.map +1 -1
  54. package/dist/constants/errors.d.ts +4 -4
  55. package/dist/constants/errors.d.ts.map +1 -1
  56. package/dist/constants/messages.d.ts +1 -1
  57. package/dist/constants/warnings.d.ts +2 -2
  58. package/dist/constants/warnings.d.ts.map +1 -1
  59. package/dist/containers/QuoteInfo/QuoteInfo.d.ts +4 -0
  60. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -0
  61. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +472 -0
  62. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -0
  63. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +17 -0
  64. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -0
  65. package/dist/containers/QuoteInfo/index.d.ts +2 -0
  66. package/dist/containers/QuoteInfo/index.d.ts.map +1 -0
  67. package/dist/hooks/useConfirmSwap/index.d.ts +2 -0
  68. package/dist/hooks/useConfirmSwap/index.d.ts.map +1 -0
  69. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +3 -0
  70. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -0
  71. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +16 -0
  72. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -0
  73. package/dist/hooks/{useConfirmSwap.d.ts → useConfirmSwap/useConfirmSwap.types.d.ts} +5 -7
  74. package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -0
  75. package/dist/hooks/{useFetchBestRoute.d.ts → useFetchQuote.d.ts} +3 -3
  76. package/dist/hooks/useFetchQuote.d.ts.map +1 -0
  77. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
  78. package/dist/hooks/useSwapInput.d.ts +4 -2
  79. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  80. package/dist/index.js +1 -1
  81. package/dist/index.js.map +4 -4
  82. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  83. package/dist/pages/Home.d.ts.map +1 -1
  84. package/dist/store/app.d.ts +2 -2
  85. package/dist/store/{bestRoute.d.ts → quote.d.ts} +25 -20
  86. package/dist/store/quote.d.ts.map +1 -0
  87. package/dist/types/index.d.ts +1 -1
  88. package/dist/types/index.d.ts.map +1 -1
  89. package/dist/types/quote.d.ts +82 -0
  90. package/dist/types/quote.d.ts.map +1 -0
  91. package/dist/utils/numbers.d.ts +1 -1
  92. package/dist/utils/numbers.d.ts.map +1 -1
  93. package/dist/utils/{routing.d.ts → quote.d.ts} +16 -12
  94. package/dist/utils/quote.d.ts.map +1 -0
  95. package/dist/utils/settings.d.ts +1 -1
  96. package/dist/utils/swap.d.ts +22 -20
  97. package/dist/utils/swap.d.ts.map +1 -1
  98. package/dist/utils/wallets.d.ts +1 -1
  99. package/package.json +3 -3
  100. package/src/components/BlockchainsSection/BlockchainsSection.tsx +3 -3
  101. package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +2 -64
  102. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +23 -26
  103. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +1 -1
  104. package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
  105. package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
  106. package/src/components/{NoRoutes/NoRoutes.helper.ts → NoResult/NoResult.helpers.ts} +16 -9
  107. package/src/components/{NoRoutes/NoRoutes.styles.ts → NoResult/NoResult.styles.ts} +2 -0
  108. package/src/components/{NoRoutes/NoRoutes.tsx → NoResult/NoResult.tsx} +7 -12
  109. package/src/components/{NoRoutes/NoRoutes.types.ts → NoResult/NoResult.types.ts} +3 -2
  110. package/src/components/NoResult/index.ts +1 -0
  111. package/src/components/Quote/Quote.styles.ts +212 -0
  112. package/src/components/Quote/Quote.tsx +347 -0
  113. package/src/components/Quote/Quote.types.ts +16 -0
  114. package/src/components/Quote/QuoteSkeleton.styles.ts +110 -0
  115. package/src/components/Quote/QuoteSkeleton.tsx +108 -0
  116. package/src/components/Quote/QuoteSkeleton.types.ts +5 -0
  117. package/src/components/Quote/QuoteSummary.styles.ts +15 -0
  118. package/src/components/Quote/QuoteSummary.tsx +46 -0
  119. package/src/components/Quote/index.ts +3 -0
  120. package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +107 -0
  121. package/src/components/{RouteErrors/RouteErrorsModalItem.tsx → QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx} +3 -3
  122. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +67 -0
  123. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +103 -0
  124. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +24 -0
  125. package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +77 -0
  126. package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +38 -0
  127. package/src/components/QuoteWarningsAndErrors/index.ts +1 -0
  128. package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
  129. package/src/components/SwapDetails/SwapDetails.tsx +13 -16
  130. package/src/components/SwitchFromAndTo.tsx +2 -2
  131. package/src/components/UpdateUrl.tsx +12 -12
  132. package/src/components/WidgetEvents.tsx +2 -3
  133. package/src/constants/errors.ts +8 -10
  134. package/src/constants/messages.ts +1 -1
  135. package/src/constants/warnings.ts +7 -7
  136. package/src/containers/QuoteInfo/QuoteInfo.styles.ts +15 -0
  137. package/src/containers/QuoteInfo/QuoteInfo.tsx +97 -0
  138. package/src/containers/QuoteInfo/QuoteInfo.types.ts +17 -0
  139. package/src/containers/QuoteInfo/index.ts +1 -0
  140. package/src/hooks/useConfirmSwap/index.ts +1 -0
  141. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +168 -0
  142. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +136 -0
  143. package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +19 -0
  144. package/src/hooks/{useFetchBestRoute.ts → useFetchQuote.ts} +3 -3
  145. package/src/hooks/useNavigateBack.ts +3 -3
  146. package/src/hooks/useSwapInput.ts +57 -23
  147. package/src/hooks/useSyncStoresWithConfig.ts +2 -2
  148. package/src/pages/ConfirmSwapPage.tsx +58 -227
  149. package/src/pages/HistoryPage.tsx +1 -1
  150. package/src/pages/Home.tsx +52 -241
  151. package/src/pages/LanguagePage.tsx +1 -1
  152. package/src/pages/LiquiditySourcePage.tsx +1 -1
  153. package/src/pages/SelectBlockchainPage.tsx +3 -3
  154. package/src/pages/SelectSwapItemsPage.tsx +2 -2
  155. package/src/pages/SettingsPage.tsx +1 -1
  156. package/src/pages/ThemePage.tsx +1 -1
  157. package/src/pages/WalletsPage.tsx +1 -1
  158. package/src/store/{bestRoute.ts → quote.ts} +42 -38
  159. package/src/types/index.ts +1 -1
  160. package/src/types/quote.ts +107 -0
  161. package/src/utils/numbers.ts +1 -1
  162. package/src/utils/quote.ts +338 -0
  163. package/src/utils/swap.ts +99 -69
  164. package/src/utils/wallets.ts +2 -2
  165. package/dist/components/NoRoutes/NoRoutes.d.ts +0 -4
  166. package/dist/components/NoRoutes/NoRoutes.d.ts.map +0 -1
  167. package/dist/components/NoRoutes/NoRoutes.helper.d.ts +0 -3
  168. package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +0 -1
  169. package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +0 -1
  170. package/dist/components/NoRoutes/index.d.ts +0 -2
  171. package/dist/components/NoRoutes/index.d.ts.map +0 -1
  172. package/dist/components/RouteErrors/RouteErrors.d.ts +0 -4
  173. package/dist/components/RouteErrors/RouteErrors.d.ts.map +0 -1
  174. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +0 -1
  175. package/dist/components/RouteErrors/RouteErrors.types.d.ts +0 -24
  176. package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +0 -1
  177. package/dist/components/RouteErrors/RouteErrorsModal.d.ts +0 -4
  178. package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +0 -1
  179. package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +0 -4
  180. package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +0 -1
  181. package/dist/components/RouteErrors/index.d.ts +0 -2
  182. package/dist/components/RouteErrors/index.d.ts.map +0 -1
  183. package/dist/hooks/useConfirmSwap.d.ts.map +0 -1
  184. package/dist/hooks/useFetchBestRoute.d.ts.map +0 -1
  185. package/dist/store/bestRoute.d.ts.map +0 -1
  186. package/dist/types/routing.d.ts +0 -65
  187. package/dist/types/routing.d.ts.map +0 -1
  188. package/dist/utils/routing.d.ts.map +0 -1
  189. package/src/components/NoRoutes/index.ts +0 -1
  190. package/src/components/RouteErrors/RouteErrors.tsx +0 -79
  191. package/src/components/RouteErrors/RouteErrors.types.ts +0 -29
  192. package/src/components/RouteErrors/RouteErrorsModal.tsx +0 -129
  193. package/src/components/RouteErrors/index.ts +0 -1
  194. package/src/hooks/useConfirmSwap.ts +0 -303
  195. package/src/types/routing.ts +0 -77
  196. package/src/utils/routing.ts +0 -321
  197. /package/src/components/{RouteErrors/RouteErrors.styles.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts} +0 -0
@@ -9,21 +9,21 @@ import { subscribeWithSelector } from 'zustand/middleware';
9
9
 
10
10
  import { ZERO } from '../constants/numbers';
11
11
  import { isPositiveNumber } from '../utils/numbers';
12
- import {
13
- createRetryRoute,
14
- getBestRouteToTokenUsdPrice,
15
- } from '../utils/routing';
12
+ import { createRetryQuote, getQuoteToTokenUsdPrice } from '../utils/quote';
16
13
  import { calcOutputUsdValue } from '../utils/swap';
17
14
 
18
15
  import { useMetaStore } from './meta';
19
16
  import createSelectors from './selectors';
20
17
 
21
- const getUsdValue = (token: Token | null, amount: string): BigNumber | null =>
18
+ export const getUsdValue = (
19
+ token: Token | null,
20
+ amount: string
21
+ ): BigNumber | null =>
22
22
  token?.usdPrice
23
23
  ? new BigNumber(amount || ZERO).multipliedBy(token?.usdPrice || 0)
24
24
  : null;
25
25
 
26
- export interface RouteState {
26
+ export interface QuoteState {
27
27
  fromBlockchain: BlockchainMeta | null;
28
28
  toBlockchain: BlockchainMeta | null;
29
29
  inputAmount: string;
@@ -32,9 +32,10 @@ export interface RouteState {
32
32
  outputUsdValue: BigNumber | null;
33
33
  fromToken: TokenWithBalance | null;
34
34
  toToken: TokenWithBalance | null;
35
- routeWalletsConfirmed: boolean;
35
+ quoteWalletsConfirmed: boolean;
36
36
  selectedWallets: Wallet[];
37
- resetRoute: () => void;
37
+ quoteWarningsConfirmed: boolean;
38
+ resetQuote: () => void;
38
39
  resetToBlockchain: () => void;
39
40
  resetFromBlockchain: () => void;
40
41
  setFromBlockchain: (chain: BlockchainMeta | null) => void;
@@ -43,19 +44,20 @@ export interface RouteState {
43
44
  setFromToken: (token: Token | null) => void;
44
45
  setToToken: (token: Token | null) => void;
45
46
  setInputAmount: (amount: string) => void;
46
- bestRoute: BestRouteResponse | null;
47
- setRoute: (bestRoute: BestRouteResponse | null) => void;
47
+ quote: BestRouteResponse | null;
48
+ setQuote: (quote: BestRouteResponse | null) => void;
48
49
  retry: (pendingSwap: PendingSwap) => void;
49
50
  switchFromAndTo: () => void;
50
- setRouteWalletConfirmed: (flag: boolean) => void;
51
+ setQuoteWalletConfirmed: (flag: boolean) => void;
51
52
  setSelectedWallets: (wallets: Wallet[]) => void;
52
53
  customDestination: string;
53
54
  setCustomDestination: (address: string) => void;
54
- resetRouteWallets: () => void;
55
+ resetQuoteWallets: () => void;
56
+ setQuoteWarningsConfirmed: (flag: boolean) => void;
55
57
  }
56
58
 
57
- export const useBestRouteStore = createSelectors(
58
- create<RouteState>()(
59
+ export const useQuoteStore = createSelectors(
60
+ create<QuoteState>()(
59
61
  subscribeWithSelector((set) => ({
60
62
  fromBlockchain: null,
61
63
  fromToken: null,
@@ -65,37 +67,38 @@ export const useBestRouteStore = createSelectors(
65
67
  outputUsdValue: new BigNumber(0),
66
68
  toBlockchain: null,
67
69
  toToken: null,
68
- bestRoute: null,
69
- routeWalletsConfirmed: false,
70
+ quote: null,
71
+ quoteWalletsConfirmed: false,
70
72
  selectedWallets: [],
71
73
  customDestination: '',
72
- setRoute: (bestRoute) =>
74
+ quoteWarningsConfirmed: false,
75
+ setQuote: (quote) =>
73
76
  set((state) => {
74
77
  let outputAmount: BigNumber | null = null;
75
78
  let outputUsdValue: BigNumber = ZERO;
76
79
  if (!isPositiveNumber(state.inputAmount)) {
77
80
  return {};
78
81
  }
79
- if (!!bestRoute) {
80
- outputAmount = !!bestRoute.result?.outputAmount
81
- ? new BigNumber(bestRoute.result?.outputAmount)
82
+ if (!!quote) {
83
+ outputAmount = !!quote.result?.outputAmount
84
+ ? new BigNumber(quote.result?.outputAmount)
82
85
  : null;
83
86
  outputUsdValue = calcOutputUsdValue(
84
- bestRoute.result?.outputAmount,
85
- getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice
87
+ quote.result?.outputAmount,
88
+ getQuoteToTokenUsdPrice(quote) || state.toToken?.usdPrice
86
89
  );
87
90
  }
88
91
  return {
89
- bestRoute,
90
- ...(!!bestRoute && {
92
+ quote: quote,
93
+ ...(!!quote && {
91
94
  outputAmount,
92
95
  outputUsdValue,
93
96
  }),
94
97
  };
95
98
  }),
96
- resetRoute: () =>
99
+ resetQuote: () =>
97
100
  set(() => ({
98
- bestRoute: null,
101
+ quote: null,
99
102
  outputAmount: null,
100
103
  outputUsdValue: new BigNumber(0),
101
104
  })),
@@ -108,7 +111,7 @@ export const useBestRouteStore = createSelectors(
108
111
  return {
109
112
  fromBlockchain: chain,
110
113
  ...(state.fromToken && {
111
- bestRoute: null,
114
+ quote: null,
112
115
  fromToken: null,
113
116
  outputAmount: null,
114
117
  outputUsdValue: null,
@@ -140,7 +143,7 @@ export const useBestRouteStore = createSelectors(
140
143
  return {
141
144
  toBlockchain: chain,
142
145
  ...(state.toToken && {
143
- bestRoute: null,
146
+ quote: null,
144
147
  toToken: null,
145
148
  outputAmount: null,
146
149
  outputUsdValue: null,
@@ -166,7 +169,7 @@ export const useBestRouteStore = createSelectors(
166
169
  ...(!amount && {
167
170
  outputAmount: new BigNumber(0),
168
171
  outputUsdValue: new BigNumber(0),
169
- bestRoute: null,
172
+ quote: null,
170
173
  }),
171
174
  ...(!!state.fromToken && {
172
175
  inputUsdValue: getUsdValue(state.fromToken, amount),
@@ -182,7 +185,7 @@ export const useBestRouteStore = createSelectors(
182
185
  toBlockchain,
183
186
  toToken,
184
187
  inputAmount,
185
- } = createRetryRoute(pendingSwap, blockchains, tokens);
188
+ } = createRetryQuote(pendingSwap, blockchains, tokens);
186
189
 
187
190
  set({
188
191
  fromBlockchain,
@@ -193,7 +196,7 @@ export const useBestRouteStore = createSelectors(
193
196
  outputUsdValue: new BigNumber(0),
194
197
  toBlockchain,
195
198
  toToken,
196
- bestRoute: null,
199
+ quote: null,
197
200
  });
198
201
  },
199
202
  switchFromAndTo: () =>
@@ -208,14 +211,13 @@ export const useBestRouteStore = createSelectors(
208
211
  state.outputAmount?.toString() || ''
209
212
  ),
210
213
  })),
211
-
212
214
  resetFromBlockchain: () =>
213
215
  set(() => ({
214
216
  fromToken: null,
215
217
  fromBlockchain: null,
216
218
  outputAmount: null,
217
219
  outputUsdValue: null,
218
- bestRoute: null,
220
+ quote: null,
219
221
  })),
220
222
  resetToBlockchain: () =>
221
223
  set(() => ({
@@ -223,20 +225,22 @@ export const useBestRouteStore = createSelectors(
223
225
  toBlockchain: null,
224
226
  outputAmount: null,
225
227
  outputUsdValue: null,
226
- bestRoute: null,
228
+ quote: null,
227
229
  })),
228
- setRouteWalletConfirmed: (flag) =>
230
+ setQuoteWalletConfirmed: (flag) =>
229
231
  set({
230
- routeWalletsConfirmed: flag,
232
+ quoteWalletsConfirmed: flag,
231
233
  }),
232
234
  setSelectedWallets: (wallets) => set({ selectedWallets: wallets }),
233
235
  setCustomDestination: (address) => set({ customDestination: address }),
234
- resetRouteWallets: () =>
236
+ resetQuoteWallets: () =>
235
237
  set({
236
- routeWalletsConfirmed: false,
238
+ quoteWalletsConfirmed: false,
237
239
  selectedWallets: [],
238
240
  customDestination: '',
239
241
  }),
242
+ setQuoteWarningsConfirmed: (flag) =>
243
+ set({ quoteWarningsConfirmed: flag }),
240
244
  }))
241
245
  )
242
246
  );
@@ -1,4 +1,4 @@
1
1
  export * from './swap';
2
2
  export * from './config';
3
- export * from './routing';
3
+ export * from './quote';
4
4
  export * from './wallets';
@@ -0,0 +1,107 @@
1
+ /* eslint-disable @typescript-eslint/prefer-enum-initializers */
2
+
3
+ import type { PriceImpactWarningLevel } from '@rango-dev/ui';
4
+ import type BigNumber from 'bignumber.js';
5
+ import type { SwapResult } from 'rango-sdk';
6
+
7
+ export enum QuoteErrorType {
8
+ NO_RESULT,
9
+ REQUEST_FAILED,
10
+ REQUEST_CANCELED,
11
+ BRIDGE_LIMIT,
12
+ INSUFFICIENT_SLIPPAGE,
13
+ }
14
+
15
+ export type NoResultError = {
16
+ type: QuoteErrorType.NO_RESULT;
17
+ diagnosisMessage?: string;
18
+ };
19
+
20
+ export type BridgeLimitError = {
21
+ type: QuoteErrorType.BRIDGE_LIMIT;
22
+ swap: SwapResult;
23
+ recommendation: string;
24
+ fromAmountRangeError: string;
25
+ };
26
+
27
+ export type InsufficientSlippageError = {
28
+ type: QuoteErrorType.INSUFFICIENT_SLIPPAGE;
29
+ recommendedSlippages: RecommendedSlippages | null;
30
+ minRequiredSlippage: string | null;
31
+ };
32
+
33
+ export type QuoteRequestFailed = { type: QuoteErrorType.REQUEST_FAILED };
34
+ export type QuoteRequestCanceled = { type: QuoteErrorType.REQUEST_CANCELED };
35
+
36
+ export type QuoteError =
37
+ | NoResultError
38
+ | BridgeLimitError
39
+ | InsufficientSlippageError
40
+ | QuoteRequestFailed
41
+ | QuoteRequestCanceled;
42
+
43
+ export enum QuoteWarningType {
44
+ HIGH_VALUE_LOSS,
45
+ UNKNOWN_PRICE,
46
+ INSUFFICIENT_SLIPPAGE,
47
+ HIGH_SLIPPAGE,
48
+ }
49
+
50
+ export enum QuoteUpdateType {
51
+ QUOTE_UPDATED,
52
+ QUOTE_SWAPPERS_UPDATED,
53
+ QUOTE_COINS_UPDATED,
54
+ QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
55
+ QUOTE_UPDATED_WITH_HIGH_VALUE_LOSS,
56
+ }
57
+
58
+ export type QuoteUpdateWarning =
59
+ | {
60
+ type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED;
61
+ newOutputAmount: string;
62
+ percentageChange: string;
63
+ }
64
+ | {
65
+ type: Exclude<
66
+ QuoteUpdateType,
67
+ QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED
68
+ >;
69
+ };
70
+
71
+ export type RecommendedSlippages = Map<number, string>;
72
+
73
+ export type InsufficientSlippageWarning = {
74
+ type: QuoteWarningType.INSUFFICIENT_SLIPPAGE;
75
+ recommendedSlippages: RecommendedSlippages | null;
76
+ minRequiredSlippage: string | null;
77
+ };
78
+
79
+ export type HighSlippageWarning = {
80
+ type: QuoteWarningType.HIGH_SLIPPAGE;
81
+ slippage: string | null;
82
+ };
83
+
84
+ export type HighValueLossWarning = {
85
+ type: QuoteWarningType.HIGH_VALUE_LOSS;
86
+ warningLevel: PriceImpactWarningLevel;
87
+ inputUsdValue: BigNumber;
88
+ outputUsdValue: BigNumber;
89
+ totalFee: BigNumber;
90
+ priceImpact: number;
91
+ };
92
+
93
+ export type UnknownPriceWarning = {
94
+ type: QuoteWarningType.UNKNOWN_PRICE;
95
+ };
96
+
97
+ export type QuoteWarning =
98
+ | HighValueLossWarning
99
+ | InsufficientSlippageWarning
100
+ | HighSlippageWarning
101
+ | UnknownPriceWarning;
102
+
103
+ export type ConfirmSwapWarnings = {
104
+ quote: QuoteWarning | null;
105
+ quoteUpdate: QuoteUpdateWarning | null;
106
+ balance: { messages: string[] } | null;
107
+ };
@@ -16,7 +16,7 @@ export const secondsToString = (s: number): string => {
16
16
  };
17
17
 
18
18
  export const numberToString = (
19
- number: BigNumber | string | null | undefined,
19
+ number: BigNumber | string | number | null | undefined,
20
20
  minDecimals: number | null = null,
21
21
  maxDecimals: number | null = null
22
22
  ): string => {
@@ -0,0 +1,338 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+ import type { QuoteError, QuoteWarning, Wallet } from '../types';
3
+ import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
4
+ import type { PriceImpactWarningLevel } from '@rango-dev/ui';
5
+ import type {
6
+ SimulationAssetAndAmount,
7
+ SimulationValidationStatus,
8
+ } from '@rango-dev/ui/dist/widget/ui/src/types/swaps';
9
+ import type {
10
+ Asset,
11
+ BestRouteResponse,
12
+ BlockchainMeta,
13
+ Token,
14
+ } from 'rango-sdk';
15
+
16
+ import { getLastSuccessfulStep } from '@rango-dev/queue-manager-rango-preset';
17
+ import BigNumber from 'bignumber.js';
18
+
19
+ import { HIGHT_PRICE_IMPACT, LOW_PRICE_IMPACT } from '../constants/routing';
20
+ import { HIGH_SLIPPAGE } from '../constants/swapSettings';
21
+ import { getUsdValue } from '../store/quote';
22
+ import { QuoteErrorType, QuoteWarningType } from '../types';
23
+
24
+ import { areEqual } from './common';
25
+ import { findBlockchain, findToken } from './meta';
26
+ import {
27
+ checkSlippageErrors,
28
+ checkSlippageWarnings,
29
+ getLimitErrorMessage,
30
+ getMinRequiredSlippage,
31
+ getPercentageChange,
32
+ getTotalFeeInUsd,
33
+ hasHighValueLoss,
34
+ hasLimitError,
35
+ hasProperSlippage,
36
+ } from './swap';
37
+
38
+ export function searchParamsToToken(
39
+ tokens: Token[],
40
+ searchParams: string | null,
41
+ chain: BlockchainMeta | null
42
+ ): Token | null {
43
+ if (!chain) {
44
+ return null;
45
+ }
46
+ return (
47
+ tokens.find((token) => {
48
+ const symbolAndAddress = searchParams?.split('--');
49
+ if (symbolAndAddress?.length === 1) {
50
+ return (
51
+ token.symbol === symbolAndAddress[0] &&
52
+ token.address === null &&
53
+ token.blockchain === chain.name
54
+ );
55
+ }
56
+ return (
57
+ token.symbol === symbolAndAddress?.[0] &&
58
+ token.address === symbolAndAddress?.[1] &&
59
+ token.blockchain === chain.name
60
+ );
61
+ }) || null
62
+ );
63
+ }
64
+
65
+ export function getQuoteToTokenUsdPrice(
66
+ quote: BestRouteResponse | null
67
+ ): number | null | undefined {
68
+ return quote?.result?.swaps[quote?.result?.swaps.length - 1].to.usdPrice;
69
+ }
70
+
71
+ export function isNumberOfSwapsChanged(
72
+ quoteA: BestRouteResponse,
73
+ quoteB: BestRouteResponse
74
+ ) {
75
+ const quoteASwaps = quoteA.result?.swaps || [];
76
+ const quoteBSwaps = quoteB.result?.swaps || [];
77
+ return quoteASwaps.length !== quoteBSwaps.length;
78
+ }
79
+
80
+ export function isQuoteSwappersUpdated(
81
+ quoteA: BestRouteResponse,
82
+ quoteB: BestRouteResponse
83
+ ) {
84
+ const quoteASwappers =
85
+ quoteA.result?.swaps.map((swap) => swap.swapperId) || [];
86
+ const quoteBSwappers =
87
+ quoteB.result?.swaps.map((swap) => swap.swapperId) || [];
88
+ return !areEqual(quoteASwappers, quoteBSwappers);
89
+ }
90
+
91
+ export function isQuoteInternalCoinsUpdated(
92
+ quoteA: BestRouteResponse,
93
+ quoteB: BestRouteResponse
94
+ ) {
95
+ const quoteAInternalCoins =
96
+ quoteA.result?.swaps.map((swap) => swap.to.symbol) || [];
97
+ const quoteBInternalCoins =
98
+ quoteB.result?.swaps.map((swap) => swap.to.symbol) || [];
99
+ return !areEqual(quoteAInternalCoins, quoteBInternalCoins);
100
+ }
101
+
102
+ export function isQuoteChanged(
103
+ quoteA: BestRouteResponse,
104
+ quoteB: BestRouteResponse
105
+ ): boolean {
106
+ return (
107
+ isNumberOfSwapsChanged(quoteA, quoteB) ||
108
+ isQuoteSwappersUpdated(quoteA, quoteB) ||
109
+ isQuoteInternalCoinsUpdated(quoteA, quoteB)
110
+ );
111
+ }
112
+
113
+ export function outToRatioHasWarning(
114
+ fromUsdValue: BigNumber | null,
115
+ outToInRatio: BigNumber | 0
116
+ ) {
117
+ return (
118
+ (parseInt(outToInRatio?.toFixed(2) || '0') <= -10 &&
119
+ (fromUsdValue === null || fromUsdValue.gte(new BigNumber(200)))) ||
120
+ (parseInt(outToInRatio?.toFixed(2) || '0') <= -5 &&
121
+ (fromUsdValue === null || fromUsdValue.gte(new BigNumber(1000))))
122
+ );
123
+ }
124
+
125
+ export function getRequiredBalanceOfWallet(
126
+ selectedWallet: Wallet,
127
+ fee: SimulationValidationStatus[] | null
128
+ ): SimulationAssetAndAmount[] | null {
129
+ if (fee === null) {
130
+ return null;
131
+ }
132
+ const relatedFeeStatus = fee
133
+ ?.find((item) => item.blockchain === selectedWallet.chain)
134
+ ?.wallets.find(
135
+ (wallet) =>
136
+ wallet.address?.toLowerCase() === selectedWallet.address.toLowerCase()
137
+ );
138
+ if (!relatedFeeStatus) {
139
+ return null;
140
+ }
141
+ return relatedFeeStatus.requiredAssets;
142
+ }
143
+
144
+ export function getPriceImpactLevel(
145
+ priceImpact: number
146
+ ): PriceImpactWarningLevel {
147
+ let warningLevel: PriceImpactWarningLevel = undefined;
148
+ if (priceImpact <= LOW_PRICE_IMPACT && priceImpact > HIGHT_PRICE_IMPACT) {
149
+ warningLevel = 'low';
150
+ } else if (priceImpact <= HIGHT_PRICE_IMPACT) {
151
+ warningLevel = 'high';
152
+ }
153
+
154
+ return warningLevel;
155
+ }
156
+
157
+ export function findCommonTokens<T extends Asset[], R extends Asset[]>(
158
+ listA: T,
159
+ listB: R
160
+ ) {
161
+ const tokenToString = (token: Asset): string =>
162
+ `${token.symbol}-${token.blockchain}-${token.address ?? ''}`;
163
+
164
+ const set = new Set();
165
+
166
+ listA.forEach((token) => set.add(tokenToString(token)));
167
+
168
+ return listB.filter((token) => set.has(tokenToString(token))) as R;
169
+ }
170
+
171
+ export function createRetryQuote(
172
+ pendingSwap: PendingSwap,
173
+ blockchains: BlockchainMeta[],
174
+ tokens: Token[]
175
+ ): {
176
+ fromBlockchain: BlockchainMeta | null;
177
+ fromToken: Token | null;
178
+ toBlockchain: BlockchainMeta | null;
179
+ toToken: Token | null;
180
+ inputAmount: string;
181
+ } {
182
+ const firstStep = pendingSwap.steps[0];
183
+ const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
184
+ const lastSuccessfulStep = getLastSuccessfulStep(pendingSwap.steps);
185
+
186
+ const toToken = {
187
+ blockchain: lastStep.toBlockchain,
188
+ symbol: lastStep.toSymbol,
189
+ address: lastStep.toSymbolAddress,
190
+ };
191
+
192
+ const fromBlockchainMeta = findBlockchain(
193
+ lastSuccessfulStep
194
+ ? lastSuccessfulStep.toBlockchain
195
+ : firstStep.fromBlockchain,
196
+ blockchains
197
+ );
198
+ const toBlockchainMeta = findBlockchain(lastStep.toBlockchain, blockchains);
199
+ const fromTokenMeta = findToken(
200
+ lastSuccessfulStep
201
+ ? {
202
+ blockchain: fromBlockchainMeta?.name ?? '',
203
+ symbol: lastSuccessfulStep.toSymbol,
204
+ address: lastSuccessfulStep.toSymbolAddress,
205
+ }
206
+ : {
207
+ blockchain: fromBlockchainMeta?.name ?? '',
208
+ symbol: firstStep.fromSymbol,
209
+ address: firstStep.fromSymbolAddress,
210
+ },
211
+ tokens
212
+ );
213
+ const toTokenMeta = findToken(toToken, tokens);
214
+ const inputAmount = lastSuccessfulStep
215
+ ? lastSuccessfulStep.outputAmount ?? ''
216
+ : pendingSwap.inputAmount;
217
+
218
+ return {
219
+ fromBlockchain: fromBlockchainMeta,
220
+ fromToken: fromTokenMeta,
221
+ toBlockchain: toBlockchainMeta,
222
+ toToken: toTokenMeta,
223
+ inputAmount,
224
+ };
225
+ }
226
+
227
+ export function generateQuoteWarnings(
228
+ quote: BestRouteResponse,
229
+ params: {
230
+ fromToken: Token;
231
+ toToken: Token;
232
+ tokens: Token[];
233
+ userSlippage: number;
234
+ }
235
+ ): QuoteWarning | null {
236
+ const { fromToken, toToken, tokens, userSlippage } = params;
237
+ const inputUsdValue = getUsdValue(fromToken, quote.requestAmount);
238
+ const outputUsdValue = getUsdValue(toToken, quote.result?.outputAmount ?? '');
239
+
240
+ if (quote.result && inputUsdValue && outputUsdValue) {
241
+ const priceImpact = getPercentageChange(
242
+ inputUsdValue.toString(),
243
+ outputUsdValue.toString()
244
+ );
245
+ const highValueLoss = hasHighValueLoss(inputUsdValue, priceImpact);
246
+
247
+ if (highValueLoss) {
248
+ const totalFee = getTotalFeeInUsd(quote.result.swaps, tokens);
249
+ const warningLevel = getPriceImpactLevel(priceImpact);
250
+ return {
251
+ type: QuoteWarningType.HIGH_VALUE_LOSS,
252
+ inputUsdValue,
253
+ outputUsdValue,
254
+ priceImpact,
255
+ totalFee,
256
+ warningLevel,
257
+ };
258
+ }
259
+ } else if (quote.result && (!inputUsdValue || !outputUsdValue)) {
260
+ return { type: QuoteWarningType.UNKNOWN_PRICE };
261
+ }
262
+
263
+ const minRequiredSlippage = getMinRequiredSlippage(quote);
264
+ const highSlippage = userSlippage > HIGH_SLIPPAGE;
265
+
266
+ if (!hasProperSlippage(params.userSlippage.toString(), minRequiredSlippage)) {
267
+ return {
268
+ type: QuoteWarningType.INSUFFICIENT_SLIPPAGE,
269
+ recommendedSlippages: checkSlippageWarnings(quote, userSlippage),
270
+ minRequiredSlippage: minRequiredSlippage,
271
+ };
272
+ } else if (
273
+ highSlippage &&
274
+ parseFloat(minRequiredSlippage ?? '0') < userSlippage
275
+ ) {
276
+ return {
277
+ type: QuoteWarningType.HIGH_SLIPPAGE,
278
+ slippage: userSlippage.toString(),
279
+ };
280
+ }
281
+
282
+ return null;
283
+ }
284
+
285
+ export function generateQuoteErrors(
286
+ quote: BestRouteResponse
287
+ ): QuoteError | null {
288
+ if (!quote.result) {
289
+ return {
290
+ type: QuoteErrorType.NO_RESULT,
291
+ diagnosisMessage: quote.diagnosisMessages?.[0],
292
+ };
293
+ }
294
+ const limitError = hasLimitError(quote);
295
+ if (limitError) {
296
+ const { swap, recommendation, fromAmountRangeError } =
297
+ getLimitErrorMessage(quote);
298
+ return {
299
+ type: QuoteErrorType.BRIDGE_LIMIT,
300
+ swap: swap,
301
+ recommendation,
302
+ fromAmountRangeError,
303
+ };
304
+ }
305
+
306
+ const recommendedSlippages = checkSlippageErrors(quote);
307
+
308
+ if (recommendedSlippages) {
309
+ const minRequiredSlippage = getMinRequiredSlippage(quote);
310
+ return {
311
+ type: QuoteErrorType.INSUFFICIENT_SLIPPAGE,
312
+ recommendedSlippages,
313
+ minRequiredSlippage,
314
+ };
315
+ }
316
+
317
+ return null;
318
+ }
319
+
320
+ export function getPriceImpact(
321
+ inputUsdValue: BigNumber | string | null,
322
+ outputUsdValue: BigNumber | string | null
323
+ ) {
324
+ const outputUsdValueIsInvalid =
325
+ typeof outputUsdValue === 'string'
326
+ ? parseFloat(outputUsdValue) <= 0
327
+ : !outputUsdValue?.gt(0);
328
+
329
+ const priceImpact =
330
+ !inputUsdValue || !outputUsdValue || outputUsdValueIsInvalid
331
+ ? null
332
+ : getPercentageChange(
333
+ inputUsdValue.toString(),
334
+ outputUsdValue.toString()
335
+ );
336
+
337
+ return priceImpact;
338
+ }