0xtrails 0.6.6 → 0.7.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 (365) hide show
  1. package/dist/aave.d.ts +10 -2
  2. package/dist/aave.d.ts.map +1 -1
  3. package/dist/analytics.d.ts +26 -0
  4. package/dist/analytics.d.ts.map +1 -1
  5. package/dist/{ccip-CbJrlK-L.js → ccip-fConRNoG.js} +21 -21
  6. package/dist/chains.d.ts +23 -8
  7. package/dist/chains.d.ts.map +1 -1
  8. package/dist/constants.d.ts +5 -5
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/customTokens.d.ts +12 -0
  11. package/dist/customTokens.d.ts.map +1 -0
  12. package/dist/decoders.d.ts +2 -2
  13. package/dist/decoders.d.ts.map +1 -1
  14. package/dist/error.d.ts.map +1 -1
  15. package/dist/fees.d.ts +37 -2
  16. package/dist/fees.d.ts.map +1 -1
  17. package/dist/gasless.d.ts +15 -36
  18. package/dist/gasless.d.ts.map +1 -1
  19. package/dist/{index-w7_dK4c5.js → index-BbajxCG_.js} +59269 -77146
  20. package/dist/index.d.ts +8 -6
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +828 -359
  23. package/dist/indexerClient.d.ts.map +1 -1
  24. package/dist/intentReceiptMonitor.d.ts +1 -1
  25. package/dist/intentReceiptMonitor.d.ts.map +1 -1
  26. package/dist/intentReceiptPoller.d.ts +1 -1
  27. package/dist/intentReceiptPoller.d.ts.map +1 -1
  28. package/dist/intents.d.ts +3 -2
  29. package/dist/intents.d.ts.map +1 -1
  30. package/dist/mode.d.ts +1 -1
  31. package/dist/mode.d.ts.map +1 -1
  32. package/dist/mutations.d.ts +2 -2
  33. package/dist/mutations.d.ts.map +1 -1
  34. package/dist/prepareSend.d.ts +2 -2
  35. package/dist/prepareSend.d.ts.map +1 -1
  36. package/dist/prices.d.ts +1 -1
  37. package/dist/prices.d.ts.map +1 -1
  38. package/dist/sequenceWallet.d.ts +2 -2
  39. package/dist/sequenceWallet.d.ts.map +1 -1
  40. package/dist/time.d.ts +6 -0
  41. package/dist/time.d.ts.map +1 -1
  42. package/dist/tokenBalances.d.ts +40 -25
  43. package/dist/tokenBalances.d.ts.map +1 -1
  44. package/dist/tokens.d.ts +54 -14
  45. package/dist/tokens.d.ts.map +1 -1
  46. package/dist/trailsClient.d.ts +1 -1
  47. package/dist/trailsClient.d.ts.map +1 -1
  48. package/dist/trailsRouter.d.ts +2 -1
  49. package/dist/trailsRouter.d.ts.map +1 -1
  50. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +3 -2
  51. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
  52. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +2 -1
  53. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
  54. package/dist/transactionIntent/execution/transactionState.d.ts +1 -1
  55. package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
  56. package/dist/transactionIntent/handlers/crossChain.d.ts +5 -3
  57. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
  58. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +5 -3
  59. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
  60. package/dist/transactionIntent/quote/feeExtractors.d.ts +1 -6
  61. package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -1
  62. package/dist/transactionIntent/quote/normalizeQuote.d.ts +4 -2
  63. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
  64. package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
  65. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
  66. package/dist/transactionIntent/types.d.ts +28 -5
  67. package/dist/transactionIntent/types.d.ts.map +1 -1
  68. package/dist/transactionIntent/utils/testnetHelpers.d.ts +0 -1
  69. package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -1
  70. package/dist/transactionIntent/validators.d.ts +0 -2
  71. package/dist/transactionIntent/validators.d.ts.map +1 -1
  72. package/dist/transactions.d.ts +2 -2
  73. package/dist/transactions.d.ts.map +1 -1
  74. package/dist/utils.d.ts +7 -0
  75. package/dist/utils.d.ts.map +1 -1
  76. package/dist/wallets.d.ts +1 -0
  77. package/dist/wallets.d.ts.map +1 -1
  78. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  79. package/dist/widget/components/AddressWalletIcon.d.ts +6 -0
  80. package/dist/widget/components/AddressWalletIcon.d.ts.map +1 -0
  81. package/dist/widget/components/ChainFilterDropdown.d.ts +2 -6
  82. package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
  83. package/dist/widget/components/ChainImage.d.ts.map +1 -1
  84. package/dist/widget/components/ChainList.d.ts +0 -5
  85. package/dist/widget/components/ChainList.d.ts.map +1 -1
  86. package/dist/widget/components/ClassicSwap.d.ts +6 -6
  87. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  88. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  89. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  90. package/dist/widget/components/DebugMenu.d.ts +1 -1
  91. package/dist/widget/components/DebugMenu.d.ts.map +1 -1
  92. package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
  93. package/dist/widget/components/DepositTracker.d.ts.map +1 -1
  94. package/dist/widget/components/Earn.d.ts +5 -5
  95. package/dist/widget/components/Earn.d.ts.map +1 -1
  96. package/dist/widget/components/FeeOption.d.ts +1 -1
  97. package/dist/widget/components/FeeOption.d.ts.map +1 -1
  98. package/dist/widget/components/FeeOptions.d.ts +2 -2
  99. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  100. package/dist/widget/components/Footer.d.ts +1 -1
  101. package/dist/widget/components/Footer.d.ts.map +1 -1
  102. package/dist/widget/components/Fund.d.ts +5 -5
  103. package/dist/widget/components/Fund.d.ts.map +1 -1
  104. package/dist/widget/components/FundMethods.d.ts +0 -1
  105. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  106. package/dist/widget/components/FundSwap.d.ts +6 -6
  107. package/dist/widget/components/FundSwap.d.ts.map +1 -1
  108. package/dist/widget/components/HookModalContent.d.ts +8 -0
  109. package/dist/widget/components/HookModalContent.d.ts.map +1 -0
  110. package/dist/widget/components/OriginSelectionAmount.d.ts +11 -0
  111. package/dist/widget/components/OriginSelectionAmount.d.ts.map +1 -0
  112. package/dist/widget/components/Pay.d.ts +5 -5
  113. package/dist/widget/components/Pay.d.ts.map +1 -1
  114. package/dist/widget/components/PoolDeposit.d.ts +5 -5
  115. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  116. package/dist/widget/components/PoolWithdraw.d.ts +3 -3
  117. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
  118. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  119. package/dist/widget/components/Receipt.d.ts +2 -1
  120. package/dist/widget/components/Receipt.d.ts.map +1 -1
  121. package/dist/widget/components/RecentTokens.d.ts +4 -4
  122. package/dist/widget/components/RecentTokens.d.ts.map +1 -1
  123. package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
  124. package/dist/widget/components/ShadowPortal.d.ts +6 -0
  125. package/dist/widget/components/ShadowPortal.d.ts.map +1 -0
  126. package/dist/widget/components/Swap.d.ts +6 -6
  127. package/dist/widget/components/Swap.d.ts.map +1 -1
  128. package/dist/widget/components/ThemeProvider.d.ts +1 -1
  129. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  130. package/dist/widget/components/TokenList.d.ts +3 -4
  131. package/dist/widget/components/TokenList.d.ts.map +1 -1
  132. package/dist/widget/components/TokenSelector.d.ts +3 -4
  133. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  134. package/dist/widget/components/Tooltip.d.ts +6 -1
  135. package/dist/widget/components/Tooltip.d.ts.map +1 -1
  136. package/dist/widget/components/TrailsHookModal.d.ts +10 -0
  137. package/dist/widget/components/TrailsHookModal.d.ts.map +1 -0
  138. package/dist/widget/components/WaasFeeOptions.d.ts +3 -0
  139. package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
  140. package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
  141. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  142. package/dist/widget/components/WidgetProviders.d.ts +14 -0
  143. package/dist/widget/components/WidgetProviders.d.ts.map +1 -0
  144. package/dist/widget/css/compiled.css +1 -1
  145. package/dist/widget/hooks/useAddressWalletIcon.d.ts +10 -0
  146. package/dist/widget/hooks/useAddressWalletIcon.d.ts.map +1 -0
  147. package/dist/widget/hooks/useBalanceVisible.d.ts +1 -1
  148. package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
  149. package/dist/widget/hooks/useChainFilter.d.ts +1 -1
  150. package/dist/widget/hooks/useChainFilter.d.ts.map +1 -1
  151. package/dist/widget/hooks/useCheckout.d.ts +13 -1
  152. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  153. package/dist/widget/hooks/useConnector.d.ts +4 -0
  154. package/dist/widget/hooks/useConnector.d.ts.map +1 -0
  155. package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
  156. package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
  157. package/dist/widget/hooks/useCustomTokenFetch.d.ts +19 -0
  158. package/dist/widget/hooks/useCustomTokenFetch.d.ts.map +1 -0
  159. package/dist/widget/hooks/useCustomTokenSearch.d.ts +20 -0
  160. package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +1 -0
  161. package/dist/widget/hooks/useDebounce.d.ts +10 -0
  162. package/dist/widget/hooks/useDebounce.d.ts.map +1 -0
  163. package/dist/widget/hooks/useDebugScreens.d.ts +7 -2
  164. package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
  165. package/dist/widget/hooks/useDefaultTokenSelection.d.ts +3 -19
  166. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  167. package/dist/widget/hooks/useDestinationSelectedToken.d.ts +1 -14
  168. package/dist/widget/hooks/useDestinationSelectedToken.d.ts.map +1 -1
  169. package/dist/widget/hooks/useEarnPool.d.ts +1 -1
  170. package/dist/widget/hooks/useEarnPool.d.ts.map +1 -1
  171. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
  172. package/dist/widget/hooks/useIsMobile.d.ts +5 -0
  173. package/dist/widget/hooks/useIsMobile.d.ts.map +1 -0
  174. package/dist/widget/hooks/useMode.d.ts +2 -2
  175. package/dist/widget/hooks/useMode.d.ts.map +1 -1
  176. package/dist/widget/hooks/useOriginSelectedToken.d.ts +2 -15
  177. package/dist/widget/hooks/useOriginSelectedToken.d.ts.map +1 -1
  178. package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
  179. package/dist/widget/hooks/usePriceImpactWarning.d.ts +1 -1
  180. package/dist/widget/hooks/usePriceImpactWarning.d.ts.map +1 -1
  181. package/dist/widget/hooks/useQuote.d.ts +173 -4
  182. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  183. package/dist/widget/hooks/useRecentTokens.d.ts +3 -3
  184. package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
  185. package/dist/widget/hooks/useRecipients.d.ts +1 -1
  186. package/dist/widget/hooks/useRecipients.d.ts.map +1 -1
  187. package/dist/widget/hooks/useSelectedFeeOption.d.ts +2 -2
  188. package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -1
  189. package/dist/widget/hooks/useSelectedFundMethod.d.ts +1 -1
  190. package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -1
  191. package/dist/widget/hooks/useSelectedRecipient.d.ts +1 -1
  192. package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
  193. package/dist/widget/hooks/useSendForm.d.ts +9 -31
  194. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  195. package/dist/widget/hooks/useSwapAmount.d.ts +1 -1
  196. package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -1
  197. package/dist/widget/hooks/useTheme.d.ts +1 -1
  198. package/dist/widget/hooks/useTheme.d.ts.map +1 -1
  199. package/dist/widget/hooks/useTokenList.d.ts +7 -31
  200. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  201. package/dist/widget/hooks/useTrailsSendTransaction.d.ts +83 -0
  202. package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -0
  203. package/dist/widget/hooks/useWalletConnectUri.d.ts +11 -0
  204. package/dist/widget/hooks/useWalletConnectUri.d.ts.map +1 -0
  205. package/dist/widget/hooks/useWidgetProps.d.ts +5 -0
  206. package/dist/widget/hooks/useWidgetProps.d.ts.map +1 -1
  207. package/dist/widget/index.d.ts +2 -0
  208. package/dist/widget/index.d.ts.map +1 -1
  209. package/dist/widget/index.js +8 -5
  210. package/dist/widget/providers/TrailsModalProvider.d.ts +65 -0
  211. package/dist/widget/providers/TrailsModalProvider.d.ts.map +1 -0
  212. package/dist/widget/providers/TrailsProvider.d.ts +1 -1
  213. package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
  214. package/dist/widget/types.d.ts +11 -18
  215. package/dist/widget/types.d.ts.map +1 -1
  216. package/dist/widget/widget.d.ts +20 -11
  217. package/dist/widget/widget.d.ts.map +1 -1
  218. package/package.json +45 -49
  219. package/src/aave.ts +387 -138
  220. package/src/analytics.ts +208 -2
  221. package/src/chains.ts +65 -64
  222. package/src/constants.ts +18 -14
  223. package/src/customTokens.ts +151 -0
  224. package/src/decoders.ts +4 -7
  225. package/src/error.ts +7 -3
  226. package/src/fees.ts +239 -125
  227. package/src/gasless.ts +54 -108
  228. package/src/index.ts +29 -9
  229. package/src/indexerClient.ts +2 -0
  230. package/src/intentReceiptMonitor.ts +1 -4
  231. package/src/intentReceiptPoller.ts +2 -2
  232. package/src/intents.ts +16 -5
  233. package/src/mode.ts +1 -1
  234. package/src/mutations.ts +7 -3
  235. package/src/prepareSend.ts +19 -14
  236. package/src/prices.ts +1 -1
  237. package/src/sequenceWallet.ts +2 -2
  238. package/src/time.ts +28 -0
  239. package/src/tokenBalances.ts +348 -153
  240. package/src/tokens.ts +393 -142
  241. package/src/trailsClient.ts +1 -1
  242. package/src/trailsRouter.ts +4 -5
  243. package/src/transactionIntent/deposits/depositOrchestrator.ts +6 -2
  244. package/src/transactionIntent/deposits/gaslessDeposit.ts +13 -7
  245. package/src/transactionIntent/deposits/standardDeposit.ts +1 -1
  246. package/src/transactionIntent/execution/transactionState.ts +1 -1
  247. package/src/transactionIntent/handlers/crossChain.ts +75 -37
  248. package/src/transactionIntent/handlers/sameChainSameToken.ts +66 -20
  249. package/src/transactionIntent/quote/feeExtractors.ts +1 -29
  250. package/src/transactionIntent/quote/normalizeQuote.ts +99 -7
  251. package/src/transactionIntent/quote/quoteHelpers.ts +1 -1
  252. package/src/transactionIntent/types.ts +31 -6
  253. package/src/transactionIntent/utils/testnetHelpers.ts +0 -5
  254. package/src/transactionIntent/validators.ts +0 -30
  255. package/src/transactions.ts +3 -3
  256. package/src/utils.ts +18 -0
  257. package/src/wallets.ts +32 -10
  258. package/src/widget/compiled.css +1 -1
  259. package/src/widget/components/AccountIntentTransactionHistory.tsx +2 -1
  260. package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +2 -2
  261. package/src/widget/components/AddressWalletIcon.tsx +29 -0
  262. package/src/widget/components/ChainFilterDropdown.tsx +2 -8
  263. package/src/widget/components/ChainImage.tsx +8 -5
  264. package/src/widget/components/ChainList.tsx +6 -8
  265. package/src/widget/components/ClassicSwap.tsx +93 -85
  266. package/src/widget/components/ConnectWallet.tsx +1 -2
  267. package/src/widget/components/ConnectedWallets.tsx +17 -4
  268. package/src/widget/components/DebugMenu.tsx +2 -2
  269. package/src/widget/components/DebugScreensList.tsx +0 -1
  270. package/src/widget/components/DepositTracker.tsx +20 -34
  271. package/src/widget/components/Earn.tsx +7 -6
  272. package/src/widget/components/FeeOption.tsx +4 -4
  273. package/src/widget/components/FeeOptions.tsx +19 -39
  274. package/src/widget/components/Footer.tsx +1 -1
  275. package/src/widget/components/Fund.tsx +23 -119
  276. package/src/widget/components/FundMethods.tsx +9 -6
  277. package/src/widget/components/FundSwap.tsx +6 -5
  278. package/src/widget/components/FundingMethodSelectorButton.tsx +2 -2
  279. package/src/widget/components/HookModalContent.tsx +306 -0
  280. package/src/widget/components/Modal.tsx +1 -1
  281. package/src/widget/components/OriginSelectionAmount.tsx +135 -0
  282. package/src/widget/components/Pay.tsx +66 -124
  283. package/src/widget/components/PoolDeposit.tsx +11 -55
  284. package/src/widget/components/PoolWithdraw.tsx +3 -3
  285. package/src/widget/components/QuoteDetails.tsx +473 -728
  286. package/src/widget/components/Receipt.tsx +74 -7
  287. package/src/widget/components/RecentTokens.tsx +8 -8
  288. package/src/widget/components/RecipientSelectorButton.tsx +4 -2
  289. package/src/widget/components/ScreenHeader.tsx +2 -2
  290. package/src/widget/components/SearchInputField.tsx +1 -1
  291. package/src/widget/components/ShadowPortal.tsx +58 -0
  292. package/src/widget/components/Swap.tsx +6 -5
  293. package/src/widget/components/ThemeProvider.tsx +1 -1
  294. package/src/widget/components/TokenList.tsx +3 -4
  295. package/src/widget/components/TokenSelector.tsx +211 -80
  296. package/src/widget/components/Tooltip.tsx +18 -7
  297. package/src/widget/components/TrailsHookModal.tsx +118 -0
  298. package/src/widget/components/WaasFeeOptions.tsx +333 -138
  299. package/src/widget/components/WalletConfirmation.tsx +7 -2
  300. package/src/widget/components/WalletConnect.tsx +197 -235
  301. package/src/widget/components/WidgetProviders.tsx +75 -0
  302. package/src/widget/hooks/useAddressWalletIcon.ts +53 -0
  303. package/src/widget/hooks/useBalanceVisible.tsx +1 -1
  304. package/src/widget/hooks/useChainFilter.tsx +1 -1
  305. package/src/widget/hooks/useCheckout.ts +13 -1
  306. package/src/widget/hooks/useConnector.tsx +18 -0
  307. package/src/widget/hooks/useCurrentScreen.tsx +3 -3
  308. package/src/widget/hooks/useCustomTokenFetch.tsx +72 -0
  309. package/src/widget/hooks/useCustomTokenSearch.tsx +402 -0
  310. package/src/widget/hooks/useDebounce.ts +25 -0
  311. package/src/widget/hooks/useDebugScreens.ts +26 -10
  312. package/src/widget/hooks/useDefaultTokenSelection.tsx +99 -143
  313. package/src/widget/hooks/useDestinationSelectedToken.tsx +1 -14
  314. package/src/widget/hooks/useEarnPool.tsx +1 -1
  315. package/src/widget/hooks/useIntentTransactionHistory.ts +20 -11
  316. package/src/widget/hooks/useIsMobile.tsx +50 -0
  317. package/src/widget/hooks/useMode.ts +2 -3
  318. package/src/widget/hooks/useOriginSelectedToken.tsx +2 -15
  319. package/src/widget/hooks/usePayMessage.tsx +31 -11
  320. package/src/widget/hooks/usePriceImpactWarning.ts +1 -1
  321. package/src/widget/hooks/useQuote.ts +189 -6
  322. package/src/widget/hooks/useRecentTokens.ts +6 -6
  323. package/src/widget/hooks/useRecipients.ts +1 -1
  324. package/src/widget/hooks/useSelectedFeeOption.tsx +2 -2
  325. package/src/widget/hooks/useSelectedFundMethod.tsx +1 -1
  326. package/src/widget/hooks/useSelectedRecipient.tsx +1 -1
  327. package/src/widget/hooks/useSendForm.ts +328 -152
  328. package/src/widget/hooks/useSwapAmount.tsx +1 -1
  329. package/src/widget/hooks/useTheme.tsx +1 -1
  330. package/src/widget/hooks/useTokenList.ts +672 -400
  331. package/src/widget/hooks/useTrailsSendTransaction.ts +949 -0
  332. package/src/widget/hooks/useWalletConnectUri.tsx +228 -0
  333. package/src/widget/hooks/useWidgetProps.tsx +3 -1
  334. package/src/widget/index.tsx +12 -0
  335. package/src/widget/providers/TrailsModalProvider.tsx +195 -0
  336. package/src/widget/providers/TrailsProvider.tsx +9 -3
  337. package/src/widget/types.ts +12 -20
  338. package/src/widget/widget.tsx +598 -385
  339. package/dist/cctp.d.ts +0 -3
  340. package/dist/cctp.d.ts.map +0 -1
  341. package/dist/lifi.d.ts +0 -4
  342. package/dist/lifi.d.ts.map +0 -1
  343. package/dist/meshconnect.d.ts +0 -171
  344. package/dist/meshconnect.d.ts.map +0 -1
  345. package/dist/relaySdk.d.ts +0 -87
  346. package/dist/relaySdk.d.ts.map +0 -1
  347. package/dist/widget/components/MeshConnectExchanges.d.ts +0 -7
  348. package/dist/widget/components/MeshConnectExchanges.d.ts.map +0 -1
  349. package/dist/widget/components/MeshConnectFlow.d.ts +0 -13
  350. package/dist/widget/components/MeshConnectFlow.d.ts.map +0 -1
  351. package/dist/widget/components/MeshConnectIframe.d.ts +0 -15
  352. package/dist/widget/components/MeshConnectIframe.d.ts.map +0 -1
  353. package/dist/widget/components/Receive.d.ts +0 -12
  354. package/dist/widget/components/Receive.d.ts.map +0 -1
  355. package/dist/widget/hooks/useSelectedMeshExchange.d.ts +0 -14
  356. package/dist/widget/hooks/useSelectedMeshExchange.d.ts.map +0 -1
  357. package/src/cctp.ts +0 -54
  358. package/src/lifi.ts +0 -108
  359. package/src/meshconnect.ts +0 -531
  360. package/src/relaySdk.ts +0 -703
  361. package/src/widget/components/MeshConnectExchanges.tsx +0 -290
  362. package/src/widget/components/MeshConnectFlow.tsx +0 -90
  363. package/src/widget/components/MeshConnectIframe.tsx +0 -500
  364. package/src/widget/components/Receive.tsx +0 -175
  365. package/src/widget/hooks/useSelectedMeshExchange.tsx +0 -46
