@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,97 +0,0 @@
1
- import type { PropTypes } from './QuoteInfo.types';
2
-
3
- import { Divider } from '@rango-dev/ui';
4
- import React from 'react';
5
-
6
- import { Quote, QuoteSkeleton } from '../../components/Quote';
7
- import { QuoteWarningsAndErrors } from '../../components/QuoteWarningsAndErrors';
8
- import {
9
- TOKEN_AMOUNT_MAX_DECIMALS,
10
- TOKEN_AMOUNT_MIN_DECIMALS,
11
- USD_VALUE_MAX_DECIMALS,
12
- USD_VALUE_MIN_DECIMALS,
13
- } from '../../constants/routing';
14
- import { useQuoteStore } from '../../store/quote';
15
- import { numberToString } from '../../utils/numbers';
16
-
17
- import { QuoteContainer } from './QuoteInfo.styles';
18
-
19
- export function QuoteInfo(props: PropTypes) {
20
- const {
21
- quote,
22
- type,
23
- loading,
24
- error,
25
- warning,
26
- refetchQuote,
27
- showWarningModal,
28
- onOpenWarningModal,
29
- onCloseWarningModal,
30
- onConfirmWarningModal,
31
- expanded = false,
32
- } = props;
33
- const { inputAmount, inputUsdValue, outputUsdValue, outputAmount } =
34
- useQuoteStore();
35
-
36
- const showQuote = quote && quote.result && !loading;
37
- return (
38
- <>
39
- {loading && (
40
- <QuoteContainer>
41
- <QuoteSkeleton type={type} expanded={expanded} />
42
- </QuoteContainer>
43
- )}
44
- {showQuote ? (
45
- <QuoteContainer>
46
- <Quote
47
- quote={quote}
48
- error={error}
49
- warning={warning}
50
- type={type}
51
- expanded={expanded}
52
- recommended={true}
53
- input={{
54
- value: numberToString(
55
- inputAmount,
56
- TOKEN_AMOUNT_MIN_DECIMALS,
57
- TOKEN_AMOUNT_MAX_DECIMALS
58
- ),
59
- usdValue: numberToString(
60
- inputUsdValue,
61
- USD_VALUE_MIN_DECIMALS,
62
- USD_VALUE_MAX_DECIMALS
63
- ),
64
- }}
65
- output={{
66
- value: numberToString(
67
- outputAmount,
68
- TOKEN_AMOUNT_MIN_DECIMALS,
69
- TOKEN_AMOUNT_MAX_DECIMALS
70
- ),
71
- usdValue: numberToString(
72
- outputUsdValue,
73
- USD_VALUE_MIN_DECIMALS,
74
- USD_VALUE_MAX_DECIMALS
75
- ),
76
- }}
77
- />
78
- </QuoteContainer>
79
- ) : null}
80
-
81
- {!warning && !error && <Divider size={16} />}
82
-
83
- {(warning || error) && (
84
- <QuoteWarningsAndErrors
85
- warning={warning}
86
- error={error}
87
- loading={loading}
88
- refetchQuote={refetchQuote}
89
- showWarningModal={showWarningModal}
90
- onOpenWarningModal={onOpenWarningModal}
91
- onCloseWarningModal={onCloseWarningModal}
92
- onConfirmWarningModal={onConfirmWarningModal}
93
- />
94
- )}
95
- </>
96
- );
97
- }
@@ -1,17 +0,0 @@
1
- import type { QuoteProps } from '../../components/Quote/Quote.types';
2
- import type { QuoteError, QuoteWarning } from '../../types';
3
- import type { BestRouteResponse } from 'rango-sdk';
4
-
5
- export type PropTypes = {
6
- quote: BestRouteResponse | null;
7
- type: QuoteProps['type'];
8
- loading: boolean;
9
- error: QuoteError | null;
10
- warning: QuoteWarning | null;
11
- expanded?: boolean;
12
- refetchQuote: () => void;
13
- showWarningModal: boolean;
14
- onOpenWarningModal: () => void;
15
- onCloseWarningModal: () => void;
16
- onConfirmWarningModal: () => void;
17
- };
@@ -1 +0,0 @@
1
- export { QuoteInfo } from './QuoteInfo';
@@ -1 +0,0 @@
1
- export { useConfirmSwap } from './useConfirmSwap';
@@ -1,168 +0,0 @@
1
- import type { ConfirmSwapFetchResult } from './useConfirmSwap.types';
2
- import type { ConfirmSwapWarnings, Wallet } from '../../types';
3
- import type { BestRouteResponse, Token } from 'rango-sdk';
4
-
5
- import { errorMessages } from '../../constants/errors';
6
- import { QuoteErrorType, QuoteUpdateType } from '../../types';
7
- import { numberToString } from '../../utils/numbers';
8
- import {
9
- generateQuoteWarnings,
10
- isNumberOfSwapsChanged,
11
- isQuoteChanged,
12
- isQuoteInternalCoinsUpdated,
13
- isQuoteSwappersUpdated,
14
- } from '../../utils/quote';
15
- import {
16
- checkSlippageErrors,
17
- getBalanceWarnings,
18
- getLimitErrorMessage,
19
- getMinRequiredSlippage,
20
- getPercentageChange,
21
- getQuoteOutputAmount,
22
- hasLimitError,
23
- isOutputAmountChangedALot,
24
- } from '../../utils/swap';
25
-
26
- /**
27
- * A request can be successful but in body of the response, it can be some case which is considered as failed.
28
- */
29
- export function throwErrorIfResponseIsNotValid(response: BestRouteResponse) {
30
- if (!response.result) {
31
- throw new Error(errorMessages().noResultError.title, {
32
- cause: {
33
- type: QuoteErrorType.NO_RESULT,
34
- diagnosisMessage: response.diagnosisMessages?.[0],
35
- },
36
- });
37
- }
38
- const limitError = hasLimitError(response);
39
- if (limitError) {
40
- const { swap, recommendation, fromAmountRangeError } =
41
- getLimitErrorMessage(response);
42
-
43
- throw new Error('bridge limit error', {
44
- cause: {
45
- type: QuoteErrorType.BRIDGE_LIMIT,
46
- swap: swap,
47
- recommendation,
48
- fromAmountRangeError,
49
- },
50
- });
51
- }
52
-
53
- const recommendedSlippages = checkSlippageErrors(response);
54
-
55
- if (recommendedSlippages) {
56
- const minRequiredSlippage = getMinRequiredSlippage(response);
57
- throw new Error('', {
58
- cause: {
59
- type: QuoteErrorType.INSUFFICIENT_SLIPPAGE,
60
- recommendedSlippages,
61
- minRequiredSlippage,
62
- },
63
- });
64
- }
65
-
66
- return response;
67
- }
68
-
69
- export function generateWarnings(
70
- previousQuote: BestRouteResponse,
71
- currentQuote: BestRouteResponse,
72
- params: {
73
- fromToken: Token;
74
- toToken: Token;
75
- tokens: Token[];
76
- selectedWallets: Wallet[];
77
- userSlippage: number;
78
- }
79
- ): ConfirmSwapWarnings {
80
- const quoteChanged = isQuoteChanged(previousQuote, currentQuote);
81
- const output: ConfirmSwapWarnings = {
82
- quote: null,
83
- quoteUpdate: null,
84
- balance: null,
85
- };
86
-
87
- const quoteWarning = generateQuoteWarnings(currentQuote, {
88
- fromToken: params.fromToken,
89
- toToken: params.toToken,
90
- tokens: params.tokens,
91
- userSlippage: params.userSlippage,
92
- });
93
-
94
- if (quoteWarning) {
95
- output.quote = quoteWarning;
96
- }
97
-
98
- if (quoteChanged) {
99
- if (isOutputAmountChangedALot(previousQuote, currentQuote)) {
100
- output.quoteUpdate = {
101
- type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
102
- newOutputAmount: numberToString(getQuoteOutputAmount(currentQuote)),
103
- percentageChange: numberToString(
104
- getPercentageChange(
105
- getQuoteOutputAmount(previousQuote) ?? '',
106
- getQuoteOutputAmount(currentQuote) ?? ''
107
- ),
108
- null,
109
- 2
110
- ),
111
- };
112
- } else if (isNumberOfSwapsChanged(previousQuote, currentQuote)) {
113
- output.quoteUpdate = {
114
- type: QuoteUpdateType.QUOTE_UPDATED,
115
- };
116
- } else if (isQuoteSwappersUpdated(previousQuote, currentQuote)) {
117
- output.quoteUpdate = {
118
- type: QuoteUpdateType.QUOTE_SWAPPERS_UPDATED,
119
- };
120
- } else if (isQuoteInternalCoinsUpdated(previousQuote, currentQuote)) {
121
- output.quoteUpdate = {
122
- type: QuoteUpdateType.QUOTE_COINS_UPDATED,
123
- };
124
- }
125
- }
126
-
127
- const balanceWarnings = getBalanceWarnings(
128
- currentQuote,
129
- params.selectedWallets
130
- );
131
- const enoughBalance = balanceWarnings.length === 0;
132
-
133
- if (!enoughBalance) {
134
- output.balance = {
135
- messages: balanceWarnings,
136
- };
137
- }
138
-
139
- return output;
140
- }
141
-
142
- export function handleQuoteErrors(error: any): ConfirmSwapFetchResult {
143
- if (error?.code === 'ERR_CANCELED') {
144
- return {
145
- swap: null,
146
- error: {
147
- type: QuoteErrorType.REQUEST_CANCELED,
148
- },
149
- warnings: null,
150
- };
151
- }
152
-
153
- if (error.cause) {
154
- return {
155
- swap: null,
156
- error: error.cause,
157
- warnings: null,
158
- };
159
- }
160
-
161
- return {
162
- swap: null,
163
- error: {
164
- type: QuoteErrorType.REQUEST_FAILED,
165
- },
166
- warnings: null,
167
- };
168
- }
@@ -1,136 +0,0 @@
1
- import type { ConfirmSwap, Params } from './useConfirmSwap.types';
2
- import type { PendingSwapSettings } from '../../types';
3
- import type { BestRouteResponse } from 'rango-sdk';
4
-
5
- import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
6
- import { useEffect } from 'react';
7
-
8
- import { useAppStore } from '../../store/AppStore';
9
- import { useQuoteStore } from '../../store/quote';
10
- import { useSettingsStore } from '../../store/settings';
11
- import { useWalletsStore } from '../../store/wallets';
12
- import { QuoteErrorType } from '../../types';
13
- import { createQuoteRequestBody, getWalletsForNewSwap } from '../../utils/swap';
14
- import { useFetchQuote } from '../useFetchQuote';
15
-
16
- import {
17
- generateWarnings,
18
- handleQuoteErrors,
19
- throwErrorIfResponseIsNotValid,
20
- } from './useConfirmSwap.helpers';
21
-
22
- export function useConfirmSwap(): ConfirmSwap {
23
- const {
24
- fromToken,
25
- toToken,
26
- inputAmount,
27
- setQuote,
28
- resetQuote,
29
- quote: initialQuote,
30
- customDestination: customDestinationFromStore,
31
- setQuoteWarningsConfirmed,
32
- } = useQuoteStore();
33
-
34
- const {
35
- slippage,
36
- customSlippage,
37
- affiliatePercent,
38
- affiliateRef,
39
- affiliateWallets,
40
- disabledLiquiditySources,
41
- } = useSettingsStore();
42
- const { connectedWallets } = useWalletsStore();
43
- const blockchains = useAppStore().blockchains();
44
- const tokens = useAppStore().tokens();
45
-
46
- const userSlippage = customSlippage || slippage;
47
-
48
- const { fetch: fetchQuote, cancelFetch, loading } = useFetchQuote();
49
-
50
- useEffect(() => cancelFetch, []);
51
-
52
- const fetch: ConfirmSwap['fetch'] = async (params: Params) => {
53
- const selectedWallets = params.selectedWallets;
54
- const customDestination =
55
- params?.customDestination ?? customDestinationFromStore;
56
-
57
- if (!fromToken || !toToken || !inputAmount || !initialQuote) {
58
- return {
59
- quote: null,
60
- swap: null,
61
- error: null,
62
- warnings: null,
63
- };
64
- }
65
-
66
- const requestBody = createQuoteRequestBody({
67
- fromToken,
68
- toToken,
69
- inputAmount,
70
- wallets: connectedWallets,
71
- selectedWallets,
72
- disabledLiquiditySources,
73
- slippage: userSlippage,
74
- affiliateRef,
75
- affiliatePercent,
76
- affiliateWallets,
77
- initialQuote: initialQuote,
78
- destination: customDestination,
79
- });
80
-
81
- let currentQuote: BestRouteResponse;
82
- try {
83
- currentQuote = await fetchQuote(requestBody).then((response) =>
84
- throwErrorIfResponseIsNotValid(response)
85
- );
86
- setQuote(currentQuote);
87
- } catch (error: any) {
88
- const confirmSwapResult = handleQuoteErrors(error);
89
- if (
90
- confirmSwapResult.error?.type === QuoteErrorType.NO_RESULT ||
91
- confirmSwapResult.error?.type === QuoteErrorType.REQUEST_FAILED
92
- ) {
93
- resetQuote();
94
- }
95
- return confirmSwapResult;
96
- }
97
-
98
- const swapSettings: PendingSwapSettings = {
99
- slippage: userSlippage.toString(),
100
- disabledSwappersGroups: disabledLiquiditySources,
101
- };
102
- const swap = calculatePendingSwap(
103
- inputAmount.toString(),
104
- currentQuote,
105
- getWalletsForNewSwap(selectedWallets),
106
- swapSettings,
107
- false,
108
- { blockchains, tokens }
109
- );
110
-
111
- const confirmSwapWarnings = generateWarnings(initialQuote, currentQuote, {
112
- fromToken,
113
- toToken,
114
- tokens: tokens,
115
- selectedWallets,
116
- userSlippage,
117
- });
118
-
119
- if (confirmSwapWarnings.quoteUpdate) {
120
- setQuoteWarningsConfirmed(false);
121
- }
122
-
123
- return {
124
- quote: currentQuote,
125
- swap,
126
- error: null,
127
- warnings: confirmSwapWarnings,
128
- };
129
- };
130
-
131
- return {
132
- loading,
133
- fetch,
134
- cancelFetch,
135
- };
136
- }
@@ -1,19 +0,0 @@
1
- import type { ConfirmSwapWarnings, QuoteError, Wallet } from '../../types';
2
- import type { PendingSwap } from 'rango-types/lib';
3
-
4
- export type ConfirmSwapFetchResult = {
5
- swap: PendingSwap | null;
6
- error: QuoteError | null;
7
- warnings: ConfirmSwapWarnings | null;
8
- };
9
-
10
- export type ConfirmSwap = {
11
- loading: boolean;
12
- fetch: (params: Params) => Promise<ConfirmSwapFetchResult>;
13
- cancelFetch: () => void;
14
- };
15
-
16
- export type Params = {
17
- selectedWallets: Wallet[];
18
- customDestination?: string;
19
- };
@@ -1,27 +0,0 @@
1
- import { useWallets } from '@rango-dev/wallets-react';
2
- import { useEffect, useRef } from 'react';
3
-
4
- import { SearchParams } from '../constants/searchParams';
5
- import { useAppStore } from '../store/AppStore';
6
-
7
- export function useForceAutoConnect(): void {
8
- const { connect, state } = useWallets();
9
- const initiated = useRef<{ [key: string]: boolean }>({});
10
- const { fetchStatus } = useAppStore();
11
- const walletType =
12
- new URLSearchParams(location.search).get(SearchParams.AUTO_CONNECT) || '';
13
- const walletState = state(walletType);
14
-
15
- useEffect(() => {
16
- const shouldTryConnect =
17
- fetchStatus === 'success' &&
18
- walletType &&
19
- walletState.installed &&
20
- !walletState.connecting &&
21
- !walletState.connected;
22
- if (shouldTryConnect && !initiated.current[walletType]) {
23
- initiated.current[walletType] = true;
24
- void connect(walletType);
25
- }
26
- }, [walletState, fetchStatus]);
27
- }
@@ -1,35 +0,0 @@
1
- import type { WidgetConfig } from '../types';
2
- import type { PropsWithChildren } from 'react';
3
-
4
- import React, { createContext, useContext, useRef } from 'react';
5
-
6
- import { createAppStore } from './app';
7
-
8
- type AppStore = ReturnType<typeof createAppStore>;
9
- type AppStoreProviderProps = PropsWithChildren<{ config?: WidgetConfig }>;
10
-
11
- export const AppStoreContext = createContext<AppStore | null>(null);
12
-
13
- export function useAppStore() {
14
- const store = useContext(AppStoreContext);
15
-
16
- if (!store) {
17
- throw new Error('Missing AppStoreContext.Provider in the tree');
18
- }
19
-
20
- return store();
21
- }
22
-
23
- export function AppStoreProvider(props: AppStoreProviderProps) {
24
- const appStoreRef = useRef<AppStore>();
25
-
26
- if (!appStoreRef.current) {
27
- appStoreRef.current = createAppStore(props.config);
28
- }
29
-
30
- return (
31
- <AppStoreContext.Provider value={appStoreRef.current}>
32
- {props.children}
33
- </AppStoreContext.Provider>
34
- );
35
- }
@@ -1,107 +0,0 @@
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
- };