@lifi/widget 1.32.8 → 2.0.0-alpha.1

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 (343) hide show
  1. package/App.js +3 -3
  2. package/AppDrawer.js +4 -3
  3. package/AppDrawer.style.d.ts +5 -5
  4. package/AppProvider.js +4 -3
  5. package/cjs/App.js +3 -3
  6. package/cjs/AppDrawer.js +4 -3
  7. package/cjs/AppDrawer.style.d.ts +5 -5
  8. package/cjs/AppProvider.js +2 -1
  9. package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +5 -5
  10. package/cjs/components/Card/CardIconButton.d.ts +29 -0
  11. package/cjs/components/Card/CardIconButton.js +17 -0
  12. package/cjs/components/Card/CardLabel.d.ts +26 -0
  13. package/cjs/components/Card/CardLabel.js +45 -0
  14. package/cjs/components/Card/CardTitle.d.ts +2 -2
  15. package/cjs/components/Card/index.d.ts +2 -0
  16. package/cjs/components/Card/index.js +2 -0
  17. package/cjs/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -0
  18. package/cjs/components/GasMessage/FundsSufficiencyMessage.js +16 -0
  19. package/cjs/components/{GasSufficiencyMessage/GasSufficiencyMessage.d.ts → GasMessage/GasMessage.d.ts} +4 -2
  20. package/cjs/components/GasMessage/GasMessage.js +19 -0
  21. package/cjs/components/GasMessage/GasMessage.style.d.ts +34 -0
  22. package/cjs/components/GasMessage/GasMessage.style.js +48 -0
  23. package/cjs/components/GasMessage/GasRefuelMessage.d.ts +3 -0
  24. package/cjs/components/GasMessage/GasRefuelMessage.js +26 -0
  25. package/cjs/components/GasMessage/GasSufficiencyMessage.d.ts +7 -0
  26. package/cjs/components/GasMessage/GasSufficiencyMessage.js +21 -0
  27. package/cjs/components/GasMessage/index.d.ts +2 -0
  28. package/cjs/components/GasMessage/index.js +18 -0
  29. package/cjs/components/Header/Header.style.d.ts +6 -6
  30. package/cjs/components/Header/NavigationHeader.js +4 -4
  31. package/cjs/components/Header/WalletHeader.js +5 -5
  32. package/cjs/components/Insurance/Insurance.d.ts +3 -0
  33. package/cjs/components/Insurance/Insurance.js +11 -0
  34. package/cjs/components/Insurance/InsuranceCard.d.ts +3 -0
  35. package/cjs/components/Insurance/InsuranceCard.js +20 -0
  36. package/cjs/components/Insurance/InsuranceCollapsed.d.ts +3 -0
  37. package/cjs/components/Insurance/InsuranceCollapsed.js +32 -0
  38. package/cjs/components/Insurance/index.d.ts +1 -0
  39. package/cjs/components/{GasSufficiencyMessage → Insurance}/index.js +1 -1
  40. package/cjs/components/Insurance/types.d.ts +14 -0
  41. package/cjs/components/Insurance/types.js +2 -0
  42. package/cjs/components/ListItemButton.d.ts +1 -1
  43. package/cjs/components/NFT/NFT.style.d.ts +1 -1
  44. package/cjs/components/PoweredBy/PoweredBy.style.d.ts +3 -12
  45. package/cjs/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +2 -2
  46. package/cjs/components/SendToWallet/SendToWallet.js +31 -25
  47. package/cjs/components/SendToWallet/SendToWallet.style.d.ts +2 -2
  48. package/cjs/components/SendToWallet/SendToWalletButton.js +3 -3
  49. package/cjs/components/SmallAvatar.d.ts +2 -2
  50. package/cjs/components/Step/CircularProgress.style.d.ts +1 -1
  51. package/cjs/components/Step/DestinationWalletAddress.d.ts +2 -2
  52. package/cjs/components/Step/DestinationWalletAddress.js +4 -8
  53. package/cjs/components/Step/GasStepProcess.d.ts +2 -2
  54. package/cjs/components/Step/GasStepProcess.js +3 -3
  55. package/cjs/components/Step/Step.d.ts +2 -2
  56. package/cjs/components/Step/Step.js +6 -8
  57. package/cjs/components/Step/StepList.d.ts +1 -1
  58. package/cjs/components/Step/StepProcess.d.ts +2 -2
  59. package/cjs/components/Step/StepProcess.js +1 -5
  60. package/cjs/components/Step/StepProcess.style.d.ts +3 -39
  61. package/cjs/components/Step/StepTimer.d.ts +2 -2
  62. package/cjs/components/Step/StepTimer.js +1 -1
  63. package/cjs/components/StepActions/StepActions.d.ts +6 -1
  64. package/cjs/components/StepActions/StepActions.js +54 -17
  65. package/cjs/components/StepActions/StepActions.style.d.ts +1 -1
  66. package/cjs/components/StepActions/types.d.ts +2 -2
  67. package/cjs/components/SwapButton/SwapButton.js +2 -2
  68. package/cjs/components/SwapButton/types.d.ts +1 -2
  69. package/cjs/components/SwapInput/SwapInput.style.d.ts +2 -2
  70. package/cjs/components/SwapInput/SwapInputAdornment.style.d.ts +3 -3
  71. package/cjs/components/SwapInput/SwapInputEndAdornment.js +18 -1
  72. package/cjs/components/SwapRouteCard/SwapRouteCard.d.ts +1 -2
  73. package/cjs/components/SwapRouteCard/SwapRouteCard.js +10 -26
  74. package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +4 -36
  75. package/cjs/components/SwapRouteCard/SwapRouteCard.style.js +7 -38
  76. package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.d.ts +3 -0
  77. package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.js +27 -0
  78. package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +5 -5
  79. package/cjs/components/SwapRouteCard/types.d.ts +2 -2
  80. package/cjs/components/SwapRouteCard/utils.d.ts +5 -0
  81. package/cjs/components/SwapRouteCard/utils.js +32 -2
  82. package/cjs/components/SwapRoutes/SwapRoutes.js +3 -12
  83. package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +4 -11
  84. package/cjs/components/SwapRoutes/{SwapRoutes.style.d.ts → SwapRoutesExpanded.style.d.ts} +0 -9
  85. package/cjs/components/SwapRoutes/{SwapRoutes.style.js → SwapRoutesExpanded.style.js} +1 -12
  86. package/cjs/components/Switch.js +4 -4
  87. package/cjs/components/Token/Token.d.ts +2 -2
  88. package/cjs/components/Token/Token.style.d.ts +2 -2
  89. package/cjs/components/TokenList/TokenList.style.d.ts +2 -2
  90. package/cjs/config/theme.js +1 -1
  91. package/cjs/config/version.d.ts +1 -1
  92. package/cjs/config/version.js +1 -1
  93. package/cjs/hooks/index.d.ts +4 -0
  94. package/cjs/hooks/index.js +4 -0
  95. package/cjs/hooks/useChains.js +2 -2
  96. package/cjs/hooks/useFeaturedTokens.d.ts +1 -1
  97. package/cjs/hooks/useFeaturedTokens.js +2 -2
  98. package/cjs/hooks/useFundsSufficiency.d.ts +5 -0
  99. package/cjs/hooks/useFundsSufficiency.js +73 -0
  100. package/cjs/hooks/useGasRecommendation.d.ts +2 -0
  101. package/cjs/hooks/useGasRecommendation.js +23 -0
  102. package/cjs/hooks/useGasRefuel.d.ts +7 -0
  103. package/cjs/hooks/useGasRefuel.js +61 -0
  104. package/cjs/hooks/useGasSufficiency.d.ts +2 -3
  105. package/cjs/hooks/useGasSufficiency.js +6 -37
  106. package/cjs/hooks/useGetTokenBalancesWithRetry.d.ts +3 -0
  107. package/cjs/hooks/useGetTokenBalancesWithRetry.js +33 -0
  108. package/cjs/hooks/useProcessMessage.d.ts +3 -3
  109. package/cjs/hooks/useSwapRoutes.d.ts +7 -2
  110. package/cjs/hooks/useSwapRoutes.js +31 -11
  111. package/cjs/hooks/useTokenAddressBalance.js +4 -2
  112. package/cjs/hooks/useTokenBalance.js +4 -22
  113. package/cjs/hooks/useTokenBalances.d.ts +1 -1
  114. package/cjs/hooks/useTokenSearch.js +2 -2
  115. package/cjs/hooks/useTokens.js +2 -3
  116. package/cjs/i18n/en.json +14 -7
  117. package/cjs/i18n/it.json +6 -2
  118. package/cjs/i18n/pt.json +234 -0
  119. package/cjs/i18n/uk.json +5 -1
  120. package/cjs/icons/InsuraceLogo.d.ts +2 -0
  121. package/cjs/icons/InsuraceLogo.js +11 -0
  122. package/cjs/icons/index.d.ts +1 -0
  123. package/cjs/icons/index.js +1 -0
  124. package/cjs/index.d.ts +0 -6
  125. package/cjs/index.js +1 -6
  126. package/cjs/pages/MainPage/MainGasMessage.d.ts +3 -0
  127. package/cjs/pages/MainPage/MainGasMessage.js +12 -0
  128. package/cjs/pages/MainPage/MainPage.js +3 -2
  129. package/cjs/pages/MainPage/MainSwapButton.js +1 -1
  130. package/cjs/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.d.ts +1 -1
  131. package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
  132. package/cjs/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +2 -2
  133. package/cjs/pages/SettingsPage/EnabledToolsButton.style.d.ts +1 -1
  134. package/cjs/pages/SettingsPage/RoutePrioritySelect.js +1 -1
  135. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +4 -3
  136. package/cjs/pages/SwapPage/ExchangeRateBottomSheet.d.ts +1 -2
  137. package/cjs/pages/SwapPage/ExchangeRateBottomSheet.js +1 -14
  138. package/cjs/pages/SwapPage/StartSwapButton.d.ts +3 -2
  139. package/cjs/pages/SwapPage/StartSwapButton.js +14 -4
  140. package/cjs/pages/SwapPage/SwapPage.js +18 -7
  141. package/cjs/pages/SwapPage/types.d.ts +9 -0
  142. package/cjs/pages/SwapPage/types.js +2 -0
  143. package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +1 -1
  144. package/cjs/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +2 -1
  145. package/cjs/providers/SDKProvider/SDKProvider.d.ts +2 -2
  146. package/cjs/providers/SDKProvider/SDKProvider.js +2 -1
  147. package/cjs/providers/SwapFormProvider/FormUpdater.js +2 -3
  148. package/cjs/providers/SwapFormProvider/SwapFormProvider.js +2 -3
  149. package/cjs/providers/SwapFormProvider/index.d.ts +1 -0
  150. package/cjs/providers/SwapFormProvider/index.js +1 -0
  151. package/cjs/providers/WidgetProvider/WidgetProvider.js +17 -4
  152. package/cjs/providers/WidgetProvider/utils.d.ts +1 -1
  153. package/cjs/providers/WidgetProvider/utils.js +2 -4
  154. package/cjs/stores/StoreProvider.js +1 -1
  155. package/cjs/stores/routes/createRouteExecutionStore.js +3 -2
  156. package/cjs/stores/routes/index.d.ts +0 -1
  157. package/cjs/stores/routes/index.js +0 -1
  158. package/cjs/stores/routes/types.d.ts +1 -5
  159. package/cjs/stores/routes/useSetExecutableRoute.d.ts +1 -1
  160. package/cjs/stores/settings/types.d.ts +1 -0
  161. package/cjs/stores/settings/useSettingsStore.js +1 -0
  162. package/cjs/types/widget.d.ts +5 -10
  163. package/cjs/utils/format.js +4 -1
  164. package/components/ActiveSwaps/ActiveSwaps.style.d.ts +5 -5
  165. package/components/Card/CardIconButton.d.ts +29 -0
  166. package/components/Card/CardIconButton.js +14 -0
  167. package/components/Card/CardLabel.d.ts +26 -0
  168. package/components/Card/CardLabel.js +42 -0
  169. package/components/Card/CardTitle.d.ts +2 -2
  170. package/components/Card/index.d.ts +2 -0
  171. package/components/Card/index.js +2 -0
  172. package/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -0
  173. package/components/GasMessage/FundsSufficiencyMessage.js +12 -0
  174. package/components/{GasSufficiencyMessage/GasSufficiencyMessage.d.ts → GasMessage/GasMessage.d.ts} +4 -2
  175. package/components/GasMessage/GasMessage.js +15 -0
  176. package/components/GasMessage/GasMessage.style.d.ts +34 -0
  177. package/components/GasMessage/GasMessage.style.js +45 -0
  178. package/components/GasMessage/GasRefuelMessage.d.ts +3 -0
  179. package/components/GasMessage/GasRefuelMessage.js +22 -0
  180. package/components/GasMessage/GasSufficiencyMessage.d.ts +7 -0
  181. package/components/GasMessage/GasSufficiencyMessage.js +17 -0
  182. package/components/GasMessage/index.d.ts +2 -0
  183. package/components/GasMessage/index.js +2 -0
  184. package/components/Header/Header.style.d.ts +6 -6
  185. package/components/Header/NavigationHeader.js +4 -4
  186. package/components/Header/WalletHeader.js +6 -6
  187. package/components/Insurance/Insurance.d.ts +3 -0
  188. package/components/Insurance/Insurance.js +7 -0
  189. package/components/Insurance/InsuranceCard.d.ts +3 -0
  190. package/components/Insurance/InsuranceCard.js +16 -0
  191. package/components/Insurance/InsuranceCollapsed.d.ts +3 -0
  192. package/components/Insurance/InsuranceCollapsed.js +28 -0
  193. package/components/Insurance/index.d.ts +1 -0
  194. package/components/Insurance/index.js +1 -0
  195. package/components/Insurance/types.d.ts +14 -0
  196. package/components/Insurance/types.js +1 -0
  197. package/components/ListItemButton.d.ts +1 -1
  198. package/components/NFT/NFT.style.d.ts +1 -1
  199. package/components/PoweredBy/PoweredBy.style.d.ts +3 -12
  200. package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +2 -2
  201. package/components/SendToWallet/SendToWallet.js +34 -28
  202. package/components/SendToWallet/SendToWallet.style.d.ts +2 -2
  203. package/components/SendToWallet/SendToWalletButton.js +4 -4
  204. package/components/SmallAvatar.d.ts +2 -2
  205. package/components/Step/CircularProgress.style.d.ts +1 -1
  206. package/components/Step/DestinationWalletAddress.d.ts +2 -2
  207. package/components/Step/DestinationWalletAddress.js +4 -8
  208. package/components/Step/GasStepProcess.d.ts +2 -2
  209. package/components/Step/GasStepProcess.js +3 -3
  210. package/components/Step/Step.d.ts +2 -2
  211. package/components/Step/Step.js +6 -8
  212. package/components/Step/StepList.d.ts +1 -1
  213. package/components/Step/StepProcess.d.ts +2 -2
  214. package/components/Step/StepProcess.js +1 -5
  215. package/components/Step/StepProcess.style.d.ts +3 -39
  216. package/components/Step/StepTimer.d.ts +2 -2
  217. package/components/Step/StepTimer.js +1 -1
  218. package/components/StepActions/StepActions.d.ts +6 -1
  219. package/components/StepActions/StepActions.js +51 -16
  220. package/components/StepActions/StepActions.style.d.ts +1 -1
  221. package/components/StepActions/types.d.ts +2 -2
  222. package/components/SwapButton/SwapButton.js +2 -2
  223. package/components/SwapButton/types.d.ts +1 -2
  224. package/components/SwapInput/SwapInput.style.d.ts +2 -2
  225. package/components/SwapInput/SwapInputAdornment.style.d.ts +3 -3
  226. package/components/SwapInput/SwapInputEndAdornment.js +19 -2
  227. package/components/SwapRouteCard/SwapRouteCard.d.ts +1 -2
  228. package/components/SwapRouteCard/SwapRouteCard.js +11 -26
  229. package/components/SwapRouteCard/SwapRouteCard.style.d.ts +4 -36
  230. package/components/SwapRouteCard/SwapRouteCard.style.js +7 -38
  231. package/components/SwapRouteCard/SwapRouteCardEssentials.d.ts +3 -0
  232. package/components/SwapRouteCard/SwapRouteCardEssentials.js +23 -0
  233. package/components/SwapRouteCard/SwapRouteCardSkeleton.js +5 -5
  234. package/components/SwapRouteCard/types.d.ts +2 -2
  235. package/components/SwapRouteCard/utils.d.ts +5 -0
  236. package/components/SwapRouteCard/utils.js +30 -1
  237. package/components/SwapRoutes/SwapRoutes.js +5 -14
  238. package/components/SwapRoutes/SwapRoutesExpanded.js +4 -11
  239. package/components/SwapRoutes/{SwapRoutes.style.d.ts → SwapRoutesExpanded.style.d.ts} +0 -9
  240. package/components/SwapRoutes/{SwapRoutes.style.js → SwapRoutesExpanded.style.js} +1 -12
  241. package/components/Switch.js +5 -5
  242. package/components/Token/Token.d.ts +2 -2
  243. package/components/Token/Token.style.d.ts +2 -2
  244. package/components/TokenList/TokenList.style.d.ts +2 -2
  245. package/config/theme.js +1 -1
  246. package/config/version.d.ts +1 -1
  247. package/config/version.js +1 -1
  248. package/hooks/index.d.ts +4 -0
  249. package/hooks/index.js +4 -0
  250. package/hooks/useChains.js +2 -2
  251. package/hooks/useFeaturedTokens.d.ts +1 -1
  252. package/hooks/useFeaturedTokens.js +2 -2
  253. package/hooks/useFundsSufficiency.d.ts +5 -0
  254. package/hooks/useFundsSufficiency.js +69 -0
  255. package/hooks/useGasRecommendation.d.ts +2 -0
  256. package/hooks/useGasRecommendation.js +19 -0
  257. package/hooks/useGasRefuel.d.ts +7 -0
  258. package/hooks/useGasRefuel.js +57 -0
  259. package/hooks/useGasSufficiency.d.ts +2 -3
  260. package/hooks/useGasSufficiency.js +7 -38
  261. package/hooks/useGetTokenBalancesWithRetry.d.ts +3 -0
  262. package/hooks/useGetTokenBalancesWithRetry.js +29 -0
  263. package/hooks/useProcessMessage.d.ts +3 -3
  264. package/hooks/useSwapRoutes.d.ts +7 -2
  265. package/hooks/useSwapRoutes.js +32 -12
  266. package/hooks/useTokenAddressBalance.js +4 -2
  267. package/hooks/useTokenBalance.js +5 -23
  268. package/hooks/useTokenBalances.d.ts +1 -1
  269. package/hooks/useTokenSearch.js +2 -2
  270. package/hooks/useTokens.js +2 -3
  271. package/i18n/en.json +14 -7
  272. package/i18n/it.json +6 -2
  273. package/i18n/pt.json +234 -0
  274. package/i18n/uk.json +5 -1
  275. package/icons/InsuraceLogo.d.ts +2 -0
  276. package/icons/InsuraceLogo.js +7 -0
  277. package/icons/index.d.ts +1 -0
  278. package/icons/index.js +1 -0
  279. package/index.d.ts +0 -6
  280. package/index.js +0 -5
  281. package/package.json +12 -12
  282. package/pages/ActiveSwapsPage/ActiveSwapsPage.js +2 -2
  283. package/pages/MainPage/MainGasMessage.d.ts +3 -0
  284. package/pages/MainPage/MainGasMessage.js +8 -0
  285. package/pages/MainPage/MainPage.js +3 -2
  286. package/pages/MainPage/MainSwapButton.js +1 -1
  287. package/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.d.ts +1 -1
  288. package/pages/SettingsPage/ColorSchemeButtonGroup.js +2 -2
  289. package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +2 -2
  290. package/pages/SettingsPage/EnabledToolsButton.style.d.ts +1 -1
  291. package/pages/SettingsPage/RoutePrioritySelect.js +1 -1
  292. package/pages/SwapDetailsPage/SwapDetailsPage.js +5 -4
  293. package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
  294. package/pages/SwapPage/ExchangeRateBottomSheet.d.ts +1 -2
  295. package/pages/SwapPage/ExchangeRateBottomSheet.js +0 -12
  296. package/pages/SwapPage/StartSwapButton.d.ts +3 -2
  297. package/pages/SwapPage/StartSwapButton.js +13 -4
  298. package/pages/SwapPage/SwapPage.js +21 -10
  299. package/pages/SwapPage/types.d.ts +9 -0
  300. package/pages/SwapPage/types.js +1 -0
  301. package/pages/SwapRoutesPage/SwapRoutesPage.js +1 -1
  302. package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +2 -1
  303. package/providers/SDKProvider/SDKProvider.d.ts +2 -2
  304. package/providers/SDKProvider/SDKProvider.js +3 -2
  305. package/providers/SwapFormProvider/FormUpdater.js +2 -3
  306. package/providers/SwapFormProvider/SwapFormProvider.js +2 -3
  307. package/providers/SwapFormProvider/index.d.ts +1 -0
  308. package/providers/SwapFormProvider/index.js +1 -0
  309. package/providers/WidgetProvider/WidgetProvider.js +17 -4
  310. package/providers/WidgetProvider/utils.d.ts +1 -1
  311. package/providers/WidgetProvider/utils.js +2 -4
  312. package/stores/StoreProvider.js +2 -2
  313. package/stores/routes/createRouteExecutionStore.js +3 -2
  314. package/stores/routes/index.d.ts +0 -1
  315. package/stores/routes/index.js +0 -1
  316. package/stores/routes/types.d.ts +1 -5
  317. package/stores/routes/useSetExecutableRoute.d.ts +1 -1
  318. package/stores/settings/types.d.ts +1 -0
  319. package/stores/settings/useSettingsStore.js +1 -0
  320. package/tsconfig.cjs.tsbuildinfo +1 -1
  321. package/types/widget.d.ts +5 -10
  322. package/utils/format.js +4 -1
  323. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +0 -31
  324. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts +0 -9
  325. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.style.js +0 -14
  326. package/cjs/components/GasSufficiencyMessage/index.d.ts +0 -1
  327. package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +0 -2
  328. package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +0 -13
  329. package/cjs/config/env.d.ts +0 -3
  330. package/cjs/config/env.js +0 -6
  331. package/cjs/stores/routes/useRecommendedRouteStore.d.ts +0 -10
  332. package/cjs/stores/routes/useRecommendedRouteStore.js +0 -39
  333. package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +0 -27
  334. package/components/GasSufficiencyMessage/GasSufficiencyMessage.style.d.ts +0 -9
  335. package/components/GasSufficiencyMessage/GasSufficiencyMessage.style.js +0 -11
  336. package/components/GasSufficiencyMessage/index.d.ts +0 -1
  337. package/components/GasSufficiencyMessage/index.js +0 -1
  338. package/components/SwapRoutes/useSetRecommendedRoute.d.ts +0 -2
  339. package/components/SwapRoutes/useSetRecommendedRoute.js +0 -9
  340. package/config/env.d.ts +0 -3
  341. package/config/env.js +0 -3
  342. package/stores/routes/useRecommendedRouteStore.d.ts +0 -10
  343. package/stores/routes/useRecommendedRouteStore.js +0 -32
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "1.32.8";
2
+ export declare const version = "2.0.0-alpha.1";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '1.32.8';
2
+ export const version = '2.0.0-alpha.1';
package/hooks/index.d.ts CHANGED
@@ -5,7 +5,11 @@ export * from './useDebouncedWatch';
5
5
  export * from './useDefaultElementId';