@@ -8,7 +8,7 @@ import type {
8
8
  } from "@0xsequence/indexer"
9
9
  import { ContractVerificationStatus } from "@0xsequence/indexer"
10
10
  import type { Page } from "@0xsequence/indexer"
11
- import type { TokenPrice as TrailsTokenPrice } from "@0xsequence/trails-api"
11
+ import type { TokenPrice } from "@0xtrails/api"
12
12
  import { QueryClient, useQuery } from "@tanstack/react-query"
13
13
  import type { Address } from "ox"
14
14
  import { useEffect, useState } from "react"
@@ -17,7 +17,7 @@ import { useIndexerGatewayClient } from "./indexerClient.js"
17
17
  import { getTokenPrices, useTokenPrices } from "./prices.js"
18
18
  import { logger } from "./logger.js"
19
19
  import { getChainInfo } from "./chains.js"
20
- import { useGetTokenImageUrl, getTokenImageUrl } from "./tokens.js"
20
+ import { getTokenImageUrl, type Token } from "./tokens.js"
21
21
  import type { TrailsClient } from "./trailsClient.js"
22
22
  import { useTrailsClient } from "./trailsClient.js"
23
23
  import { getFullErrorMessage } from "./error.js"
@@ -29,6 +29,139 @@ export type Price = {
29
29
  currency: string
30
30
  }
