0xtrails 0.2.5 → 0.3.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 (267) hide show
  1. package/dist/aave.d.ts +2 -0
  2. package/dist/aave.d.ts.map +1 -1
  3. package/dist/abortController.d.ts +8 -0
  4. package/dist/abortController.d.ts.map +1 -0
  5. package/dist/{ccip-CXlshvBY.js → ccip-BMB3uDZt.js} +1 -1
  6. package/dist/config.d.ts +0 -5
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/constants.d.ts +4 -4
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/error.d.ts +4 -1
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/fees.d.ts +19 -0
  13. package/dist/fees.d.ts.map +1 -0
  14. package/dist/{index-_QuyGrjU.js → index-QXPUrZVv.js} +48719 -50852
  15. package/dist/index.d.ts +9 -8
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +811 -784
  18. package/dist/intentReceiptMonitor.d.ts +24 -0
  19. package/dist/intentReceiptMonitor.d.ts.map +1 -0
  20. package/dist/intentReceiptPoller.d.ts +69 -0
  21. package/dist/intentReceiptPoller.d.ts.map +1 -0
  22. package/dist/intents.d.ts +15 -11
  23. package/dist/intents.d.ts.map +1 -1
  24. package/dist/morpho.d.ts +6 -5
  25. package/dist/morpho.d.ts.map +1 -1
  26. package/dist/mutations.d.ts +16 -0
  27. package/dist/mutations.d.ts.map +1 -0
  28. package/dist/preconditions.d.ts +5 -4
  29. package/dist/preconditions.d.ts.map +1 -1
  30. package/dist/prepareSend.d.ts +7 -258
  31. package/dist/prepareSend.d.ts.map +1 -1
  32. package/dist/prices.d.ts +9 -6
  33. package/dist/prices.d.ts.map +1 -1
  34. package/dist/sequenceWallet.d.ts +3 -16
  35. package/dist/sequenceWallet.d.ts.map +1 -1
  36. package/dist/tokenBalances.d.ts +17 -13
  37. package/dist/tokenBalances.d.ts.map +1 -1
  38. package/dist/trails.d.ts +24 -40
  39. package/dist/trails.d.ts.map +1 -1
  40. package/dist/transactionIntent/constants.d.ts +7 -0
  41. package/dist/transactionIntent/constants.d.ts.map +1 -0
  42. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +44 -0
  43. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -0
  44. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +30 -0
  45. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -0
  46. package/dist/transactionIntent/deposits/index.d.ts +4 -0
  47. package/dist/transactionIntent/deposits/index.d.ts.map +1 -0
  48. package/dist/transactionIntent/deposits/standardDeposit.d.ts +30 -0
  49. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -0
  50. package/dist/transactionIntent/execution/index.d.ts +2 -0
  51. package/dist/transactionIntent/execution/index.d.ts.map +1 -0
  52. package/dist/transactionIntent/execution/transactionState.d.ts +5 -0
  53. package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -0
  54. package/dist/transactionIntent/handlers/crossChain.d.ts +82 -0
  55. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -0
  56. package/dist/transactionIntent/handlers/index.d.ts +4 -0
  57. package/dist/transactionIntent/handlers/index.d.ts.map +1 -0
  58. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +62 -0
  59. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +1 -0
  60. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +72 -0
  61. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -0
  62. package/dist/transactionIntent/index.d.ts +9 -0
  63. package/dist/transactionIntent/index.d.ts.map +1 -0
  64. package/dist/transactionIntent/quote/feeExtractors.d.ts +17 -0
  65. package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -0
  66. package/dist/transactionIntent/quote/index.d.ts +4 -0
  67. package/dist/transactionIntent/quote/index.d.ts.map +1 -0
  68. package/dist/transactionIntent/quote/normalizeQuote.d.ts +34 -0
  69. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -0
  70. package/dist/transactionIntent/quote/quoteHelpers.d.ts +5 -0
  71. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -0
  72. package/dist/transactionIntent/types.d.ts +131 -0
  73. package/dist/transactionIntent/types.d.ts.map +1 -0
  74. package/dist/transactionIntent/utils/balanceChecker.d.ts +18 -0
  75. package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -0
  76. package/dist/transactionIntent/utils/index.d.ts +4 -0
  77. package/dist/transactionIntent/utils/index.d.ts.map +1 -0
  78. package/dist/transactionIntent/utils/lifiHelpers.d.ts +10 -0
  79. package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +1 -0
  80. package/dist/transactionIntent/utils/testnetHelpers.d.ts +3 -0
  81. package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -0
  82. package/dist/transactionIntent/validators.d.ts +6 -0
  83. package/dist/transactionIntent/validators.d.ts.map +1 -0
  84. package/dist/transactions.d.ts +6 -3
  85. package/dist/transactions.d.ts.map +1 -1
  86. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
  87. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
  88. package/dist/widget/components/AccountSettings.d.ts.map +1 -1
  89. package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
  90. package/dist/widget/components/ClassicSwap.d.ts +2 -3
  91. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  92. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  93. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  94. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  95. package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
  96. package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
  97. package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
  98. package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
  99. package/dist/widget/components/Earn.d.ts +2 -3
  100. package/dist/widget/components/Earn.d.ts.map +1 -1
  101. package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
  102. package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
  103. package/dist/widget/components/FeeBreakdown.d.ts +9 -0
  104. package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
  105. package/dist/widget/components/FeeOptions.d.ts +5 -13
  106. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  107. package/dist/widget/components/Fund.d.ts +2 -3
  108. package/dist/widget/components/Fund.d.ts.map +1 -1
  109. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  110. package/dist/widget/components/FundSwap.d.ts +2 -3
  111. package/dist/widget/components/FundSwap.d.ts.map +1 -1
  112. package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
  113. package/dist/widget/components/Identicon.d.ts.map +1 -1
  114. package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
  115. package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
  116. package/dist/widget/components/Modal.d.ts.map +1 -1
  117. package/dist/widget/components/Pay.d.ts +2 -3
  118. package/dist/widget/components/Pay.d.ts.map +1 -1
  119. package/dist/widget/components/PoolDeposit.d.ts +3 -3
  120. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  121. package/dist/widget/components/PoolWithdraw.d.ts +3 -20
  122. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
  123. package/dist/widget/components/QuoteDetails.d.ts +2 -0
  124. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  125. package/dist/widget/components/Receipt.d.ts.map +1 -1
  126. package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
  127. package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
  128. package/dist/widget/components/Swap.d.ts +2 -3
  129. package/dist/widget/components/Swap.d.ts.map +1 -1
  130. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  131. package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
  132. package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
  133. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  134. package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
  135. package/dist/widget/components/Tooltip.d.ts +9 -0
  136. package/dist/widget/components/Tooltip.d.ts.map +1 -0
  137. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  138. package/dist/widget/components/WaasFeeOptions.d.ts +1 -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/css/compiled.css +2 -2
  143. package/dist/widget/hooks/useCheckout.d.ts +17 -4
  144. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  145. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  146. package/dist/widget/hooks/useQuote.d.ts +82 -0
  147. package/dist/widget/hooks/useQuote.d.ts.map +1 -0
  148. package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
  149. package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
  150. package/dist/widget/hooks/useSendForm.d.ts +5 -6
  151. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  152. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  153. package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
  154. package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
  155. package/dist/widget/index.js +2 -2
  156. package/dist/widget/widget.d.ts +17 -7
  157. package/dist/widget/widget.d.ts.map +1 -1
  158. package/package.json +19 -21
  159. package/src/aave.ts +54 -1
  160. package/src/abortController.ts +35 -0
  161. package/src/config.ts +57 -58
  162. package/src/constants.ts +11 -9
  163. package/src/error.ts +21 -3
  164. package/src/fees.ts +210 -0
  165. package/src/index.ts +35 -13
  166. package/src/intentReceiptMonitor.ts +102 -0
  167. package/src/intentReceiptPoller.ts +299 -0
  168. package/src/intents.ts +205 -171
  169. package/src/morpho.ts +58 -9
  170. package/src/mutations.ts +129 -0
  171. package/src/preconditions.ts +16 -21
  172. package/src/prepareSend.ts +92 -4699
  173. package/src/prices.ts +26 -22
  174. package/src/relaySdk.ts +2 -2
  175. package/src/sequenceWallet.ts +6 -73
  176. package/src/tokenBalances.ts +175 -69
  177. package/src/trails.ts +230 -722
  178. package/src/transactionIntent/constants.ts +11 -0
  179. package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
  180. package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
  181. package/src/transactionIntent/deposits/index.ts +3 -0
  182. package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
  183. package/src/transactionIntent/execution/index.ts +1 -0
  184. package/src/transactionIntent/execution/transactionState.ts +35 -0
  185. package/src/transactionIntent/handlers/crossChain.ts +1707 -0
  186. package/src/transactionIntent/handlers/index.ts +3 -0
  187. package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
  188. package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
  189. package/src/transactionIntent/index.ts +9 -0
  190. package/src/transactionIntent/quote/feeExtractors.ts +81 -0
  191. package/src/transactionIntent/quote/index.ts +3 -0
  192. package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
  193. package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
  194. package/src/transactionIntent/types.ts +157 -0
  195. package/src/transactionIntent/utils/balanceChecker.ts +96 -0
  196. package/src/transactionIntent/utils/index.ts +3 -0
  197. package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
  198. package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
  199. package/src/transactionIntent/validators.ts +57 -0
  200. package/src/transactions.ts +98 -71
  201. package/src/widget/compiled.css +2 -2
  202. package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
  203. package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
  204. package/src/widget/components/AccountSettings.tsx +70 -41
  205. package/src/widget/components/ChainFilterDropdown.tsx +24 -3
  206. package/src/widget/components/ClassicSwap.tsx +44 -107
  207. package/src/widget/components/ConfigDisplay.tsx +0 -11
  208. package/src/widget/components/ConnectWallet.tsx +4 -1
  209. package/src/widget/components/ConnectedWallets.tsx +51 -25
  210. package/src/widget/components/DynamicInputStyles.tsx +76 -0
  211. package/src/widget/components/DynamicSizeInputField.tsx +109 -0
  212. package/src/widget/components/Earn.tsx +34 -45
  213. package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
  214. package/src/widget/components/FeeBreakdown.tsx +155 -0
  215. package/src/widget/components/FeeOption.tsx +2 -2
  216. package/src/widget/components/FeeOptions.tsx +151 -112
  217. package/src/widget/components/Fund.tsx +10 -29
  218. package/src/widget/components/FundMethods.tsx +4 -3
  219. package/src/widget/components/FundSwap.tsx +2 -3
  220. package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
  221. package/src/widget/components/Identicon.tsx +164 -95
  222. package/src/widget/components/MeshConnectExchanges.tsx +2 -15
  223. package/src/widget/components/Modal.tsx +0 -12
  224. package/src/widget/components/Pay.tsx +72 -75
  225. package/src/widget/components/PoolDeposit.tsx +221 -242
  226. package/src/widget/components/PoolWithdraw.tsx +347 -469
  227. package/src/widget/components/PriceImpactWarning.tsx +1 -1
  228. package/src/widget/components/QuoteDetails.tsx +906 -484
  229. package/src/widget/components/Receipt.tsx +16 -2
  230. package/src/widget/components/RecipientSelectorButton.tsx +7 -5
  231. package/src/widget/components/Recipients.tsx +1 -1
  232. package/src/widget/components/ScreenHeader.tsx +60 -36
  233. package/src/widget/components/Swap.tsx +2 -3
  234. package/src/widget/components/ThemeProvider.tsx +2 -1
  235. package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
  236. package/src/widget/components/TokenImage.tsx +1 -1
  237. package/src/widget/components/TokenSelector.tsx +62 -53
  238. package/src/widget/components/TokenSelectorButton.tsx +38 -15
  239. package/src/widget/components/Tooltip.tsx +51 -0
  240. package/src/widget/components/TransferPendingVertical.tsx +12 -8
  241. package/src/widget/components/WaasFeeOptions.tsx +139 -4
  242. package/src/widget/components/WalletConfirmation.tsx +23 -13
  243. package/src/widget/components/WalletConnect.tsx +93 -29
  244. package/src/widget/hooks/useAmountUsd.ts +9 -9
  245. package/src/widget/hooks/useCheckout.ts +97 -9
  246. package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
  247. package/src/widget/hooks/useQuote.ts +466 -0
  248. package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
  249. package/src/widget/hooks/useSendForm.ts +45 -51
  250. package/src/widget/hooks/useTokenList.ts +34 -26
  251. package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
  252. package/src/widget/widget.tsx +365 -390
  253. package/dist/apiClient.d.ts +0 -9
  254. package/dist/apiClient.d.ts.map +0 -1
  255. package/dist/intentEntrypoint.d.ts +0 -114
  256. package/dist/intentEntrypoint.d.ts.map +0 -1
  257. package/dist/metaTxnMonitor.d.ts +0 -15
  258. package/dist/metaTxnMonitor.d.ts.map +0 -1
  259. package/dist/metaTxns.d.ts +0 -11
  260. package/dist/metaTxns.d.ts.map +0 -1
  261. package/dist/relayer.d.ts +0 -43
  262. package/dist/relayer.d.ts.map +0 -1
  263. package/src/apiClient.ts +0 -35
  264. package/src/intentEntrypoint.ts +0 -203
  265. package/src/metaTxnMonitor.ts +0 -171
  266. package/src/metaTxns.ts +0 -45
  267. package/src/relayer.ts +0 -289
