@rango-dev/widget-embedded 0.17.1-next.9 → 0.19.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 (271) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/QueueManager.d.ts +1 -2
  3. package/dist/QueueManager.d.ts.map +1 -1
  4. package/dist/Wallets.d.ts +0 -1
  5. package/dist/Wallets.d.ts.map +1 -1
  6. package/dist/Widget.d.ts +1 -1
  7. package/dist/Widget.d.ts.map +1 -1
  8. package/dist/components/AppRouter.d.ts +2 -0
  9. package/dist/components/AppRouter.d.ts.map +1 -1
  10. package/dist/components/AppRoutes.d.ts +6 -1
  11. package/dist/components/AppRoutes.d.ts.map +1 -1
  12. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +3 -1
  13. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
  14. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
  15. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  16. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +3 -1
  17. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
  18. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  19. package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts +4 -1
  20. package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts.map +1 -1
  21. package/dist/components/NoRoutes/NoRoutes.d.ts +4 -0
  22. package/dist/components/NoRoutes/NoRoutes.d.ts.map +1 -0
  23. package/dist/components/NoRoutes/NoRoutes.helper.d.ts +3 -0
  24. package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +1 -0
  25. package/dist/components/{NoResult/NoResult.styles.d.ts → NoRoutes/NoRoutes.styles.d.ts} +1 -1
  26. package/dist/components/{NoResult/NoResult.styles.d.ts.map → NoRoutes/NoRoutes.styles.d.ts.map} +1 -1
  27. package/dist/components/{NoResult/NoResult.types.d.ts → NoRoutes/NoRoutes.types.d.ts} +3 -3
  28. package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +1 -0
  29. package/dist/components/NoRoutes/index.d.ts +2 -0
  30. package/dist/components/NoRoutes/index.d.ts.map +1 -0
  31. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  32. package/dist/components/RouteErrors/RouteErrors.d.ts +4 -0
  33. package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -0
  34. package/dist/components/{QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts → RouteErrors/RouteErrors.styles.d.ts} +1 -1
  35. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -0
  36. package/dist/components/RouteErrors/RouteErrors.types.d.ts +24 -0
  37. package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -0
  38. package/dist/components/RouteErrors/RouteErrorsModal.d.ts +4 -0
  39. package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -0
  40. package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +4 -0
  41. package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +1 -0
  42. package/dist/components/RouteErrors/index.d.ts +2 -0
  43. package/dist/components/RouteErrors/index.d.ts.map +1 -0
  44. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  45. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  46. package/dist/components/UpdateUrl.d.ts +6 -1
  47. package/dist/components/UpdateUrl.d.ts.map +1 -1
  48. package/dist/components/WidgetEvents.d.ts.map +1 -1
  49. package/dist/constants/errors.d.ts +4 -4
  50. package/dist/constants/errors.d.ts.map +1 -1
  51. package/dist/constants/messages.d.ts +1 -1
  52. package/dist/constants/searchParams.d.ts +1 -2
  53. package/dist/constants/searchParams.d.ts.map +1 -1
  54. package/dist/constants/warnings.d.ts +2 -2
  55. package/dist/constants/warnings.d.ts.map +1 -1
  56. package/dist/hooks/{useConfirmSwap/useConfirmSwap.types.d.ts → useConfirmSwap.d.ts} +7 -5
  57. package/dist/hooks/useConfirmSwap.d.ts.map +1 -0
  58. package/dist/hooks/{useFetchQuote.d.ts → useFetchBestRoute.d.ts} +3 -3
  59. package/dist/hooks/useFetchBestRoute.d.ts.map +1 -0
  60. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
  61. package/dist/hooks/useSwapInput.d.ts +2 -4
  62. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  63. package/dist/hooks/useSyncStoresWithConfig.d.ts +2 -1
  64. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
  65. package/dist/hooks/useWalletList.d.ts.map +1 -1
  66. package/dist/index.js +1 -1
  67. package/dist/index.js.map +4 -4
  68. package/dist/pages/ConfirmSwapPage.d.ts +6 -1
  69. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  70. package/dist/pages/Home.d.ts.map +1 -1
  71. package/dist/pages/LiquiditySourcePage.d.ts +2 -1
  72. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  73. package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
  74. package/dist/pages/SettingsPage.d.ts +6 -1
  75. package/dist/pages/SettingsPage.d.ts.map +1 -1
  76. package/dist/pages/WalletsPage.d.ts +8 -1
  77. package/dist/pages/WalletsPage.d.ts.map +1 -1
  78. package/dist/store/app.d.ts +23 -5
  79. package/dist/store/app.d.ts.map +1 -1
  80. package/dist/store/{quote.d.ts → bestRoute.d.ts} +27 -39
  81. package/dist/store/bestRoute.d.ts.map +1 -0
  82. package/dist/store/meta.d.ts +23 -0
  83. package/dist/store/meta.d.ts.map +1 -0
  84. package/dist/store/settings.d.ts +2 -3
  85. package/dist/store/settings.d.ts.map +1 -1
  86. package/dist/store/slices/config.d.ts +2 -3
  87. package/dist/store/slices/config.d.ts.map +1 -1
  88. package/dist/store/slices/data.d.ts +0 -3
  89. package/dist/store/slices/data.d.ts.map +1 -1
  90. package/dist/store/wallets.d.ts +4 -5
  91. package/dist/store/wallets.d.ts.map +1 -1
  92. package/dist/types/config.d.ts +5 -5
  93. package/dist/types/config.d.ts.map +1 -1
  94. package/dist/types/index.d.ts +1 -1
  95. package/dist/types/index.d.ts.map +1 -1
  96. package/dist/types/routing.d.ts +65 -0
  97. package/dist/types/routing.d.ts.map +1 -0
  98. package/dist/utils/numbers.d.ts +1 -1
  99. package/dist/utils/numbers.d.ts.map +1 -1
  100. package/dist/utils/{quote.d.ts → routing.d.ts} +12 -16
  101. package/dist/utils/routing.d.ts.map +1 -0
  102. package/dist/utils/settings.d.ts +2 -3
  103. package/dist/utils/settings.d.ts.map +1 -1
  104. package/dist/utils/swap.d.ts +22 -25
  105. package/dist/utils/swap.d.ts.map +1 -1
  106. package/dist/utils/wallets.d.ts +2 -2
  107. package/dist/utils/wallets.d.ts.map +1 -1
  108. package/package.json +8 -8
  109. package/src/QueueManager.tsx +14 -14
  110. package/src/Wallets.tsx +15 -35
  111. package/src/Widget.tsx +24 -11
  112. package/src/components/AppRouter.tsx +5 -6
  113. package/src/components/AppRoutes.tsx +39 -6
  114. package/src/components/BlockchainList/BlockchainList.tsx +4 -4
  115. package/src/components/BlockchainsSection/BlockchainsSection.tsx +7 -7
  116. package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +64 -2
  117. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +40 -28
  118. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +3 -1
  119. package/src/components/ConfirmWalletsModal/WalletList.tsx +5 -6
  120. package/src/components/ConfirmWalletsModal/WalletList.type.ts +4 -1
  121. package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
  122. package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
  123. package/src/components/{NoResult/NoResult.helpers.ts → NoRoutes/NoRoutes.helper.ts} +9 -16
  124. package/src/components/{NoResult/NoResult.styles.ts → NoRoutes/NoRoutes.styles.ts} +0 -2
  125. package/src/components/{NoResult/NoResult.tsx → NoRoutes/NoRoutes.tsx} +12 -10
  126. package/src/components/{NoResult/NoResult.types.ts → NoRoutes/NoRoutes.types.ts} +2 -3
  127. package/src/components/NoRoutes/index.ts +1 -0
  128. package/src/components/NotificationContent/NotificationContent.tsx +2 -3
  129. package/src/components/RouteErrors/RouteErrors.tsx +79 -0
  130. package/src/components/RouteErrors/RouteErrors.types.ts +29 -0
  131. package/src/components/RouteErrors/RouteErrorsModal.tsx +129 -0
  132. package/src/components/{QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx → RouteErrors/RouteErrorsModalItem.tsx} +3 -3
  133. package/src/components/RouteErrors/index.ts +1 -0
  134. package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
  135. package/src/components/SwapDetails/SwapDetails.tsx +22 -18
  136. package/src/components/SwitchFromAndTo.tsx +2 -2
  137. package/src/components/TokenList/TokenList.tsx +6 -5
  138. package/src/components/UpdateUrl.tsx +26 -36
  139. package/src/components/WidgetEvents.tsx +2 -4
  140. package/src/constants/errors.ts +10 -8
  141. package/src/constants/messages.ts +1 -1
  142. package/src/constants/searchParams.ts +0 -1
  143. package/src/constants/warnings.ts +7 -7
  144. package/src/hooks/useConfirmSwap.ts +303 -0
  145. package/src/hooks/{useFetchQuote.ts → useFetchBestRoute.ts} +3 -3
  146. package/src/hooks/useNavigateBack.ts +3 -3
  147. package/src/hooks/useSwapInput.ts +23 -58
  148. package/src/hooks/useSyncStoresWithConfig.ts +19 -22
  149. package/src/hooks/useWalletList.ts +5 -3
  150. package/src/pages/ConfirmSwapPage.tsx +235 -58
  151. package/src/pages/HistoryPage.tsx +1 -1
  152. package/src/pages/Home.tsx +247 -58
  153. package/src/pages/LanguagePage.tsx +1 -1
  154. package/src/pages/LiquiditySourcePage.tsx +32 -23
  155. package/src/pages/SelectBlockchainPage.tsx +7 -6
  156. package/src/pages/SelectSwapItemsPage.tsx +5 -5
  157. package/src/pages/SettingsPage.tsx +13 -9
  158. package/src/pages/SwapDetailsPage.tsx +3 -3
  159. package/src/pages/ThemePage.tsx +1 -1
  160. package/src/pages/WalletsPage.tsx +12 -5
  161. package/src/store/app.ts +6 -18
  162. package/src/store/{quote.ts → bestRoute.ts} +60 -68
  163. package/src/store/meta.ts +39 -0
  164. package/src/store/settings.ts +4 -7
  165. package/src/store/slices/config.ts +15 -25
  166. package/src/store/slices/data.ts +29 -64
  167. package/src/store/wallets.ts +8 -11
  168. package/src/types/config.ts +5 -5
  169. package/src/types/index.ts +1 -1
  170. package/src/types/routing.ts +77 -0
  171. package/src/utils/numbers.ts +1 -1
  172. package/src/utils/routing.ts +321 -0
  173. package/src/utils/settings.ts +7 -8
  174. package/src/utils/swap.ts +85 -113
  175. package/src/utils/wallets.ts +17 -29
  176. package/dist/components/NoResult/NoResult.d.ts +0 -4
  177. package/dist/components/NoResult/NoResult.d.ts.map +0 -1
  178. package/dist/components/NoResult/NoResult.helpers.d.ts +0 -4
  179. package/dist/components/NoResult/NoResult.helpers.d.ts.map +0 -1
  180. package/dist/components/NoResult/NoResult.types.d.ts.map +0 -1
  181. package/dist/components/NoResult/index.d.ts +0 -2
  182. package/dist/components/NoResult/index.d.ts.map +0 -1
  183. package/dist/components/Quote/Quote.d.ts +0 -4
  184. package/dist/components/Quote/Quote.d.ts.map +0 -1
  185. package/dist/components/Quote/Quote.styles.d.ts +0 -1429
  186. package/dist/components/Quote/Quote.styles.d.ts.map +0 -1
  187. package/dist/components/Quote/Quote.types.d.ts +0 -22
  188. package/dist/components/Quote/Quote.types.d.ts.map +0 -1
  189. package/dist/components/Quote/QuoteSkeleton.d.ts +0 -4
  190. package/dist/components/Quote/QuoteSkeleton.d.ts.map +0 -1
  191. package/dist/components/Quote/QuoteSkeleton.styles.d.ts +0 -319
  192. package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +0 -1
  193. package/dist/components/Quote/QuoteSkeleton.types.d.ts +0 -6
  194. package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +0 -1
  195. package/dist/components/Quote/QuoteSummary.d.ts +0 -11
  196. package/dist/components/Quote/QuoteSummary.d.ts.map +0 -1
  197. package/dist/components/Quote/QuoteSummary.styles.d.ts +0 -158
  198. package/dist/components/Quote/QuoteSummary.styles.d.ts.map +0 -1
  199. package/dist/components/Quote/index.d.ts +0 -4
  200. package/dist/components/Quote/index.d.ts.map +0 -1
  201. package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +0 -11
  202. package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +0 -1
  203. package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +0 -4
  204. package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +0 -1
  205. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +0 -4
  206. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +0 -1
  207. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +0 -9
  208. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +0 -1
  209. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +0 -1
  210. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +0 -22
  211. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +0 -1
  212. package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +0 -11
  213. package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +0 -1
  214. package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +0 -11
  215. package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +0 -1
  216. package/dist/components/QuoteWarningsAndErrors/index.d.ts +0 -2
  217. package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +0 -1
  218. package/dist/containers/QuoteInfo/QuoteInfo.d.ts +0 -4
  219. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +0 -1
  220. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +0 -472
  221. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +0 -1
  222. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +0 -17
  223. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +0 -1
  224. package/dist/containers/QuoteInfo/index.d.ts +0 -2
  225. package/dist/containers/QuoteInfo/index.d.ts.map +0 -1
  226. package/dist/hooks/useConfirmSwap/index.d.ts +0 -2
  227. package/dist/hooks/useConfirmSwap/index.d.ts.map +0 -1
  228. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +0 -3
  229. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +0 -1
  230. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +0 -16
  231. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +0 -1
  232. package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +0 -1
  233. package/dist/hooks/useFetchQuote.d.ts.map +0 -1
  234. package/dist/hooks/useForceAutoConnect.d.ts +0 -2
  235. package/dist/hooks/useForceAutoConnect.d.ts.map +0 -1
  236. package/dist/store/AppStore.d.ts +0 -11
  237. package/dist/store/AppStore.d.ts.map +0 -1
  238. package/dist/store/quote.d.ts.map +0 -1
  239. package/dist/types/quote.d.ts +0 -82
  240. package/dist/types/quote.d.ts.map +0 -1
  241. package/dist/utils/quote.d.ts.map +0 -1
  242. package/src/components/NoResult/index.ts +0 -1
  243. package/src/components/Quote/Quote.styles.ts +0 -212
  244. package/src/components/Quote/Quote.tsx +0 -345
  245. package/src/components/Quote/Quote.types.ts +0 -16
  246. package/src/components/Quote/QuoteSkeleton.styles.ts +0 -110
  247. package/src/components/Quote/QuoteSkeleton.tsx +0 -108
  248. package/src/components/Quote/QuoteSkeleton.types.ts +0 -5
  249. package/src/components/Quote/QuoteSummary.styles.ts +0 -15
  250. package/src/components/Quote/QuoteSummary.tsx +0 -46
  251. package/src/components/Quote/index.ts +0 -3
  252. package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +0 -107
  253. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +0 -67
  254. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +0 -103
  255. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +0 -24
  256. package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +0 -77
  257. package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +0 -38
  258. package/src/components/QuoteWarningsAndErrors/index.ts +0 -1
  259. package/src/containers/QuoteInfo/QuoteInfo.styles.ts +0 -15
  260. package/src/containers/QuoteInfo/QuoteInfo.tsx +0 -97
  261. package/src/containers/QuoteInfo/QuoteInfo.types.ts +0 -17
  262. package/src/containers/QuoteInfo/index.ts +0 -1
  263. package/src/hooks/useConfirmSwap/index.ts +0 -1
  264. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +0 -168
  265. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +0 -136
  266. package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +0 -19
  267. package/src/hooks/useForceAutoConnect.ts +0 -27
  268. package/src/store/AppStore.tsx +0 -35
  269. package/src/types/quote.ts +0 -107
  270. package/src/utils/quote.ts +0 -338
  271. /package/src/components/{QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts → RouteErrors/RouteErrors.styles.ts} +0 -0