31
31
 
32
+ // ============================================================================
33
+ // Conversion Helpers for TokenBalance -> Token
34
+ // ============================================================================
35
+
36
+ /**
37
+ * Converts TokenBalance to Token
38
+ */
39
+ function convertTokenBalanceToToken(
40
+ token: TokenBalance,
41
+ priceData?: TokenPrice,
42
+ chainInfo?: ReturnType<typeof getChainInfo>,
43
+ ): Token {
44
+ const chainId = token.contractInfo?.chainId || 0
45
+ const chain = chainInfo || getChainInfo(chainId)
46
+ const contractAddress = token.contractAddress || zeroAddress
47
+
48
+ const result: Token = {
49
+ symbol: token.contractInfo?.symbol || "???",
50
+ name: token.contractInfo?.name || "Unknown Token",
51
+ decimals: token.contractInfo?.decimals || 18,
52
+ contractAddress,
53
+ chainId,
54
+ chainName: chain?.name || `Chain ${chainId}`,
55
+ imageUrl: getTokenImageUrl({
56
+ chainId,
57
+ contractAddress,
58
+ symbol: token.contractInfo?.symbol || "???",
59
+ fallbackImageUrl: token.contractInfo?.logoURI,
60
+ }),
61
+ isNativeToken: false,
62
+ }
63
+
64
+ // Format balance if available
65
+ if (token.balance) {
66
+ const decimals = result.decimals
67
+ const balanceFields = formatBalanceFields(token.balance, decimals)
68
+ result.balance = balanceFields.balance
69
+ result.balanceFormatted = balanceFields.balanceFormatted
70
+ result.balanceDisplay = balanceFields.balanceDisplay
71
+ }
72
+
73
+ // Add price and USD balance if price data is available
74
+ if (priceData?.priceUsd !== undefined) {
75
+ const priceFields = formatPriceFields(priceData.priceUsd)
76
+ result.priceUsd = priceFields.priceUsd
77
+ result.priceUsdFormatted = priceFields.priceUsdFormatted
78
+ result.priceUsdDisplay = priceFields.priceUsdDisplay
79
+
80
+ if (token.balance) {
81
+ const price: Price = {
82
+ value: priceData.priceUsd,
83
+ currency: "USD",
84
+ }
85
+ const balanceUsd = getTokenBalanceUsd(token, price)
86
+ if (balanceUsd !== undefined) {
87
+ const usdFields = formatUsdFields(balanceUsd)
88
+ result.balanceUsd = usdFields.balanceUsd
89
+ result.balanceUsdFormatted = usdFields.balanceUsdFormatted
90
+ result.balanceUsdDisplay = usdFields.balanceUsdDisplay
91
+ }
92
+ }
93
+ }
94
+
95
+ // Default isSufficientBalance to true
96
+ result.isSufficientBalance = true
97
+
98
+ return result
99
+ }
100
+
101
+ /**
102
+ * Converts NativeTokenBalance to Token
103
+ */
104
+ function convertNativeTokenBalanceToToken(
105
+ token: NativeTokenBalance,
106
+ priceData?: TokenPrice,
107
+ chainInfo?: ReturnType<typeof getChainInfo>,
108
+ ): Token {
109
+ const chainId = token.chainId
110
+ const chain = chainInfo || getChainInfo(chainId)
111
+ const symbol = chain?.nativeCurrency.symbol || "ETH"
112
+
113
+ const result: Token = {
114
+ symbol,
115
+ name: chain?.nativeCurrency.name || "Native Token",
116
+ decimals: chain?.nativeCurrency.decimals || 18,
117
+ contractAddress: zeroAddress,
118
+ chainId,
119
+ chainName: chain?.name || `Chain ${chainId}`,
120
+ imageUrl: getTokenImageUrl({
121
+ chainId,
122
+ contractAddress: zeroAddress,
123
+ symbol,
124
+ }),
125
+ isNativeToken: true,
126
+ }
127
+
128
+ // Format balance if available
129
+ if (token.balance) {
130
+ const decimals = result.decimals
131
+ const balanceFields = formatBalanceFields(token.balance, decimals)
132
+ result.balance = balanceFields.balance
133
+ result.balanceFormatted = balanceFields.balanceFormatted
134
+ result.balanceDisplay = balanceFields.balanceDisplay
135
+ }
136
+
137
+ // Add price and USD balance if price data is available
138
+ if (priceData?.priceUsd !== undefined) {
139
+ const priceFields = formatPriceFields(priceData.priceUsd)
140
+ result.priceUsd = priceFields.priceUsd
141
+ result.priceUsdFormatted = priceFields.priceUsdFormatted
142
+ result.priceUsdDisplay = priceFields.priceUsdDisplay
143
+
144
+ if (token.balance) {
145
+ const price: Price = {
146
+ value: priceData.priceUsd,
147
+ currency: "USD",
148
+ }
149
+ const balanceUsd = getTokenBalanceUsd(token, price)
150
+ if (balanceUsd !== undefined) {
151
+ const usdFields = formatUsdFields(balanceUsd)
152
+ result.balanceUsd = usdFields.balanceUsd
153
+ result.balanceUsdFormatted = usdFields.balanceUsdFormatted
154
+ result.balanceUsdDisplay = usdFields.balanceUsdDisplay
155
+ }
156
+ }
157
+ }
158
+
159
+ // Default isSufficientBalance to true
160
+ result.isSufficientBalance = true
161
+
162
+ return result
163
+ }
164
+
32
165
  const REFRESH_INTERVAL = 10000 // 10 seconds