@@ -10,7 +10,6 @@ import {
10
10
  zeroAddress,
11
11
  } from "viem"
12
12
  import { useAccount } from "wagmi"
13
- import { useAPIClient } from "../../apiClient.js"
14
13
  import { getChainInfo, useSupportedChains } from "../../chains.js"
15
14
  import { getFullErrorMessage, getPrettifiedErrorMessage } from "../../error.js"
16
15
  import {
@@ -18,11 +17,11 @@ import {
18
17
  TradeType,
19
18
  type PrepareSendReturn,
20
19
  type PrepareSendQuote,
20
+ type SelectedFeeToken,
21
21
  } from "../../prepareSend.js"
22
22
  import type { TransactionState } from "../../transactions.js"
23
23
  import { getTokenPrice, useTokenPrices, normalizeNumber } from "../../prices.js"
24
24
  import { useQueryParams } from "../../queryParams.js"
25
- import { getRelayer } from "../../relayer.js"
26
25
  import {
27
26
  formatRawAmount,
28
27
  formatUsdAmountDisplay,
@@ -84,19 +83,18 @@ export type OnCompleteProps = {
84
83
  }
85
84
 
86
85
  export type UseSendProps = {
87
- account: Account
86
+ account?: Account
88
87
  toAmount?: string
89
88
  toRecipient?: string
90
89
  toChainId?: number
91
90
  toToken?: string
92
91
  toCalldata?: string
93
92
  refundAddress?: string
94
- walletClient: WalletClient
93
+ walletClient?: WalletClient
95
94
  onTransactionStateChange: (transactionStates: TransactionState[]) => void
96
95
  onError: (error: Error | string | null) => void
97
96
  onWaitingForWalletConfirm: (quote: PrepareSendQuote) => void
98
97
  paymasterUrls?: PaymasterUrl[]
99
- gasless?: boolean
100
98
  onSend: (amount: string, recipient: string) => void
101
99
  onConfirm: () => void
102
100
  onComplete: (result: OnCompleteProps) => void
@@ -165,7 +163,7 @@ export type UseSendReturn = {
165
163
  destTokenPrices: TokenPrice[] | null
166
164
  sourceTokenPrices: TokenPrice[] | null
167
165
  selectedToken?: Token
168
- selectedFeeToken: FeeOption | null
166
+ selectedFeeToken: SelectedFeeToken | undefined
169
167
  setIsChainDropdownOpen: (isOpen: boolean) => void
170
168
  setIsTokenDropdownOpen: (isOpen: boolean) => void
171
169
  toAmountFormatted: string
@@ -194,7 +192,6 @@ export function useSendForm({
194
192
  onError,
195
193
  onWaitingForWalletConfirm,
196
194
  paymasterUrls,
197
- gasless,
198
195
  selectedToken,
199
196
  onSend,
200
197
  onConfirm,
@@ -435,7 +432,6 @@ export function useSendForm({
435
432
  }
436
433
  }, [selectedDestToken, defaultDestToken])
437
434
 
438
- const apiClient = useAPIClient()
439
435
  const trailsClient = useTrailsClient()
440
436
 
441
437
  // Get user's token balances for balance checking
@@ -462,8 +458,8 @@ export function useSendForm({
462
458
  selectedDestToken && destTokenAddress && selectedDestinationChain?.id
463
459
  ? [
464
460
  {
465
- tokenId: selectedDestToken.symbol,
466
- contractAddress: destTokenAddress,
461
+ tokenSymbol: selectedDestToken.symbol,
462
+ tokenAddress: destTokenAddress,
467
463
  chainId: selectedDestinationChain.id,
468
464
  },
469
465
  ]
@@ -474,20 +470,20 @@ export function useSendForm({
474
470
 
475
471
  const { tokenPrices: destTokenPrices } = useTokenPrices(
476
472
  destTokenPricesInput,
477
- apiClient,
473
+ trailsClient,
478
474
  )
479
475
 
480
476
  const { tokenPrices: sourceTokenPrices } = useTokenPrices(
481
477
  selectedToken
482
478
  ? [
483
479
  {
484
- tokenId: selectedToken.symbol,
485
- contractAddress: selectedToken.contractAddress,
480
+ tokenSymbol: selectedToken.symbol,
481
+ tokenAddress: selectedToken.contractAddress,
486
482
  chainId: selectedToken.chainId,
487
483
  },
488
484
  ]
489
485
  : [],
490
- apiClient,
486
+ trailsClient,
491
487
  )
492
488
 
493
489
  // Update selectedChain when toChainId prop changes
@@ -569,7 +565,7 @@ export function useSendForm({
569
565
  selectedToken?.balance && selectedToken?.contractInfo?.decimals
570
566
  ? formatRawAmount(
571
567
  selectedToken.balance,
572
- selectedToken.contractInfo?.decimals!,
568
+ selectedToken.contractInfo?.decimals,
573
569
  )
574
570
  : "0"
575
571
  const balanceUsdDisplay = selectedToken?.balanceUsdFormatted ?? ""
@@ -579,8 +575,8 @@ export function useSendForm({
579
575
  const amountUsdDisplay = useMemo(() => {
580
576
  const tokenPrice =
581
577
  tradeType === TradeType.EXACT_INPUT
582
- ? (sourceTokenPrices?.[0]?.price?.value ?? 0) // For fund form, use source token price
583
- : (destTokenPrices?.[0]?.price?.value ?? 0) // For payment form, use dest token price
578
+ ? (sourceTokenPrices?.[0]?.priceUsd ?? 0) // For fund form, use source token price
579
+ : (destTokenPrices?.[0]?.priceUsd ?? 0) // For payment form, use dest token price
584
580
  const amountUsd = Number(amount) * tokenPrice
585
581
  return formatUsdAmountDisplay(amountUsd)
586
582
  }, [amount, destTokenPrices, sourceTokenPrices, tradeType])
@@ -616,6 +612,11 @@ export function useSendForm({
616
612
 
617
613
  // Calculate raw amount (in wei/smallest unit)
618
614
  const amountRaw = useMemo(() => {
615
+ // Skip validation during initialization when no tokens are selected
616
+ if (!selectedToken && !selectedDestToken) {
617
+ return "0"
618
+ }
619
+
619
620
  if (
620
621
  !amount &&
621
622
  !(selectedToken?.contractInfo?.decimals || selectedDestToken?.decimals)
@@ -687,6 +688,7 @@ export function useSendForm({
687
688
  const getQuote = useCallback(async () => {
688
689
  // Only get quote if all required inputs are present
689
690
  if (
691
+ !account ||
690
692
  !amount ||
691
693
  !destinationTokenAddress ||
692
694
  !isValidRecipient ||
@@ -719,12 +721,6 @@ export function useSendForm({
719
721
  setError(null)
720
722
  setQuoteError(null)
721
723
 
722
- const originRelayer = getRelayer(undefined, selectedToken.chainId)
723
- const destinationRelayer = getRelayer(
724
- undefined,
725
- selectedDestinationChain.id,
726
- )
727
-
728
724
  const sourceTokenDecimals = selectedToken.contractInfo?.decimals
729
725
  const destinationTokenDecimals = selectedDestToken.decimals
730
726
 
@@ -742,12 +738,16 @@ export function useSendForm({
742
738
  }
743
739
 
744
740
  let sourceTokenPriceUsd = selectedToken.tokenPriceUsd ?? null
745
- let destinationTokenPriceUsd = destTokenPrices?.[0]?.price?.value ?? null
741
+ let destinationTokenPriceUsd = destTokenPrices?.[0]?.priceUsd ?? null
746
742
 
747
743
  if (!sourceTokenPriceUsd) {
748
744
  try {
749
- const price = await getTokenPrice(apiClient, selectedToken)
750
- sourceTokenPriceUsd = price?.price?.value ?? null
745
+ const price = await getTokenPrice(trailsClient, {
746
+ tokenAddress: selectedToken.contractAddress,
747
+ tokenSymbol: selectedToken.symbol,
748
+ chainId: selectedToken.chainId,
749
+ })
750
+ sourceTokenPriceUsd = price?.priceUsd ?? null
751
751
  } catch (error) {
752
752
  logger.console.error(
753
753
  "[trails-sdk] Error getting source token price:",
@@ -758,12 +758,12 @@ export function useSendForm({
758
758
 
759
759
  if (!destinationTokenPriceUsd) {
760
760
  try {
761
- const price = await getTokenPrice(apiClient, {
762
- tokenId: selectedDestToken.symbol,
763
- contractAddress: destinationTokenAddress ?? "",
761
+ const price = await getTokenPrice(trailsClient, {
762
+ tokenSymbol: selectedDestToken.symbol,
763
+ tokenAddress: destinationTokenAddress ?? "",
764
764
  chainId: selectedDestinationChain.id,
765
765
  })
766
- destinationTokenPriceUsd = price?.price?.value ?? null
766
+ destinationTokenPriceUsd = price?.priceUsd ?? null
767
767
  } catch (error) {
768
768
  logger.console.error(
769
769
  "[trails-sdk] Error getting destination token price:",
@@ -801,17 +801,14 @@ export function useSendForm({
801
801
  } else {
802
802
  const originChain = getChainInfo(selectedToken.chainId)
803
803
  const nativeTokenSymbol = originChain?.nativeCurrency?.symbol ?? ""
804
- const nativePrice = await getTokenPrice(apiClient, {
805
- tokenId: nativeTokenSymbol,
806
- contractAddress: zeroAddress,
804
+ const nativePrice = await getTokenPrice(trailsClient, {
805
+ tokenSymbol: nativeTokenSymbol,
806
+ tokenAddress: zeroAddress,
807
807
  chainId: selectedToken.chainId,
808
808
  })
809
- nativeTokenPriceUsd = nativePrice?.price?.value ?? 0
809
+ nativeTokenPriceUsd = nativePrice?.priceUsd ?? 0
810
810
  }
811
811
 
812
- // Disable gasless for sequence-waas wallet
813
- const effectiveGasless = walletId === "sequence-waas" ? false : gasless
814
-
815
812
  const options = {
816
813
  account,
817
814
  originTokenAddress: selectedToken.contractAddress,
@@ -832,10 +829,7 @@ export function useSendForm({
832
829
  destinationTokenSymbol: selectedDestToken.symbol,
833
830
  fee: "0",
834
831
  client: walletClient,
835
- apiClient,
836
832
  trailsClient,
837
- originRelayer,
838
- destinationRelayer,
839
833
  destinationCalldata: toCalldata,
840
834
  refundAddress,
841
835
  dryMode: isDryMode,
@@ -848,13 +842,12 @@ export function useSendForm({
848
842
  paymasterUrls?.find(
849
843
  (p) => p.chainId.toString() === selectedToken.chainId.toString(),
850
844
  )?.url ?? undefined,
851
- gasless: effectiveGasless,
852
845
  originNativeTokenPriceUsd: nativeTokenPriceUsd,
853
846
  quoteProvider: effectiveQuoteProvider,
854
847
  mode,
855
848
  fundMethod,
856
849
  checkoutOnHandlers,
857
- selectedFeeToken,
850
+ selectedFeeToken: selectedFeeToken ?? undefined,
858
851
  walletId,
859
852
  }
860
853
 
@@ -882,7 +875,6 @@ export function useSendForm({
882
875
  isDryMode,
883
876
  account,
884
877
  walletClient,
885
- apiClient,
886
878
  trailsClient,
887
879
  selectedDestToken?.decimals,
888
880
  recipient,
@@ -896,10 +888,9 @@ export function useSendForm({
896
888
  toCalldata,
897
889
  refundAddress,
898
890
  paymasterUrls,
899
- gasless,
900
891
  handleTransactionStateChange,
901
892
  isValidRecipient,
902
- destTokenPrices?.[0]?.price?.value,
893
+ destTokenPrices?.[0]?.priceUsd,
903
894
  amount,
904
895
  selectedDestToken,
905
896
  selectedDestinationChain,
@@ -945,6 +936,7 @@ export function useSendForm({
945
936
  selectedToken?.chainId,
946
937
  selectedToken?.balance,
947
938
  selectedToken?.tokenPriceUsd,
939
+ recipient, // Add recipient to trigger quote re-fetch when it changes
948
940
  // selectedFeeToken is passed to send() at execution time, not needed here
949
941
  ])
950
942
 
@@ -958,7 +950,8 @@ export function useSendForm({
958
950
  }, [prepareSendResult, toAmountFormatted])
959
951
 
960
952
  const quotedDestinationAmountDisplay = useMemo(() => {
961
- return formatAmountDisplay(quotedDestinationAmount || "0")
953
+ const formattedAmount = formatAmount(quotedDestinationAmount || 0)
954
+ return Number(formattedAmount) === 0 ? "0" : formattedAmount
962
955
  }, [quotedDestinationAmount])
963
956
 
964
957
  // Set raw fee options in the hook whenever prepareSendResult changes
@@ -1077,15 +1070,15 @@ export function useSendForm({
1077
1070
  )
1078
1071
  // Wait for full send to complete
1079
1072
  const {
1080
- originUserTxReceipt,
1073
+ depositUserTxnReceipt,
1081
1074
  originMetaTxnReceipt,
1082
1075
  destinationMetaTxnReceipt,
1083
1076
  } = await send({
1084
1077
  onOriginSend,
1085
- selectedFeeToken, // Pass current value at execution time
1078
+ selectedFeeToken: selectedFeeToken ?? undefined, // Pass current value at execution time
1086
1079
  })
1087
1080
  logger.console.log("[trails-sdk] send() completed, receipts:", {
1088
- originUserTxReceipt,
1081
+ depositUserTxnReceipt,
1089
1082
  originMetaTxnReceipt,
1090
1083
  destinationMetaTxnReceipt,
1091
1084
  })
@@ -1158,6 +1151,7 @@ export function useSendForm({
1158
1151
 
1159
1152
  // Get button text based on recipient and calldata
1160
1153
  const buttonText = useMemo(() => {
1154
+ if (!account?.address) return "Connect your wallet"
1161
1155
  if (!selectedToken) return "Select a token"
1162
1156
  if (!amount) return "Enter an amount"
1163
1157
  if (!selectedDestToken?.symbol) return "Select a token"
@@ -1251,7 +1245,7 @@ export function useSendForm({
1251
1245
  amount,
1252
1246
  isValidRecipient,
1253
1247
  recipient,
1254
- account.address,
1248
+ account?.address,
1255
1249
  selectedDestToken?.symbol,
1256
1250
  isWaitingForWalletConfirm,
1257
1251
  isSubmitting,
@@ -1342,7 +1336,7 @@ export function useSendForm({
1342
1336
  destTokenPrices: destTokenPrices ?? null,
1343
1337
  sourceTokenPrices: sourceTokenPrices ?? null,
1344
1338
  selectedToken,
1345
- selectedFeeToken,
1339
+ selectedFeeToken: selectedFeeToken ?? undefined,
1346
1340
  setIsChainDropdownOpen,
1347
1341
  setIsTokenDropdownOpen,
1348
1342
  toAmountFormatted: quotedDestinationAmount,
@@ -17,7 +17,7 @@ import {
17
17
  } from "../../tokenBalances.js"
18
18
  import { getFormatttedTokenName, useSupportedTokens } from "../../tokens.js"
19
19
  import { useIndexerGatewayClient } from "../../indexerClient.js"
20
- import { useAPIClient } from "../../apiClient.js"
20
+ import { useTrailsClient } from "../../trailsClient.js"
21
21
  import { useTokenPrices } from "../../prices.js"
22
22
  import { logger } from "../../logger.js"
23
23
 
@@ -136,7 +136,7 @@ export function useTokenList({
136
136
  const [searchQuery, setSearchQuery] = useState("")
137
137
  const { address } = useAccount()
138
138
  const indexerGatewayClient = useIndexerGatewayClient()
139
- const apiClient = useAPIClient()
139
+ const trailsClient = useTrailsClient()
140
140
  const {
141
141
  sortedTokens: allSortedTokens,
142
142
  isLoadingSortedTokens,
@@ -160,8 +160,8 @@ export function useTokenList({
160
160
 
161
161
  return filteredTokens.map((token: any) => ({
162
162
  chainId: token.chainId,
163
- contractAddress: token.contractAddress || zeroAddress,
164
- tokenId: token.symbol,
163
+ tokenAddress: token.contractAddress || zeroAddress,
164
+ tokenSymbol: token.symbol,
165
165
  }))
166
166
  }
167
167
 
@@ -169,15 +169,15 @@ export function useTokenList({
169
169
 
170
170
  return supportedTokens.map((token: any) => ({
171
171
  chainId: token.chainId,
172
- contractAddress: token.contractAddress || zeroAddress,
173
- tokenId: token.symbol,
172
+ tokenAddress: token.contractAddress || zeroAddress,
173
+ tokenSymbol: token.symbol,
174
174
  }))
175
175
  }, [allSupportedTokens, supportedTokens, fundMethod])
176
176
 
177
177
  const {
178
178
  tokenPrices: supportedTokenPrices,
179
179
  isLoadingTokenPrices: isLoadingSupportedTokenPrices,
180
- } = useTokenPrices(supportedTokensForPricing, apiClient)
180
+ } = useTokenPrices(supportedTokensForPricing, trailsClient)
181
181
 
182
182
  // Determine loading state based on fund method and allSupportedTokens
183
183
  const isLoadingTokens =
@@ -222,7 +222,7 @@ export function useTokenList({
222
222
  // Find price data for this token
223
223
  const priceData = supportedTokenPrices?.find(
224
224
  (p: any) =>
225
- p.token.contractAddress?.toLowerCase() ===
225
+ p.token.tokenAddress?.toLowerCase() ===
226
226
  (token.contractAddress || zeroAddress).toLowerCase() &&
227
227
  p.token.chainId === token.chainId,
228
228
  )
@@ -237,10 +237,11 @@ export function useTokenList({
237
237
  balance: "0", // No balance info for QR code and exchange modes
238
238
  balanceUsd: 0,
239
239
  balanceUsdFormatted: "0",
240
- price: priceData?.price || { value: 0, currency: "USD" },
241
- price24hVol:
242
- (priceData as unknown as { price24hVol: { value: number } })
243
- ?.price24hVol?.value || 0,
240
+ price:
241
+ priceData?.priceUsd !== undefined
242
+ ? { value: priceData.priceUsd, currency: "USD" }
243
+ : { value: 0, currency: "USD" },
244
+ price24hVol: 0, // Volume data not available in new API
244
245
  imageUrl: token.imageUrl,
245
246
  symbol: token.symbol,
246
247
  isSufficientBalance: true, // Always true for QR code and exchange modes
@@ -254,10 +255,11 @@ export function useTokenList({
254
255
  balance: "0", // No balance info for QR code and exchange modes
255
256
  balanceUsd: 0,
256
257
  balanceUsdFormatted: "0",
257
- price: priceData?.price || { value: 0, currency: "USD" },
258
- price24hVol:
259
- (priceData as unknown as { price24hVol: { value: number } })
260
- ?.price24hVol?.value || 0,
258
+ price:
259
+ priceData?.priceUsd !== undefined
260
+ ? { value: priceData.priceUsd, currency: "USD" }
261
+ : { value: 0, currency: "USD" },
262
+ price24hVol: 0, // Volume data not available in new API
261
263
  imageUrl: token.imageUrl,
262
264
  contractInfo: {
263
265
  decimals: token.decimals,
@@ -520,8 +522,8 @@ export function useTokenList({
520
522
 
521
523
  const filteredTokensFormatted = useMemo(() => {
522
524
  // Get base formatted tokens
523
- const baseFormattedTokens = filteredTokens.map(
524
- (token: TokenBalanceExtended): TokenFormatted => {
525
+ const baseFormattedTokens = filteredTokens
526
+ .map((token: TokenBalanceExtended): TokenFormatted | null => {
525
527
  const isNative =
526
528
  !("contractAddress" in token) || token.contractAddress === zeroAddress
527
529
  const chainInfo = getChainInfo(token.chainId)
@@ -544,7 +546,15 @@ export function useTokenList({
544
546
  )
545
547
  const decimals = isNative ? 18 : token.contractInfo?.decimals
546
548
  if (!decimals) {
547
- throw new Error("Decimals not found")
549
+ logger.console.warn(
550
+ "[trails-sdk] Missing decimals for token, skipping:",
551
+ {
552
+ token: isNative ? token : token.contractInfo,
553
+ chainId: token.chainId,
554
+ isNative,
555
+ },
556
+ )
557
+ return null // Return null to filter out tokens without decimals
548
558
  }
549
559
  const formattedBalance = formatRawAmount(token.balance, decimals)
550
560
  const priceUsd = Number(token.price?.value) ?? 0
@@ -611,8 +621,8 @@ export function useTokenList({
611
621
  isSufficientBalance,
612
622
  chainName,
613
623
  }
614
- },
615
- )
624
+ })
625
+ .filter(Boolean) as TokenFormatted[] // Filter out null values for tokens without decimals
616
626
 
617
627
  // If allSupportedTokens is true, combine with supported tokens
618
628
  if (allSupportedTokens) {
@@ -641,7 +651,7 @@ export function useTokenList({
641
651
  // Find price data for this supported token
642
652
  const priceData = supportedTokenPrices?.find(
643
653
  (p: any) =>
644
- p.token.contractAddress?.toLowerCase() ===
654
+ p.token.tokenAddress?.toLowerCase() ===
645
655
  (supportedToken.contractAddress || zeroAddress).toLowerCase() &&
646
656
  p.token.chainId === supportedToken.chainId,
647
657
  )
@@ -659,10 +669,8 @@ export function useTokenList({
659
669
  balance: "",
660
670
  balanceFormatted: "",
661
671
  balanceUsdFormatted: "",
662
- priceUsd: priceData?.price?.value || 0,
663
- price24hVol:
664
- (priceData as unknown as { price24hVol: { value: number } })
665
- ?.price24hVol?.value || 0, // Add price data for volume sorting
672
+ priceUsd: priceData?.priceUsd || 0,
673
+ price24hVol: 0, // Volume data not available in new API
666
674
  isSufficientBalance: true,
667
675
  // Use any type to bypass strict type checking for now
668
676
  } as any
@@ -0,0 +1,128 @@
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ useState,
5
+ useCallback,
6
+ type ReactNode,
7
+ } from "react"
8
+ import type { Screen } from "./useCurrentScreen.js"
9
+ import { logger } from "../../logger.js"
10
+
11
+ export type WalletConnectionPurpose =
12
+ | "general" // Default: switch active wallet
13
+ | "recipient-selection" // Don't switch, set as recipient only
14
+ | "fund-method-selection" // Don't switch, use for funding only
15
+
16
+ interface WalletConnectionContextValue {
17
+ purpose: WalletConnectionPurpose
18
+ originScreen: Screen | null
19
+ connectedWalletAddress: string | null
20
+ originalActiveWalletAddress: string | null
21
+ originalActiveConnector: any | null
22
+ }
23
+
24
+ interface WalletConnectionContextType {
25
+ connectionContext: WalletConnectionContextValue
26
+ setConnectionContext: (
27
+ purpose: WalletConnectionPurpose,
28
+ originScreen?: Screen,
29
+ originalActiveWalletAddress?: string,
30
+ originalActiveConnector?: any,
31
+ ) => void
32
+ setConnectedWalletAddress: (address: string) => void
33
+ clearConnectionContext: () => void
34
+ isRecipientSelection: boolean
35
+ isFundMethodSelection: boolean
36
+ }
37
+
38
+ const WalletConnectionContext =
39
+ createContext<WalletConnectionContextType | null>(null)
40
+
41
+ interface WalletConnectionProviderProps {
42
+ children: ReactNode
43
+ }
44
+
45
+ const DEFAULT_CONTEXT: WalletConnectionContextValue = {
46
+ purpose: "general",
47
+ originScreen: null,
48
+ connectedWalletAddress: null,
49
+ originalActiveWalletAddress: null,
50
+ originalActiveConnector: null,
51
+ }
52
+
53
+ export function WalletConnectionProvider({
54
+ children,
55
+ }: WalletConnectionProviderProps) {
56
+ const [connectionContext, setContext] =
57
+ useState<WalletConnectionContextValue>(DEFAULT_CONTEXT)
58
+
59
+ const setConnectionContext = useCallback(
60
+ (
61
+ purpose: WalletConnectionPurpose,
62
+ originScreen?: Screen,
63
+ originalActiveWalletAddress?: string,
64
+ originalActiveConnector?: any,
65
+ ) => {
66
+ logger.console.log("[trails-sdk] Setting wallet connection context:", {
67
+ purpose,
68
+ originScreen,
69
+ originalActiveWalletAddress,
70
+ hasOriginalConnector: !!originalActiveConnector,
71
+ })
72
+ setContext({
73
+ purpose,
74
+ originScreen: originScreen || null,
75
+ connectedWalletAddress: null,
76
+ originalActiveWalletAddress: originalActiveWalletAddress || null,
77
+ originalActiveConnector: originalActiveConnector || null,
78
+ })
79
+ },
80
+ [],
81
+ )
82
+
83
+ const setConnectedWalletAddress = useCallback((address: string) => {
84
+ logger.console.log(
85
+ "[trails-sdk] Setting connected wallet address:",
86
+ address,
87
+ )
88
+ setContext((prev) => ({
89
+ ...prev,
90
+ connectedWalletAddress: address,
91
+ }))
92
+ }, [])
93
+
94
+ const clearConnectionContext = useCallback(() => {
95
+ logger.console.log("[trails-sdk] Clearing wallet connection context")
96
+ setContext(DEFAULT_CONTEXT)
97
+ }, [])
98
+
99
+ const isRecipientSelection =
100
+ connectionContext.purpose === "recipient-selection"
101
+ const isFundMethodSelection =
102
+ connectionContext.purpose === "fund-method-selection"
103
+
104
+ const value: WalletConnectionContextType = {
105
+ connectionContext,
106
+ setConnectionContext,
107
+ setConnectedWalletAddress,
108
+ clearConnectionContext,
109
+ isRecipientSelection,
110
+ isFundMethodSelection,
111
+ }
112
+
113
+ return (
114
+ <WalletConnectionContext.Provider value={value}>
115
+ {children}
116
+ </WalletConnectionContext.Provider>
117
+ )
118
+ }
119
+
120
+ export function useWalletConnectionContext() {
121
+ const context = useContext(WalletConnectionContext)
122
+ if (!context) {
123
+ throw new Error(
124
+ "useWalletConnectionContext must be used within a WalletConnectionProvider",
125
+ )
126
+ }
127
+ return context
128
+ }