@@ -1,9 +1,71 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+ import type { Step } from '@rango-dev/ui/dist/widget/ui/src/components/BestRoute/BestRoute.types';
1
3
  import type { BestRouteResponse, BlockchainMeta } from 'rango-sdk';
2
4
 
3
- export function getRequiredWallets(quote: BestRouteResponse | null): string[] {
5
+ import {
6
+ TOKEN_AMOUNT_MAX_DECIMALS,
7
+ TOKEN_AMOUNT_MIN_DECIMALS,
8
+ USD_VALUE_MAX_DECIMALS,
9
+ USD_VALUE_MIN_DECIMALS,
10
+ } from '../../constants/routing';
11
+ import { getBlockchainShortNameFor } from '../../utils/meta';
12
+ import { numberToString } from '../../utils/numbers';
13
+
14
+ export function formatBestRoute(
15
+ bestRoute: BestRouteResponse,
16
+ blockchains: BlockchainMeta[]
17
+ ): Step[] | undefined {
18
+ return bestRoute.result?.swaps.map((swap) => {
19
+ return {
20
+ swapper: { displayName: swap.swapperId, image: swap.swapperLogo },
21
+ from: {
22
+ token: { displayName: swap.from.symbol, image: swap.from.logo },
23
+ chain: {
24
+ displayName:
25
+ getBlockchainShortNameFor(swap.from.blockchain, blockchains) ?? '',
26
+ image: swap.from.blockchainLogo,
27
+ },
28
+ price: {
29
+ value: numberToString(
30
+ swap.fromAmount,
31
+ TOKEN_AMOUNT_MIN_DECIMALS,
32
+ TOKEN_AMOUNT_MAX_DECIMALS
33
+ ),
34
+ usdValue: numberToString(
35
+ swap.from.usdPrice?.toString(),
36
+ USD_VALUE_MIN_DECIMALS,
37
+ USD_VALUE_MAX_DECIMALS
38
+ ),
39
+ },
40
+ },
41
+ to: {
42
+ token: { displayName: swap.to.symbol, image: swap.to.logo },
43
+ chain: {
44
+ displayName:
45
+ getBlockchainShortNameFor(swap.to.blockchain, blockchains) ?? '',
46
+ image: swap.to.blockchainLogo,
47
+ },
48
+ price: {
49
+ value: numberToString(
50
+ swap.toAmount,
51
+ TOKEN_AMOUNT_MIN_DECIMALS,
52
+ TOKEN_AMOUNT_MAX_DECIMALS
53
+ ),
54
+ usdValue: numberToString(
55
+ swap.to.usdPrice?.toString(),
56
+ USD_VALUE_MIN_DECIMALS,
57
+ USD_VALUE_MAX_DECIMALS
58
+ ),
59
+ },
60
+ },
61
+ };
62
+ });
63
+ }
64
+
65
+ export function getRequiredWallets(route: BestRouteResponse | null): string[] {
4
66
  const wallets: string[] = [];
5
67
 
6
- quote?.result?.swaps.forEach((swap) => {
68
+ route?.result?.swaps.forEach((swap) => {
7
69
  const currentStepFromBlockchain = swap.from.blockchain;
8
70
  const currentStepToBlockchain = swap.to.blockchain;
9
71
  let lastAddedWallet = wallets[wallets.length - 1];
@@ -18,11 +18,11 @@ import {
18
18
  import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
19
19
  import { useNavigate } from 'react-router-dom';
20
20
 
21
- import { getQuoteErrorMessage } from '../../constants/errors';
21
+ import { getConfirmSwapErrorMessage } from '../../constants/errors';
22
22
  import { navigationRoutes } from '../../constants/navigationRoutes';
23
- import { getQuoteUpdateWarningMessage } from '../../constants/warnings';
24
- import { useAppStore } from '../../store/AppStore';
25
- import { useQuoteStore } from '../../store/quote';
23
+ import { getRouteWarningMessage } from '../../constants/warnings';
24
+ import { useBestRouteStore } from '../../store/bestRoute';
25
+ import { useMetaStore } from '../../store/meta';
26
26
  import { useWalletsStore } from '../../store/wallets';
27
27
  import { confirmSwapDisabled } from '../../utils/swap';
28
28
 
@@ -50,24 +50,23 @@ const NUMBER_OF_WALLETS_TO_DISPLAY = 2;
50
50
 
51
51
  export function ConfirmWalletsModal(props: PropTypes) {
52
52
  //TODO: move component's logics to a custom hook
53
- const { open, onClose, onCancel, onCheckBalance, loading } = props;
54
- const config = useAppStore().config;
55
- const blockchains = useAppStore().blockchains();
53
+ const { open, onClose, onCancel, onCheckBalance, config, loading } = props;
54
+ const { blockchains } = useMetaStore.use.meta();
56
55
  const {
57
- quote,
58
- setSelectedWallets: selectQuoteWallets,
59
- quoteWalletsConfirmed: quoteWalletsConfirmed,
60
- setQuoteWalletConfirmed: setQuoteWalletConfirmed,
56
+ bestRoute,
57
+ setSelectedWallets: selectRouteWallets,
58
+ routeWalletsConfirmed,
59
+ setRouteWalletConfirmed,
61
60
  customDestination,
62
61
  setCustomDestination,
63
- } = useQuoteStore();
62
+ } = useBestRouteStore();
64
63
  const { connectedWallets, selectWallets } = useWalletsStore();
65
64
 
66
65
  const [showMoreWalletFor, setShowMoreWalletFor] = useState('');
67
66
  const [balanceWarnings, setBalanceWarnings] = useState<string[]>([]);
68
67
  const [error, setError] = useState('');
69
- const [quoteWarning, setQuoteWarning] = useState<
70
- ConfirmSwapWarnings['quoteUpdate'] | null
68
+ const [routeWarning, setRouteWarning] = useState<
69
+ ConfirmSwapWarnings['route'] | null
71
70
  >(null);
72
71
  const [destination, setDestination] = useState(customDestination);
73
72
  const [showCustomDestination, setShowCustomDestination] = useState(
@@ -75,15 +74,22 @@ export function ConfirmWalletsModal(props: PropTypes) {
75
74
  );
76
75
  const customDestinationRef = useRef<HTMLDivElement | null>(null);
77
76
 
78
- const requiredWallets = getRequiredWallets(quote);
77
+ const requiredWallets = getRequiredWallets(bestRoute);
78
+ const customDestinationEnabled =
79
+ typeof config?.customDestination === 'undefined'
80
+ ? true
81
+ : config.customDestination;
79
82
 
80
83
  const lastStepToBlockchain = blockchains.find(
81
84
  (blockchain) =>
82
85
  blockchain.name ===
83
- quote?.result?.swaps[quote?.result?.swaps.length - 1].to.blockchain
86
+ bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1].to
87
+ .blockchain
84
88
  );
85
89
  const isWalletRequiredFor = (blockchain: string) =>
86
- !!quote?.result?.swaps.find((swap) => swap.from.blockchain === blockchain);
90
+ !!bestRoute?.result?.swaps.find(
91
+ (swap) => swap.from.blockchain === blockchain
92
+ );
87
93
 
88
94
  const [selectableWallets, setSelectableWallets] = useState<ConnectedWallet[]>(
89
95
  connectedWallets.filter((connectedWallet) => {
@@ -169,16 +175,16 @@ export function ConfirmWalletsModal(props: PropTypes) {
169
175
  (wallet) => wallet.selected
170
176
  );
171
177
  selectWallets(lastSelectedWallets);
172
- selectQuoteWallets(lastSelectedWallets);
178
+ selectRouteWallets(lastSelectedWallets);
173
179
  setCustomDestination(destination);
174
- setQuoteWalletConfirmed(true);
180
+ setRouteWalletConfirmed(true);
175
181
  onClose();
176
182
  };
177
183
 
178
184
  const onConfirmWallets = async () => {
179
185
  setBalanceWarnings([]);
180
186
  setError('');
181
- setQuoteWarning(null);
187
+ setRouteWarning(null);
182
188
  const selectedWallets = connectedWallets.filter((connectedWallet) =>
183
189
  selectableWallets.find(
184
190
  (selectableWallet) =>
@@ -195,11 +201,11 @@ export function ConfirmWalletsModal(props: PropTypes) {
195
201
  if (warnings?.balance?.messages) {
196
202
  setBalanceWarnings(warnings.balance.messages);
197
203
  }
198
- if (warnings?.quoteUpdate) {
199
- setQuoteWarning(warnings.quoteUpdate);
204
+ if (warnings?.route) {
205
+ setRouteWarning(warnings.route);
200
206
  }
201
207
  if (result.error) {
202
- setError(getQuoteErrorMessage(result.error));
208
+ setError(getConfirmSwapErrorMessage(result.error));
203
209
  }
204
210
 
205
211
  if (!result.error && (!warnings?.balance?.messages.length || 0 > 0)) {
@@ -243,7 +249,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
243
249
  <Modal
244
250
  open={open}
245
251
  onClose={() => {
246
- if (!quoteWalletsConfirmed) {
252
+ if (!routeWalletsConfirmed) {
247
253
  navigate(navigationRoutes.home, { replace: true });
248
254
  }
249
255
  onClose();
@@ -259,7 +265,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
259
265
  loading,
260
266
  showCustomDestination,
261
267
  destination,
262
- quote,
268
+ bestRoute,
263
269
  selectableWallets,
264
270
  lastStepToBlockchain
265
271
  )}
@@ -317,6 +323,9 @@ export function ConfirmWalletsModal(props: PropTypes) {
317
323
  chain={showMoreWalletFor}
318
324
  isSelected={isSelected}
319
325
  selectWallet={onChange}
326
+ multiWallets={config?.multiWallets ?? true}
327
+ supportedWallets={config?.wallets ?? []}
328
+ config={config}
320
329
  onShowMore={setShowMoreWalletFor.bind(null, showMoreWalletFor)}
321
330
  />
322
331
  </div>
@@ -330,12 +339,12 @@ export function ConfirmWalletsModal(props: PropTypes) {
330
339
  <Divider size={12} />
331
340
  </>
332
341
  )}
333
- {quoteWarning && (
342
+ {routeWarning && (
334
343
  <>
335
344
  <Alert
336
345
  variant="alarm"
337
346
  type="warning"
338
- title={getQuoteUpdateWarningMessage(quoteWarning)}
347
+ title={getRouteWarningMessage(routeWarning)}
339
348
  />
340
349
  <Divider size={12} />
341
350
  </>
@@ -374,6 +383,9 @@ export function ConfirmWalletsModal(props: PropTypes) {
374
383
  chain={requiredWallet}
375
384
  isSelected={isSelected}
376
385
  selectWallet={onChange}
386
+ multiWallets={config?.multiWallets ?? true}
387
+ supportedWallets={config?.wallets ?? []}
388
+ config={config}
377
389
  limit={NUMBER_OF_WALLETS_TO_DISPLAY}
378
390
  onShowMore={() =>
379
391
  setShowMoreWalletFor(blockchain?.name ?? '')
@@ -381,7 +393,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
381
393
  />
382
394
  </ListContainer>
383
395
  {!isLastWallet && <Divider size={32} />}
384
- {isLastWallet && config?.customDestination && (
396
+ {isLastWallet && customDestinationEnabled && (
385
397
  <CustomDestination>
386
398
  <CollapsibleRoot
387
399
  ref={customDestinationRef}
@@ -1,9 +1,11 @@
1
- import type { ConfirmSwap } from '../../hooks/useConfirmSwap/useConfirmSwap.types';
1
+ import type { WidgetConfig } from '../..';
2
+ import type { ConfirmSwap } from '../../hooks/useConfirmSwap';
2
3
 
3
4
  export type PropTypes = {
4
5
  open: boolean;
5
6
  onClose: () => void;
6
7
  onCancel: () => void;
7
8
  onCheckBalance: ConfirmSwap['fetch'];
9
+ config?: WidgetConfig;
8
10
  loading: boolean;
9
11
  };
@@ -23,7 +23,7 @@ import {
23
23
  TIME_TO_CLOSE_MODAL,
24
24
  TIME_TO_IGNORE_MODAL,
25
25
  } from '../../pages/WalletsPage';
26
- import { useAppStore } from '../../store/AppStore';
26
+ import { useMetaStore } from '../../store/meta';
27
27
  import { useWalletsStore } from '../../store/wallets';
28
28
  import { getBlockchainDisplayNameFor } from '../../utils/meta';
29
29
  import {
@@ -41,11 +41,10 @@ import {
41
41
  } from './WalletList.styles';
42
42
 
43
43
  export function WalletList(props: PropTypes) {
44
- const { chain, isSelected, selectWallet, limit, onShowMore } = props;
45
- const { config } = useAppStore();
44
+ const { config, chain, isSelected, selectWallet, limit, onShowMore } = props;
46
45
 
47
46
  const connectedWallets = useWalletsStore.use.connectedWallets();
48
- const { blockchains } = useAppStore();
47
+ const { blockchains } = useMetaStore.use.meta();
49
48
  const [openWalletStateModal, setOpenWalletStateModal] =
50
49
  useState<WalletType>('');
51
50
  const [experimentalChainWallet, setExperimentalChainWallet] =
@@ -138,7 +137,7 @@ export function WalletList(props: PropTypes) {
138
137
  });
139
138
  const conciseAddress = address ? getConciseAddress(address) : '';
140
139
 
141
- const experimentalChain = isExperimentalChain(blockchains(), chain);
140
+ const experimentalChain = isExperimentalChain(blockchains, chain);
142
141
 
143
142
  const experimentalChainNotAdded = !connectedWallets.find(
144
143
  (connectedWallet) =>
@@ -181,7 +180,7 @@ export function WalletList(props: PropTypes) {
181
180
  experimentalChainWallet?.chain
182
181
  ? getBlockchainDisplayNameFor(
183
182
  experimentalChainWallet.chain,
184
- blockchains()
183
+ blockchains
185
184
  )
186
185
  : undefined;
187
186
  return (
@@ -1,9 +1,12 @@
1
- import type { Wallet } from '../../types';
1
+ import type { Wallet, WidgetConfig } from '../../types';
2
2
 
3
3
  export type PropTypes = {
4
4
  chain: string;
5
+ supportedWallets: WidgetConfig['wallets'];
5
6
  isSelected: (walletType: string, chain: string) => boolean;
6
7
  selectWallet: (wallet: Wallet) => void;
8
+ multiWallets: boolean;
9
+ config?: WidgetConfig;
7
10
  limit?: number;
8
11
  onShowMore: () => void;
9
12
  };
@@ -10,11 +10,11 @@ export const Container = styled('div', {
10
10
  display: 'flex',
11
11
  },
12
12
 
13
- '.quote-summary': {
13
+ '.route-summary': {
14
14
  padding: '$15 $0',
15
15
  },
16
16
 
17
- '.quote-summary-item': {
17
+ '.route-summary-item': {
18
18
  display: 'flex',
19
19
  justifyContent: 'space-between',
20
20
  alignItems: 'center',
@@ -26,7 +26,7 @@ export const Container = styled('div', {
26
26
  alignItems: 'center',
27
27
  },
28
28
 
29
- '.quote-summary-separator': {
29
+ '.route-summary-separator': {
30
30
  width: '0px',
31
31
  height: '$16',
32
32
  borderLeft: '1px solid $neutral400',
@@ -6,8 +6,8 @@ import { Container, StepSeparator } from './LoadingSwapDetails.styles';
6
6
  import { LoadingSwapDetailStep } from './LoadingSwapDetailStep';
7
7
 
8
8
  export function LoadingSwapDetails() {
9
- const quoteSummary = (
10
- <div className="quote-summary-item">
9
+ const routeSummary = (
10
+ <div className="route-summary-item">
11
11
  <div className="token-amount">
12
12
  <ChainToken loading size="medium" chainImage="" tokenImage="" />
13
13
  <Divider size={8} direction="horizontal" />
@@ -27,10 +27,10 @@ export function LoadingSwapDetails() {
27
27
  <Skeleton width={60} height={10} variant="rounded" />
28
28
  </div>
29
29
 
30
- <div className="quote-summary">
31
- {quoteSummary}
32
- <div className="quote-summary-separator"></div>
33
- {quoteSummary}
30
+ <div className="route-summary">
31
+ {routeSummary}
32
+ <div className="route-summary-separator"></div>
33
+ {routeSummary}
34
34
  </div>
35
35
 
36
36
  <div className="swaps-steps">
@@ -1,40 +1,33 @@
1
- import type { Info } from './NoResult.types';
1
+ import type { Info } from './NoRoutes.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
4
 
5
5
  import { errorMessages } from '../../constants/errors';
6
- import {
7
- type NoResultError,
8
- QuoteErrorType,
9
- type QuoteRequestFailed,
10
- } from '../../types';
11
6
 
12
7
  export function makeInfo(
13
- error: NoResultError | QuoteRequestFailed | null,
8
+ diagnosisMessage: string | null,
14
9
  disabledLiquiditySources: string[],
10
+ hasError: boolean,
15
11
  toggleAllLiquiditySources: (shouldReset: boolean) => void,
16
- refetchQuote: () => void
12
+ refetchBestRoute: () => void
17
13
  ): Info {
18
- if (error?.type === QuoteErrorType.REQUEST_FAILED) {
14
+ if (hasError) {
19
15
  return {
20
16
  alert: {
21
17
  type: 'warning',
22
18
  text: errorMessages().genericServerError,
23
19
  action: {
24
- onClick: refetchQuote,
20
+ onClick: refetchBestRoute,
25
21
  title: i18n.t('Retry'),
26
22
  },
27
23
  },
28
24
  description: '',
29
25
  };
30
- } else if (
31
- error?.type === QuoteErrorType.NO_RESULT &&
32
- error.diagnosisMessage
33
- ) {
26
+ } else if (diagnosisMessage) {
34
27
  return {
35
28
  alert: {
36
29
  type: 'error',
37
- text: error.diagnosisMessage,
30
+ text: diagnosisMessage,
38
31
  action: null,
39
32
  },
40
33
  description: '',
@@ -54,6 +47,6 @@ export function makeInfo(
54
47
  }
55
48
  return {
56
49
  alert: null,
57
- description: errorMessages().noResultError.description,
50
+ description: errorMessages().noRoutesError.description,
58
51
  };
59
52
  }
@@ -1,11 +1,9 @@
1
1
  import { styled } from '@rango-dev/ui';
2
2
 
3
3
  export const Container = styled('div', {
4
- minHeight: '162px',
5
4
  display: 'flex',
6
5
  flexDirection: 'column',
7
6
  alignItems: 'center',
8
- justifyContent: 'center',
9
7
  });
10
8
 
11
9
  export const Footer = styled('div', {
@@ -1,4 +1,4 @@
1
- import type { PropTypes } from './NoResult.types';
1
+ import type { PropTypes } from './NoRoutes.types';
2
2
 
3
3
  import {
4
4
  Alert,
@@ -11,25 +11,27 @@ import {
11
11
  import React from 'react';
12
12
 
13
13
  import { errorMessages } from '../../constants/errors';
14
- import { useAppStore } from '../../store/AppStore';
14
+ import { useMetaStore } from '../../store/meta';
15
15
  import { useSettingsStore } from '../../store/settings';
16
16
 
17
- import { makeInfo } from './NoResult.helpers';
18
- import { Container, Footer, PrefixIcon } from './NoResult.styles';
17
+ import { makeInfo } from './NoRoutes.helper';
18
+ import { Container, Footer, PrefixIcon } from './NoRoutes.styles';
19
19
 
20
- export function NoResult(props: PropTypes) {
21
- const { fetch, error } = props;
20
+ export function NoRoutes(props: PropTypes) {
21
+ const { diagnosisMessage, fetch, error } = props;
22
22
  const disabledLiquiditySources =
23
23
  useSettingsStore.use.disabledLiquiditySources();
24
+ const loadingMetaStatus = useMetaStore.use.loadingStatus();
24
25
  const toggleAllLiquiditySources =
25
26
  useSettingsStore.use.toggleAllLiquiditySources();
26
27
 
27
- const swappers = useAppStore().swappers();
28
+ const hasError = error || loadingMetaStatus === 'failed';
28
29
 
29
30
  const info = makeInfo(
30
- error,
31
+ diagnosisMessage ?? null,
31
32
  disabledLiquiditySources,
32
- () => toggleAllLiquiditySources(swappers, true),
33
+ hasError,
34
+ toggleAllLiquiditySources,
33
35
  fetch
34
36
  );
35
37
 
@@ -38,7 +40,7 @@ export function NoResult(props: PropTypes) {
38
40
  <NoRouteIcon size={24} color="gray" />
39
41
  <Divider size={4} />
40
42
  <Typography variant="title" size="small">
41
- {errorMessages().noResultError.title}
43
+ {errorMessages().noRoutesError.title}
42
44
  </Typography>
43
45
  {!!info.description && (
44
46
  <Typography
@@ -1,8 +1,7 @@
1
- import type { NoResultError, QuoteRequestFailed } from '../../types';
2
-
3
1
  export interface PropTypes {
4
2
  fetch: () => void;
5
- error: NoResultError | QuoteRequestFailed | null;
3
+ error: boolean;
4
+ diagnosisMessage?: string;
6
5
  }
7
6
 
8
7
  type AlertAction = {
@@ -0,0 +1 @@
1
+ export { NoRoutes } from './NoRoutes';
@@ -10,7 +10,7 @@ import {
10
10
  import React from 'react';
11
11
  import { useNavigate } from 'react-router-dom';
12
12
 
13
- import { useAppStore } from '../../store/AppStore';
13
+ import { useMetaStore } from '../../store/meta';
14
14
  import { useNotificationStore } from '../../store/notification';
15
15
  import { useUiStore } from '../../store/ui';
16
16
 
@@ -26,8 +26,7 @@ export function NotificationContent() {
26
26
  const { getUnreadNotifications } = useNotificationStore();
27
27
 
28
28
  const notifications: Notification[] = getUnreadNotifications();
29
- const blockchains = useAppStore().blockchains();
30
- const tokens = useAppStore().tokens();
29
+ const { tokens, blockchains } = useMetaStore.use.meta();
31
30
  const sortedNotification = notifications
32
31
  .sort((a, b) => b.creationTime - a.creationTime)
33
32
  .slice(0, MAX_NOTIFICATIONS_DISPLAYED);
@@ -0,0 +1,79 @@
1
+ import type { PropTypes } from './RouteErrors.types';
2
+
3
+ import { Alert, Divider, InfoIcon } from '@rango-dev/ui';
4
+ import React from 'react';
5
+
6
+ import { errorMessages } from '../../constants/errors';
7
+ import { useBestRouteStore } from '../../store/bestRoute';
8
+ import { hasLimitError, LimitErrorMessage } from '../../utils/swap';
9
+
10
+ import { Action, Alerts } from './RouteErrors.styles';
11
+ import { RouteErrorsModal } from './RouteErrorsModal';
12
+
13
+ const WARNING_LEVEL_LIMIT = -10;
14
+
15
+ export function RouteErrors(props: PropTypes) {
16
+ const { bestRoute } = useBestRouteStore();
17
+ const {
18
+ highValueLoss,
19
+ percentageChange,
20
+ priceImpactCanNotBeComputed,
21
+ openModal,
22
+ onToggle,
23
+ totalFeeInUsd,
24
+ outputUsdValue,
25
+ inputUsdValue,
26
+ loading,
27
+ extraSpace,
28
+ } = props;
29
+ const error = hasLimitError(bestRoute);
30
+ const { recommendation } = LimitErrorMessage(bestRoute);
31
+
32
+ const showWarnings = !error && (highValueLoss || priceImpactCanNotBeComputed);
33
+ const showAlerts = showWarnings || error;
34
+
35
+ return (
36
+ <>
37
+ {(loading || (extraSpace && !showAlerts)) && <Divider size={20} />}
38
+ {showAlerts && (
39
+ <Alerts>
40
+ {showWarnings && (
41
+ <>
42
+ <Alert
43
+ title={
44
+ highValueLoss
45
+ ? errorMessages().highValueLossError.title
46
+ : errorMessages().unknownPriceError.title
47
+ }
48
+ type={
49
+ highValueLoss && !!percentageChange?.lt(WARNING_LEVEL_LIMIT)
50
+ ? 'error'
51
+ : 'warning'
52
+ }
53
+ variant="alarm"
54
+ action={
55
+ <Action onClick={() => onToggle(true)}>
56
+ <InfoIcon size={12} color="gray" />
57
+ </Action>
58
+ }
59
+ />
60
+ </>
61
+ )}
62
+ {error && (
63
+ <Alert type="error" variant="alarm" title={recommendation} />
64
+ )}
65
+ </Alerts>
66
+ )}
67
+
68
+ <RouteErrorsModal
69
+ highValueLoss={highValueLoss}
70
+ open={openModal}
71
+ onToggle={onToggle}
72
+ percentageChange={percentageChange}
73
+ inputUsdValue={inputUsdValue}
74
+ outputUsdValue={outputUsdValue}
75
+ totalFeeInUsd={totalFeeInUsd}
76
+ />
77
+ </>
78
+ );
79
+ }
@@ -0,0 +1,29 @@
1
+ import type BigNumber from 'bignumber.js';
2
+
3
+ export interface PropTypes {
4
+ openModal: boolean;
5
+ onToggle: (open: boolean) => void;
6
+ totalFeeInUsd: BigNumber | null;
7
+ outputUsdValue: BigNumber | null;
8
+ inputUsdValue: BigNumber | null;
9
+ percentageChange: BigNumber | null;
10
+ highValueLoss: boolean;
11
+ priceImpactCanNotBeComputed: boolean;
12
+ loading: boolean;
13
+ extraSpace: boolean;
14
+ }
15
+
16
+ type ModalPropTypesKeys = keyof Omit<
17
+ PropTypes,
18
+ 'priceImpactCanNotBeComputed' | 'openModal' | 'extraSpace' | 'loading'
19
+ >;
20
+
21
+ export type ModalPropTypes = Pick<PropTypes, ModalPropTypesKeys> & {
22
+ open: boolean;
23
+ };
24
+
25
+ export interface ModalContentData {
26
+ title: string;
27
+ value: string;
28
+ valueColor?: string;
29
+ }