0xtrails 0.8.2 → 0.8.3

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 (68) hide show
  1. package/dist/aave.d.ts.map +1 -1
  2. package/dist/{ccip-ru_Yzdas.js → ccip-Bs-QcZXm.js} +13 -13
  3. package/dist/constants.d.ts +2 -0
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/fees.d.ts +11 -17
  6. package/dist/fees.d.ts.map +1 -1
  7. package/dist/{index-Si7cO9V7.js → index-C_EsqqSn.js} +20320 -20063
  8. package/dist/index.js +425 -847
  9. package/dist/intents.d.ts +1 -2
  10. package/dist/intents.d.ts.map +1 -1
  11. package/dist/prepareSend.d.ts.map +1 -1
  12. package/dist/recover.d.ts +8 -9
  13. package/dist/recover.d.ts.map +1 -1
  14. package/dist/tokenBalances.d.ts +51 -0
  15. package/dist/tokenBalances.d.ts.map +1 -1
  16. package/dist/trailsRouter.d.ts +15 -0
  17. package/dist/trailsRouter.d.ts.map +1 -1
  18. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +1 -3
  19. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
  20. package/dist/transactionIntent/deposits/standardDeposit.d.ts +1 -3
  21. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
  22. package/dist/transactionIntent/handlers/crossChain.d.ts +2 -4
  23. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
  24. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +5 -4
  25. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
  26. package/dist/transactionIntent/quote/normalizeQuote.d.ts +1 -1
  27. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
  28. package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
  29. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
  30. package/dist/transactionIntent/types.d.ts +11 -18
  31. package/dist/transactionIntent/types.d.ts.map +1 -1
  32. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  33. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  34. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  35. package/dist/widget/components/SlippageToleranceSettings.d.ts +2 -1
  36. package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
  37. package/dist/widget/css/compiled.css +1 -1
  38. package/dist/widget/hooks/useQuote.d.ts +94 -35
  39. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  40. package/dist/widget/hooks/useSendForm.d.ts +2 -2
  41. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  42. package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -1
  43. package/dist/widget/index.js +1 -1
  44. package/package.json +2 -2
  45. package/src/aave.ts +4 -0
  46. package/src/constants.ts +4 -0
  47. package/src/fees.ts +47 -72
  48. package/src/intents.ts +1 -3
  49. package/src/morpho.ts +1 -1
  50. package/src/prepareSend.ts +42 -6
  51. package/src/recover.ts +116 -172
  52. package/src/tokenBalances.ts +301 -1
  53. package/src/trailsRouter.ts +77 -0
  54. package/src/transactionIntent/deposits/depositOrchestrator.ts +0 -6
  55. package/src/transactionIntent/deposits/standardDeposit.ts +167 -184
  56. package/src/transactionIntent/handlers/crossChain.ts +8 -11
  57. package/src/transactionIntent/handlers/sameChainSameToken.ts +619 -608
  58. package/src/transactionIntent/quote/normalizeQuote.ts +32 -46
  59. package/src/transactionIntent/quote/quoteHelpers.ts +4 -2
  60. package/src/transactionIntent/types.ts +11 -18
  61. package/src/widget/compiled.css +1 -1
  62. package/src/widget/components/AccountIntentTransactionHistory.tsx +50 -18
  63. package/src/widget/components/ClassicSwap.tsx +25 -30
  64. package/src/widget/components/QuoteDetails.tsx +18 -27
  65. package/src/widget/components/SlippageToleranceSettings.tsx +55 -25
  66. package/src/widget/hooks/useQuote.ts +317 -79
  67. package/src/widget/hooks/useSendForm.ts +123 -764
  68. package/src/widget/hooks/useTrailsSendTransaction.ts +0 -2
