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
package/src/config.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import {
2
2
  PROD_SEQUENCE_INDEXER_URL,
3
- PROD_SEQUENCE_API_URL,
4
3
  DEFAULT_WALLETCONNECT_PROJECT_ID,
5
4
  DEFAULT_SLIPPAGE_TOLERANCE,
6
5
  PROD_SEQUENCE_PROJECT_ACCESS_KEY,
7
6
  DEV_SEQUENCE_INDEXER_URL,
8
- DEV_SEQUENCE_API_URL,
9
7
  DEV_TRAILS_API_URL,
10
8
  DEV_SEQUENCE_PROJECT_ACCESS_KEY,
11
9
  DEFAULT_SEQUENCE_ENV,
@@ -23,7 +21,6 @@ export const globalConfig: {
23
21
  sequenceProjectAccessKey: string
24
22
  sequenceIndexerUrl: string
25
23
  sequenceNodeGatewayUrl: string
26
- sequenceApiUrl: string
27
24
  trailsApiUrl: string
28
25
  sequenceEnv: SequenceEnv
29
26
  walletConnectProjectId: string
@@ -36,7 +33,6 @@ export const globalConfig: {
36
33
  sequenceProjectAccessKey: declareSequenceProjectAccessKey(),
37
34
  sequenceIndexerUrl: declareSequenceIndexerUrl(),
38
35
  sequenceNodeGatewayUrl: declareSequenceNodeGatewayUrl(),
39
- sequenceApiUrl: declareSequenceApiUrl(),
40
36
  trailsApiUrl: declareTrailsApiUrl(),
41
37
  walletConnectProjectId: DEFAULT_WALLETCONNECT_PROJECT_ID,
42
38
  slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
@@ -48,27 +44,38 @@ export function declareSequenceEnv(): SequenceEnv {
48
44
  if (typeof window !== "undefined" && (import.meta as any)?.hot) {
49
45
  return "local"
50
46
  }
51
- if (typeof process !== "undefined") {
52
- if (getEnvVar("ENV") === "local") {
53
- return "local"
54
- }
55
- if (getEnvVar("ENV") === "development" || getEnvVar("ENV") === "dev") {
56
- return "dev"
57
- }
58
47
 
59
- // Special handling for Cloudflare Pages branches
60
- const cfPagesBranch = getEnvVar("CF_PAGES_BRANCH")
61
- if (cfPagesBranch) {
62
- // If running on Cloudflare Pages, all branches except "production" default to dev
63
- if (cfPagesBranch === "prod" || cfPagesBranch === "production") {
64
- return "prod"
65
- }
66
- return "dev"
67
- }
48
+ // Check explicit ENV variable first
49
+ const explicitEnv = getEnvVar("ENV")
50
+ if (explicitEnv === "local") {
51
+ return "local"
52
+ }
53
+ if (explicitEnv === "development" || explicitEnv === "dev") {
54
+ return "dev"
55
+ }
56
+ if (explicitEnv === "production" || explicitEnv === "prod") {
57
+ return "prod"
58
+ }
68
59
 
69
- if (getEnvVar("ENV") === "production" || getEnvVar("ENV") === "prod") {
60
+ // Special handling for Cloudflare Pages branches
61
+ const cfPagesBranch = getEnvVar("CF_PAGES_BRANCH")
62
+ if (cfPagesBranch) {
63
+ // If running on Cloudflare Pages, all branches except "production" default to dev
64
+ if (cfPagesBranch === "prod" || cfPagesBranch === "production") {
70
65
  return "prod"
71
66
  }
67
+ // Preview mode and other branches default to dev
68
+ return "dev"
69
+ }
70
+
71
+ // If we're in a browser/Cloudflare environment but no explicit env is set,
72
+ // check if we have dev environment variables set (indicating non-prod)
73
+ // This helps with Cloudflare Workers preview mode
74
+ if (typeof window !== "undefined" || typeof process === "undefined") {
75
+ // In browser/Cloudflare Workers context, if no explicit prod indicators,
76
+ // default to dev for safety (unless explicitly set to prod)
77
+ // This prevents accidental prod usage in preview/staging environments
78
+ return "dev"
72
79
  }
73
80
 
74
81
  return DEFAULT_SEQUENCE_ENV
@@ -81,16 +88,6 @@ export function declareSequenceIndexerUrl() {
81
88
  return DEV_SEQUENCE_INDEXER_URL
82
89
  }
83
90
 
84
- export function declareSequenceApiUrl() {
85
- if (declareSequenceEnv() === "prod") {
86
- return PROD_SEQUENCE_API_URL
87
- }
88
- if (declareSequenceEnv() === "local") {
89
- return getEnvVar("SEQUENCE_API_URL") || DEV_SEQUENCE_API_URL
90
- }
91
- return DEV_SEQUENCE_API_URL
92
- }
93
-
94
91
  export function declareTrailsApiUrl() {
95
92
  if (declareSequenceEnv() === "prod") {
96
93
  return PROD_TRAILS_API_URL
@@ -109,17 +106,18 @@ export function declareSequenceNodeGatewayUrl() {
109
106
  }
110
107
 
111
108
  export function declareSequenceProjectAccessKey() {
112
- const sequenceEnv = declareSequenceEnv()
113
-
114
- // Check for explicit env var override
115
- if (typeof process !== "undefined") {
116
- const envVarKey = getEnvVar("SEQUENCE_PROJECT_ACCESS_KEY")
117
- if (envVarKey) {
118
- return envVarKey
119
- }
109
+ // Check for explicit env var override first (works in all environments)
110
+ const envVarKey =
111
+ getEnvVar("SEQUENCE_PROJECT_ACCESS_KEY") ||
112
+ getEnvVar("PROJECT_ACCESS_KEY") ||
113
+ getEnvVar("VITE_SEQUENCE_PROJECT_ACCESS_KEY") ||
114
+ getEnvVar("VITE_PROJECT_ACCESS_KEY")
115
+ if (envVarKey) {
116
+ return envVarKey
120
117
  }
121
118
 
122
119
  // Use dev/prod keys based on environment
120
+ const sequenceEnv = declareSequenceEnv()
123
121
  if (sequenceEnv === "prod") {
124
122
  return PROD_SEQUENCE_PROJECT_ACCESS_KEY
125
123
  }
@@ -171,14 +169,6 @@ export function getSequenceNodeGatewayUrl() {
171
169
  return globalConfig.sequenceNodeGatewayUrl
172
170
  }
173
171
 
174
- export function setSequenceApiUrl(sequenceApiUrl: string) {
175
- globalConfig.sequenceApiUrl = sequenceApiUrl
176
- }
177
-
178
- export function getSequenceApiUrl() {
179
- return globalConfig.sequenceApiUrl
180
- }
181
-
182
172
  export function setTrailsApiUrl(trailsApiUrl: string) {
183
173
  globalConfig.trailsApiUrl = trailsApiUrl
184
174
  }
@@ -192,16 +182,12 @@ export function setSequenceEnv(sequenceEnv: SequenceEnv) {
192
182
 
193
183
  if (sequenceEnv === "prod") {
194
184
  setSequenceIndexerUrl(PROD_SEQUENCE_INDEXER_URL)
195
- setSequenceApiUrl(PROD_SEQUENCE_API_URL)
196
185
  setTrailsApiUrl(PROD_TRAILS_API_URL)
197
186
  setSequenceNodeGatewayUrl(PROD_SEQUENCE_NODE_GATEWAY_URL)
198
187
  setSequenceProjectAccessKey(PROD_SEQUENCE_PROJECT_ACCESS_KEY)
199
188
  }
200
189
 
201
190
  if (sequenceEnv === "local") {
202
- if (getEnvVar("SEQUENCE_API_URL")) {
203
- setSequenceApiUrl(getEnvVar("SEQUENCE_API_URL"))
204
- }
205
191
  if (getEnvVar("TRAILS_API_URL")) {
206
192
  setTrailsApiUrl(getEnvVar("TRAILS_API_URL"))
207
193
  }
@@ -209,7 +195,6 @@ export function setSequenceEnv(sequenceEnv: SequenceEnv) {
209
195
 
210
196
  if (sequenceEnv === "dev") {
211
197
  setSequenceIndexerUrl(DEV_SEQUENCE_INDEXER_URL)
212
- setSequenceApiUrl(DEV_SEQUENCE_API_URL)
213
198
  setTrailsApiUrl(DEV_TRAILS_API_URL)
214
199
  setSequenceNodeGatewayUrl(DEV_SEQUENCE_NODE_GATEWAY_URL)
215
200
  setSequenceProjectAccessKey(DEV_SEQUENCE_PROJECT_ACCESS_KEY)
@@ -272,14 +257,28 @@ export const FeatureFlags = {
272
257
  }
273
258
 
274
259
  export function getEnvVar(name: string) {
275
- if (typeof process !== "undefined") {
276
- return process?.env?.[name]
277
- }
260
+ // In Vite/browser environments, check import.meta.env first
261
+ // This is where Vite injects environment variables at build time
278
262
  if ((import.meta as any)?.env) {
279
- return (import.meta as any).env[name]
263
+ // Check for VITE_ prefixed version first (Vite convention)
264
+ const vitePrefixed = (import.meta as any).env[`VITE_${name}`]
265
+ if (vitePrefixed !== undefined && vitePrefixed !== "") {
266
+ return vitePrefixed
267
+ }
268
+ // Check direct name (for variables injected via vite.config.ts define)
269
+ const direct = (import.meta as any).env[name]
270
+ if (direct !== undefined && direct !== "") {
271
+ return direct
272
+ }
280
273
  }
281
- if ((import.meta as any).env[`VITE_${name}`]) {
282
- return (import.meta as any).env[`VITE_${name}`]
274
+
275
+ // Fall back to process.env for Node.js environments
276
+ if (typeof process !== "undefined" && process?.env) {
277
+ const value = process.env[name]
278
+ if (value !== undefined && value !== "") {
279
+ return value
280
+ }
283
281
  }
282
+
284
283
  return undefined
285
284
  }
package/src/constants.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AddressOverrides } from "@0xsequence/trails-api"
1
+ import type { TrailsAddressOverrides } from "@0xsequence/trails-api"
2
2
  import type { Context as ContextLike } from "@0xsequence/wallet-primitives"
3
3
  import type { Address } from "ox"
4
4
 
@@ -10,12 +10,13 @@ export const SEQUENCE_V3_CONTRACT_ADDRESSES: ContextLike.Context = {
10
10
  "0x6041600e3d396021805130553df33d3d36153402601f57363d3d373d363d30545af43d82803e903d91601f57fd5bf3" as Address.Address,
11
11
  }
12
12
 
13
- export const SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES: AddressOverrides = {
14
- sequenceWalletFactoryAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.factory,
15
- sequenceWalletMainModuleAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.stage1,
16
- sequenceWalletMainModuleUpgradableAddress:
17
- SEQUENCE_V3_CONTRACT_ADDRESSES.stage2,
18
- } as AddressOverrides
13
+ export const SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES: TrailsAddressOverrides =
14
+ {
15
+ sequenceWalletFactoryAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.factory,
16
+ sequenceWalletMainModuleAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.stage1,
17
+ sequenceWalletMainModuleUpgradableAddress:
18
+ SEQUENCE_V3_CONTRACT_ADDRESSES.stage2,
19
+ } as TrailsAddressOverrides
19
20
 
20
21
  export const TRAILS_ROUTER_ADDRESS: Address.Address =
21
22
  "0xc4415c5CabD726bA06042af752a528B3dbc263F7"
@@ -30,11 +31,9 @@ export const DEFAULT_SEQUENCE_ENV = "prod"
30
31
 
31
32
  export const PROD_SEQUENCE_NODE_GATEWAY_URL = "https://nodes.sequence.app"
32
33
  export const PROD_SEQUENCE_INDEXER_URL = "https://indexer.sequence.app"
33
- export const PROD_SEQUENCE_API_URL = "https://api.sequence.app"
34
34
  export const PROD_TRAILS_API_URL = "https://trails-api.sequence.app"
35
35
  export const DEV_SEQUENCE_NODE_GATEWAY_URL = "https://dev-nodes.sequence.app"
36
36
  export const DEV_SEQUENCE_INDEXER_URL = "https://dev-indexer.sequence.app"
37
- export const DEV_SEQUENCE_API_URL = "https://dev-api.sequence.app"
38
37
  export const DEV_TRAILS_API_URL = "https://dev-trails-api.sequence-dev.app"
39
38
 
40
39
  export const LOCAL_TRAILS_API_URL = "http://localhost:4422"
@@ -55,3 +54,6 @@ export const DEFAULT_WALLETCONNECT_PROJECT_ID =
55
54
  export const SITE_URL = "https://trails.build/"
56
55
 
57
56
  export const DEFAULT_SLIPPAGE_TOLERANCE = "0.05" // 0.001 = 0.1%, 0.005 = 0.5%, 0.03 = 3%, 0.05 = 5%
57
+
58
+ export const DEFAULT_MODE = "pay"
59
+ export const DEFAULT_THEME = "light"
package/src/error.ts CHANGED
@@ -21,7 +21,18 @@ export function getErrorString(err: unknown): string {
21
21
  return err instanceof Error ? err.message : (err?.toString() ?? "")
22
22
  }
23
23
 
24
- export function getIsWalletRejectedError(err: unknown) {
24
+ export function getIsUserRejectionError(
25
+ err: unknown,
26
+ ): err is UserRejectionError {
27
+ // Check if it's an instance of UserRejectionError (or has the name property)
28
+ if (
29
+ err instanceof UserRejectionError ||
30
+ (err instanceof Error && err.name === "UserRejectionError")
31
+ ) {
32
+ return true
33
+ }
34
+
35
+ // Check if the error message indicates a user rejection
25
36
  const isRejected = /rejected|denied|user rejected the request/gi.test(
26
37
  getErrorString(err).toLowerCase(),
27
38
  )
@@ -43,6 +54,13 @@ export class InsufficientBalanceError extends Error {
43
54
  }
44
55
  }
45
56
 
57
+ export class UserRejectionError extends Error {
58
+ constructor(message: string) {
59
+ super(message)
60
+ this.name = "UserRejectionError"
61
+ }
62
+ }
63
+
46
64
  export function getIsApiError(err: unknown) {
47
65
  const isApiError = /request aborted|not deployed/gi.test(
48
66
  getErrorString(err).toLowerCase(),
@@ -144,8 +162,8 @@ export function getPrettifiedErrorMessage(
144
162
  if (isApiError) {
145
163
  return "An API error occurred. Please try again later."
146
164
  }
147
- const isWalletRejectedError = getIsWalletRejectedError(err)
148
- if (isWalletRejectedError) {
165
+ const isUserRejectionError = getIsUserRejectionError(err)
166
+ if (isUserRejectionError) {
149
167
  return "The wallet rejected the request. Please try again."
150
168
  }
151
169
  const isWalletAlreadyConnected = getIsWalletAlreadyConnectedError(err)
package/src/fees.ts ADDED
@@ -0,0 +1,210 @@
1
+ import type { Intent } from "@0xsequence/trails-api"
2
+ import { getTokenInfo } from "./tokens.js"
3
+ import { formatRawAmount, formatUsdAmountDisplay } from "./tokenBalances.js"
4
+ import { zeroAddress } from "viem"
5
+
6
+ export interface FeeItem {
7
+ amount: string
8
+ tokenSymbol: string
9
+ tokenAddress: string
10
+ chainId: number
11
+ usdValue: string
12
+ }
13
+
14
+ export interface TrailsFeeBreakdown {
15
+ originRelayFee?: FeeItem
16
+ destinationRelayFee?: FeeItem
17
+ providerFee?: FeeItem
18
+ trailsFee?: FeeItem
19
+ totalUsdValue?: string
20
+ originChainId?: number
21
+ destinationChainId?: number
22
+ }
23
+
24
+ // Helper function to format token amounts with proper decimal conversion
25
+ async function formatTokenAmount(
26
+ amount: string | number | undefined,
27
+ tokenAddress: string,
28
+ chainId: number,
29
+ ): Promise<string> {
30
+ if (!amount) return "0"
31
+ const num = typeof amount === "string" ? parseFloat(amount) : amount
32
+ if (num === 0) return "0"
33
+
34
+ // Get token info to determine decimals
35
+ const tokenInfo = await getTokenInfo(chainId, tokenAddress)
36
+ if (!tokenInfo?.decimals) {
37
+ throw new Error(
38
+ `Token decimals not found for token ${tokenAddress} on chain ${chainId}`,
39
+ )
40
+ }
41
+
42
+ // Use existing formatRawAmount utility
43
+ const formatted = formatRawAmount(BigInt(Math.floor(num)), tokenInfo.decimals)
44
+
45
+ // Handle very small amounts
46
+ const numFormatted = parseFloat(formatted)
47
+ if (numFormatted < 0.000001 && numFormatted > 0) return "<0.000001"
48
+
49
+ return formatted
50
+ }
51
+
52
+ // Extract fee breakdown from intent data
53
+ export async function extractTrailsFeeBreakdown(
54
+ intent: Intent,
55
+ ): Promise<TrailsFeeBreakdown | null> {
56
+ const fees = intent?.fees
57
+ if (!fees) {
58
+ return null
59
+ }
60
+
61
+ // Get chain IDs from the calls array to determine origin and destination chains
62
+ const calls = intent?.calls || []
63
+ const originChainId: number | undefined = calls[0]?.chainId // First call is origin chain
64
+ const destinationChainId: number | undefined = calls[1]?.chainId // Second call is destination chain
65
+
66
+ // Use the origin and destination gas fees
67
+ const originChainQuote = fees.originGas
68
+ const destinationChainQuote = fees.destinationGas
69
+
70
+ // If we can't find any chain quotes, return null
71
+ if (!originChainQuote && !destinationChainQuote) {
72
+ console.warn(
73
+ "[trails-sdk] Could not find any chain quotes for fee breakdown",
74
+ {
75
+ originChainId,
76
+ destinationChainId,
77
+ },
78
+ )
79
+ return null
80
+ }
81
+
82
+ const breakdown: TrailsFeeBreakdown = {}
83
+
84
+ // Extract origin relay fee if available
85
+ if (originChainQuote && originChainId !== undefined) {
86
+ const originTokenSymbol = originChainQuote.nativeTokenSymbol || "ETH"
87
+ const originChainIdNum =
88
+ typeof originChainId === "bigint" ? Number(originChainId) : originChainId
89
+ const nativeTokenAddress = zeroAddress
90
+
91
+ breakdown.originRelayFee = {
92
+ amount: await formatTokenAmount(
93
+ originChainQuote.totalFeeAmount.toString(),
94
+ nativeTokenAddress,
95
+ originChainIdNum,
96
+ ),
97
+ tokenSymbol: originTokenSymbol,
98
+ tokenAddress: nativeTokenAddress,
99
+ chainId: originChainIdNum,
100
+ usdValue: formatUsdAmountDisplay(originChainQuote.totalFeeUsd),
101
+ }
102
+ breakdown.originChainId = originChainIdNum
103
+ }
104
+
105
+ // Extract destination relay fee if available
106
+ if (destinationChainQuote && destinationChainId !== undefined) {
107
+ const destinationTokenSymbol =
108
+ destinationChainQuote.nativeTokenSymbol || "ETH"
109
+ const destinationChainIdNum =
110
+ typeof destinationChainId === "bigint"
111
+ ? Number(destinationChainId)
112
+ : destinationChainId
113
+ const nativeTokenAddress = zeroAddress
114
+
115
+ breakdown.destinationRelayFee = {
116
+ amount: await formatTokenAmount(
117
+ destinationChainQuote.totalFeeAmount.toString(),
118
+ nativeTokenAddress,
119
+ destinationChainIdNum,
120
+ ),
121
+ tokenSymbol: destinationTokenSymbol,
122
+ tokenAddress: nativeTokenAddress,
123
+ chainId: destinationChainIdNum,
124
+ usdValue: formatUsdAmountDisplay(destinationChainQuote.totalFeeUsd),
125
+ }
126
+ breakdown.destinationChainId = destinationChainIdNum
127
+ }
128
+
129
+ // Extract provider fee from provider fees if available
130
+ const providerFeeAmount = fees.provider?.quoteProviderFeeUsd
131
+ const providerFeeRawAmount = fees.provider?.quoteProviderFee
132
+ if (
133
+ (providerFeeAmount !== undefined || providerFeeRawAmount !== undefined) &&
134
+ originChainId !== undefined
135
+ ) {
136
+ const feeTokenAddress = fees.feeTokenAddress || zeroAddress
137
+ const originChainIdNum =
138
+ typeof originChainId === "bigint" ? Number(originChainId) : originChainId
139
+
140
+ // Get token info to determine the actual token symbol
141
+ const feeTokenInfo = await getTokenInfo(originChainIdNum, feeTokenAddress)
142
+ if (!feeTokenInfo?.symbol) {
143
+ throw new Error(
144
+ `Token symbol not found for provider fee token ${feeTokenAddress} on chain ${originChainIdNum}`,
145
+ )
146
+ }
147
+
148
+ breakdown.providerFee = {
149
+ amount: await formatTokenAmount(
150
+ providerFeeRawAmount?.toString(),
151
+ feeTokenAddress,
152
+ originChainIdNum,
153
+ ),
154
+ tokenSymbol: feeTokenInfo.symbol,
155
+ tokenAddress: feeTokenAddress,
156
+ chainId: originChainIdNum,
157
+ usdValue: formatUsdAmountDisplay(providerFeeAmount),
158
+ }
159
+ }
160
+
161
+ // Extract Trails platform fee from provider fees if available
162
+ const trailsFeeAmount = fees.provider?.trailsFeeUsd
163
+ const trailsFeeRawAmount = fees.provider?.trailsFee
164
+ if (
165
+ (trailsFeeAmount !== undefined || trailsFeeRawAmount !== undefined) &&
166
+ originChainId !== undefined
167
+ ) {
168
+ const feeTokenAddress = fees.feeTokenAddress || zeroAddress
169
+ const originChainIdNum =
170
+ typeof originChainId === "bigint" ? Number(originChainId) : originChainId
171
+
172
+ // Get token info to determine the actual token symbol
173
+ const feeTokenInfo = await getTokenInfo(originChainIdNum, feeTokenAddress)
174
+ if (!feeTokenInfo?.symbol) {
175
+ throw new Error(
176
+ `Token symbol not found for trails fee token ${feeTokenAddress} on chain ${originChainIdNum}`,
177
+ )
178
+ }
179
+
180
+ breakdown.trailsFee = {
181
+ amount: await formatTokenAmount(
182
+ trailsFeeRawAmount?.toString(),
183
+ feeTokenAddress,
184
+ originChainIdNum,
185
+ ),
186
+ tokenSymbol: feeTokenInfo.symbol,
187
+ tokenAddress: feeTokenAddress,
188
+ chainId: originChainIdNum,
189
+ usdValue: formatUsdAmountDisplay(trailsFeeAmount),
190
+ }
191
+ }
192
+
193
+ // Calculate total USD value from the actual data
194
+ const originUsd =
195
+ typeof originChainQuote?.totalFeeUsd === "string"
196
+ ? parseFloat(originChainQuote.totalFeeUsd)
197
+ : originChainQuote?.totalFeeUsd || 0
198
+ const destinationUsd =
199
+ typeof destinationChainQuote?.totalFeeUsd === "string"
200
+ ? parseFloat(destinationChainQuote.totalFeeUsd)
201
+ : destinationChainQuote?.totalFeeUsd || 0
202
+ const providerUsd =
203
+ typeof providerFeeAmount === "number" ? providerFeeAmount : 0
204
+ const trailsUsd = typeof trailsFeeAmount === "number" ? trailsFeeAmount : 0
205
+ const totalUsd = originUsd + destinationUsd + providerUsd + trailsUsd
206
+
207
+ breakdown.totalUsdValue = formatUsdAmountDisplay(totalUsd)
208
+
209
+ return breakdown
210
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  // Be explicit about what we export
2
2
 
3
- export { getAPIClient, useAPIClient } from "./apiClient.js"
3
+ export {
4
+ InsufficientBalanceError,
5
+ UserRejectionError,
6
+ getIsUserRejectionError,
7
+ } from "./error.js"
4
8
  export {
5
9
  getSupportedChains,
6
10
  useSupportedChains,
@@ -13,7 +17,6 @@ export {
13
17
  useIndexerGatewayClient,
14
18
  } from "./indexerClient.js"
15
19
  export type {
16
- GetIntentCallsPayloadsReturn,
17
20
  OriginCallParams,
18
21
  QuoteProvider,
19
22
  TrailsFee,
@@ -21,15 +24,20 @@ export type {
21
24
  export {
22
25
  calculateIntentAddress,
23
26
  calculateOriginAndDestinationIntentAddresses,
24
- commitIntentConfig,
25
- getIntentCallsPayloads,
27
+ commitIntent,
28
+ getIntent,
26
29
  sendOriginTransaction,
27
30
  } from "./intents.js"
28
- export type {
29
- MetaTxn,
30
- MetaTxnStatus,
31
- } from "./metaTxnMonitor.js"
32
- export { useMetaTxnsMonitor } from "./metaTxnMonitor.js"
31
+ export type { IntentReceiptStatus } from "./intentReceiptMonitor.js"
32
+ export { useIntentReceiptMonitor } from "./intentReceiptMonitor.js"
33
+ export {
34
+ pollIntentReceipt,
35
+ type IntentReceiptPollerOptions,
36
+ type IntentReceiptPollerCallbacks,
37
+ type OnOriginTransactionFound,
38
+ type OnDestinationTransactionFound,
39
+ type OnReceiptUpdate,
40
+ } from "./intentReceiptPoller.js"
33
41
  export {
34
42
  prepareSend,
35
43
  useQuote,
@@ -82,20 +90,20 @@ export type { SupportedToken } from "./tokens.js"
82
90
  export { getTxTimeDiff } from "./transactions.js"
83
91
  export { useTrails } from "./trails.js"
84
92
  export type { WagmiAccount } from "./trails.js"
93
+ export {
94
+ useCommitIntent,
95
+ useExecuteIntent,
96
+ } from "./mutations.js"
85
97
  export type { Mode } from "./mode.js"
86
98
  export { TRAILS_ROUTER_PLACEHOLDER_AMOUNT } from "./trailsRouter.js"
87
99
  export { getERC20TransferData } from "./encoders.js"
88
- export { getRelayer, useRelayers } from "./relayer.js"
89
- export { relayerSendMetaTx, getMetaTxnReceipt } from "./metaTxns.js"
90
100
  export {
91
101
  declareSequenceEnv,
92
102
  getSequenceProjectAccessKey,
93
- getSequenceApiUrl,
94
103
  getTrailsApiUrl,
95
104
  getSequenceIndexerUrl,
96
105
  getSequenceEnv,
97
106
  setSequenceProjectAccessKey,
98
- setSequenceApiUrl,
99
107
  setTrailsApiUrl,
100
108
  setSequenceIndexerUrl,
101
109
  setSequenceNodeGatewayUrl,
@@ -115,3 +123,17 @@ export {
115
123
  useTrailsClient,
116
124
  TrailsClient,
117
125
  } from "./trailsClient.js"
126
+ export type {
127
+ IntentReceipt,
128
+ IntentTransaction as IntentTransactionReceipt,
129
+ IntentStatus,
130
+ TransactionStatus,
131
+ WaitIntentReceiptRequest,
132
+ WaitIntentReceiptResponse,
133
+ GetIntentReceiptRequest,
134
+ GetIntentReceiptResponse,
135
+ QuoteIntentRequest,
136
+ Intent,
137
+ ExecuteIntentRequest,
138
+ ExecuteIntentResponse,
139
+ } from "@0xsequence/trails-api"
@@ -0,0 +1,102 @@
1
+ import type { TrailsClient } from "./trailsClient.js"
2
+ import type {
3
+ IntentReceipt,
4
+ WaitIntentReceiptResponse,
5
+ } from "@0xsequence/trails-api"
6
+ import { type Query, useQuery } from "@tanstack/react-query"
7
+ import { logger } from "./logger.js"
8
+
9
+ const POLL_INTERVAL = 150 // 150 ms
10
+
11
+ export type IntentReceiptStatus = {
12
+ intentReceipt: IntentReceipt | null
13
+ done: boolean
14
+ isLoading: boolean
15
+ isError: boolean
16
+ error: Error | null
17
+ }
18
+
19
+ /**
20
+ * Hook to monitor intent execution status using the WaitIntentReceipt API.
21
+ * This replaces the old useMetaTxnsMonitor approach which polled individual meta-transactions.
22
+ *
23
+ * The WaitIntentReceipt API is a long-polling endpoint that:
24
+ * - Blocks up to 28 seconds waiting for status changes
25
+ * - Returns unified status for both origin and destination transactions
26
+ * - Sets done=true when intent reaches terminal status (SUCCEEDED or FAILED)
27
+ *
28
+ * @param intentId - The intent ID to monitor (usually committedOriginIntentAddress)
29
+ * @param trailsClient - TrailsClient instance for API calls
30
+ * @returns IntentReceiptStatus with current receipt, done flag, and loading states
31
+ */
32
+ export const useIntentReceiptMonitor = (
33
+ intentId: string | undefined,
34
+ trailsClient: TrailsClient,
35
+ ): IntentReceiptStatus => {
36
+ const queryResult = useQuery({
37
+ queryKey: ["waitIntentReceipt", intentId],
38
+ queryFn: async (): Promise<WaitIntentReceiptResponse> => {
39
+ if (!intentId) {
40
+ throw new Error("Intent ID is required for monitoring")
41
+ }
42
+
43
+ logger.console.log(
44
+ `[trails-sdk] 🔍 Monitoring intent receipt for ${intentId}`,
45
+ )
46
+
47
+ const response = await trailsClient.waitIntentReceipt({
48
+ intentId,
49
+ })
50
+
51
+ logger.console.log(
52
+ `[trails-sdk] 📊 Intent ${intentId} status: ${response.intentReceipt.status}, done: ${response.done}`,
53
+ )
54
+
55
+ return response
56
+ },
57
+ enabled: !!intentId,
58
+ refetchIntervalInBackground: true,
59
+ refetchInterval: (
60
+ query: Query<
61
+ WaitIntentReceiptResponse,
62
+ Error,
63
+ WaitIntentReceiptResponse,
64
+ ReadonlyArray<unknown>
65
+ >,
66
+ ) => {
67
+ const data = query.state.data
68
+
69
+ // If no data yet, continue polling
70
+ if (!data) return POLL_INTERVAL
71
+
72
+ // If done flag is true, stop polling
73
+ if (data.done) {
74
+ logger.console.log(
75
+ `[trails-sdk] ✅ Intent monitoring complete for ${intentId}`,
76
+ )
77
+ return false
78
+ }
79
+
80
+ // Otherwise continue polling
81
+ return POLL_INTERVAL
82
+ },
83
+ retry: (failureCount: number, error: Error) => {
84
+ if (failureCount >= 30) {
85
+ logger.console.error(
86
+ `[trails-sdk] ❌ Giving up on intent ${intentId} after 30 failed API attempts:`,
87
+ error,
88
+ )
89
+ return false
90
+ }
91
+ return true
92
+ },
93
+ })
94
+
95
+ return {
96
+ intentReceipt: queryResult.data?.intentReceipt ?? null,
97
+ done: queryResult.data?.done ?? false,
98
+ isLoading: queryResult.isLoading,
99
+ isError: queryResult.isError,
100
+ error: queryResult.error,
101
+ }
102
+ }