@rango-dev/widget-embedded 0.12.1-next.9 → 0.14.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 (279) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/Widget.d.ts.map +1 -1
  3. package/dist/components/AppRouter.d.ts +5 -2
  4. package/dist/components/AppRouter.d.ts.map +1 -1
  5. package/dist/components/AppRoutes.d.ts.map +1 -1
  6. package/dist/components/BlockchainList/BlockchainList.d.ts.map +1 -1
  7. package/dist/components/BlockchainList/BlockchainList.helpers.d.ts.map +1 -1
  8. package/dist/components/BlockchainList/BlockchainList.styles.d.ts +14 -4
  9. package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
  10. package/dist/components/BlockchainsSection/BlockchainsSection.d.ts.map +1 -1
  11. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +6 -1
  12. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
  13. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +1 -1
  14. package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
  15. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +94 -17
  16. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  17. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  18. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  19. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +18 -3
  20. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
  21. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +25 -284
  22. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  23. package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +1 -0
  24. package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
  25. package/dist/components/HeaderButtons/HomeButtons.d.ts.map +1 -1
  26. package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +1 -1
  27. package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
  28. package/dist/components/Layout/Layout.d.ts.map +1 -1
  29. package/dist/components/Layout/Layout.styles.d.ts +18 -3
  30. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  31. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +6 -1
  32. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  33. package/dist/components/LoadingSwapDetails/LoadingSwapDetailStep.d.ts +4 -0
  34. package/dist/components/LoadingSwapDetails/LoadingSwapDetailStep.d.ts.map +1 -0
  35. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.d.ts +3 -0
  36. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.d.ts.map +1 -0
  37. package/dist/components/{SelectableCategoryList/SelectableCategoryList.styles.d.ts → LoadingSwapDetails/LoadingSwapDetails.styles.d.ts} +21 -6
  38. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -0
  39. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.types.d.ts +4 -0
  40. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.types.d.ts.map +1 -0
  41. package/dist/components/LoadingSwapDetails/index.d.ts +2 -0
  42. package/dist/components/LoadingSwapDetails/index.d.ts.map +1 -0
  43. package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +1 -1
  44. package/dist/components/NoRoutes/NoRoutes.styles.d.ts +18 -3
  45. package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
  46. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  47. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +24 -4
  48. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  49. package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -1
  50. package/dist/components/RouteErrors/RouteErrors.styles.d.ts +24 -4
  51. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
  52. package/dist/components/RouteErrors/RouteErrors.types.d.ts +3 -1
  53. package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -1
  54. package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -1
  55. package/dist/components/SearchInput/SearchInput.styles.d.ts +6 -1
  56. package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
  57. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +23 -151
  58. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
  59. package/dist/components/SettingsContainer/index.d.ts +1 -1
  60. package/dist/components/SettingsContainer/index.d.ts.map +1 -1
  61. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  62. package/dist/components/Slippage/Slippage.styles.d.ts +24 -4
  63. package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
  64. package/dist/components/SwapDetails/SwapDetails.Placeholder.d.ts.map +1 -1
  65. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  66. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts +2 -9
  67. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
  68. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +35 -153
  69. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  70. package/dist/components/SwapDetails/SwapDetails.types.d.ts +1 -1
  71. package/dist/components/SwapDetails/SwapDetails.types.d.ts.map +1 -1
  72. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +6 -1
  73. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
  74. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +2 -1
  75. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  76. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
  77. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  78. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  79. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +6 -1
  80. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
  81. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -1
  82. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  83. package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
  84. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +24 -4
  85. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
  86. package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
  87. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  88. package/dist/components/TokenList/TokenList.helpers.d.ts.map +1 -1
  89. package/dist/components/TokenList/TokenList.styles.d.ts +207 -9
  90. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  91. package/dist/components/TokenList/TokenList.types.d.ts +1 -1
  92. package/dist/components/TokenList/TokenList.types.d.ts.map +1 -1
  93. package/dist/components/UpdateUrl.d.ts +6 -1
  94. package/dist/components/UpdateUrl.d.ts.map +1 -1
  95. package/dist/components/WalletModal/WalletModalContent.styles.d.ts +24 -4
  96. package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
  97. package/dist/components/WidgetEvents.d.ts.map +1 -1
  98. package/dist/constants/errors.d.ts +2 -2
  99. package/dist/constants/routing.d.ts +12 -2
  100. package/dist/constants/routing.d.ts.map +1 -1
  101. package/dist/constants.d.ts +2 -0
  102. package/dist/constants.d.ts.map +1 -0
  103. package/dist/globalStyles.d.ts +1 -1
  104. package/dist/globalStyles.d.ts.map +1 -1
  105. package/dist/hooks/useNavigateBack.d.ts.map +1 -1
  106. package/dist/hooks/usePrepareBlockchainList.d.ts +18 -0
  107. package/dist/hooks/usePrepareBlockchainList.d.ts.map +1 -0
  108. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  109. package/dist/hooks/useSyncStoresWithConfig.d.ts +3 -0
  110. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -0
  111. package/dist/hooks/useTheme.d.ts +3 -6
  112. package/dist/hooks/useTheme.d.ts.map +1 -1
  113. package/dist/hooks/useWalletProviders.d.ts +3 -3
  114. package/dist/hooks/useWalletProviders.d.ts.map +1 -1
  115. package/dist/index.js +1 -1
  116. package/dist/index.js.map +4 -4
  117. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  118. package/dist/pages/Home.d.ts.map +1 -1
  119. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  120. package/dist/pages/SelectBlockchainPage.d.ts +1 -2
  121. package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
  122. package/dist/pages/SelectSwapItemsPage.d.ts +1 -5
  123. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  124. package/dist/pages/SettingsPage.d.ts.map +1 -1
  125. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  126. package/dist/pages/WalletsPage.d.ts.map +1 -1
  127. package/dist/services/httpService.d.ts +0 -1
  128. package/dist/services/httpService.d.ts.map +1 -1
  129. package/dist/store/app.d.ts +26 -0
  130. package/dist/store/app.d.ts.map +1 -0
  131. package/dist/store/bestRoute.d.ts +4 -8
  132. package/dist/store/bestRoute.d.ts.map +1 -1
  133. package/dist/store/meta.d.ts +0 -2
  134. package/dist/store/meta.d.ts.map +1 -1
  135. package/dist/store/slices/config.d.ts +8 -0
  136. package/dist/store/slices/config.d.ts.map +1 -0
  137. package/dist/store/slices/data.d.ts +26 -0
  138. package/dist/store/slices/data.d.ts.map +1 -0
  139. package/dist/store/wallets.d.ts.map +1 -1
  140. package/dist/types/config.d.ts +3 -0
  141. package/dist/types/config.d.ts.map +1 -1
  142. package/dist/utils/common.d.ts +1 -0
  143. package/dist/utils/common.d.ts.map +1 -1
  144. package/dist/utils/configs.d.ts +5 -0
  145. package/dist/utils/configs.d.ts.map +1 -1
  146. package/dist/utils/meta.d.ts +1 -0
  147. package/dist/utils/meta.d.ts.map +1 -1
  148. package/dist/utils/numbers.d.ts +3 -1
  149. package/dist/utils/numbers.d.ts.map +1 -1
  150. package/dist/utils/routing.d.ts +6 -3
  151. package/dist/utils/routing.d.ts.map +1 -1
  152. package/dist/utils/settings.d.ts +1 -0
  153. package/dist/utils/settings.d.ts.map +1 -1
  154. package/dist/utils/swap.d.ts +1 -1
  155. package/dist/utils/swap.d.ts.map +1 -1
  156. package/dist/utils/time.d.ts +2 -2
  157. package/dist/utils/time.d.ts.map +1 -1
  158. package/dist/utils/wallets.d.ts +1 -1
  159. package/dist/utils/wallets.d.ts.map +1 -1
  160. package/package.json +8 -8
  161. package/readme.md +3 -1
  162. package/src/Widget.tsx +22 -3
  163. package/src/components/AppRouter.tsx +38 -7
  164. package/src/components/AppRoutes.tsx +4 -28
  165. package/src/components/BlockchainList/BlockchainList.helpers.ts +1 -1
  166. package/src/components/BlockchainList/BlockchainList.styles.ts +6 -5
  167. package/src/components/BlockchainList/BlockchainList.tsx +6 -9
  168. package/src/components/BlockchainsSection/BlockchainsSection.tsx +29 -42
  169. package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +33 -7
  170. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +48 -7
  171. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +59 -16
  172. package/src/components/ConfirmWalletsModal/WalletList.tsx +66 -22
  173. package/src/components/HeaderButtons/HeaderButtons.styles.ts +2 -2
  174. package/src/components/HeaderButtons/HeaderButtons.types.ts +1 -0
  175. package/src/components/HeaderButtons/HomeButtons.tsx +18 -5
  176. package/src/components/HeaderButtons/UnreadNotificationsBadge.tsx +1 -2
  177. package/src/components/HeaderButtons/WalletButton.tsx +4 -1
  178. package/src/components/Layout/Layout.styles.ts +5 -3
  179. package/src/components/Layout/Layout.tsx +5 -20
  180. package/src/components/LoadingSwapDetails/LoadingSwapDetailStep.tsx +41 -0
  181. package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +78 -0
  182. package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +53 -0
  183. package/src/components/LoadingSwapDetails/LoadingSwapDetails.types.ts +3 -0
  184. package/src/components/LoadingSwapDetails/index.ts +1 -0
  185. package/src/components/NoRoutes/NoRoutes.helper.ts +4 -2
  186. package/src/components/NotificationContent/NotificationContent.tsx +3 -7
  187. package/src/components/RouteErrors/RouteErrors.styles.ts +2 -1
  188. package/src/components/RouteErrors/RouteErrors.tsx +37 -26
  189. package/src/components/RouteErrors/RouteErrors.types.ts +3 -1
  190. package/src/components/RouteErrors/RouteErrorsModal.tsx +42 -14
  191. package/src/components/SettingsContainer/SettingsContainer.style.ts +2 -7
  192. package/src/components/SettingsContainer/index.ts +0 -1
  193. package/src/components/Slippage/Slippage.tsx +6 -2
  194. package/src/components/Slippage/SlippageTooltipContent.tsx +1 -1
  195. package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +52 -16
  196. package/src/components/SwapDetails/SwapDetails.helpers.tsx +19 -33
  197. package/src/components/SwapDetails/SwapDetails.styles.ts +10 -14
  198. package/src/components/SwapDetails/SwapDetails.tsx +143 -101
  199. package/src/components/SwapDetails/SwapDetails.types.ts +1 -1
  200. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +5 -4
  201. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +6 -7
  202. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -0
  203. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -1
  204. package/src/components/SwapsGroup/SwapsGroup.tsx +3 -2
  205. package/src/components/SwitchFromAndTo.tsx +1 -35
  206. package/src/components/TokenList/TokenList.helpers.ts +6 -8
  207. package/src/components/TokenList/TokenList.styles.ts +7 -1
  208. package/src/components/TokenList/TokenList.tsx +29 -23
  209. package/src/components/TokenList/TokenList.types.ts +1 -1
  210. package/src/components/UpdateUrl.tsx +7 -1
  211. package/src/components/WidgetEvents.tsx +9 -3
  212. package/src/constants/errors.ts +2 -2
  213. package/src/constants/routing.ts +17 -2
  214. package/src/constants.ts +1 -0
  215. package/src/globalStyles.ts +1 -4
  216. package/src/hooks/useFetchBestRoute.ts +2 -2
  217. package/src/hooks/useNavigateBack.ts +10 -0
  218. package/src/hooks/usePrepareBlockchainList.ts +125 -0
  219. package/src/hooks/useSwapInput.ts +17 -3
  220. package/src/hooks/useSyncStoresWithConfig.ts +102 -0
  221. package/src/hooks/useTheme.ts +37 -75
  222. package/src/hooks/useWalletProviders.ts +7 -7
  223. package/src/pages/ConfirmSwapPage.tsx +65 -36
  224. package/src/pages/HistoryPage.tsx +2 -2
  225. package/src/pages/Home.tsx +114 -50
  226. package/src/pages/LanguagePage.tsx +1 -1
  227. package/src/pages/LiquiditySourcePage.tsx +22 -18
  228. package/src/pages/SelectBlockchainPage.tsx +19 -20
  229. package/src/pages/SelectSwapItemsPage.tsx +66 -88
  230. package/src/pages/SettingsPage.tsx +42 -15
  231. package/src/pages/SwapDetailsPage.tsx +9 -2
  232. package/src/pages/ThemePage.tsx +1 -1
  233. package/src/pages/WalletsPage.tsx +11 -5
  234. package/src/services/httpService.ts +4 -5
  235. package/src/store/app.ts +15 -0
  236. package/src/store/bestRoute.ts +45 -71
  237. package/src/store/meta.ts +11 -29
  238. package/src/store/slices/config.ts +26 -0
  239. package/src/store/slices/data.ts +203 -0
  240. package/src/store/wallets.ts +0 -27
  241. package/src/types/config.ts +3 -0
  242. package/src/utils/common.ts +3 -0
  243. package/src/utils/configs.ts +8 -2
  244. package/src/utils/meta.ts +7 -0
  245. package/src/utils/numbers.ts +3 -2
  246. package/src/utils/routing.ts +76 -14
  247. package/src/utils/settings.ts +15 -0
  248. package/src/utils/swap.ts +82 -26
  249. package/src/utils/time.ts +69 -36
  250. package/src/utils/wallets.ts +49 -29
  251. package/dist/components/BlockchainsChip/BlockchainsChip.d.ts +0 -5
  252. package/dist/components/BlockchainsChip/BlockchainsChip.d.ts.map +0 -1
  253. package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts +0 -151
  254. package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts.map +0 -1
  255. package/dist/components/BlockchainsChip/BlockchainsChip.types.d.ts +0 -6
  256. package/dist/components/BlockchainsChip/BlockchainsChip.types.d.ts.map +0 -1
  257. package/dist/components/BlockchainsChip/index.d.ts +0 -2
  258. package/dist/components/BlockchainsChip/index.d.ts.map +0 -1
  259. package/dist/components/BlockchainsSection/BlockchainSection.helpers.d.ts +0 -3
  260. package/dist/components/BlockchainsSection/BlockchainSection.helpers.d.ts.map +0 -1
  261. package/dist/components/SelectableCategoryList/SelectableCategoryList.d.ts +0 -4
  262. package/dist/components/SelectableCategoryList/SelectableCategoryList.d.ts.map +0 -1
  263. package/dist/components/SelectableCategoryList/SelectableCategoryList.helpers.d.ts +0 -4
  264. package/dist/components/SelectableCategoryList/SelectableCategoryList.helpers.d.ts.map +0 -1
  265. package/dist/components/SelectableCategoryList/SelectableCategoryList.styles.d.ts.map +0 -1
  266. package/dist/components/SelectableCategoryList/SelectableCategoryList.types.d.ts +0 -12
  267. package/dist/components/SelectableCategoryList/SelectableCategoryList.types.d.ts.map +0 -1
  268. package/dist/components/SelectableCategoryList/index.d.ts +0 -2
  269. package/dist/components/SelectableCategoryList/index.d.ts.map +0 -1
  270. package/src/components/BlockchainsChip/BlockchainsChip.styles.ts +0 -30
  271. package/src/components/BlockchainsChip/BlockchainsChip.tsx +0 -15
  272. package/src/components/BlockchainsChip/BlockchainsChip.types.ts +0 -4
  273. package/src/components/BlockchainsChip/index.ts +0 -1
  274. package/src/components/BlockchainsSection/BlockchainSection.helpers.ts +0 -20
  275. package/src/components/SelectableCategoryList/SelectableCategoryList.helpers.ts +0 -20
  276. package/src/components/SelectableCategoryList/SelectableCategoryList.styles.ts +0 -21
  277. package/src/components/SelectableCategoryList/SelectableCategoryList.tsx +0 -79
  278. package/src/components/SelectableCategoryList/SelectableCategoryList.types.ts +0 -12
  279. package/src/components/SelectableCategoryList/index.ts +0 -1