package/dist/index.js CHANGED
@@ -1,993 +1,571 @@
1
- import { l as o, u as gt, t as Ht, a as Ot, b as Lt, g as M, I as bt, c as pt, d as Ct, e as yt, f as It, h as ut, i as St, T as K, p as wt, j as J, k as qt, m as ft, n as Nt, o as Tt, q as At } from "./index-Si7cO9V7.js";
2
- import { r as te, al as ee, aq as ne, aA as oe, az as se, an as re, ay as ae, U as ie, K as ce, as as le, at as de, af as ue, L as ge, M as me, N as fe, a6 as Te, ax as ke, av as he, a7 as Ce, a9 as Ae, ah as Ee, aa as pe, a8 as ye, X as Ie, R as Se, G as we, J as Ue, am as Pe, Y as De, ar as xe, v as Re, s as ve, C as He, y as Oe, z as Le, B as be, A as qe, w as Ne, x as Be, D as Fe, ao as Me, H as Qe, E as We, a1 as $e, ab as _e, ap as Ge, ak as je, ae as Ke, aj as Je, ai as Xe, ag as ze, Q as Ve, O as Ze, P as Ye, au as tn, Z as en, S as nn, W as on, a3 as sn, _ as rn, $ as an, aw as cn, V as ln, F as dn, a4 as un, a0 as gn, a5 as mn, a2 as fn, ac as Tn, ad as kn } from "./index-Si7cO9V7.js";
3
- import { useQuery as Ut, useMutation as kt } from "@tanstack/react-query";
4
- import { useRef as Pt, useCallback as dt } from "react";
5
- import { useWalletClient as Bt, useAccount as Ft, useChainId as Mt } from "wagmi";
6
- import { zeroAddress as x, erc20Abi as Dt } from "viem";
7
- import { useIndexerGatewayClient as xt } from "@0xsequence/hooks";
8
- import { useIndexerGatewayClient as Cn } from "@0xsequence/hooks";
9
- const Et = 150, Xt = (d, n) => {
10
- const s = Ut({
11
- queryKey: ["waitIntentReceipt", d],
1
+ import { l as d, u as he, a as Ae, b as Ie, c as Ce, d as we, e as Ee, g as O, f as _, h as ee, T as H, i as Se, j as te, k as ye, p as pe, m as B } from "./index-C_EsqqSn.js";
2
+ import { I as Ve, aj as ze, ao as Ke, ay as ve, ax as Je, al as Ye, aw as Ze, U as be, G as et, aq as tt, ar as nt, ad as ot, H as st, J as rt, K as at, a4 as it, av as ct, at as dt, a5 as lt, a7 as ut, af as ft, a8 as Tt, a6 as mt, V as gt, P as kt, C as ht, E as At, ak as It, W as Ct, ap as wt, o as Et, n as St, x as yt, s as pt, t as Pt, w as Rt, v as Ut, q as Ht, r as xt, y as Lt, am as Ot, z as Bt, D as Dt, A as Mt, $ as Wt, a9 as qt, an as Ft, ai as Nt, ac as jt, ah as _t, ag as $t, ae as Qt, N as Gt, L as Xt, M as Vt, as as zt, X as Kt, Q as vt, F as Jt, S as Yt, a1 as Zt, Y as bt, Z as en, au as tn, R as nn, O as on, B as sn, a2 as rn, _ as an, a3 as cn, a0 as dn, aa as ln, ab as un } from "./index-C_EsqqSn.js";
3
+ import { useQuery as Pe, useMutation as Re } from "@tanstack/react-query";
4
+ import { useRef as Ue, useCallback as D } from "react";
5
+ import { useWalletClient as He, useAccount as xe, useChainId as Le } from "wagmi";
6
+ import { zeroAddress as p, erc20Abi as Oe } from "viem";
7
+ import { useIndexerGatewayClient as Be } from "@0xsequence/hooks";
8
+ import { useIndexerGatewayClient as Tn } from "@0xsequence/hooks";
9
+ const ne = 150, $e = (s, h) => {
10
+ const A = Pe({
11
+ queryKey: ["waitIntentReceipt", s],
12
12
  queryFn: async () => {
13
- if (!d)
13
+ if (!s)
14
14
  throw new Error("Intent ID is required for monitoring");
15
- o.console.log(
16
- `[trails-sdk] 🔍 Monitoring intent receipt for ${d}`
15
+ d.console.log(
16
+ `[trails-sdk] 🔍 Monitoring intent receipt for ${s}`
17
17
  );
18
- const a = await n.waitIntentReceipt({
19
- intentId: d
18
+ const T = await h.waitIntentReceipt({
19
+ intentId: s
20
20
  });
21
- return o.console.log(
22
- `[trails-sdk] 📊 Intent ${d} status: ${a.intentReceipt.status}, done: ${a.done}`
23
- ), a;
21
+ return d.console.log(
22
+ `[trails-sdk] 📊 Intent ${s} status: ${T.intentReceipt.status}, done: ${T.done}`
23
+ ), T;
24
24
  },
25
- enabled: !!d,
25
+ enabled: !!s,
26
26
  refetchIntervalInBackground: !0,
27
- refetchInterval: (a) => {
28
- const i = a.state.data;
29
- return i && i.done ? (o.console.log(
30
- `[trails-sdk] ✅ Intent monitoring complete for ${d}`
31
- ), !1) : Et;
27
+ refetchInterval: (T) => {
28
+ const I = T.state.data;
29
+ return I && I.done ? (d.console.log(
30
+ `[trails-sdk] ✅ Intent monitoring complete for ${s}`
31
+ ), !1) : ne;
32
32
  },
33
- retry: (a, i) => a >= 30 ? (o.console.error(
34
- `[trails-sdk] ❌ Giving up on intent ${d} after 30 failed API attempts:`,
35
- i
33
+ retry: (T, I) => T >= 30 ? (d.console.error(
34
+ `[trails-sdk] ❌ Giving up on intent ${s} after 30 failed API attempts:`,
35
+ I
36
36
  ), !1) : !0
37
37
  });
38
38
  return {
39
- intentReceipt: s.data?.intentReceipt ?? null,
40
- done: s.data?.done ?? !1,
41
- isLoading: s.isLoading,
42
- isError: s.isError,
43
- error: s.error
39
+ intentReceipt: A.data?.intentReceipt ?? null,
40
+ done: A.data?.done ?? !1,
41
+ isLoading: A.isLoading,
42
+ isError: A.isError,
43
+ error: A.error
44
44
  };
45
45
  };
46
- function Rt() {
47
- const d = gt();
48
- return kt({
49
- mutationFn: async (n) => {
50
- o.console.log("[trails-sdk] useCommitIntent: Starting commit", {
51
- intentId: n.intentId,
52
- originIntentAddress: n.originIntentAddress
53
- });
54
- const s = n.quoteRequest.originChainId.toString(), a = n.quoteRequest.destinationChainId.toString();
55
- try {
56
- Ht({
57
- intentAddress: n.originIntentAddress,
58
- userAddress: n.ownerAddress,
59
- originChainId: s ? Number(s) : void 0,
60
- destinationChainId: a ? Number(a) : void 0
61
- });
62
- const i = await d.commitIntent({
63
- intent: n
64
- });
65
- return o.console.log("[trails-sdk] useCommitIntent: Commit successful", {
66
- intentId: n.intentId,
67
- response: i
68
- }), Ot({
69
- intentAddress: n.originIntentAddress,
70
- userAddress: n.ownerAddress,
71
- originChainId: s ? Number(s) : void 0,
72
- destinationChainId: a ? Number(a) : void 0
73
- }), i;
74
- } catch (i) {
75
- throw Lt({
76
- error: M(i),
77
- userAddress: n.ownerAddress,
78
- intentAddress: n.originIntentAddress,
79
- originChainId: s ? Number(s) : void 0,
80
- destinationChainId: a ? Number(a) : void 0
81
- }), i;
82
- }
83
- }
84
- });
85
- }
86
- function vt() {
87
- const d = gt();
88
- return kt({
89
- mutationFn: async ({
90
- intentId: n,
91
- depositTransactionHash: s,
92
- depositSignature: a
93
- }) => {
94
- if (o.console.log("[trails-sdk] useExecuteIntent: Starting execution", {
95
- intentId: n,
96
- depositTransactionHash: s,
97
- hasDepositSignature: !!a
98
- }), !s && !a)
99
- throw new Error(
100
- "[trails-sdk] Either depositTransactionHash or depositSignature must be provided"
101
- );
102
- let i;
103
- try {
104
- i = await d.executeIntent({
105
- intentId: n,
106
- depositTransactionHash: s,
107
- depositSignature: a
108
- });
109
- } catch (T) {
110
- if (o.console.error(
111
- "[trails-sdk] useExecuteIntent: Error executing intent",
112
- {
113
- intentId: n,
114
- error: T,
115
- errorJSON: JSON.stringify(T, null, 2)
116
- }
117
- ), T instanceof Error && T?.message?.includes("status=SUCCEEDED") || T instanceof Error && T?.cause?.message?.includes("status=SUCCEEDED") || T instanceof Error && JSON.stringify(T).includes("status=SUCCEEDED") || T instanceof bt && T?.cause?.toString().includes("status=SUCCEEDED") || JSON.stringify(T).includes("status=SUCCEEDED"))
118
- return o.console.error(
119
- "[trails-sdk] useExecuteIntent: Intent already succeeded, treating as success",
120
- { intentId: n }
121
- ), {
122
- intentId: n,
123
- intentStatus: "SUCCEEDED"
124
- };
125
- throw o.console.error(
126
- "[trails-sdk] useExecuteIntent did not throw IntentStatusError and is not a SUCCEEDED intent",
127
- {
128
- intentId: n,
129
- error: T,
130
- errorJSON: JSON.stringify(T, null, 2)
131
- }
132
- ), T;
133
- }
134
- return o.console.log(
135
- "[trails-sdk] useExecuteIntent: Execution successful",
136
- {
137
- intentId: n,
138
- response: i
139
- }
140
- ), i;
141
- }
142
- });
143
- }
144
- function zt({
145
- walletClient: d,
146
- fromTokenAddress: n,
147
- fromChainId: s,
148
- toTokenAddress: a,
149
- toChainId: i,
150
- swapAmount: T,
151
- tradeType: nt,
152
- toRecipient: H,
153
- toCalldata: ot,
154
- slippageTolerance: X,
155
- onStatusUpdate: z,
156
- checkoutOnHandlers: V,
157
- swapProvider: Q,
158
- bridgeProvider: O,
159
- paymasterUrl: mt,
160
- selectedFeeOption: st,
161
- nodeGatewayEnv: rt,
162
- abortSignal: W,
163
- apiKey: L,
164
- isSmartWallet: at
165
- } = {}) {
166
- rt && (globalThis.__testNodeGatewayEnv = rt);
167
- const R = Pt(new AbortController()), it = W ? (() => {
168
- const g = new AbortController();
169
- return W.addEventListener("abort", () => {
170
- g.abort(), R.current?.abort();
171
- }), R.current?.signal.addEventListener("abort", () => {
172
- g.abort();
173
- }), g.signal;
174
- })() : R.current.signal, { trailsApiKey: C, trailsApiUrl: Z, sequenceIndexerUrl: A } = pt(), Y = C, b = gt({
175
- apiKey: C,
176
- hostname: Z
177
- }), $ = xt(), t = Ct(s ?? void 0), r = Ct(i ?? void 0), { supportedTokens: u } = yt(), k = Rt(), m = vt(), { data: E, isLoading: P, error: w, refetch: I } = Ut({
178
- queryKey: [
179
- "prepareSend",
180
- n,
181
- s,
182
- a,
183
- i,
184
- T?.toString(),
185
- H,
186
- ot,
187
- nt,
188
- X,
189
- Q,
190
- O,
191
- L,
192
- at
193
- ],
194
- queryFn: async () => {
195
- try {
196
- if (R.current.signal.aborted && (o.console.log(
197
- "[trails-sdk] Resetting aborted controller for new query"
198
- ), R.current = new AbortController()), !d || !b || !n || !a || !T || !H || !s || !i || !$)
199
- return null;
200
- let g = [];
201
- try {
202
- g = (await It({
203
- account: d.account.address,
204
- indexerGatewayClient: $,
205
- trailsClient: b
206
- })).balances;
207
- } catch (l) {
208
- const f = M(l), D = f.includes("Cross-Origin") || f.includes("CORS") || f.includes("Same Origin Policy"), j = f.includes("fetch failed") || f.includes("network");
209
- if (D || j)
210
- o.console.warn(
211
- "[trails-sdk] [useQuote] Network or CORS error fetching balances, proceeding with quote using zero balance:",
212
- {
213
- error: f,
214
- account: d.account.address
215
- }
216
- ), g = [];
217
- else
218
- throw l;
219
- }
220
- const y = g.find(
221
- (l) => l.chainId === s && (l.contractAddress?.toLowerCase() === n.toLowerCase() || !l.contractAddress && n === x)
222
- )?.balance ?? "0";
223
- let v = 0;
224
- try {
225
- const f = ut(s)?.nativeCurrency?.symbol ?? "";
226
- f && (v = (await St(b, {
227
- tokenSymbol: f,
228
- tokenAddress: x,
229
- chainId: s
230
- }))?.priceUsd ?? 0, o.console.log(
231
- "[trails-sdk] [useQuote] Origin native token price:",
232
- {
233
- chainId: s,
234
- symbol: f,
235
- priceUsd: v
236
- }
237
- ));
238
- } catch (l) {
239
- o.console.error(
240
- "[trails-sdk] [useQuote] Error getting origin native token price:",
241
- l
242
- );
243
- }
244
- const U = async (l, f) => {
245
- try {
246
- const D = f === s ? t : f === i ? r : null;
247
- if (!D)
248
- return o.console.warn(
249
- `[trails-sdk] No RPC client available for chain ${f}`
250
- ), null;
251
- if (l.toLowerCase() === x.toLowerCase())
252
- return ut(f)?.nativeCurrency.decimals ?? 18;
253
- const j = await D.readContract({
254
- address: l,
255
- abi: Dt,
256
- functionName: "decimals"
257
- });
258
- return o.console.log(
259
- `[trails-sdk] Fetched decimals on-chain for token ${l} on chain ${f}: ${j}`
260
- ), j;
261
- } catch (D) {
262
- return o.console.error(
263
- `[trails-sdk] Error fetching decimals on-chain for token ${l} on chain ${f}:`,
264
- D
265
- ), null;
266
- }
267
- }, S = u?.find(
268
- (l) => l.contractAddress?.toLowerCase() === n?.toLowerCase() && l.chainId === s
269
- ), q = u?.find(
270
- (l) => l.contractAddress?.toLowerCase() === a?.toLowerCase() && l.chainId === i
271
- );
272
- let N = S?.decimals;
273
- if (!N && n && s) {
274
- o.console.warn(
275
- "[trails-sdk] [useQuote] Source token decimals not found in token list, fetching on-chain:",
276
- {
277
- originToken: S,
278
- fromTokenAddress: n,
279
- fromChainId: s
280
- }
281
- );
282
- const l = await U(
283
- n,
284
- s
285
- );
286
- l !== null && (N = l);
287
- }
288
- if (!N)
289
- throw o.console.error(
290
- "[trails-sdk] [useQuote] Source token decimals not found:",
291
- {
292
- originToken: S,
293
- fromTokenAddress: n,
294
- fromChainId: s
295
- }
296
- ), new Error("Source token decimals not found");
297
- let B = q?.decimals;
298
- if (!B && a && i) {
299
- o.console.warn(
300
- "[trails-sdk] Destination token decimals not found in token list, fetching on-chain:",
301
- {
302
- destinationToken: q,
303
- toTokenAddress: a,
304
- toChainId: i
305
- }
306
- );
307
- const l = await U(
308
- a,
309
- i
310
- );
311
- l !== null && (B = l);
312
- }
313
- if (!B)
314
- throw o.console.error(
315
- "[trails-sdk] Destination token decimals not found:",
316
- {
317
- destinationToken: q,
318
- toTokenAddress: a,
319
- toChainId: i
320
- }
321
- ), new Error("Destination token decimals not found");
322
- const ct = q?.symbol ?? "", tt = S?.symbol ?? "", et = {
323
- account: d.account,
324
- originTokenAddress: n,
325
- originChainId: s,
326
- originTokenBalance: y,
327
- destinationChainId: i,
328
- recipient: H,
329
- destinationTokenAddress: a,
330
- swapAmount: T.toString(),
331
- tradeType: nt ?? K.EXACT_OUTPUT,
332
- originTokenSymbol: tt,
333
- destinationTokenSymbol: ct,
334
- destinationCalldata: ot,
335
- client: d,
336
- trailsClient: b,
337
- sourceTokenDecimals: N,
338
- destinationTokenDecimals: B,
339
- fee: "0",
340
- dryMode: !1,
341
- onTransactionStateChange: z ?? (() => {
342
- }),
343
- slippageTolerance: X?.toString(),
344
- swapProvider: Q,
345
- bridgeProvider: O,
346
- paymasterUrl: mt,
347
- selectedFeeOption: st ?? null,
348
- abortSignal: it,
349
- originNativeTokenPriceUsd: v,
350
- commitIntentFn: k.mutateAsync,
351
- executeIntentFn: m.mutateAsync,
352
- checkoutOnHandlers: V,
353
- sequenceIndexerUrl: A,
354
- sequenceProjectAccessKey: Y,
355
- originPublicClient: t ?? void 0,
356
- destinationPublicClient: r ?? void 0,
357
- isSmartWallet: at ?? void 0,
358
- trailsApiKey: C,
359
- trailsApiUrl: Z
360
- };
361
- o.console.log("[trails-sdk] options", et);
362
- const { quote: c, send: lt } = await wt(et);
363
- return {
364
- quote: {
365
- fromAmount: c.originAmount,
366
- toAmount: c.destinationAmount,
367
- fromAmountMin: c.originAmountMin,
368
- toAmountMin: c.destinationAmountMin,
369
- originToken: c.originToken,
370
- destinationToken: c.destinationToken,
371
- originChain: c.originChain,
372
- destinationChain: c.destinationChain,
373
- fees: c.fees,
374
- priceImpact: c.priceImpact,
375
- priceImpactUsd: c.priceImpactUsd ?? void 0,
376
- priceImpactUsdDisplay: c.priceImpactUsdDisplay ?? void 0,
377
- completionEstimateSeconds: c.completionEstimateSeconds,
378
- slippageTolerance: c.slippageTolerance,
379
- transactionStates: c.transactionStates,
380
- originTokenRate: c.originTokenRate,
381
- destinationTokenRate: c.destinationTokenRate,
382
- routeProviders: c.routeProviders,
383
- fromAmountUsdDisplay: c.originAmountUsdDisplay ?? void 0,
384
- toAmountUsdDisplay: c.destinationAmountUsdDisplay ?? void 0,
385
- gasCostUsd: c.gasCostUsd ?? void 0,
386
- gasCostUsdDisplay: c.gasCostUsdDisplay ?? void 0,
387
- gasCost: c.gasCost ?? void 0,
388
- gasCostFormatted: c.gasCostFormatted ?? void 0,
389
- totalFeesUsd: c.grandTotalUsd ?? void 0,
390
- totalFeesUsdDisplay: c.grandTotalUsdDisplay ?? void 0,
391
- totalGasUsd: c.totalGasUsd ?? void 0,
392
- totalGasUsdDisplay: c.totalGasUsdDisplay ?? void 0,
393
- allProviderFeesUsd: c.allProviderFeesUsd ?? void 0,
394
- allProviderFeesUsdDisplay: c.allProviderFeesUsdDisplay ?? void 0
395
- },
396
- swap: async () => {
397
- const {
398
- depositUserTxnReceipt: l,
399
- destinationIntentTransaction: f,
400
- totalCompletionSeconds: D
401
- } = await lt({
402
- selectedFeeOption: st ?? null
403
- });
404
- return {
405
- originTransaction: {
406
- transactionHash: l?.transactionHash,
407
- explorerUrl: J({
408
- txHash: l?.transactionHash,
409
- chainId: s
410
- }),
411
- receipt: l
412
- },
413
- destinationTransaction: {
414
- transactionHash: f?.txnHash,
415
- explorerUrl: J({
416
- txHash: f?.txnHash,
417
- chainId: i
418
- }),
419
- receipt: f
420
- },
421
- totalCompletionSeconds: D
422
- };
423
- }
424
- };
425
- } catch (g) {
426
- throw o.console.error(
427
- "[trails-sdk] [useQuote] Error getting quote:",
428
- g
429
- ), M(g);
430
- }
431
- },
432
- // Prevent unnecessary refetching
433
- enabled: !!(d && b && n && a && T && H && s && i && $ && // !isLoadingTokens &&
434
- u && u.length > 0),
435
- staleTime: 30 * 1e3,
436
- // Consider data fresh for 30 seconds
437
- refetchOnWindowFocus: !1,
438
- // Don't refetch when window regains focus
439
- refetchOnMount: !1,
440
- // Don't refetch on component remount if data exists
441
- refetchInterval: !1,
442
- // Disable automatic polling
443
- retry: 2,
444
- // Limit retry attempts
445
- refetchOnReconnect: !0
446
- // Refetch when network reconnects
447
- });
448
- return {
449
- quote: E?.quote || null,
450
- swap: E?.swap || null,
451
- isLoadingQuote: P,
452
- quoteError: w,
453
- quoteErrorPrettified: qt(w),
454
- refetchQuote: () => I(),
455
- abort: () => {
456
- o.console.log("[trails-sdk] useQuote abort() called"), o.console.log(
457
- "[trails-sdk] Active operations before abort:",
458
- ft.getAll()
459
- ), R.current.abort(), ft.abortAll(), o.console.log(
460
- "[trails-sdk] Abort completed, active operations:",
461
- ft.getAll()
462
- );
463
- }
464
- };
465
- }
466
- function Vt(d) {
467
- const { data: n } = Bt(), { chainId: s } = Ft(), a = Mt(), i = gt(), { trailsApiKey: T, sequenceIndexerUrl: nt } = pt(), {
468
- openModal: H,
469
- setPendingSelection: ot,
470
- setHostTransactionState: X,
471
- setHostTransactionQuote: z,
472
- setHostTransactionStates: V,
473
- setHostTransactionTimestamp: Q,
474
- hostTransactionState: O,
475
- setReceiptActionButtonText: mt,
476
- setOnReceiptAction: st,
477
- retryTransactionRef: rt
478
- } = Nt(), W = xt(), { supportedTokens: L } = yt(), at = Rt(), R = vt(), it = Pt(null), C = dt(
479
- (t) => {
480
- X((r) => ({
481
- status: t.status ?? r.status,
482
- details: t.details === null ? void 0 : t.details ? { ...r.details, ...t.details } : r.details,
483
- error: t.error === null ? void 0 : t.error !== void 0 ? t.error : r.error,
484
- result: t.result === null ? void 0 : t.result ? { ...r.result, ...t.result } : r.result,
485
- retryEnabled: t.retryEnabled !== void 0 ? t.retryEnabled : r.retryEnabled
46
+ function Qe(s) {
47
+ const { data: h } = He(), { chainId: A } = xe(), T = Le(), I = he(), { trailsApiKey: oe, sequenceIndexerUrl: se } = Ae(), {
48
+ openModal: $,
49
+ setPendingSelection: re,
50
+ setHostTransactionState: Q,
51
+ setHostTransactionQuote: M,
52
+ setHostTransactionStates: W,
53
+ setHostTransactionTimestamp: q,
54
+ hostTransactionState: x,
55
+ setReceiptActionButtonText: ae,
56
+ setOnReceiptAction: ie,
57
+ retryTransactionRef: ce
58
+ } = Ie(), F = Be(), { supportedTokens: P } = Ce(), de = we(), le = Ee(), G = Ue(null), m = D(
59
+ (e) => {
60
+ Q((n) => ({
61
+ status: e.status ?? n.status,
62
+ details: e.details === null ? void 0 : e.details ? { ...n.details, ...e.details } : n.details,
63
+ error: e.error === null ? void 0 : e.error !== void 0 ? e.error : n.error,
64
+ result: e.result === null ? void 0 : e.result ? { ...n.result, ...e.result } : n.result,
65
+ retryEnabled: e.retryEnabled !== void 0 ? e.retryEnabled : n.retryEnabled
486
66
  }));
487
67
  },
488
- [X]
489
- ), Z = async (t, r, u) => {
490
- if (o.console.log(
68
+ [Q]
69
+ ), X = async (e, n, o) => {
70
+ if (d.console.log(
491
71
  "[trails-sdk] [useTrailsSendTransaction] Executing transaction",
492
- { variables: t, originSelection: r }
493
- ), !n || !n.account)
72
+ { variables: e, originSelection: n }
73
+ ), !h || !h.account)
494
74
  throw new Error(
495
75
  "Wallet client not available. Please connect your wallet."
496
76
  );
497
- if (!t.to)
77
+ if (!e.to)
498
78
  throw new Error("Transaction 'to' address is required.");
499
- let k, m, E;
500
- if (r)
501
- k = r.fromTokenAddress, m = r.fromChainId, E = r.fromAmount;
502
- else if (t.fromTokenAddress && t.fromChainId && t.fromAmount)
503
- k = t.fromTokenAddress, m = t.fromChainId, E = t.fromAmount;
504
- else if (t.to && t.value !== void 0) {
505
- const e = s || a;
506
- if (!e)
79
+ let a, r, g;
80
+ if (n)
81
+ a = n.fromTokenAddress, r = n.fromChainId, g = n.fromAmount;
82
+ else if (e.fromTokenAddress && e.fromChainId && e.fromAmount)
83
+ a = e.fromTokenAddress, r = e.fromChainId, g = e.fromAmount;
84
+ else if (e.to && e.value !== void 0) {
85
+ const t = A || T;
86
+ if (!t)
507
87
  throw new Error("Chain ID not available. Please connect your wallet.");
508
- m = e, k = x, E = t.value.toString();
88
+ r = t, a = p, g = e.value.toString();
509
89
  } else
510
90
  throw new Error(
511
91
  "Origin token parameters are required. Please provide 'value' (native token), or 'fromTokenAddress'/'fromChainId'/'fromAmount' (ERC20 token), or select via modal."
512
92
  );
513
- const P = s || a;
514
- if (!P)
93
+ const w = A || T;
94
+ if (!w)
515
95
  throw new Error("Chain ID not available. Please connect your wallet.");
516
- let w, I, g, p;
517
- if (t.tokenAddress && t.tokenAmount)
518
- w = t.tokenAddress, I = L?.find(
519
- (h) => h.contractAddress?.toLowerCase() === t.tokenAddress?.toLowerCase()
520
- )?.chainId ?? P, g = t.tokenAmount, p = t.to;
521
- else if (t.to && t.value !== void 0)
522
- w = x, I = P, g = t.value.toString(), p = t.to;
96
+ let C, k, c, l;
97
+ if (e.tokenAddress && e.tokenAmount)
98
+ C = e.tokenAddress, k = P?.find(
99
+ (i) => i.contractAddress?.toLowerCase() === e.tokenAddress?.toLowerCase()
100
+ )?.chainId ?? w, c = e.tokenAmount, l = e.to;
101
+ else if (e.to && e.value !== void 0)
102
+ C = p, k = w, c = e.value.toString(), l = e.to;
523
103
  else
524
104
  throw new Error(
525
105
  "Either 'value' or 'tokenAddress'/'tokenAmount' must be provided."
526
106
  );
527
- const y = t.tokenAddress && t.tokenAmount ? K.EXACT_OUTPUT : K.EXACT_INPUT;
528
- if (y === K.EXACT_INPUT && !E)
107
+ const f = e.tokenAddress && e.tokenAmount ? H.EXACT_OUTPUT : H.EXACT_INPUT;
108
+ if (f === H.EXACT_INPUT && !g)
529
109
  throw new Error(
530
110
  "Origin amount is required for this transaction. Please provide 'value' or 'fromAmount'."
531
111
  );
532
- const v = y === K.EXACT_OUTPUT ? g : E;
533
- let U = [];
112
+ const L = f === H.EXACT_OUTPUT ? c : g;
113
+ let E = [];
534
114
  try {
535
- U = (await It({
536
- account: n.account.address,
537
- indexerGatewayClient: W,
538
- trailsClient: i
115
+ E = (await Se({
116
+ account: h.account.address,
117
+ indexerGatewayClient: F,
118
+ trailsClient: I
539
119
  })).balances;
540
- } catch (e) {
541
- o.console.warn(
120
+ } catch (t) {
121
+ d.console.warn(
542
122
  "[trails-sdk] [useTrailsSendTransaction] Error fetching balances, proceeding with zero balance",
543
- e
544
- ), U = [];
123
+ t
124
+ ), E = [];
545
125
  }
546
- const q = U.find(
547
- (e) => e.chainId === m && (e.contractAddress?.toLowerCase() === k?.toLowerCase() || !e.contractAddress && k === x)
126
+ const z = E.find(
127
+ (t) => t.chainId === r && (t.contractAddress?.toLowerCase() === a?.toLowerCase() || !t.contractAddress && a === p)
548
128
  )?.balance ?? "0";
549
- let N = 0;
129
+ let K = 0;
550
130
  try {
551
- const h = ut(m)?.nativeCurrency?.symbol ?? "";
552
- h && (N = (await St(i, {
553
- tokenSymbol: h,
554
- tokenAddress: x,
555
- chainId: m
131
+ const i = te(r)?.nativeCurrency?.symbol ?? "";
132
+ i && (K = (await ye(I, {
133
+ tokenSymbol: i,
134
+ tokenAddress: p,
135
+ chainId: r
556
136
  }))?.priceUsd ?? 0);
557
- } catch (e) {
558
- o.console.warn(
137
+ } catch (t) {
138
+ d.console.warn(
559
139
  "[trails-sdk] [useTrailsSendTransaction] Error getting native token price",
560
- e
140
+ t
561
141
  );
562
142
  }
563
- const B = L?.find(
564
- (e) => e.contractAddress?.toLowerCase() === k?.toLowerCase() && e.chainId === m
565
- ), ct = L?.find(
566
- (e) => e.contractAddress?.toLowerCase() === w?.toLowerCase() && e.chainId === I
567
- ), { getChainRpcClient: tt } = await import("./index-Si7cO9V7.js").then((e) => e.aZ), et = tt(m), c = tt(I), lt = async (e, h) => {
143
+ const v = P?.find(
144
+ (t) => t.contractAddress?.toLowerCase() === a?.toLowerCase() && t.chainId === r
145
+ ), J = P?.find(
146
+ (t) => t.contractAddress?.toLowerCase() === C?.toLowerCase() && t.chainId === k
147
+ ), { getChainRpcClient: j } = await import("./index-C_EsqqSn.js").then((t) => t.aX), Y = j(r), Z = j(k), b = async (t, i) => {
568
148
  try {
569
- const F = h === m ? et : h === I ? c : tt(h);
570
- return F ? e.toLowerCase() === x.toLowerCase() ? ut(h)?.nativeCurrency.decimals ?? 18 : await F.readContract({
571
- address: e,
572
- abi: Dt,
149
+ const y = i === r ? Y : i === k ? Z : j(i);
150
+ return y ? t.toLowerCase() === p.toLowerCase() ? te(i)?.nativeCurrency.decimals ?? 18 : await y.readContract({
151
+ address: t,
152
+ abi: Oe,
573
153
  functionName: "decimals"
574
154
  }) : null;
575
- } catch (F) {
576
- return o.console.error(
577
- `[trails-sdk] Error fetching decimals on-chain for token ${e} on chain ${h}:`,
578
- F
155
+ } catch (y) {
156
+ return d.console.error(
157
+ `[trails-sdk] Error fetching decimals on-chain for token ${t} on chain ${i}:`,
158
+ y
579
159
  ), null;
580
160
  }
581
161
  };
582
- let _ = B?.decimals;
583
- if (!_ && k) {
584
- const e = await lt(
585
- k,
586
- m
162
+ let R = v?.decimals;
163
+ if (!R && a) {
164
+ const t = await b(
165
+ a,
166
+ r
587
167
  );
588
- e !== null && (_ = e);
168
+ t !== null && (R = t);
589
169
  }
590
- _ || (_ = 18);
591
- let G = ct?.decimals;
592
- if (!G && w) {
593
- const e = await lt(
594
- w,
595
- I
170
+ R || (R = 18);
171
+ let U = J?.decimals;
172
+ if (!U && C) {
173
+ const t = await b(
174
+ C,
175
+ k
596
176
  );
597
- e !== null && (G = e);
177
+ t !== null && (U = t);
598
178
  }
599
- G || (G = 18);
600
- const l = ct?.symbol ?? "", f = B?.symbol ?? "", D = (e) => {
601
- u?.trackInWidget && V(e), d?.onStatusUpdate?.(e);
602
- }, { send: j, quote: ht } = await wt({
603
- account: n.account,
604
- originTokenAddress: k,
605
- originChainId: m,
606
- originTokenBalance: q,
607
- destinationChainId: I,
608
- recipient: p,
609
- destinationTokenAddress: w,
610
- swapAmount: v,
611
- tradeType: y,
612
- originTokenSymbol: f,
613
- destinationTokenSymbol: l,
614
- fee: "0",
615
- client: n,
616
- dryMode: !1,
617
- trailsClient: i,
618
- destinationCalldata: t.data ? t.data.toString() : void 0,
619
- onTransactionStateChange: D,
620
- sourceTokenDecimals: _,
621
- destinationTokenDecimals: G,
622
- paymasterUrl: d?.paymasterUrl,
623
- slippageTolerance: d?.slippageTolerance?.toString(),
624
- originNativeTokenPriceUsd: N,
625
- swapProvider: d?.swapProvider,
626
- bridgeProvider: d?.bridgeProvider,
627
- commitIntentFn: at.mutateAsync,
628
- executeIntentFn: R.mutateAsync,
629
- checkoutOnHandlers: d?.checkoutOnHandlers,
630
- sequenceIndexerUrl: nt,
631
- sequenceProjectAccessKey: T,
632
- originPublicClient: et ?? void 0,
633
- destinationPublicClient: c ?? void 0,
634
- isSmartWallet: d?.isSmartWallet ?? void 0
179
+ U || (U = 18);
180
+ const fe = J?.symbol ?? "", Te = v?.symbol ?? "", me = (t) => {
181
+ o?.trackInWidget && W(t), s?.onStatusUpdate?.(t);
182
+ }, { send: ge, quote: ke } = await pe({
183
+ account: h.account,
184
+ originTokenAddress: a,
185
+ originChainId: r,
186
+ originTokenBalance: z,
187
+ destinationChainId: k,
188
+ recipient: l,
189
+ destinationTokenAddress: C,
190
+ swapAmount: L,
191
+ tradeType: f,
192
+ originTokenSymbol: Te,
193
+ destinationTokenSymbol: fe,
194
+ client: h,
195
+ trailsClient: I,
196
+ destinationCalldata: e.data ? e.data.toString() : void 0,
197
+ onTransactionStateChange: me,
198
+ sourceTokenDecimals: R,
199
+ destinationTokenDecimals: U,
200
+ paymasterUrl: s?.paymasterUrl,
201
+ slippageTolerance: s?.slippageTolerance?.toString(),
202
+ originNativeTokenPriceUsd: K,
203
+ swapProvider: s?.swapProvider,
204
+ bridgeProvider: s?.bridgeProvider,
205
+ commitIntentFn: de.mutateAsync,
206
+ executeIntentFn: le.mutateAsync,
207
+ checkoutOnHandlers: s?.checkoutOnHandlers,
208
+ sequenceIndexerUrl: se,
209
+ sequenceProjectAccessKey: oe,
210
+ originPublicClient: Y ?? void 0,
211
+ destinationPublicClient: Z ?? void 0,
212
+ isSmartWallet: s?.isSmartWallet ?? void 0
635
213
  });
636
- u?.trackInWidget && (z(ht ?? null), O.details || C({
214
+ o?.trackInWidget && (M(ke ?? null), x.details || m({
637
215
  details: {
638
- to: p,
639
- tokenAddress: w,
640
- tokenAmount: y === K.EXACT_OUTPUT ? g : void 0,
641
- toChainId: I,
642
- data: t.data
216
+ to: l,
217
+ tokenAddress: C,
218
+ tokenAmount: f === H.EXACT_OUTPUT ? c : void 0,
219
+ toChainId: k,
220
+ data: e.data
643
221
  }
644
- }), (!O.status || O.status === "idle") && Q(Date.now()));
222
+ }), (!x.status || x.status === "idle") && q(Date.now()));
645
223
  try {
646
- u?.trackInWidget && C({ retryEnabled: !1 });
224
+ o?.trackInWidget && m({ retryEnabled: !1 });
647
225
  const {
648
- depositUserTxnReceipt: e,
649
- destinationIntentTransaction: h,
650
- totalCompletionSeconds: F
651
- } = await j({
226
+ depositUserTxnReceipt: t,
227
+ destinationIntentTransaction: i,
228
+ totalCompletionSeconds: y
229
+ } = await ge({
652
230
  selectedFeeOption: null,
653
231
  // Transition to "pending" when wallet signature is complete
654
232
  onOriginSend: () => {
655
- u?.trackInWidget && C({ status: "pending", error: null });
233
+ o?.trackInWidget && m({ status: "pending", error: null });
656
234
  }
657
235
  });
658
- return u?.trackInWidget && C({
236
+ return o?.trackInWidget && m({
659
237
  status: "success",
660
238
  result: {
661
- originTxHash: e?.transactionHash,
662
- originExplorerUrl: e?.transactionHash ? J({
663
- txHash: e.transactionHash,
664
- chainId: m
239
+ originTxHash: t?.transactionHash,
240
+ originExplorerUrl: t?.transactionHash ? B({
241
+ txHash: t.transactionHash,
242
+ chainId: r
665
243
  }) : void 0,
666
- destinationTxHash: h?.txnHash,
667
- destinationExplorerUrl: h?.txnHash ? J({
668
- txHash: h.txnHash,
669
- chainId: I
244
+ destinationTxHash: i?.txnHash,
245
+ destinationExplorerUrl: i?.txnHash ? B({
246
+ txHash: i.txnHash,
247
+ chainId: k
670
248
  }) : void 0
671
249
  }
672
250
  }), {
673
251
  originTransaction: {
674
- transactionHash: e?.transactionHash,
675
- explorerUrl: J({
676
- txHash: e?.transactionHash,
677
- chainId: m
252
+ transactionHash: t?.transactionHash,
253
+ explorerUrl: B({
254
+ txHash: t?.transactionHash,
255
+ chainId: r
678
256
  }),
679
- receipt: e
257
+ receipt: t
680
258
  },
681
259
  destinationTransaction: {
682
- transactionHash: h?.txnHash,
683
- explorerUrl: J({
684
- txHash: h?.txnHash,
685
- chainId: I
260
+ transactionHash: i?.txnHash,
261
+ explorerUrl: B({
262
+ txHash: i?.txnHash,
263
+ chainId: k
686
264
  }),
687
- receipt: h
265
+ receipt: i
688
266
  },
689
- totalCompletionSeconds: F
267
+ totalCompletionSeconds: y
690
268
  };
691
- } catch (e) {
692
- if (u?.trackInWidget) {
693
- const h = Tt(e);
694
- C(h ? {
269
+ } catch (t) {
270
+ if (o?.trackInWidget) {
271
+ const i = _(t);
272
+ m(i ? {
695
273
  status: "confirmation",
696
274
  error: null,
697
275
  retryEnabled: !0
698
276
  } : {
699
277
  status: "error",
700
- error: M(e),
278
+ error: O(t),
701
279
  retryEnabled: !1
702
280
  });
703
281
  }
704
- throw e;
282
+ throw t;
705
283
  }
706
- }, A = kt({
707
- mutationFn: async (t) => {
708
- o.console.log(
284
+ }, u = Re({
285
+ mutationFn: async (e) => {
286
+ d.console.log(
709
287
  "[trails-sdk] [useTrailsSendTransaction] Starting transaction",
710
- t
711
- ), mt(
712
- d?.receiptActionButtonText ?? "Transact Again"
713
- ), st(d?.onReceiptAction ?? null);
714
- const r = t.value !== void 0, u = t.fromTokenAddress !== void 0 && t.fromChainId !== void 0, k = r || u;
715
- let m;
716
- if (t.tokenAddress && L) {
717
- const g = L.find(
718
- (p) => p.contractAddress?.toLowerCase() === t.tokenAddress?.toLowerCase()
288
+ e
289
+ ), ae(
290
+ s?.receiptActionButtonText ?? "Transact Again"
291
+ ), ie(s?.onReceiptAction ?? null);
292
+ const n = e.value !== void 0, o = e.fromTokenAddress !== void 0 && e.fromChainId !== void 0, a = n || o;
293
+ let r;
294
+ if (e.tokenAddress && P) {
295
+ const c = P.find(
296
+ (l) => l.contractAddress?.toLowerCase() === e.tokenAddress?.toLowerCase()
719
297
  );
720
- g && (m = g.chainId);
298
+ c && (r = c.chainId);
721
299
  }
722
- m || (m = s || a);
723
- let E = !0, P = !0;
724
- if (n?.account)
300
+ r || (r = A || T);
301
+ let g = !0, w = !0;
302
+ if (h?.account)
725
303
  try {
726
- if (k) {
727
- let g, p, y;
728
- t.value !== void 0 ? (g = x, p = s || a || 1, y = t.value.toString()) : t.fromTokenAddress && t.fromChainId && (g = t.fromTokenAddress, p = t.fromChainId, y = t.fromAmount), g && p && y && y !== "0" && (E = await At({
729
- account: n.account.address,
730
- token: g,
731
- amount: y,
732
- chainId: p,
733
- indexerGatewayClient: W,
734
- trailsClient: i
735
- }), o.console.log(
304
+ if (a) {
305
+ let c, l, f;
306
+ e.value !== void 0 ? (c = p, l = A || T || 1, f = e.value.toString()) : e.fromTokenAddress && e.fromChainId && (c = e.fromTokenAddress, l = e.fromChainId, f = e.fromAmount), c && l && f && f !== "0" && (g = await ee({
307
+ account: h.account.address,
308
+ token: c,
309
+ amount: f,
310
+ chainId: l,
311
+ indexerGatewayClient: F,
312
+ trailsClient: I
313
+ }), d.console.log(
736
314
  "[trails-sdk] [useTrailsSendTransaction] Origin token balance check:",
737
315
  {
738
- tokenAddress: g,
739
- amount: y,
740
- chainId: p,
741
- hasSufficientBalance: E
316
+ tokenAddress: c,
317
+ amount: f,
318
+ chainId: l,
319
+ hasSufficientBalance: g
742
320
  }
743
321
  ));
744
322
  }
745
- E && t.tokenAddress && t.tokenAmount && (P = await At({
746
- account: n.account.address,
747
- token: t.tokenAddress,
748
- amount: t.tokenAmount,
749
- chainId: m,
750
- indexerGatewayClient: W,
751
- trailsClient: i
752
- }), o.console.log(
323
+ g && e.tokenAddress && e.tokenAmount && (w = await ee({
324
+ account: h.account.address,
325
+ token: e.tokenAddress,
326
+ amount: e.tokenAmount,
327
+ chainId: r,
328
+ indexerGatewayClient: F,
329
+ trailsClient: I
330
+ }), d.console.log(
753
331
  "[trails-sdk] [useTrailsSendTransaction] Destination token balance check:",
754
332
  {
755
- tokenAddress: t.tokenAddress,
756
- tokenAmount: t.tokenAmount,
757
- chainId: m,
758
- hasSufficientBalance: P
333
+ tokenAddress: e.tokenAddress,
334
+ tokenAmount: e.tokenAmount,
335
+ chainId: r,
336
+ hasSufficientBalance: w
759
337
  }
760
338
  ));
761
- } catch (g) {
762
- o.console.warn(
339
+ } catch (c) {
340
+ d.console.warn(
763
341
  "[trails-sdk] [useTrailsSendTransaction] Error checking balances, defaulting to origin selection:",
764
- g
765
- ), E = !1, P = !1;
342
+ c
343
+ ), g = !1, w = !1;
766
344
  }
767
- const w = !k || !E || !P;
768
- if (o.console.log(
345
+ const C = !a || !g || !w;
346
+ if (d.console.log(
769
347
  "[trails-sdk] [useTrailsSendTransaction] Origin selection decision:",
770
348
  {
771
- hasOriginParams: k,
772
- hasSufficientOriginBalance: E,
773
- hasSufficientDestinationTokenBalance: P,
774
- needsOriginSelection: w
349
+ hasOriginParams: a,
350
+ hasSufficientOriginBalance: g,
351
+ hasSufficientDestinationTokenBalance: w,
352
+ needsOriginSelection: C
775
353
  }
776
- ), w) {
777
- const g = !(t.tokenAddress && t.tokenAmount), p = {
778
- to: t.to,
779
- tokenAddress: t.tokenAddress,
780
- tokenAmount: t.tokenAmount,
781
- toChainId: m,
782
- data: t.data
354
+ ), C) {
355
+ const c = !(e.tokenAddress && e.tokenAmount), l = {
356
+ to: e.to,
357
+ tokenAddress: e.tokenAddress,
358
+ tokenAmount: e.tokenAmount,
359
+ toChainId: r,
360
+ data: e.data
783
361
  };
784
- return C({
362
+ return m({
785
363
  status: "awaiting-origin",
786
- details: p,
364
+ details: l,
787
365
  error: null,
788
366
  result: null
789
- }), z(null), V([]), Q(Date.now()), new Promise((y, v) => {
790
- ot({
791
- resolve: async (U) => {
367
+ }), M(null), W([]), q(Date.now()), new Promise((f, L) => {
368
+ re({
369
+ resolve: async (E) => {
792
370
  try {
793
- C({ status: "confirmation" });
794
- const S = await Z(t, U, {
371
+ m({ status: "confirmation" });
372
+ const S = await X(e, E, {
795
373
  trackInWidget: !0
796
374
  });
797
- y(S);
375
+ f(S);
798
376
  } catch (S) {
799
- Tt(S) || C({
377
+ _(S) || m({
800
378
  status: "error",
801
- error: M(S)
802
- }), v(S);
379
+ error: O(S)
380
+ }), L(S);
803
381
  }
804
382
  },
805
- reject: (U) => {
806
- const S = U instanceof Error ? U : new Error(String(U));
807
- C({
383
+ reject: (E) => {
384
+ const S = E instanceof Error ? E : new Error(String(E));
385
+ m({
808
386
  status: "error",
809
- error: M(S)
810
- }), v(S);
387
+ error: O(S)
388
+ }), L(S);
811
389
  },
812
- requireAmountInput: g
390
+ requireAmountInput: c
813
391
  }), setTimeout(() => {
814
- o.console.log(
392
+ d.console.log(
815
393
  "[trails-sdk] [useTrailsSendTransaction] Calling openModal()"
816
- ), H();
394
+ ), $();
817
395
  }, 0);
818
396
  });
819
397
  }
820
- const I = {
821
- to: t.to,
822
- tokenAddress: t.tokenAddress,
823
- tokenAmount: t.tokenAmount,
824
- toChainId: m,
825
- data: t.data
398
+ const k = {
399
+ to: e.to,
400
+ tokenAddress: e.tokenAddress,
401
+ tokenAmount: e.tokenAmount,
402
+ toChainId: r,
403
+ data: e.data
826
404
  };
827
- return C({
405
+ return m({
828
406
  status: "confirmation",
829
- details: I,
407
+ details: k,
830
408
  error: null,
831
409
  result: null
832
- }), z(null), V([]), Q(Date.now()), H(), Z(t, void 0, { trackInWidget: !0 });
410
+ }), M(null), W([]), q(Date.now()), $(), X(e, void 0, { trackInWidget: !0 });
833
411
  },
834
- onSuccess: (t, r) => {
835
- o.console.log(
412
+ onSuccess: (e, n) => {
413
+ d.console.log(
836
414
  "[trails-sdk] [useTrailsSendTransaction] Transaction successful",
837
- { data: t, variables: r }
838
- ), d?.onSuccess?.(t, r);
415
+ { data: e, variables: n }
416
+ ), s?.onSuccess?.(e, n);
839
417
  },
840
- onError: (t, r) => {
841
- o.console.error(
418
+ onError: (e, n) => {
419
+ d.console.error(
842
420
  "[trails-sdk] [useTrailsSendTransaction] Transaction error",
843
- { error: t, variables: r }
421
+ { error: e, variables: n }
844
422
  );
845
- const u = M(t), k = Tt(t);
846
- O.status !== "idle" && !k && C({
423
+ const o = O(e), a = _(e);
424
+ x.status !== "idle" && !a && m({
847
425
  status: "error",
848
- error: u
849
- }), d?.onError?.(new Error(u), r);
426
+ error: o
427
+ }), s?.onError?.(new Error(o), n);
850
428
  },
851
- onSettled: (t, r, u) => {
852
- o.console.log(
429
+ onSettled: (e, n, o) => {
430
+ d.console.log(
853
431
  "[trails-sdk] [useTrailsSendTransaction] Transaction settled",
854
- { data: t, error: r, variables: u }
855
- ), d?.onSettled?.(t, r, u);
432
+ { data: e, error: n, variables: o }
433
+ ), s?.onSettled?.(e, n, o);
856
434
  }
857
- }), Y = dt(
858
- (t, r) => {
859
- A.mutate(t, {
860
- onSuccess: (u) => {
861
- r?.onSuccess?.(u);
435
+ }), N = D(
436
+ (e, n) => {
437
+ u.mutate(e, {
438
+ onSuccess: (o) => {
439
+ n?.onSuccess?.(o);
862
440
  },
863
- onError: (u) => {
864
- r?.onError?.(u);
441
+ onError: (o) => {
442
+ n?.onError?.(o);
865
443
  },
866
- onSettled: (u, k) => {
867
- r?.onSettled?.(u, k);
444
+ onSettled: (o, a) => {
445
+ n?.onSettled?.(o, a);
868
446
  }
869
447
  });
870
448
  },
871
- [A]
872
- ), b = dt(
873
- async (t, r) => A.mutateAsync(t, {
874
- onSuccess: (u) => {
875
- r?.onSuccess?.(u);
449
+ [u]
450
+ ), ue = D(
451
+ async (e, n) => u.mutateAsync(e, {
452
+ onSuccess: (o) => {
453
+ n?.onSuccess?.(o);
876
454
  },
877
- onError: (u) => {
878
- r?.onError?.(u);
455
+ onError: (o) => {
456
+ n?.onError?.(o);
879
457
  },
880
- onSettled: (u, k) => {
881
- r?.onSettled?.(u, k);
458
+ onSettled: (o, a) => {
459
+ n?.onSettled?.(o, a);
882
460
  }
883
461
  }),
884
- [A]
885
- ), $ = dt(() => {
886
- it.current && Y(it.current);
887
- }, [Y]);
888
- return rt.current = $, {
889
- sendTransaction: Y,
890
- sendTransactionAsync: b,
891
- retry: $,
892
- data: A.data,
893
- error: A.error,
894
- isPending: A.isPending,
895
- isSuccess: A.isSuccess,
896
- isError: A.isError,
897
- isIdle: A.isIdle,
898
- status: A.status,
899
- reset: A.reset,
900
- variables: A.variables
462
+ [u]
463
+ ), V = D(() => {
464
+ G.current && N(G.current);
465
+ }, [N]);
466
+ return ce.current = V, {
467
+ sendTransaction: N,
468
+ sendTransactionAsync: ue,
469
+ retry: V,
470
+ data: u.data,
471
+ error: u.error,
472
+ isPending: u.isPending,
473
+ isSuccess: u.isSuccess,
474
+ isError: u.isError,
475
+ isIdle: u.isIdle,
476
+ status: u.status,
477
+ reset: u.reset,
478
+ variables: u.variables
901
479
  };
902
480
  }
903
481
  export {
904
- te as InsufficientBalanceError,
905
- ee as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
906
- K as TradeType,
907
- ne as TrailsClient,
908
- oe as TrailsHookModal,
909
- se as TrailsModalProvider,
910
- re as TrailsProvider,
911
- ae as TrailsWidget,
912
- ie as UserRejectionError,
913
- ce as attemptSwitchChain,
914
- le as buildRefundTransaction,
915
- de as buildRefundTransactionWithSignature,
916
- ue as calcAmountUsdPrice,
917
- ge as calculateIntentAddress,
918
- me as calculateOriginAndDestinationIntentAddresses,
919
- fe as commitIntent,
920
- Te as convertApiTokenInfoToToken,
921
- ke as createModalController,
922
- he as determineRefundCall,
923
- Ce as formatBalanceFields,
924
- Ae as formatPriceFields,
925
- Ee as formatTvl,
926
- pe as formatUsdAmountFormatted,
927
- ye as formatUsdFields,
928
- Ie as getAccountTotalBalanceUsd,
929
- Se as getAccountTransactionHistory,
930
- we as getAllChains,
931
- ut as getChainInfo,
932
- Ue as getChainRpcClient,
933
- Pe as getERC20TransferData,
934
- At as getHasSufficientBalanceToken,
935
- De as getHasSufficientBalanceUsd,
936
- xe as getIntent,
937
- Re as getIsApiError,
938
- ve as getIsBalanceTooLowError,
939
- He as getIsInsufficientLiquidityError,
940
- Oe as getIsNoAvailableQuoteError,
941
- Le as getIsQuoteFailedError,
942
- be as getIsQuoteInputError,
943
- qe as getIsQuoteTokenError,
944
- Ne as getIsRateLimitedError,
945
- Be as getIsRequiredAmountNotMetError,
946
- Tt as getIsUserRejectionError,
947
- Fe as getIsWalletAlreadyConnectedError,
948
- Me as getMinLogLevel,
949
- qt as getPrettifiedErrorMessage,
950
- Qe as getRpcUrl,
951
- We as getSupportedChains,
952
- $e as getSupportedTokens,
953
- St as getTokenPrice,
954
- _e as getTokenPrices,
955
- Ge as getTrailsClient,
956
- je as getTxTimeDiff,
957
- Ke as invalidateTokenPricesCache,
958
- Je as isValidInteger,
959
- Xe as isValidNumeric,
960
- o as logger,
961
- ze as normalizeNumber,
962
- Ve as pollIntentReceipt,
963
- wt as prepareSend,
964
- Ze as quoteIntent,
965
- Ye as sendOriginTransaction,
966
- tn as signPayload,
967
- en as useAccountTotalBalanceUsd,
968
- nn as useAccountTransactionHistory,
969
- Ct as useChainRpcClient,
970
- Rt as useCommitIntent,
971
- vt as useExecuteIntent,
972
- on as useGetIntent,
973
- sn as useGetTokenImageUrl,
974
- rn as useHasSufficientBalanceToken,
975
- an as useHasSufficientBalanceUsd,
976
- Cn as useIndexerGatewayClient,
977
- Xt as useIntentReceiptMonitor,
978
- cn as useIntentRecover,
979
- ln as useIntentTransactionHistory,
980
- zt as useQuote,
981
- dn as useSupportedChains,
982
- yt as useSupportedTokens,
983
- un as useTokenAddress,
984
- gn as useTokenBalances,
985
- mn as useTokenInfo,
986
- fn as useTokenList,
987
- Tn as useTokenPrice,
988
- kn as useTokenPrices,
989
- pt as useTrails,
990
- gt as useTrailsClient,
991
- Nt as useTrailsModal,
992
- Vt as useTrailsSendTransaction
482
+ Ve as InsufficientBalanceError,
483
+ ze as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
484
+ H as TradeType,
485
+ Ke as TrailsClient,
486
+ ve as TrailsHookModal,
487
+ Je as TrailsModalProvider,
488
+ Ye as TrailsProvider,
489
+ Ze as TrailsWidget,
490
+ be as UserRejectionError,
491
+ et as attemptSwitchChain,
492
+ tt as buildRefundTransaction,
493
+ nt as buildRefundTransactionWithSignature,
494
+ ot as calcAmountUsdPrice,
495
+ st as calculateIntentAddress,
496
+ rt as calculateOriginAndDestinationIntentAddresses,
497
+ at as commitIntent,
498
+ it as convertApiTokenInfoToToken,
499
+ ct as createModalController,
500
+ dt as determineRefundCall,
501
+ lt as formatBalanceFields,
502
+ ut as formatPriceFields,
503
+ ft as formatTvl,
504
+ Tt as formatUsdAmountFormatted,
505
+ mt as formatUsdFields,
506
+ gt as getAccountTotalBalanceUsd,
507
+ kt as getAccountTransactionHistory,
508
+ ht as getAllChains,
509
+ te as getChainInfo,
510
+ At as getChainRpcClient,
511
+ It as getERC20TransferData,
512
+ ee as getHasSufficientBalanceToken,
513
+ Ct as getHasSufficientBalanceUsd,
514
+ wt as getIntent,
515
+ Et as getIsApiError,
516
+ St as getIsBalanceTooLowError,
517
+ yt as getIsInsufficientLiquidityError,
518
+ pt as getIsNoAvailableQuoteError,
519
+ Pt as getIsQuoteFailedError,
520
+ Rt as getIsQuoteInputError,
521
+ Ut as getIsQuoteTokenError,
522
+ Ht as getIsRateLimitedError,
523
+ xt as getIsRequiredAmountNotMetError,
524
+ _ as getIsUserRejectionError,
525
+ Lt as getIsWalletAlreadyConnectedError,
526
+ Ot as getMinLogLevel,
527
+ Bt as getPrettifiedErrorMessage,
528
+ Dt as getRpcUrl,
529
+ Mt as getSupportedChains,
530
+ Wt as getSupportedTokens,
531
+ ye as getTokenPrice,
532
+ qt as getTokenPrices,
533
+ Ft as getTrailsClient,
534
+ Nt as getTxTimeDiff,
535
+ jt as invalidateTokenPricesCache,
536
+ _t as isValidInteger,
537
+ $t as isValidNumeric,
538
+ d as logger,
539
+ Qt as normalizeNumber,
540
+ Gt as pollIntentReceipt,
541
+ pe as prepareSend,
542
+ Xt as quoteIntent,
543
+ Vt as sendOriginTransaction,
544
+ zt as signPayload,
545
+ Kt as useAccountTotalBalanceUsd,
546
+ vt as useAccountTransactionHistory,
547
+ Jt as useChainRpcClient,
548
+ we as useCommitIntent,
549
+ Ee as useExecuteIntent,
550
+ Yt as useGetIntent,
551
+ Zt as useGetTokenImageUrl,
552
+ bt as useHasSufficientBalanceToken,
553
+ en as useHasSufficientBalanceUsd,
554
+ Tn as useIndexerGatewayClient,
555
+ $e as useIntentReceiptMonitor,
556
+ tn as useIntentRecover,
557
+ nn as useIntentTransactionHistory,
558
+ on as useQuote,
559
+ sn as useSupportedChains,
560
+ Ce as useSupportedTokens,
561
+ rn as useTokenAddress,
562
+ an as useTokenBalances,
563
+ cn as useTokenInfo,
564
+ dn as useTokenList,
565
+ ln as useTokenPrice,
566
+ un as useTokenPrices,
567
+ Ae as useTrails,
568
+ he as useTrailsClient,
569
+ Ie as useTrailsModal,
570
+ Qe as useTrailsSendTransaction
993
571
  };