6
6
  export * from './useExpandableVariant';
7
7
  export * from './useFeaturedTokens';
8
+ export * from './useFundsSufficiency';
9
+ export * from './useGasRecommendation';
10
+ export * from './useGasRefuel';
8
11
  export * from './useGasSufficiency';
12
+ export * from './useGetTokenBalancesWithRetry';
9
13
  export * from './useInitializer';
10
14
  export * from './useNavigateBack';
11
15
  export * from './useProcessMessage';
package/hooks/index.js CHANGED
@@ -5,7 +5,11 @@ export * from './useDebouncedWatch';
5
5
  export * from './useDefaultElementId';
6
6
  export * from './useExpandableVariant';
7
7
  export * from './useFeaturedTokens';
8
+ export * from './useFundsSufficiency';
9
+ export * from './useGasRecommendation';
10
+ export * from './useGasRefuel';
8
11
  export * from './useGasSufficiency';
12
+ export * from './useGetTokenBalancesWithRetry';
9
13
  export * from './useInitializer';
10
14
  export * from './useNavigateBack';
11
15
  export * from './useProcessMessage';
@@ -4,13 +4,13 @@ import { useFormContext } from 'react-hook-form';
4
4
  import { isItemAllowed, SwapFormKey, useLiFi, useWidgetConfig, } from '../providers';