33
166
 
34
167
  // Initialize query client for token balances
@@ -62,36 +195,10 @@ export function isNativeToken(
62
195
  return false
63
196
  }
64
197
 
65
- export interface TokenBalanceWithPrice extends TokenBalance {
66
- price?: Price
67
- balanceUsd?: number
68
- balanceUsdFormatted?: string
69
- chainName?: string
70
- imageUrl?: string
71
- symbol?: string
72
- name?: string
73
- decimals?: number
74
- }
75
-
76
- export interface NativeTokenBalanceWithPrice extends NativeTokenBalance {
77
- price?: Price
78
- balanceUsd?: number
79
- balanceUsdFormatted?: string
80
- symbol?: string
81
- chainName?: string
82
- imageUrl?: string
83
- name?: string
84
- decimals?: number
85
- }
86
-
87
- export type TokenBalanceExtended =
88
- | TokenBalanceWithPrice
89
- | NativeTokenBalanceWithPrice
90
-
91
- export function sortTokensByPriority(
92
- a: TokenBalanceExtended,
93
- b: TokenBalanceExtended,
94
- ): number {
198
+ /**
199
+ * Sort function for Token by priority
200
+ */
201
+ export function sortTokensByPriority(a: Token, b: Token): number {
95
202
  // First sort by USD balance if available
96
203
  const aUsdBalance = a.balanceUsd ?? 0
97
204
  const bUsdBalance = b.balanceUsd ?? 0
@@ -105,48 +212,29 @@ export function sortTokensByPriority(
105
212
  if (aUsdBalance > 0 && bUsdBalance === 0) return -1
106
213
  if (aUsdBalance === 0 && bUsdBalance > 0) return 1
107
214
 
108
- // If both have zero balance, sort by volume
215
+ // If both have zero balance, sort by price volume (if available)
109
216
  if (aUsdBalance === 0 && bUsdBalance === 0) {
110
- const aVolume = getTokenVolume24h(a.price)
111
- const bVolume = getTokenVolume24h(b.price)
112
- if (aVolume !== bVolume) {
113
- return bVolume - aVolume // Higher volume first for zero balance tokens
114
- }
217
+ // Note: price24hVol is not in Token, so we skip volume sorting
218
+ // This can be added later if needed
115
219
  }
116
220
 
117
221
  // Then sort by native token status
118
- if (isNativeToken(a) && !isNativeToken(b)) return -1
119
- if (!isNativeToken(a) && isNativeToken(b)) return 1
222
+ if (a.isNativeToken && !b.isNativeToken) return -1
223
+ if (!a.isNativeToken && b.isNativeToken) return 1
120
224
 
121
225
  // Then sort by token balance
122
226
  try {
123
- const balanceA = BigInt(a.balance)
124
- const balanceB = BigInt(b.balance)
227
+ const balanceA = BigInt(a.balance || "0")
228
+ const balanceB = BigInt(b.balance || "0")
125
229
  if (balanceA > balanceB) return -1
126
230
  if (balanceA < balanceB) return 1
127
231
  } catch {
128
- // If balance comparison fails, continue to volume sorting
232
+ // If balance comparison fails, continue
129
233
  }
130
234
 
131
235
  return 0
132
236
  }
133
237
 
134
- // Helper function to extract 24h volume from price data
135
- function getTokenVolume24h(price?: any): number {
136
- // Try different possible volume field names from the API
137
- if (!price) return 0
138
-
139
- // Primary: use price24hVol if available, otherwise try other common field names
140
- return Number(
141
- price.price24hVol ||
142
- price.volume24h ||
143
- price.volume_24h ||
144
- price.vol24h ||
145
- price.dailyVolume ||
146
- 0,
147
- )
148
- }
149
-
150
238
  export interface GetTokenBalancesWithPrice {
151
239
  page: Page
152
240
  nativeBalances: Array<
@@ -178,12 +266,11 @@ export function useTokenBalances(
178
266
  isLoadingPrices: boolean
179
267
  isLoadingSortedTokens: boolean
180
268
  balanceError: Error | null
181
- sortedTokens: TokenBalanceExtended[]
269
+ sortedTokens: Token[]
182
270
  } {
183
271
  // Always call hooks unconditionally to fix React rules violation
184
272
  const hookIndexerClient = useIndexerGatewayClient()
185
273
  const hookTrailsClient = useTrailsClient()
186
- const { getTokenImageUrl } = useGetTokenImageUrl()
187
274
 
188
275
  // Use passed parameters if available, otherwise use hook results
189
276
  const indexerClient = indexerGatewayClient ?? hookIndexerClient
@@ -294,7 +381,7 @@ export function useTokenBalances(
294
381
  )
295
382
 
296
383
  const { data: sortedTokens = [], isLoading: isLoadingSortedTokens } =
297
- useQuery<TokenBalanceExtended[]>({
384
+ useQuery<Token[]>({
298
385
  queryKey: [
299
386
  "tokenBalances",
300
387
  "sorted",
@@ -307,76 +394,36 @@ export function useTokenBalances(
307
394
  return []
308
395
  }
309
396
 
310
- const balances = [
311
- ...tokenBalancesData.nativeBalances.map((token) => ({
312
- ...token,
313
- contractAddress: zeroAddress, // Native tokens always use zero address
314
- chainName: getChainInfo(token.chainId)?.name || "",
315
- symbol: token.symbol ?? (token as any).contractInfo?.symbol,
316
- name: (token as any).name ?? (token as any).contractInfo?.name,
317
- decimals:
318
- (token as any).decimals ??
319
- (token as any).contractInfo?.decimals ??
320
- 18, // Use token decimals or default to 18
321
- imageUrl: getTokenImageUrl({
322
- chainId: token.chainId,
323
- contractAddress: zeroAddress,
324
- symbol: token.symbol ?? (token as any).contractInfo?.symbol,
325
- fallbackImageUrl: (token as any).contractInfo?.logoURI,
326
- }),
327
- })),
328
- ...tokenBalancesData.balances.map((token) => ({
329
- ...token,
330
- contractAddress: token.contractAddress,
331
- chainName: getChainInfo(token.contractInfo?.chainId)?.name || "",
332
- symbol: token.contractInfo?.symbol,
333
- name: token.contractInfo?.name,
334
- decimals: token.contractInfo?.decimals,
335
- imageUrl: getTokenImageUrl({
336
- chainId: token.contractInfo?.chainId || 0,
337
- contractAddress: token.contractAddress,
338
- symbol: token.contractInfo?.symbol,
339
- fallbackImageUrl: token.contractInfo?.logoURI,
340
- }),
341
- })),
342
- ].filter((token) => {
343
- try {
344
- return BigInt(token.balance) > 0n
345
- } catch {
346
- return false
347
- }
348
- })
349
-
350
- // First pass: add prices to all tokens
351
- const tokensWithPrices = balances.map((token) => {
352
- const isNative = isNativeToken(token)
353
- const priceData: TrailsTokenPrice | undefined = tokenPrices.find(
354
- (p) =>
355
- p.token.tokenAddress ===
356
- (isNative ? zeroAddress : token.contractAddress) &&
357
- p.token.chainId ===
358
- (isNative ? token.chainId : token.contractInfo?.chainId),
359
- )
360
-
361
- if (priceData?.priceUsd !== undefined) {
362
- // Create a Price object compatible with the indexer API
363
- const price: Price = {
364
- value: priceData.priceUsd,
365
- currency: "USD",
366
- }
367
- const tokenWithPrice = { ...token, price }
368
- tokenWithPrice.balanceUsd = getTokenBalanceUsd(token, price)
369
- tokenWithPrice.balanceUsdFormatted = getTokenBalanceUsdFormatted(
370
- token,
371
- price,
397
+ // Build Token directly from balances
398
+ const trailsTokens: Token[] = [
399
+ ...tokenBalancesData.nativeBalances.map((token) => {
400
+ const priceData = tokenPrices.find(
401
+ (p) =>
402
+ p.token.tokenAddress === zeroAddress &&
403
+ p.token.chainId === token.chainId,
372
404
  )
373
- return tokenWithPrice
374
- }
375
-
376
- return token
377
- })
405
+ return convertNativeTokenBalanceToToken(token, priceData)
406
+ }),
407
+ ...tokenBalancesData.balances.map((token) => {
408
+ const priceData = tokenPrices.find(
409
+ (p) =>
410
+ p.token.tokenAddress?.toLowerCase() ===
411
+ token.contractAddress.toLowerCase() &&
412
+ p.token.chainId === token.contractInfo?.chainId,
413
+ )
414
+ return convertTokenBalanceToToken(token, priceData)
415
+ }),
416
+ ]
417
+ .filter((token) => {
418
+ try {
419
+ return token.balance && BigInt(token.balance) > 0n
420
+ } catch {
421
+ return false
422
+ }
423
+ })
424
+ .sort(sortTokensByPriority)
378
425
 
379
- return tokensWithPrices.sort(sortTokensByPriority)
426
+ return trailsTokens
380
427
  },
381
428
  enabled:
382
429
  !isLoadingBalances &&
@@ -593,6 +640,160 @@ export function getTokenBalanceUsdFormatted(
593
640
  return formatUsdAmountDisplay(balanceUsd)
594
641
  }
595
642
 
643
+ /**
644
+ * Formats USD value without currency symbol (for formatted fields)
645
+ * Similar to formatUsdAmountDisplay but without the $ sign
646
+ */
647
+ export function formatUsdAmountFormatted(value: number | string = 0): string {
648
+ if (!value) {
649
+ value = 0
650
+ }
651
+
652
+ const numValue = Number(value)
653
+
654
+ // Validate input
655
+ if (!Number.isFinite(numValue) || Number.isNaN(numValue)) {
656
+ return "0.00"
657
+ }
658
+
659
+ // Handle negative values explicitly
660
+ const isNegative = numValue < 0
661
+ const absValue = Math.abs(numValue)
662
+
663
+ // Cap at reasonable max to prevent display issues (100 trillion)
664
+ const MAX_DISPLAY_VALUE = 100_000_000_000_000
665
+ const cappedValue = Math.min(absValue, MAX_DISPLAY_VALUE)
666
+
667
+ // For very small amounts (less than 0.01), show 3 decimal places
668
+ if (cappedValue > 0 && cappedValue < 0.01) {
669
+ const formatted = Number(cappedValue).toLocaleString(undefined, {
670
+ maximumFractionDigits: 3,
671
+ minimumFractionDigits: 3,
672
+ useGrouping: false,
673
+ })
674
+ return isNegative ? `-${formatted}` : formatted
675
+ }
676
+
677
+ // For amounts >= 0.01, use standard 2 decimal places
678
+ const formatted = Number(cappedValue).toLocaleString(undefined, {
679
+ maximumFractionDigits: 2,
680
+ minimumFractionDigits: 2,
681
+ useGrouping: false,
682
+ })
683
+ return isNegative ? `-${formatted}` : formatted
684
+ }
685
+
686
+ /**
687
+ * Formats balance fields (raw → formatted → display)
688
+ * Returns all three versions for Token
689
+ */
690
+ export function formatBalanceFields(
691
+ balance: string | bigint,
692
+ decimals: number,
693
+ ): {
694
+ balance: string // Raw value as string (e.g., "1000000000000000000")
695
+ balanceFormatted: string // Formatted with decimals, no commas (e.g., "1.0")
696
+ balanceDisplay: string // Display with commas (e.g., "1,000.00")
697
+ } {
698
+ if (!balance) {
699
+ return {
700
+ balance: "0",
701
+ balanceFormatted: "0",
702
+ balanceDisplay: "0",
703
+ }
704
+ }
705
+
706
+ try {
707
+ // Validate decimals
708
+ if (!Number.isInteger(decimals) || decimals < 1 || decimals > 18) {
709
+ throw new Error("Invalid decimals")
710
+ }
711
+
712
+ const balanceBigInt = BigInt(balance)
713
+ const balanceString = balanceBigInt.toString()
714
+
715
+ // Check for negative balance
716
+ if (balanceBigInt < 0n) {
717
+ throw new Error("Negative balance")
718
+ }
719
+
720
+ // Format using formatUnits
721
+ const formatted = formatUnits(balanceBigInt, decimals)
722
+
723
+ // balanceFormatted: no commas (uses formatAmount with useGrouping: false)
724
+ const balanceFormatted = formatAmount(formatted)
725
+
726
+ // balanceDisplay: with commas (uses formatAmountDisplay with useGrouping: true)
727
+ const balanceDisplay = formatAmountDisplay(formatted)
728
+
729
+ return {
730
+ balance: balanceString,
731
+ balanceFormatted,
732
+ balanceDisplay,
733
+ }
734
+ } catch (err) {
735
+ logger.console.error("[trails-sdk] Error formatting balance fields:", {
736
+ balance,
737
+ decimals,
738
+ err,
739
+ })
740
+ // Return safe defaults on error
741
+ return {
742
+ balance: typeof balance === "string" ? balance : balance.toString(),
743
+ balanceFormatted: "0",
744
+ balanceDisplay: "0",
745
+ }
746
+ }
747
+ }
748
+
749
+ /**
750
+ * Formats USD value fields (raw → formatted → display)
751
+ * Returns all three versions for Token
752
+ */
753
+ export function formatUsdFields(usdValue: number | string | null | undefined): {
754
+ balanceUsd?: number // Raw number (e.g., 1000.50)
755
+ balanceUsdFormatted?: string // Formatted, no commas or $ (e.g., "1000.50")
756
+ balanceUsdDisplay?: string // Display with commas and $ (e.g., "$1,000.50")
757
+ } {
758
+ if (usdValue === null || usdValue === undefined) {
759
+ return {}
760
+ }
761
+
762
+ const numValue = Number(usdValue)
763
+
764
+ // Validate input
765
+ if (!Number.isFinite(numValue) || Number.isNaN(numValue)) {
766
+ return {
767
+ balanceUsd: 0,
768
+ balanceUsdFormatted: "0.00",
769
+ balanceUsdDisplay: "$0.00",
770
+ }
771
+ }
772
+
773
+ return {
774
+ balanceUsd: numValue,
775
+ balanceUsdFormatted: formatUsdAmountFormatted(numValue),
776
+ balanceUsdDisplay: formatUsdAmountDisplay(numValue),
777
+ }
778
+ }
779
+
780
+ /**
781
+ * Formats price fields (raw → formatted → display)
782
+ * Returns all three versions for Token
783
+ */
784
+ export function formatPriceFields(price: number | string | null | undefined): {
785
+ priceUsd?: number // Raw number (e.g., 1.50)
786
+ priceUsdFormatted?: string // Formatted, no commas or $ (e.g., "1.50")
787
+ priceUsdDisplay?: string // Display with commas and $ (e.g., "$1.50")
788
+ } {
789
+ const usdFields = formatUsdFields(price)
790
+ return {
791
+ priceUsd: usdFields.balanceUsd,
792
+ priceUsdFormatted: usdFields.balanceUsdFormatted,
793
+ priceUsdDisplay: usdFields.balanceUsdDisplay,
794
+ }
795
+ }
796
+
596
797
  export function useTokenBalanceUsdFormat(
597
798
  token: TokenBalance | NativeTokenBalance,
598
799
  tokenPrice: Price,
@@ -772,7 +973,7 @@ export type GetTokenBalancesWithPricesParams = {
772
973
  }
773
974
 
774
975
  export type GetTokenBalancesWithPriceReturn = {
775
- balances: TokenBalanceWithPrice[]
976
+ balances: Token[]
776
977
  }
777
978
 
778
979
  export async function getTokenBalancesWithPrices({
@@ -792,9 +993,10 @@ export async function getTokenBalancesWithPrices({
792
993
  tokenSymbol: t.contractInfo?.symbol || "",
793
994
  })),
794
995
  )
795
- const balancesWithPrices = tokens.map((b) => {
796
- const priceData: TrailsTokenPrice | undefined = tokenPrices.find((p) => {
797
- const isSameChain = p.token.chainId === b.chainId
996
+ const balancesWithPrices: Token[] = tokens.map((b) => {
997
+ const priceData: TokenPrice | undefined = tokenPrices.find((p) => {
998
+ const tokenChainId = b.chainId ?? (b as any).contractInfo?.chainId
999
+ const isSameChain = p.token.chainId === tokenChainId
798
1000
  let isSameToken = p.token.tokenAddress === b.contractAddress
799
1001
  if (!b.contractAddress) {
800
1002
  isSameToken =
@@ -803,20 +1005,14 @@ export async function getTokenBalancesWithPrices({
803
1005
  return isSameChain && isSameToken
804
1006
  })
805
1007
 
806
- // Convert TrailsTokenPrice to Price format for compatibility
807
- const price: Price | undefined =
808
- priceData?.priceUsd !== undefined
809
- ? { value: priceData.priceUsd, currency: "USD" }
810
- : undefined
811
-
812
- return {
813
- ...b,
814
- price,
815
- balanceUsd: price ? getTokenBalanceUsd(b, price) : undefined,
816
- balanceUsdFormatted: price
817
- ? getTokenBalanceUsdFormatted(b, price)
818
- : undefined,
1008
+ const isNative = isNativeToken(b)
1009
+ if (isNative) {
1010
+ return convertNativeTokenBalanceToToken(
1011
+ b as NativeTokenBalance,
1012
+ priceData,
1013
+ )
819
1014
  }
1015
+ return convertTokenBalanceToToken(b as TokenBalance, priceData)
820
1016
  })
821
1017
 
822
1018
  return {
@@ -858,7 +1054,7 @@ export function useAccountTokenBalance({
858
1054
  })
859
1055
  const tokenBalance = balances.find(
860
1056
  (b) =>
861
- b.chainId === chainId &&
1057
+ (b.chainId ?? 0) === chainId &&
862
1058
  (b.contractAddress?.toLowerCase() === token.toLowerCase() ||
863
1059
  (!b.contractAddress && token === zeroAddress)),
864
1060
  )
@@ -895,21 +1091,20 @@ export async function getHasSufficientBalanceToken({
895
1091
  indexerGatewayClient,
896
1092
  trailsClient,
897
1093
  })
898
- const tokenBalance: TokenBalanceExtended | null | undefined = balances.find(
1094
+ const tokenBalance = balances.find(
899
1095
  (b) =>
900
- b.chainId === chainId &&
1096
+ (b.chainId ?? 0) === chainId &&
901
1097
  (b.contractAddress?.toLowerCase() === token.toLowerCase() ||
902
1098
  (!b.contractAddress && token === zeroAddress)),
903
1099
  )
904
1100
  if (!tokenBalance) {
905
1101
  return false
906
1102
  }
907
- const isNative = isNativeToken(tokenBalance)
908
- const decimals = isNative ? 18 : tokenBalance?.contractInfo?.decimals
1103
+ const decimals = tokenBalance.decimals
909
1104
  if (!decimals) {
910
1105
  throw new Error("Decimals not found")
911
1106
  }
912
- return tokenBalance?.balance
1107
+ return tokenBalance.balance
913
1108
  ? BigInt(tokenBalance.balance) >= parseUnits(amount, decimals)
914
1109
  : false
915
1110
  }