@@ -21,6 +21,7 @@ import {
21
21
  } from '@rango-dev/ui';
22
22
  import React, { forwardRef, useEffect, useState } from 'react';
23
23
 
24
+ import { useAppStore } from '../../store/app';
24
25
  import { useMetaStore } from '../../store/meta';
25
26
  import { useWalletsStore } from '../../store/wallets';
26
27
  import { generateRangeColors } from '../../utils/common';
@@ -28,6 +29,7 @@ import { generateRangeColors } from '../../utils/common';
28
29
  import { LoadingTokenList } from './LoadingTokenList';
29
30
  import {
30
31
  BalanceContainer,
32
+ Container,
31
33
  End,
32
34
  ImageSection,
33
35
  List,
@@ -82,13 +84,14 @@ const renderDesc = (props: RenderDescProps) => {
82
84
  };
83
85
 
84
86
  export function TokenList(props: PropTypes) {
85
- const { list, searchedFor = '', onChange } = props;
87
+ const { list, searchedFor = '', onChange, selectedBlockchain } = props;
86
88
 
87
89
  const [tokens, setTokens] = useState<TokenWithBalance[]>(list);
88
90
  const loadingStatus = useMetaStore.use.loadingStatus();
89
91
  const [hasNextPage, setHasNextPage] = useState<boolean>(true);
90
92
  const loadingWallet = useWalletsStore.use.loading();
91
93
  const { blockchains } = useMetaStore.use.meta();
94
+ const { isTokenPinned } = useAppStore();
92
95
 
93
96
  // eslint-disable-next-line react/display-name
94
97
  const innerElementType: React.FC<CommonProps> = forwardRef((render, ref) => {
@@ -131,27 +134,29 @@ export function TokenList(props: PropTypes) {
131
134
  return (
132
135
  <VirtualizedList
133
136
  Item={({ index, style }) => {
134
- const address = tokens[index].address || '';
137
+ const token = tokens[index];
138
+
139
+ const address = token.address || '';
135
140
  const blockchain = blockchains.find(
136
- (blockchain) => blockchain.name === tokens[index].blockchain
141
+ (blockchain) => blockchain.name === token.blockchain
137
142
  );
138
143
  const color = generateRangeColors(
139
- tokens[index].symbol,
144
+ token.symbol,
140
145
  blockchain?.color || ''
141
146
  );
142
147
 
143
148
  const customCssForTag = {
144
- $$color: color[`${tokens[index].symbol}100`],
149
+ $$color: color[`${token.symbol}100`],
145
150
  [`.${darkTheme} &`]: {
146
- $$color: color[`${tokens[index].symbol}900`],
151
+ $$color: color[`${token.symbol}900`],
147
152
  },
148
153
  backgroundColor: '$$color',
149
154
  };
150
155
 
151
156
  const customCssForTagTitle = {
152
- $$color: color[`${tokens[index].symbol}700`],
157
+ $$color: color[`${token.symbol}700`],
153
158
  [`.${darkTheme} &`]: {
154
- $$color: color[`${tokens[index].symbol}100`],
159
+ $$color: color[`${token.symbol}100`],
155
160
  },
156
161
  color: '$$color',
157
162
  };
@@ -167,14 +172,14 @@ export function TokenList(props: PropTypes) {
167
172
  height: style?.height,
168
173
  }}
169
174
  tab-index={index}
170
- key={`${tokens[index].symbol}${tokens[index].address}`}
171
- id={`${tokens[index].symbol}${tokens[index].address}`}
175
+ key={`${token.symbol}${token.address}`}
176
+ id={`${token.symbol}${token.address}`}
172
177
  hasDivider
173
178
  onClick={() => onChange(tokens[index])}
174
179
  start={
175
180
  <ImageSection>
176
- <Image src={tokens[index].image} size={30} />
177
- {tokens[index].pin && (
181
+ <Image src={token.image} size={30} />
182
+ {isTokenPinned(token) && (
178
183
  <Pin>
179
184
  <PinIcon size={12} color="gray" />
180
185
  </Pin>
@@ -183,11 +188,11 @@ export function TokenList(props: PropTypes) {
183
188
  }
184
189
  title={
185
190
  blockchain?.type === 'COSMOS' ||
186
- !!tokens[index].name ||
187
- (!tokens[index].name && !address) ? (
191
+ !!token.name ||
192
+ (!token.name && !address) ? (
188
193
  <Title>
189
194
  <Typography variant="title" size="xmedium">
190
- {tokens[index].symbol}
195
+ {token.symbol}
191
196
  </Typography>
192
197
  <Divider direction="horizontal" size={4} />
193
198
  <Tag css={customCssForTag}>
@@ -195,7 +200,7 @@ export function TokenList(props: PropTypes) {
195
200
  variant="body"
196
201
  size="xsmall"
197
202
  css={customCssForTagTitle}>
198
- {tokens[index].blockchain}
203
+ {token.blockchain}
199
204
  </TagTitle>
200
205
  </Tag>
201
206
  </Title>
@@ -210,12 +215,12 @@ export function TokenList(props: PropTypes) {
210
215
  token: tokens[index],
211
216
  customCssForTag,
212
217
  customCssForTagTitle,
213
- name: tokens[index].name,
218
+ name: token.name,
214
219
  url: blockchain.info.addressUrl
215
220
  .split('{wallet}')
216
221
  .join(address),
217
222
  })
218
- : tokens[index].name || undefined
223
+ : token.name || undefined
219
224
  }
220
225
  end={
221
226
  loadingWallet ? (
@@ -228,15 +233,15 @@ export function TokenList(props: PropTypes) {
228
233
  tokens[index]?.balance && (
229
234
  <BalanceContainer>
230
235
  <Typography variant="title" size="small">
231
- {tokens[index].balance?.amount}
236
+ {token.balance?.amount}
232
237
  </Typography>
233
238
  <div />
234
- {tokens[index].balance?.usdValue && (
239
+ {token.balance?.usdValue && (
235
240
  <Typography
236
241
  variant="body"
237
242
  color="neutral800"
238
243
  size="xsmall">
239
- {`$${tokens[index].balance?.usdValue}`}
244
+ {`$${token.balance?.usdValue}`}
240
245
  </Typography>
241
246
  )}
242
247
  </BalanceContainer>
@@ -252,18 +257,19 @@ export function TokenList(props: PropTypes) {
252
257
  loadNextPage={loadNextPage}
253
258
  innerElementType={innerElementType}
254
259
  size={60}
260
+ key={`${selectedBlockchain}-${searchedFor}`}
255
261
  />
256
262
  );
257
263
  };
258
264
 
259
265
  return (
260
- <div>
266
+ <Container>
261
267
  <Typography variant="label" size="large">
262
268
  {i18n.t('Select Token')}
263
269
  </Typography>
264
270
  <Divider size={4} />
265
271
  {loadingStatus === 'loading' && <LoadingTokenList size={PAGE_SIZE} />}
266
272
  {loadingStatus === 'success' && <List>{renderList()}</List>}
267
- </div>
273
+ </Container>
268
274
  );
269
275
  }
@@ -5,13 +5,13 @@ export interface TokenWithBalance extends Token {
5
5
  amount: string;
6
6
  usdValue: string;
7
7
  };
8
- pin?: boolean;
9
8
  }
10
9
 
11
10
  export interface PropTypes {
12
11
  list: TokenWithBalance[];
13
12
  searchedFor?: string;
14
13
  onChange: (token: TokenWithBalance) => void;
14
+ selectedBlockchain?: string;
15
15
  }
16
16
 
17
17
  export interface LoadingTokenListProps {
@@ -1,3 +1,5 @@
1
+ import type { WidgetConfig } from '../types';
2
+
1
3
  import { useEffect, useRef } from 'react';
2
4
  import {
3
5
  createSearchParams,
@@ -7,12 +9,15 @@ import {
7
9
 
8
10
  import { navigationRoutes } from '../constants/navigationRoutes';
9
11
  import { SearchParams } from '../constants/searchParams';
12
+ import { useSyncStoresWithConfig } from '../hooks/useSyncStoresWithConfig';
10
13
  import { useBestRouteStore } from '../store/bestRoute';
11
14
  import { useMetaStore } from '../store/meta';
12
15
  import { useUiStore } from '../store/ui';
13
16
  import { searchParamsToToken } from '../utils/routing';
14
17
 
15
- export function UpdateUrl() {
18
+ type Props = { config: WidgetConfig | undefined };
19
+
20
+ export function UpdateUrl(props: Props) {
16
21
  const firstRender = useRef(true);
17
22
  const [searchParams, setSearchParams] = useSearchParams();
18
23
  const location = useLocation();
@@ -31,6 +36,7 @@ export function UpdateUrl() {
31
36
  const loadingStatus = useMetaStore.use.loadingStatus();
32
37
  const { blockchains, tokens } = useMetaStore.use.meta();
33
38
  const setSelectedSwap = useUiStore.use.setSelectedSwap();
39
+ useSyncStoresWithConfig(props.config);
34
40
 
35
41
  useEffect(() => {
36
42
  const params: Record<string, string> = {};
@@ -16,7 +16,7 @@ export function WidgetEvents() {
16
16
  const connectedWallets = useWalletsStore.use.connectedWallets();
17
17
  const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
18
18
  const setNotification = useNotificationStore.use.setNotification();
19
-
19
+ const setAsRead = useNotificationStore.use.setAsRead();
20
20
  const widgetEvents = useEvents();
21
21
 
22
22
  useEffect(() => {
@@ -42,10 +42,16 @@ export function WidgetEvents() {
42
42
  toAccount && getWalletsDetails([toAccount]);
43
43
  }
44
44
  if (
45
- event.type === StepEventType.TX_EXECUTION_BLOCKED &&
46
- validBlockedStatuses.includes(event.status)
45
+ (event.type === StepEventType.TX_EXECUTION_BLOCKED &&
46
+ validBlockedStatuses.includes(event.status)) ||
47
+ event.type === StepEventType.FAILED
47
48
  ) {
48
49
  setNotification(event, route);
50
+ } else if (
51
+ event.type === StepEventType.TX_EXECUTION ||
52
+ event.type === StepEventType.CHECK_STATUS
53
+ ) {
54
+ setAsRead(route.requestId);
49
55
  }
50
56
  });
51
57
 
@@ -22,7 +22,7 @@ export const errorMessages = {
22
22
  decreaseAmount: i18n.t('Bridge Limit Error: Please decrease your amount'),
23
23
  },
24
24
  highValueLossError: {
25
- impacTitle: i18n.t('High Price Impact'),
25
+ impactTitle: i18n.t('High Price Impact'),
26
26
  title: i18n.t('Price impact is too high!'),
27
27
  description: i18n.t(
28
28
  'The price impact is significantly higher than the allowed amount. If you are sure, continue, otherwise, change the swap.'
@@ -35,7 +35,7 @@ export const errorMessages = {
35
35
  ),
36
36
  },
37
37
  unknownPriceError: {
38
- impacTitle: i18n.t('USD Price Unknown'),
38
+ impactTitle: i18n.t('USD Price Unknown'),
39
39
  title: i18n.t('USD Price Unknown, Cannot calculate Price Impact.'),
40
40
  description: i18n.t(
41
41
  'USD Price Unknown, Cannot calculate Price Impact. The price impact may be higher than usual. Are you sure to continue the Swap?'
@@ -1,2 +1,17 @@
1
- export const LOW_PRICE_IMPACT = 3;
2
- export const HIGHT_PRICE_IMPACT = 10;
1
+ export const LOW_PRICE_IMPACT = -3;
2
+ export const HIGHT_PRICE_IMPACT = -10;
3
+
4
+ export const TOKEN_AMOUNT_MIN_DECIMALS = 6;
5
+ export const TOKEN_AMOUNT_MAX_DECIMALS = 6;
6
+
7
+ export const USD_VALUE_MIN_DECIMALS = 4;
8
+ export const USD_VALUE_MAX_DECIMALS = 4;
9
+
10
+ export const GAS_FEE_MIN_DECIMALS = 2;
11
+ export const GAS_FEE_MAX_DECIMALS = 2;
12
+
13
+ export const PERCENTAGE_CHANGE_MIN_DECIMALS = 2;
14
+ export const PERCENTAGE_CHANGE_MAX_DECIMALS = 2;
15
+
16
+ export const BALANCE_MIN_DECIMALS = 8;
17
+ export const BALANCE_MAX_DECIMALS = 8;
@@ -0,0 +1 @@
1
+ export const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
@@ -1,12 +1,9 @@
1
1
  import { globalCss } from '@rango-dev/ui';
2
2
 
3
- export const globalFont = (fontFamily: string) =>
3
+ export const globalFont = () =>
4
4
  globalCss({
5
5
  '@import': [
6
6
  "url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap')",
7
7
  "url('https://fonts.cdnfonts.com/css/times-new-roman')",
8
8
  ],
9
- body: {
10
- fontFamily,
11
- },
12
9
  })();
@@ -12,11 +12,11 @@ interface UseFetchBestRoute {
12
12
 
13
13
  export function useFetchBestRoute(): UseFetchBestRoute {
14
14
  const [loading, setLoading] = useState(false);
15
- const cancel = () => abortController.current?.abort();
16
15
  const abortController = useRef<AbortController | null>(null);
16
+ const cancel = () => abortController.current?.abort();
17
17
 
18
18
  const fetch: UseFetchBestRoute['fetch'] = async (requestBody) => {
19
- abortController.current?.abort();
19
+ cancel();
20
20
  abortController.current = new AbortController();
21
21
 
22
22
  setLoading(true);
@@ -1,10 +1,12 @@
1
1
  import { useInRouterContext, useNavigate } from 'react-router-dom';
2
2
 
3
3
  import { navigationRoutes } from '../constants/navigationRoutes';
4
+ import { useBestRouteStore } from '../store/bestRoute';
4
5
 
5
6
  export function useNavigateBack() {
6
7
  const isRouterInContext = useInRouterContext();
7
8
  const navigate = useNavigate();
9
+ const routeWalletsConfirmed = useBestRouteStore.use.routeWalletsConfirmed();
8
10
 
9
11
  navigationRoutes;
10
12
 
@@ -20,6 +22,14 @@ export function useNavigateBack() {
20
22
  // eslint-disable-next-line @typescript-eslint/no-magic-numbers
21
23
  navigate(-1);
22
24
  } else {
25
+ if (
26
+ [navigationRoutes.settings, navigationRoutes.wallets].includes(
27
+ currentRoute
28
+ ) &&
29
+ routeWalletsConfirmed
30
+ ) {
31
+ return navigate('/' + navigationRoutes.confirmSwap, { replace: true });
32
+ }
23
33
  if (
24
34
  [
25
35
  navigationRoutes.fromSwap,
@@ -0,0 +1,125 @@
1
+ import type { BlockchainMeta } from 'rango-sdk';
2
+
3
+ import { useMemo, useRef } from 'react';
4
+
5
+ interface PrepareListOptions {
6
+ limit?: number;
7
+ selected?: string;
8
+ }
9
+
10
+ interface PrepareListOutput {
11
+ list: BlockchainMeta[];
12
+ more: BlockchainMeta[];
13
+ }
14
+
15
+ /**
16
+ *
17
+ * UI needs some specific logics like limiting the list and sorting,
18
+ * this function is getting the raw blockchains list and return a list for showing in UI.
19
+ *
20
+ */
21
+ export function usePrepareBlockchainList(
22
+ blockchains: BlockchainMeta[],
23
+ options?: PrepareListOptions
24
+ ): PrepareListOutput {
25
+ const prevSelectedBlockchain = useRef({ index: -1, name: '' });
26
+
27
+ blockchains.sort(sortByMostUsedBlockchains);
28
+
29
+ const blockchainsHash = blockchains
30
+ .map((blockchain) => blockchain.name)
31
+ .join('-');
32
+
33
+ return useMemo(() => {
34
+ const list: BlockchainMeta[] = blockchains;
35
+ let more: BlockchainMeta[] = [];
36
+
37
+ // Checking `limit` has set and it should be more than of the list items.
38
+ if (options?.limit && blockchains.length > options.limit) {
39
+ const start = options.limit;
40
+ /** Try find the blockchain and returns the index. */
41
+ const selectedIndex = options.selected
42
+ ? blockchains.findIndex(
43
+ (blockchains) => blockchains.name === options.selected
44
+ )
45
+ : -1;
46
+
47
+ const prevSelectedBlockchainWasInMoreSection =
48
+ prevSelectedBlockchain.current.index > options.limit - 1 &&
49
+ !!blockchains.find(
50
+ (blockchains) =>
51
+ blockchains.name === prevSelectedBlockchain.current.name
52
+ );
53
+
54
+ /*
55
+ * If the selected blockchain is in `more` section, we should move it to front of the list
56
+ */
57
+ if (
58
+ options.selected &&
59
+ ((prevSelectedBlockchainWasInMoreSection &&
60
+ selectedIndex < options.limit - 1) ||
61
+ selectedIndex > options.limit - 1)
62
+ ) {
63
+ blockchains.sort(
64
+ generateSortBySelectedFor(
65
+ prevSelectedBlockchainWasInMoreSection
66
+ ? prevSelectedBlockchain.current.name
67
+ : options.selected
68
+ )
69
+ );
70
+ }
71
+
72
+ /*
73
+ * Splice will modify the original list and returns the deleted items
74
+ * We use the deleted items as `more`
75
+ */
76
+ more = list.splice(start);
77
+ prevSelectedBlockchain.current = {
78
+ index: selectedIndex,
79
+ name: options.selected ?? '',
80
+ };
81
+ }
82
+
83
+ return {
84
+ list,
85
+ more,
86
+ };
87
+ }, [blockchainsHash]);
88
+ }
89
+
90
+ function generateSortBySelectedFor(selected: string) {
91
+ /** Move `selected` blockchain to the front of list. */
92
+ return function sortBySelected(a: BlockchainMeta, b: BlockchainMeta) {
93
+ if (a.name === selected) {
94
+ return -1;
95
+ }
96
+ if (b.name === selected) {
97
+ return 1;
98
+ }
99
+
100
+ return 0;
101
+ };
102
+ }
103
+
104
+ /** There is a hardcoded list of blockchains that we want to show them first in the list. */
105
+ function sortByMostUsedBlockchains(a: BlockchainMeta, b: BlockchainMeta) {
106
+ const mostUsed = ['ETH', 'COSMOS', 'OSMOSIS'];
107
+ const aIndexInMostUsed = mostUsed.findIndex((token) => token === a.name);
108
+ const bIndexInMostUsed = mostUsed.findIndex((token) => token === b.name);
109
+ const aIsMostUsed = aIndexInMostUsed > -1;
110
+ const bIsMostUsed = bIndexInMostUsed > -1;
111
+
112
+ if (aIsMostUsed && bIsMostUsed) {
113
+ return aIndexInMostUsed > bIndexInMostUsed ? 1 : -1;
114
+ }
115
+
116
+ if (aIsMostUsed) {
117
+ return -1;
118
+ }
119
+
120
+ if (bIsMostUsed) {
121
+ return 1;
122
+ }
123
+
124
+ return 0;
125
+ }
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useRef, useState } from 'react';
2
2
 
3
3
  import { useBestRouteStore } from '../store/bestRoute';
4
4
  import { useSettingsStore } from '../store/settings';
@@ -41,6 +41,7 @@ export function useSwapInput(): UseSwapInput {
41
41
  disabledLiquiditySources,
42
42
  } = useSettingsStore();
43
43
  const [error, setError] = useState('');
44
+ const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
44
45
  const userSlippage = customSlippage ?? slippage;
45
46
  const hasTokensValue = !fromToken || !toToken;
46
47
  const shouldSkipRequest =
@@ -53,6 +54,7 @@ export function useSwapInput(): UseSwapInput {
53
54
  setLoading(true);
54
55
  }
55
56
  if (!shouldSkipRequest) {
57
+ resetRoute();
56
58
  const requestBody = createBestRouteRequestBody({
57
59
  fromToken,
58
60
  toToken,
@@ -87,7 +89,8 @@ export function useSwapInput(): UseSwapInput {
87
89
  useEffect(() => {
88
90
  if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
89
91
  setLoading(false);
90
- return cancelFetch();
92
+ cancelFetch();
93
+ return;
91
94
  }
92
95
  if (shouldSkipRequest) {
93
96
  return;
@@ -96,7 +99,18 @@ export function useSwapInput(): UseSwapInput {
96
99
  setLoading(true);
97
100
  debouncedFetch();
98
101
  return cancelFetch;
99
- }, [inputAmount]);
102
+ }, [inputAmount, shouldSkipRequest]);
103
+
104
+ useEffect(() => {
105
+ const disabledLiquiditySourceReset =
106
+ !!prevDisabledLiquiditySources.current.length &&
107
+ !disabledLiquiditySources.length;
108
+ if (!shouldSkipRequest && disabledLiquiditySourceReset) {
109
+ fetch();
110
+ }
111
+ prevDisabledLiquiditySources.current = disabledLiquiditySources;
112
+ return cancelFetch;
113
+ }, [disabledLiquiditySources.length]);
100
114
 
101
115
  return { fetch, loading, error };
102
116
  }
@@ -0,0 +1,102 @@
1
+ import type { WidgetConfig } from '../types';
2
+ import type { Asset } from 'rango-sdk';
3
+
4
+ import { useEffect, useRef } from 'react';
5
+
6
+ import { useBestRouteStore } from '../store/bestRoute';
7
+ import { useMetaStore } from '../store/meta';
8
+ import { useSettingsStore } from '../store/settings';
9
+ import { tokensAreEqual } from '../utils/wallets';
10
+
11
+ export function useSyncStoresWithConfig(config: WidgetConfig | undefined) {
12
+ const {
13
+ setInputAmount,
14
+ setToToken,
15
+ setToBlockchain,
16
+ setFromBlockchain,
17
+ setFromToken,
18
+ } = useBestRouteStore();
19
+
20
+ const {
21
+ meta: { tokens, blockchains },
22
+ loadingStatus: loadingMetaStatus,
23
+ } = useMetaStore();
24
+
25
+ const { setAffiliateRef, setAffiliatePercent, setAffiliateWallets } =
26
+ useSettingsStore();
27
+
28
+ const prevConfigFromToken = useRef<Asset | undefined>(undefined);
29
+ const prevConfigToToken = useRef<Asset | undefined>(undefined);
30
+ const prevConfigFromBlockchain = useRef<string | undefined>(undefined);
31
+ const prevConfigToBlockchain = useRef<string | undefined>(undefined);
32
+
33
+ useEffect(() => {
34
+ setInputAmount(config?.amount?.toString() || '');
35
+ }, [config?.amount]);
36
+
37
+ useEffect(() => {
38
+ if (loadingMetaStatus === 'success') {
39
+ const chain = blockchains.find(
40
+ (chain) => chain.name === config?.from?.blockchain
41
+ );
42
+ const token = tokens.find((t) =>
43
+ tokensAreEqual(t, config?.from?.token || null)
44
+ );
45
+
46
+ if (chain || (!chain && prevConfigFromBlockchain.current)) {
47
+ setFromBlockchain(chain ?? null);
48
+ }
49
+
50
+ if (token || (!token && prevConfigFromToken.current)) {
51
+ setFromToken(token ?? null);
52
+ }
53
+
54
+ prevConfigFromBlockchain.current = config?.from?.blockchain;
55
+ prevConfigFromToken.current = config?.from?.token;
56
+ }
57
+ }, [
58
+ config?.from?.token?.symbol,
59
+ config?.from?.token?.address,
60
+ config?.from?.blockchain,
61
+ config?.from?.blockchain,
62
+ loadingMetaStatus,
63
+ ]);
64
+
65
+ useEffect(() => {
66
+ if (loadingMetaStatus === 'success') {
67
+ const chain = blockchains.find(
68
+ (chain) => chain.name === config?.to?.blockchain
69
+ );
70
+ const token = tokens.find((t) =>
71
+ tokensAreEqual(t, config?.to?.token || null)
72
+ );
73
+
74
+ if (chain || (!chain && prevConfigToBlockchain.current)) {
75
+ setToBlockchain(chain ?? null);
76
+ }
77
+
78
+ if (token || (!token && prevConfigToToken.current)) {
79
+ setToToken(token ?? null);
80
+ }
81
+
82
+ prevConfigToBlockchain.current = config?.to?.blockchain;
83
+ prevConfigToToken.current = config?.to?.token;
84
+ }
85
+ }, [
86
+ config?.to?.token?.symbol,
87
+ config?.to?.token?.address,
88
+ config?.to?.token?.blockchain,
89
+ config?.to?.blockchain,
90
+ loadingMetaStatus,
91
+ ]);
92
+
93
+ useEffect(() => {
94
+ setAffiliateRef(config?.affiliate?.ref ?? null);
95
+ setAffiliatePercent(config?.affiliate?.percent ?? null);
96
+ setAffiliateWallets(config?.affiliate?.wallets ?? null);
97
+ }, [
98
+ config?.affiliate?.ref,
99
+ config?.affiliate?.percent,
100
+ config?.affiliate?.wallets,
101
+ ]);
102
+ }