5
5
  import { useChainOrderStore } from '../stores';
6
6
  export const useChains = () => {
7
- const { disabledChains, chains } = useWidgetConfig();
7
+ const { chains } = useWidgetConfig();
8
8
  const lifi = useLiFi();
9
9
  const { getValues, setValue } = useFormContext();
10
10
  const initializeChains = useChainOrderStore((state) => state.initializeChains);
11
11
  const { data, isLoading } = useQuery(['chains'], async () => {
12
12
  const availableChains = await lifi.getChains();
13
- const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains, disabledChains));
13
+ const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains));
14
14
  const chainOrder = initializeChains(filteredChains.map((chain) => chain.id));
15
15
  const [fromChainValue, toChainValue] = getValues([
16
16
  SwapFormKey.FromChain,
@@ -1 +1 @@
1
- export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").Token[];
1
+ export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").Token[] | undefined;
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useWidgetConfig } from '../providers';
3
3
  export const useFeaturedTokens = (selectedChainId) => {
4
- const { featuredTokens, tokens } = useWidgetConfig();
5
- return useMemo(() => [...(tokens?.featured ?? []), ...(featuredTokens ?? [])].filter((token) => token.chainId === selectedChainId), [featuredTokens, selectedChainId, tokens?.featured]);
4
+ const { tokens } = useWidgetConfig();
5
+ return useMemo(() => tokens?.featured?.filter((token) => token.chainId === selectedChainId), [selectedChainId, tokens?.featured]);
6
6
  };
@@ -0,0 +1,5 @@
1
+ import type { Route } from '@lifi/sdk';
2
+ export declare const useFundsSufficiency: (route?: Route) => {
3
+ insufficientFunds: boolean | undefined;
4
+ isInitialLoading: boolean;
5
+ };
@@ -0,0 +1,69 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import Big from 'big.js';
3
+ import { useWatch } from 'react-hook-form';
4
+ import { SwapFormKey, useWallet } from '../providers';
5
+ import { isRouteDone } from '../stores';
6
+ import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
7
+ import { useTokenAddressBalance } from './useTokenAddressBalance';
8
+ const refetchInterval = 30000;
9
+ export const useFundsSufficiency = (route) => {
10
+ const { account, provider } = useWallet();
11
+ const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
12
+ const [fromChainId, fromTokenAddress, fromAmount] = useWatch({
13
+ name: [
14
+ SwapFormKey.FromChain,
15
+ SwapFormKey.FromToken,
16
+ SwapFormKey.FromAmount,
17
+ ],
18
+ });
19
+ let chainId = fromChainId;
20
+ let tokenAddress = fromTokenAddress;
21
+ if (route) {
22
+ chainId = route.fromToken.chainId;
23
+ tokenAddress = route.fromToken.address;
24
+ }
25
+ const { token, isLoading } = useTokenAddressBalance(chainId, tokenAddress);
26
+ const { data: insufficientFunds, isInitialLoading } = useQuery([
27
+ 'funds-sufficiency-check',
28
+ account.address,
29
+ chainId,
30
+ tokenAddress,
31
+ route?.id ?? fromAmount,
32
+ ], async () => {
33
+ if (!account.address || !token) {
34
+ return;
35
+ }
36
+ let currentTokenBalance = Big(token?.amount || 0);
37
+ if (!route || isRouteDone(route)) {
38
+ const insufficientFunds = currentTokenBalance.lt(Big(fromAmount || 0));
39
+ return insufficientFunds;
40
+ }
41
+ const currentAction = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]?.action;
42
+ if (token.chainId === currentAction.fromToken.chainId &&
43
+ token.address === currentAction.fromToken.address &&
44
+ currentTokenBalance.gt(0)) {
45
+ const insufficientFunds = Big(route.fromAmount)
46
+ .div(10 ** route.fromToken.decimals)
47
+ .gt(currentTokenBalance);
48
+ return insufficientFunds;
49
+ }
50
+ const tokenBalances = await getTokenBalancesWithRetry(account.address, [
51
+ currentAction.fromToken,
52
+ ]);
53
+ currentTokenBalance = Big(tokenBalances?.[0]?.amount || 0);
54
+ const insufficientFunds = Big(currentAction.fromAmount)
55
+ .div(10 ** currentAction.fromToken.decimals)
56
+ .gt(currentTokenBalance);
57
+ return insufficientFunds;
58
+ }, {
59
+ enabled: Boolean(account.address && token && !isLoading),
60
+ refetchInterval,
61
+ staleTime: refetchInterval,
62
+ cacheTime: refetchInterval,
63
+ keepPreviousData: true,
64
+ });
65
+ return {
66
+ insufficientFunds,
67
+ isInitialLoading,
68
+ };
69
+ };
@@ -0,0 +1,2 @@
1
+ import type { ChainId } from '@lifi/sdk';
2
+ export declare const useGasRecommendation: (chainId: ChainId, fromChain?: ChainId, fromToken?: string) => import("@tanstack/react-query").UseQueryResult<import("@lifi/sdk").GasRecommendationResponse, unknown>;
@@ -0,0 +1,19 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { useLiFi } from '../providers';
3
+ const refetchInterval = 60000;
4
+ export const useGasRecommendation = (chainId, fromChain, fromToken) => {
5
+ const lifi = useLiFi();
6
+ return useQuery(['gas-recommendation', chainId, fromChain, fromToken], async ({ queryKey: [_, chainId, fromChain, fromToken] }) => {
7
+ const gasRecommendation = await lifi.getGasRecommendation({
8
+ chainId: chainId,
9
+ fromChain: fromChain,
10
+ fromToken: fromToken,
11
+ });
12
+ return gasRecommendation;
13
+ }, {
14
+ enabled: Boolean(chainId),
15
+ refetchInterval,
16
+ staleTime: refetchInterval,
17
+ cacheTime: refetchInterval,
18
+ });
19
+ };
@@ -0,0 +1,7 @@
1
+ export declare const useGasRefuel: () => {
2
+ enabled: boolean;
3
+ availble: boolean | undefined;
4
+ isLoading: boolean;
5
+ chain: import("@lifi/types").ExtendedChain | undefined;
6
+ gasRecommendation: import("@lifi/types").GasRecommendationResponse | undefined;
7
+ };
@@ -0,0 +1,57 @@
1
+ import Big from 'big.js';
2
+ import { useMemo } from 'react';
3
+ import { useWatch } from 'react-hook-form';
4
+ import { useChains } from '.';
5
+ import { SwapFormKey } from '../providers';
6
+ import { useGasRecommendation } from './useGasRecommendation';
7
+ import { useTokenBalance } from './useTokenBalance';
8
+ export const useGasRefuel = () => {
9
+ const { getChainById } = useChains();
10
+ const [fromChainId, fromTokenAddress, toChainId, toTokenAddress, toAddress] = useWatch({
11
+ name: [
12
+ SwapFormKey.FromChain,
13
+ SwapFormKey.FromToken,
14
+ SwapFormKey.ToChain,
15
+ SwapFormKey.ToToken,
16
+ SwapFormKey.ToAddress,
17
+ ],
18
+ });
19
+ const toChain = getChainById(toChainId);
20
+ const { token: nativeToken } = useTokenBalance(toChainId && toChain?.nativeToken, toAddress);
21
+ const { data: gasRecommendation, isLoading } = useGasRecommendation(toChainId, fromChainId, fromTokenAddress);
22
+ const enabled = useMemo(() => {
23
+ if (
24
+ // We don't allow same chain refuel.
25
+ // If a user runs out of gas, he can't send a source chain transaction.
26
+ fromChainId === toChainId ||
27
+ // We don't want to apply auto refuel when swapping to native tokens
28
+ toChain?.nativeToken.address === toTokenAddress ||
29
+ !gasRecommendation?.available ||
30
+ !gasRecommendation.recommended ||
31
+ !nativeToken) {
32
+ return false;
33
+ }
34
+ const tokenBalance = Big(nativeToken.amount ?? 0);
35
+ // check if the user balance < 50% of the recommended amount
36
+ const recommendedAmount = Big(gasRecommendation.recommended.amount)
37
+ .div(10 ** gasRecommendation.recommended.token.decimals)
38
+ .div(2);
39
+ const insufficientGas = tokenBalance.lt(recommendedAmount);
40
+ return insufficientGas;
41
+ }, [
42
+ fromChainId,
43
+ gasRecommendation?.available,
44
+ gasRecommendation?.recommended,
45
+ nativeToken,
46
+ toChain?.nativeToken.address,
47
+ toChainId,
48
+ toTokenAddress,
49
+ ]);
50
+ return {
51
+ enabled: enabled,
52
+ availble: gasRecommendation?.available,
53
+ isLoading: isLoading,
54
+ chain: toChain,
55
+ gasRecommendation,
56
+ };
57
+ };
@@ -9,7 +9,6 @@ export interface GasSufficiency {
9
9
  chain?: EVMChain;
10
10
  }
11
11
  export declare const useGasSufficiency: (route?: Route) => {
12
- insufficientGas: GasSufficiency[] | null | undefined;
13
- insufficientFunds: boolean | null | undefined;
14
- isLoading: boolean;
12
+ insufficientGas: GasSufficiency[] | undefined;
13
+ isInitialLoading: boolean;
15
14
  };
@@ -1,17 +1,15 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import Big from 'big.js';
3
- import { useChains } from '.';
3
+ import { useChains, useGetTokenBalancesWithRetry } from '.';
4
4
  import { useWallet } from '../providers';
5
- import { isRouteDone } from '../stores';
6
- import { useTokenBalance } from './useTokenBalance';
7
5
  const refetchInterval = 30000;
8
6
  export const useGasSufficiency = (route) => {
9
- const { account } = useWallet();
7
+ const { account, provider } = useWallet();
10
8
  const { getChainById } = useChains();
11
- const { token: fromToken, getTokenBalancesWithRetry } = useTokenBalance(route?.fromToken);
12
- const { data: insufficientGas, isInitialLoading: insufficientGasLoading } = useQuery(['gas-sufficiency-check', account.address, route?.id], async () => {
9
+ const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
10
+ const { data: insufficientGas, isInitialLoading } = useQuery(['gas-sufficiency-check', account.address, route?.id], async () => {
13
11
  if (!account.address || !route) {
14
- return null;
12
+ return;
15
13
  }
16
14
  const gasCosts = route.steps
17
15
  .filter((step) => !step.execution || step.execution.status !== 'DONE')
@@ -39,7 +37,7 @@ export const useGasSufficiency = (route) => {
39
37
  }
40
38
  const tokenBalances = await getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
41
39
  if (!tokenBalances?.length) {
42
- return null;
40
+ return;
43
41
  }
44
42
  [route.fromChainId, route.toChainId].forEach((chainId) => {
45
43
  if (gasCosts[chainId]) {
@@ -68,37 +66,8 @@ export const useGasSufficiency = (route) => {
68
66
  staleTime: refetchInterval,
69
67
  cacheTime: refetchInterval,
70
68
  });
71
- const { data: insufficientFunds, isInitialLoading: insufficientFundsLoading, } = useQuery(['funds-sufficiency-check', account.address, route?.id], async () => {
72
- if (!account.address || !fromToken || !route || isRouteDone(route)) {
73
- return null;
74
- }
75
- let currentTokenBalance = Big(fromToken?.amount ?? 0);
76
- const currentAction = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]?.action;
77
- if (fromToken.chainId === currentAction.fromToken.chainId &&
78
- fromToken.address === currentAction.fromToken.address &&
79
- currentTokenBalance.gt(0)) {
80
- const insufficientFunds = Big(route.fromAmount)
81
- .div(10 ** route.fromToken.decimals)
82
- .gt(currentTokenBalance);
83
- return insufficientFunds;
84
- }
85
- const tokenBalances = await getTokenBalancesWithRetry(account.address, [
86
- currentAction.fromToken,
87
- ]);
88
- currentTokenBalance = Big(tokenBalances?.[0]?.amount ?? 0);
89
- const insufficientFunds = Big(currentAction.fromAmount)
90
- .div(10 ** currentAction.fromToken.decimals)
91
- .gt(currentTokenBalance);
92
- return insufficientFunds;
93
- }, {
94
- enabled: Boolean(account.address && route && fromToken),
95
- refetchInterval,
96
- staleTime: refetchInterval,
97
- cacheTime: refetchInterval,
98
- });
99
69
  return {
100
70
  insufficientGas,
101
- insufficientFunds,
102
- isLoading: insufficientGasLoading || insufficientFundsLoading,
71
+ isInitialLoading,
103
72
  };
104
73
  };
@@ -0,0 +1,3 @@
1
+ import type { Provider } from '@ethersproject/providers';
2
+ import type { Token, TokenAmount } from '@lifi/sdk';
3
+ export declare const useGetTokenBalancesWithRetry: (provider?: Provider) => (accountAddress: string, tokens: Token[], depth?: number) => Promise<TokenAmount[] | undefined>;
@@ -0,0 +1,29 @@
1
+ import { isAddress } from '@ethersproject/address';
2
+ import { useCallback } from 'react';
3
+ import { useLiFi } from '../providers';
4
+ export const useGetTokenBalancesWithRetry = (provider) => {
5
+ const lifi = useLiFi();
6
+ const getTokenBalancesWithRetry = useCallback(async (accountAddress, tokens, depth = 0) => {
7
+ try {
8
+ const walletAddress = isAddress(accountAddress)
9
+ ? accountAddress
10
+ : await provider?.resolveName(accountAddress);
11
+ const tokenBalances = await lifi.getTokenBalances(walletAddress, tokens);
12
+ if (!tokenBalances.every((token) => token.blockNumber)) {
13
+ if (depth > 10) {
14
+ console.warn('Token balance backoff depth exceeded.');
15
+ return undefined;
16
+ }
17
+ await new Promise((resolve) => {
18
+ setTimeout(resolve, 1.5 ** depth * 100);
19
+ });
20
+ return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
21
+ }
22
+ return tokenBalances;
23
+ }
24
+ catch (error) {
25
+ //
26
+ }
27
+ }, [lifi, provider]);
28
+ return getTokenBalancesWithRetry;
29
+ };
@@ -1,10 +1,10 @@
1
- import type { EVMChain, Process, Step } from '@lifi/sdk';
1
+ import type { EVMChain, LifiStep, Process } from '@lifi/sdk';
2
2
  import type { TFunction } from 'i18next';
3
- export declare const useProcessMessage: (step?: Step, process?: Process) => {
3
+ export declare const useProcessMessage: (step?: LifiStep, process?: Process) => {
4
4
  title?: string | undefined;
5
5
  message?: string | undefined;
6
6
  };
7
- export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step: Step, process: Process): {
7
+ export declare function getProcessMessage(t: TFunction, getChainById: (chainId: number) => EVMChain | undefined, step: LifiStep, process: Process): {
8
8
  title?: string;
9
9
  message?: string;
10
10
  };
@@ -1,10 +1,15 @@
1
1
  import type { Route, RoutesResponse } from '@lifi/sdk';
2
- export declare const useSwapRoutes: () => {
2
+ interface SwapRoutesProps {
3
+ onSettled?: (data?: RoutesResponse) => void;
4
+ insurableRoute?: Route;
5
+ }
6
+ export declare const useSwapRoutes: ({ onSettled, insurableRoute, }?: SwapRoutesProps) => {
3
7
  routes: Route[] | undefined;
4
8
  isLoading: boolean;
5
9
  isFetching: boolean;
6
10
  isFetched: boolean;
7
11
  dataUpdatedAt: number;
8
12
  refetchTime: number;
9
- refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<RoutesResponse, any>>;
13
+ refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<RoutesResponse, unknown>>;
10
14
  };
15
+ export {};
@@ -4,18 +4,19 @@ import { useQuery, useQueryClient } from '@tanstack/react-query';
4
4
  import Big from 'big.js';
5
5
  import { useWatch } from 'react-hook-form';
6
6
  import { v4 as uuidv4 } from 'uuid';
7
- import { useDebouncedWatch, useToken } from '.';
7
+ import { useDebouncedWatch, useGasRefuel, useToken } from '.';
8
8
  import { SwapFormKey, useLiFi, useWallet, useWidgetConfig } from '../providers';
9
9
  import { useSettings } from '../stores';
10
10
  const refetchTime = 60000;
11
- export const useSwapRoutes = () => {
11
+ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
12
12
  const lifi = useLiFi();
13
- const { variant, sdkConfig } = useWidgetConfig();
13
+ const { variant, sdkConfig, insurance } = useWidgetConfig();
14
14
  const { account, provider } = useWallet();
15
15
  const queryClient = useQueryClient();
16
- const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
16
+ const { slippage, enabledBridges, enabledAutoRefuel, enabledExchanges, routePriority, } = useSettings([
17
17
  'slippage',
18
18
  'routePriority',
19
+ 'enabledAutoRefuel',
19
20
  'enabledBridges',
20
21
  'enabledExchanges',
21
22
  ]);
@@ -35,6 +36,7 @@ export const useSwapRoutes = () => {
35
36
  });
36
37
  const { token: fromToken } = useToken(fromChainId, fromTokenAddress);
37
38
  const { token: toToken } = useToken(toChainId, toTokenAddress);
39
+ const { enabled: enabledRefuel, gasRecommendation } = useGasRefuel();
38
40
  const hasAmount = (!isNaN(fromTokenAmount) && Number(fromTokenAmount) > 0) ||
39
41
  (!isNaN(toTokenAmount) && Number(toTokenAmount) > 0);
40
42
  const contractCallQuoteEnabled = variant === 'nft'
@@ -66,12 +68,12 @@ export const useSwapRoutes = () => {
66
68
  routePriority,
67
69
  variant,
68
70
  sdkConfig?.defaultRouteOptions?.allowSwitchChain,
71
+ enabledRefuel && enabledAutoRefuel,
72
+ gasRecommendation?.fromAmount,
73
+ insurance,
74
+ insurableRoute?.id,
69
75
  ];
70
- const previousDataUpdatedAt = queryClient.getQueryState(queryKey)?.dataUpdatedAt;
71
- const refetchInterval = previousDataUpdatedAt
72
- ? Math.min(Math.abs(refetchTime - (Date.now() - previousDataUpdatedAt)), refetchTime)
73
- : refetchTime;
74
- const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, async ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toAddress, toChainId, toTokenAddress, toTokenAmount, toContractAddress, toContractCallData, toContractGasLimit, slippage, enabledBridges, enabledExchanges, routePriority, variant, allowSwitchChain,], signal, }) => {
76
+ const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } = useQuery(queryKey, async ({ queryKey: [_, fromAddress, fromChainId, fromTokenAddress, fromTokenAmount, toAddress, toChainId, toTokenAddress, toTokenAmount, toContractAddress, toContractCallData, toContractGasLimit, slippage, enabledBridges, enabledExchanges, routePriority, variant, allowSwitchChain, enabledRefuel, gasRecommendationFromAmount, insurance, insurableRouteId,], signal, }) => {
75
77
  let toWalletAddress;
76
78
  try {
77
79
  toWalletAddress =
@@ -117,9 +119,20 @@ export const useSwapRoutes = () => {
117
119
  toAddress: toAddress,
118
120
  gasCostUSD: contractCallQuote.estimate.gasCosts?.[0].amountUSD,
119
121
  steps: [contractCallQuote],
122
+ insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
120
123
  };
121
124
  return { routes: [route] };
122
125
  }
126
+ const allowedBridges = insurableRoute
127
+ ? insurableRoute.steps.flatMap((step) => step.includedSteps
128
+ .filter((includedStep) => includedStep.type === 'cross')
129
+ .map((includedStep) => includedStep.toolDetails.key))
130
+ : enabledBridges;
131
+ const allowedExchanges = insurableRoute
132
+ ? insurableRoute.steps.flatMap((step) => step.includedSteps
133
+ .filter((includedStep) => includedStep.type === 'swap')
134
+ .map((includedStep) => includedStep.toolDetails.key))
135
+ : enabledExchanges;
123
136
  return lifi.getRoutes({
124
137
  fromChainId,
125
138
  fromAmount,
@@ -128,23 +141,29 @@ export const useSwapRoutes = () => {
128
141
  toTokenAddress,
129
142
  fromAddress,
130
143
  toAddress: toWalletAddress,
144
+ fromAmountForGas: enabledRefuel && gasRecommendationFromAmount
145
+ ? gasRecommendationFromAmount
146
+ : undefined,
131
147
  options: {
132
148
  slippage: formattedSlippage,
133
149
  bridges: {
134
- allow: enabledBridges,
150
+ allow: allowedBridges,
135
151
  },
136
152
  exchanges: {
137
- allow: enabledExchanges,
153
+ allow: allowedExchanges,
138
154
  },
139
155
  order: routePriority,
140
156
  allowSwitchChain: variant === 'refuel' ? false : allowSwitchChain,
157
+ insurance: insurance ? Boolean(insurableRoute) : undefined,
141
158
  },
142
159
  }, { signal });
143
160
  }, {
144
161
  enabled: isEnabled,
145
- refetchInterval,
146
162
  staleTime: refetchTime,
147
163
  cacheTime: refetchTime,
164
+ refetchInterval(data, query) {
165
+ return Math.min(Math.abs(refetchTime - (Date.now() - query.state.dataUpdatedAt)), refetchTime);
166
+ },
148
167
  retry(failureCount, error) {
149
168
  if (error?.code === LifiErrorCode.NotFound) {
150
169
  return false;
@@ -170,6 +189,7 @@ export const useSwapRoutes = () => {
170
189
  });
171
190
  }
172
191
  },
192
+ onSettled,
173
193
  });
174
194
  return {
175
195
  routes: data?.routes,
@@ -3,8 +3,10 @@ import { useTokenBalances } from './useTokenBalances';
3
3
  export const useTokenAddressBalance = (chainId, tokenAddress) => {
4
4
  const { tokens, tokensWithBalance, isBalanceLoading, refetch } = useTokenBalances(chainId);
5
5
  const token = useMemo(() => {
6
- const token = (tokensWithBalance ?? tokens)?.find((token) => token.address === tokenAddress && token.chainId === chainId);
7
- return token;
6
+ if (tokenAddress && chainId) {
7
+ const token = (tokensWithBalance ?? tokens)?.find((token) => token.address === tokenAddress && token.chainId === chainId);
8
+ return token;
9
+ }
8
10
  }, [chainId, tokenAddress, tokens, tokensWithBalance]);
9
11
  return {
10
12
  token,
@@ -1,32 +1,14 @@
1
1
  import { useQuery, useQueryClient } from '@tanstack/react-query';
2
2
  import { useCallback, useMemo } from 'react';
3
- import { useLiFi, useWallet } from '../providers';
3
+ import { useWallet } from '../providers';
4
4
  import { formatTokenAmount } from '../utils';
5
+ import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
5
6
  const defaultRefetchInterval = 30000;
6
7
  export const useTokenBalance = (token, accountAddress) => {
7
- const lifi = useLiFi();
8
- const { account } = useWallet();
8
+ const { account, provider } = useWallet();
9
9
  const queryClient = useQueryClient();
10
- const walletAddress = accountAddress ?? account.address;
11
- const getTokenBalancesWithRetry = useCallback(async (accountAddress, tokens, depth = 0) => {
12
- try {
13
- const tokenBalances = await lifi.getTokenBalances(accountAddress, tokens);
14
- if (!tokenBalances.every((token) => token.blockNumber)) {
15
- if (depth > 10) {
16
- console.warn('Token balance backoff depth exceeded.');
17
- return undefined;
18
- }
19
- await new Promise((resolve) => {
20
- setTimeout(resolve, 1.5 ** depth * 100);
21
- });
22
- return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
23
- }
24
- return tokenBalances;
25
- }
26
- catch (error) {
27
- //
28
- }
29
- }, [lifi]);
10
+ const walletAddress = accountAddress || account.address;
11
+ const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
30
12
  const tokenBalanceQueryKey = useMemo(() => ['token-balance', walletAddress, token?.chainId, token?.address], [token?.address, token?.chainId, walletAddress]);
31
13
  const { data, isLoading, refetch } = useQuery(tokenBalanceQueryKey, async ({ queryKey: [, accountAddress] }) => {
32
14
  const cachedToken = queryClient
@@ -2,7 +2,7 @@ import type { Token } from '../types';
2
2
  export declare const useTokenBalances: (selectedChainId?: number) => {
3
3
  tokens: Token[];
4
4
  tokensWithBalance: Token[] | undefined;
5
- featuredTokens: import("@lifi/types").Token[];
5
+ featuredTokens: import("@lifi/types").Token[] | undefined;
6
6
  isLoading: boolean;
7
7
  isBalanceLoading: boolean;
8
8
  refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<Token[], unknown>>;
@@ -10,9 +10,9 @@ export const useTokenSearch = (chainId, tokenQuery, enabled) => {
10
10
  if (token) {
11
11
  queryClient.setQueriesData(['tokens'], (data) => {
12
12
  if (data &&
13
- !data.tokens[chainId].some((t) => t.address === token.address)) {
13
+ !data.tokens[chainId]?.some((t) => t.address === token.address)) {
14
14
  const clonedData = { ...data };
15
- clonedData.tokens[chainId].push(token);
15
+ clonedData.tokens[chainId]?.push(token);
16
16
  return clonedData;
17
17
  }
18
18
  });
@@ -8,14 +8,14 @@ export const useTokens = (selectedChainId) => {
8
8
  const { data, isLoading, dataUpdatedAt } = useQuery(['tokens'], () => lifi.getTokens());
9
9
  const { getChainById, isLoading: isSupportedChainsLoading } = useChains();
10
10
  const featuredTokens = useFeaturedTokens(selectedChainId);
11
- const { tokens: configTokens, chains: configChains, disabledChains, } = useWidgetConfig();
11
+ const { tokens: configTokens, chains: configChains } = useWidgetConfig();
12
12
  const tokens = useMemo(() => {
13
13
  if (isSupportedChainsLoading) {
14
14
  return [];
15
15
  }
16
16
  const chainAllowed = selectedChainId &&
17
17
  getChainById(selectedChainId) &&
18
- isItemAllowed(selectedChainId, configChains, disabledChains);
18
+ isItemAllowed(selectedChainId, configChains);
19
19
  if (!chainAllowed) {
20
20
  return [];
21
21
  }
@@ -44,7 +44,6 @@ export const useTokens = (selectedChainId) => {
44
44
  selectedChainId,
45
45
  getChainById,
46
46
  configChains,
47
- disabledChains,
48
47
  configTokens?.allow,
49
48
  configTokens?.deny,
50
49
  featuredTokens,