@agg-build/hooks 4.26.1 → 4.27.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 (45) hide show
  1. package/dist/deposit.d.mts +142 -138
  2. package/dist/deposit.d.mts.map +1 -0
  3. package/dist/deposit.d.ts +142 -138
  4. package/dist/deposit.d.ts.map +1 -0
  5. package/dist/deposit.js +751 -2414
  6. package/dist/deposit.mjs +744 -727
  7. package/dist/deposit.mjs.map +1 -0
  8. package/dist/index-CbNR3EIA.d.mts +341 -0
  9. package/dist/index-CbNR3EIA.d.mts.map +1 -0
  10. package/dist/index-CsP1jRMD.d.ts +341 -0
  11. package/dist/index-CsP1jRMD.d.ts.map +1 -0
  12. package/dist/index-D0fXU85a.d.mts +743 -0
  13. package/dist/index-D0fXU85a.d.mts.map +1 -0
  14. package/dist/index-D0fXU85a.d.ts +743 -0
  15. package/dist/index-D0fXU85a.d.ts.map +1 -0
  16. package/dist/index.d.mts +6458 -7515
  17. package/dist/index.d.mts.map +1 -0
  18. package/dist/index.d.ts +6458 -7515
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +7451 -11417
  21. package/dist/index.mjs +7154 -5221
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/use-ramp-session-7RAG9tvY.js +30 -0
  24. package/dist/use-ramp-session-BFWHCtuc.mjs +21 -0
  25. package/dist/use-ramp-session-BFWHCtuc.mjs.map +1 -0
  26. package/dist/use-sync-balances-BkcqInJh.mjs +1779 -0
  27. package/dist/use-sync-balances-BkcqInJh.mjs.map +1 -0
  28. package/dist/{use-sync-balances-CeD8qZWP.d.ts → use-sync-balances-CVEg__2V.d.mts} +7 -8
  29. package/dist/use-sync-balances-CVEg__2V.d.mts.map +1 -0
  30. package/dist/{use-sync-balances-CeD8qZWP.d.mts → use-sync-balances-CVEg__2V.d.ts} +7 -8
  31. package/dist/use-sync-balances-CVEg__2V.d.ts.map +1 -0
  32. package/dist/use-sync-balances-HryB8Q7F.js +1974 -0
  33. package/dist/withdraw--f5kYKJA.mjs +1474 -0
  34. package/dist/withdraw--f5kYKJA.mjs.map +1 -0
  35. package/dist/withdraw-BXWZYmJa.js +1591 -0
  36. package/dist/withdraw.d.mts +3 -351
  37. package/dist/withdraw.d.ts +3 -351
  38. package/dist/withdraw.js +10 -2229
  39. package/dist/withdraw.mjs +3 -20
  40. package/package.json +7 -6
  41. package/dist/chunk-JFJNW2PD.mjs +0 -5649
  42. package/dist/chunk-LNIAMJTZ.mjs +0 -505
  43. package/dist/chunk-OZQ3K47U.mjs +0 -31
  44. package/dist/use-deposit-addresses-B9ICS-3U.d.mts +0 -236
  45. package/dist/use-deposit-addresses-B9ICS-3U.d.ts +0 -236
@@ -1,505 +0,0 @@
1
- import {
2
- __async,
3
- __spreadValues,
4
- invalidateUserMoneyState,
5
- useAggBalanceState,
6
- useAggClient,
7
- useAggWebSocket,
8
- useAggWebSocketConnectionState,
9
- useDepositAddresses,
10
- useManagedBalances,
11
- useOnWithdrawalLifecycle,
12
- useSyncBalances,
13
- useWithdrawManaged
14
- } from "./chunk-JFJNW2PD.mjs";
15
-
16
- // src/withdraw/use-withdraw-flow.ts
17
- import { useCallback, useEffect, useMemo, useState } from "react";
18
- var EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
19
- var SOLANA_ADDRESS_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
20
- var SOLANA_CHAIN_ID = 792703809;
21
- var WITHDRAWAL_SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([
22
- 1,
23
- // Ethereum
24
- 137,
25
- // Polygon
26
- 42161,
27
- // Arbitrum
28
- 8453,
29
- // Base
30
- 56,
31
- // BNB
32
- SOLANA_CHAIN_ID,
33
- 1337
34
- // Hyperliquid
35
- ]);
36
- var isValidDestinationAddress = (address, chainId) => {
37
- if (chainId === SOLANA_CHAIN_ID) return SOLANA_ADDRESS_REGEX.test(address);
38
- return EVM_ADDRESS_REGEX.test(address);
39
- };
40
- var detectDestinationAddressKind = (address) => {
41
- const trimmed = address.trim();
42
- if (!trimmed) return null;
43
- if (EVM_ADDRESS_REGEX.test(trimmed)) return "evm";
44
- if (SOLANA_ADDRESS_REGEX.test(trimmed)) return "solana";
45
- return null;
46
- };
47
- var DEFAULT_WITHDRAW_SUMMARY = {
48
- amountReceived: "",
49
- network: "",
50
- toWallet: "",
51
- fees: "\u2014"
52
- };
53
- var formatRawTokenAmount = (rawAmount, decimals) => {
54
- if (!rawAmount) return "0";
55
- const raw = BigInt(rawAmount);
56
- const divisor = BigInt(`1${"0".repeat(decimals)}`);
57
- const whole = raw / divisor;
58
- const remainder = raw % divisor;
59
- if (remainder === BigInt(0)) return whole.toString();
60
- return `${whole.toString()}.${remainder.toString().padStart(decimals, "0").replace(/0+$/, "")}`;
61
- };
62
- var formatRawTokenAmountForDisplay = (rawAmount, decimals, fractionDigits = 2) => {
63
- const [wholePart, fractionalPart = ""] = formatRawTokenAmount(rawAmount, decimals).split(".");
64
- const normalizedFraction = fractionalPart.padEnd(fractionDigits, "0").slice(0, fractionDigits);
65
- return `${wholePart}.${normalizedFraction}`;
66
- };
67
- var parseTokenAmountToRaw = (amount, decimals) => {
68
- const normalizedAmount = amount.trim();
69
- if (!normalizedAmount || !/^\d*(?:\.\d*)?$/.test(normalizedAmount)) {
70
- return null;
71
- }
72
- const [wholePart = "0", fractionalPart = ""] = normalizedAmount.split(".");
73
- if (fractionalPart.length > decimals) return null;
74
- const normalizedWhole = wholePart === "" ? "0" : wholePart;
75
- const normalizedFraction = fractionalPart.padEnd(decimals, "0");
76
- try {
77
- return `${BigInt(normalizedWhole)}${normalizedFraction}`.replace(/^0+(?=\d)/, "");
78
- } catch (e) {
79
- return null;
80
- }
81
- };
82
- var shortenAddress = (address) => address.length > 12 ? `${address.slice(0, 6)}...${address.slice(-4)}` : address;
83
- function useWithdrawFlow(options) {
84
- var _a, _b, _c, _d, _e;
85
- const { open, onOpenChange } = options;
86
- const { totalBalance } = useAggBalanceState();
87
- const { balances } = useManagedBalances({ enabled: open });
88
- const { supportedChains } = useDepositAddresses({ enabled: open });
89
- const withdrawMutation = useWithdrawManaged();
90
- const syncBalances = useSyncBalances();
91
- const ws = useAggWebSocket();
92
- useEffect(() => {
93
- if (!open) return;
94
- syncBalances.mutate(void 0, {
95
- onError: () => {
96
- }
97
- });
98
- }, [open]);
99
- const [withdrawDestination, setWithdrawDestination] = useState("");
100
- const [withdrawAmount, setWithdrawAmount] = useState("");
101
- const [withdrawToken, setWithdrawToken] = useState("USDC");
102
- const [withdrawNetwork, setWithdrawNetwork] = useState("");
103
- const [withdrawSummary, setWithdrawSummary] = useState(DEFAULT_WITHDRAW_SUMMARY);
104
- const [withdrawalId, setWithdrawalId] = useState(null);
105
- const [isMax, setIsMax] = useState(false);
106
- const detectedAddressKind = useMemo(
107
- () => detectDestinationAddressKind(withdrawDestination),
108
- [withdrawDestination]
109
- );
110
- const networkOptions = useMemo(
111
- () => (supportedChains != null ? supportedChains : []).filter((chain) => WITHDRAWAL_SUPPORTED_CHAIN_IDS.has(chain.chainId)).map((chain) => {
112
- const value = String(chain.chainId);
113
- const isSolana = chain.chainId === SOLANA_CHAIN_ID;
114
- const disabled = detectedAddressKind === "solana" ? !isSolana : detectedAddressKind === "evm" ? isSolana : false;
115
- return { value, label: chain.name, disabled };
116
- }),
117
- [supportedChains, detectedAddressKind]
118
- );
119
- const firstEnabledNetwork = (_d = (_c = (_a = networkOptions.find((option) => !option.disabled)) == null ? void 0 : _a.value) != null ? _c : (_b = networkOptions[0]) == null ? void 0 : _b.value) != null ? _d : "";
120
- const isCurrentNetworkSelectable = networkOptions.some(
121
- (option) => option.value === withdrawNetwork && !option.disabled
122
- );
123
- const resolvedWithdrawNetwork = isCurrentNetworkSelectable ? withdrawNetwork : firstEnabledNetwork;
124
- useEffect(() => {
125
- if (!networkOptions.length) return;
126
- if (!isCurrentNetworkSelectable && firstEnabledNetwork) {
127
- setWithdrawNetwork(firstEnabledNetwork);
128
- }
129
- }, [networkOptions, isCurrentNetworkSelectable, firstEnabledNetwork]);
130
- const tokenOptions = useMemo(() => {
131
- var _a2, _b2, _c2;
132
- const selectedChainId = Number(resolvedWithdrawNetwork);
133
- const supportedTokensForNetwork = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens) != null ? _b2 : [];
134
- const withdrawableSymbols = new Set(supportedTokensForNetwork.map((token) => token.symbol));
135
- return ((_c2 = balances == null ? void 0 : balances.cash) != null ? _c2 : []).filter((cashEntry) => withdrawableSymbols.has(cashEntry.tokenSymbol)).map((cashEntry) => ({
136
- value: cashEntry.tokenSymbol,
137
- label: cashEntry.tokenSymbol
138
- }));
139
- }, [balances, resolvedWithdrawNetwork, supportedChains]);
140
- const resolvedWithdrawToken = tokenOptions.some((option) => option.value === withdrawToken) ? withdrawToken : ((_e = tokenOptions[0]) == null ? void 0 : _e.value) || "";
141
- useEffect(() => {
142
- if (!tokenOptions.length) return;
143
- if (!tokenOptions.some((option) => option.value === withdrawToken)) {
144
- setWithdrawToken(tokenOptions[0].value);
145
- }
146
- }, [tokenOptions, withdrawToken]);
147
- const selectedCashEntry = useMemo(
148
- () => balances == null ? void 0 : balances.cash.find((cashEntry) => cashEntry.tokenSymbol === resolvedWithdrawToken),
149
- [balances, resolvedWithdrawToken]
150
- );
151
- const selectedTokenDecimals = useMemo(() => {
152
- var _a2, _b2, _c2, _d2;
153
- const selectedChainId = Number(resolvedWithdrawNetwork);
154
- return (_d2 = (_c2 = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens.find((token) => token.symbol === resolvedWithdrawToken)) == null ? void 0 : _b2.decimals) != null ? _c2 : selectedCashEntry == null ? void 0 : selectedCashEntry.decimals) != null ? _d2 : 6;
155
- }, [
156
- resolvedWithdrawNetwork,
157
- resolvedWithdrawToken,
158
- selectedCashEntry == null ? void 0 : selectedCashEntry.decimals,
159
- supportedChains
160
- ]);
161
- const exactBalance = useMemo(() => {
162
- if (!selectedCashEntry) return "0";
163
- return formatRawTokenAmount(selectedCashEntry.totalRaw, selectedCashEntry.decimals);
164
- }, [selectedCashEntry]);
165
- const balanceDisplay = useMemo(() => {
166
- if (!selectedCashEntry) return `0.00 ${resolvedWithdrawToken || withdrawToken}`;
167
- return `${formatRawTokenAmountForDisplay(
168
- selectedCashEntry.totalRaw,
169
- selectedCashEntry.decimals
170
- )} ${resolvedWithdrawToken}`;
171
- }, [resolvedWithdrawToken, selectedCashEntry, withdrawToken]);
172
- const resetFlowState = useCallback(() => {
173
- setWithdrawDestination("");
174
- setWithdrawAmount("");
175
- setWithdrawToken("USDC");
176
- setWithdrawNetwork("");
177
- setWithdrawSummary(DEFAULT_WITHDRAW_SUMMARY);
178
- setWithdrawalId(null);
179
- setIsMax(false);
180
- }, []);
181
- const handleWithdrawOpenChange = useCallback(
182
- (isOpen) => {
183
- if (!isOpen) resetFlowState();
184
- onOpenChange(isOpen);
185
- },
186
- [onOpenChange, resetFlowState]
187
- );
188
- useEffect(() => {
189
- if (!open) resetFlowState();
190
- }, [open, resetFlowState]);
191
- const handleWithdrawProvider = useCallback(() => __async(null, null, function* () {
192
- var _a2, _b2;
193
- const destinationChainId = Number(resolvedWithdrawNetwork);
194
- const trimmedDestination = withdrawDestination.trim();
195
- const amountRaw = parseTokenAmountToRaw(withdrawAmount, selectedTokenDecimals);
196
- if (!amountRaw || BigInt(amountRaw) <= BigInt(0)) {
197
- throw new Error("Enter a withdrawal amount greater than zero.");
198
- }
199
- if (!Number.isFinite(destinationChainId) || destinationChainId <= 0) {
200
- throw new Error("Select a destination network.");
201
- }
202
- if (!isValidDestinationAddress(trimmedDestination, destinationChainId)) {
203
- const expected = destinationChainId === SOLANA_CHAIN_ID ? "a Solana wallet address (base58, 32\u201344 chars)" : "an EVM destination address (0x\u2026 40 hex chars)";
204
- throw new Error(`Enter ${expected}.`);
205
- }
206
- if (selectedCashEntry) {
207
- const scaleBy = (n, exp) => {
208
- if (exp <= 0) return n;
209
- return n * BigInt(`1${"0".repeat(exp)}`);
210
- };
211
- const balanceInDestFrame = (() => {
212
- const native = BigInt(selectedCashEntry.totalRaw);
213
- if (selectedCashEntry.decimals === selectedTokenDecimals) return native;
214
- if (selectedCashEntry.decimals > selectedTokenDecimals) {
215
- return native / scaleBy(BigInt(1), selectedCashEntry.decimals - selectedTokenDecimals);
216
- }
217
- return scaleBy(native, selectedTokenDecimals - selectedCashEntry.decimals);
218
- })();
219
- if (!isMax && BigInt(amountRaw) > balanceInDestFrame) {
220
- throw new Error("Withdrawal amount exceeds your available balance.");
221
- }
222
- }
223
- ws == null ? void 0 : ws.connect();
224
- yield new Promise((resolve, reject) => {
225
- withdrawMutation.mutate(
226
- __spreadValues({
227
- amountRaw,
228
- tokenSymbol: resolvedWithdrawToken,
229
- destinationAddress: trimmedDestination,
230
- destinationChainId
231
- }, isMax ? { max: true } : {}),
232
- {
233
- onSuccess: (data) => {
234
- setWithdrawalId(data.withdrawalId);
235
- resolve();
236
- },
237
- onError: reject
238
- }
239
- );
240
- });
241
- setWithdrawSummary({
242
- amountReceived: `${formatRawTokenAmountForDisplay(amountRaw, selectedTokenDecimals)} ${resolvedWithdrawToken}`,
243
- network: (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === destinationChainId)) == null ? void 0 : _a2.name) != null ? _b2 : resolvedWithdrawNetwork,
244
- toWallet: shortenAddress(trimmedDestination),
245
- fees: "\u2014"
246
- });
247
- }), [
248
- isMax,
249
- resolvedWithdrawNetwork,
250
- resolvedWithdrawToken,
251
- selectedCashEntry,
252
- selectedTokenDecimals,
253
- supportedChains,
254
- withdrawAmount,
255
- withdrawDestination,
256
- withdrawMutation,
257
- ws
258
- ]);
259
- return {
260
- open,
261
- onOpenChange: handleWithdrawOpenChange,
262
- withdrawFlow: {
263
- balance: totalBalance,
264
- balanceDisplay,
265
- amount: withdrawAmount,
266
- destinationWallet: withdrawDestination,
267
- tokenOptions,
268
- networkOptions,
269
- selectedToken: resolvedWithdrawToken,
270
- selectedNetwork: resolvedWithdrawNetwork,
271
- purchaseSummary: withdrawSummary,
272
- withdrawalId,
273
- isMax
274
- },
275
- onWithdrawDestinationChange: setWithdrawDestination,
276
- onWithdrawAmountChange: useCallback((v) => {
277
- setIsMax(false);
278
- setWithdrawAmount(v);
279
- }, []),
280
- onWithdrawTokenChange: setWithdrawToken,
281
- onWithdrawNetworkChange: setWithdrawNetwork,
282
- onMaxClick: useCallback(() => {
283
- setIsMax(true);
284
- setWithdrawAmount(exactBalance === "0" ? "0" : exactBalance);
285
- }, [exactBalance]),
286
- onSelectWithdrawProvider: useCallback(
287
- (_providerId) => __async(null, null, function* () {
288
- return handleWithdrawProvider();
289
- }),
290
- [handleWithdrawProvider]
291
- ),
292
- onDoneWithdraw: useCallback(() => handleWithdrawOpenChange(false), [handleWithdrawOpenChange])
293
- };
294
- }
295
-
296
- // src/withdraw/use-withdraw-estimate.ts
297
- import { useMemo as useMemo2 } from "react";
298
- function useWithdrawEstimate({
299
- amount,
300
- selectedToken,
301
- selectedNetwork
302
- }) {
303
- return useMemo2(() => {
304
- const numAmount = Number(amount);
305
- if (!amount || isNaN(numAmount) || numAmount <= 0 || !selectedToken || !selectedNetwork) {
306
- return null;
307
- }
308
- const network = selectedNetwork.toLowerCase();
309
- let feeVal = 0.1;
310
- let reserveVal = 0.2;
311
- if (network === "1" || network === "mainnet" || network === "ethereum") {
312
- feeVal = 1.22;
313
- reserveVal = 0.3;
314
- } else if (network === "137" || network === "polygon") {
315
- feeVal = 0.05;
316
- reserveVal = 0.15;
317
- } else if (network === "42161" || network === "arbitrum") {
318
- feeVal = 0.05;
319
- reserveVal = 0.15;
320
- } else if (network === "8453" || network === "base") {
321
- feeVal = 0.05;
322
- reserveVal = 0.15;
323
- } else if (network === "56" || network === "bnb" || network === "bsc") {
324
- feeVal = 0.1;
325
- reserveVal = 0.2;
326
- } else if (network === "792703809" || network === "solana") {
327
- feeVal = 0.01;
328
- reserveVal = 0.04;
329
- } else if (network === "1337" || network === "hyperliquid") {
330
- feeVal = 0.02;
331
- reserveVal = 0.08;
332
- }
333
- const youReceiveVal = Math.max(0, numAmount - feeVal);
334
- return {
335
- estimatedFees: `~$${feeVal.toFixed(2)}`,
336
- networkReserve: `~$${reserveVal.toFixed(2)}`,
337
- youReceive: `~${youReceiveVal.toFixed(2)} ${selectedToken}`
338
- };
339
- }, [amount, selectedToken, selectedNetwork]);
340
- }
341
-
342
- // src/withdraw/use-withdrawal-lifecycle.ts
343
- import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo3, useRef, useState as useState2 } from "react";
344
- import { useQueryClient } from "@tanstack/react-query";
345
- var INITIAL_STATE = {
346
- pending: true,
347
- status: null,
348
- requestedAmountRaw: null,
349
- completedAmountRaw: null,
350
- feeRaw: null,
351
- terminal: false,
352
- lastLeg: null,
353
- legs: [],
354
- errorMessage: null,
355
- timestamp: null
356
- };
357
- var restLegToWsLeg = (leg) => ({
358
- sourceChainId: leg.sourceChainId,
359
- destChainId: leg.destChainId,
360
- type: leg.type,
361
- // The wire-level WS leg status enum and the REST leg status enum are the
362
- // same union (planned/submitted/confirmed/failed). Keep the cast narrow to
363
- // avoid pulling the SDK enum apart for a one-line bridge.
364
- status: leg.status,
365
- amountRaw: leg.amountRaw,
366
- txHash: leg.txHash,
367
- bridgeOperationId: leg.bridgeOperationId
368
- });
369
- var mergeLegs = (prev, snapshot, delta) => {
370
- if (snapshot) return snapshot;
371
- if (!delta) return prev;
372
- const idx = prev.findIndex(
373
- (l) => l.sourceChainId === delta.sourceChainId && l.destChainId === delta.destChainId && l.type === delta.type
374
- );
375
- if (idx === -1) return [...prev, delta];
376
- const next = prev.slice();
377
- next[idx] = delta;
378
- return next;
379
- };
380
- var restToLifecycleState = (response) => {
381
- var _a, _b, _c;
382
- return {
383
- pending: false,
384
- status: response.status,
385
- requestedAmountRaw: response.requested.amountRaw,
386
- completedAmountRaw: (_a = response.completedAmountRaw) != null ? _a : null,
387
- feeRaw: (_b = response.expected.feeRaw) != null ? _b : null,
388
- terminal: response.status === "completed" || response.status === "partial" || response.status === "failed",
389
- lastLeg: null,
390
- legs: response.legs.map(restLegToWsLeg),
391
- errorMessage: (_c = response.errorMessage) != null ? _c : null,
392
- // No server timestamp on the REST response — we use 0 as "older than any
393
- // WS timestamp" so a subsequent WS event always wins. Callers that read
394
- // `timestamp` should treat 0/null interchangeably as "unset".
395
- timestamp: 0
396
- };
397
- };
398
- function useWithdrawalLifecycle(withdrawalId) {
399
- const client = useAggClient();
400
- const wsConnected = useAggWebSocketConnectionState();
401
- const queryClient = useQueryClient();
402
- const [state, setState] = useState2(INITIAL_STATE);
403
- const stateRef = useRef(state);
404
- stateRef.current = state;
405
- const balanceRefetchedForRef = useRef(null);
406
- useEffect2(() => {
407
- setState(INITIAL_STATE);
408
- }, [withdrawalId]);
409
- useEffect2(() => {
410
- if (!withdrawalId) return;
411
- let cancelled = false;
412
- (() => __async(null, null, function* () {
413
- try {
414
- const response = yield client.getWithdrawalStatus(withdrawalId);
415
- if (cancelled) return;
416
- if (response.withdrawalId !== withdrawalId) return;
417
- const current = stateRef.current;
418
- const wsAlreadyWon = current.timestamp != null && current.timestamp > 0;
419
- if (wsAlreadyWon) return;
420
- setState(restToLifecycleState(response));
421
- } catch (e) {
422
- }
423
- }))();
424
- return () => {
425
- cancelled = true;
426
- };
427
- }, [client, withdrawalId, wsConnected]);
428
- const handler = useMemo3(() => {
429
- if (!withdrawalId) return null;
430
- return (msg) => {
431
- if (msg.withdrawalId !== withdrawalId) return;
432
- setState((prev) => {
433
- var _a, _b, _c, _d, _e;
434
- return {
435
- pending: false,
436
- status: msg.status,
437
- requestedAmountRaw: (_a = msg.requestedAmountRaw) != null ? _a : prev.requestedAmountRaw,
438
- completedAmountRaw: (_b = msg.completedAmountRaw) != null ? _b : prev.completedAmountRaw,
439
- feeRaw: (_c = msg.feeRaw) != null ? _c : null,
440
- terminal: msg.terminal,
441
- lastLeg: (_d = msg.leg) != null ? _d : null,
442
- // `legs[]` is the cumulative server-known truth. Snapshots
443
- // (`pending` / terminal rollup) carry a full `legs[]` and replace
444
- // it. Intermediate per-leg deltas carry only `leg` (no `legs[]`)
445
- // — merge the delta into the existing array by
446
- // (sourceChainId, destChainId, type) so the timeline UI doesn't
447
- // collapse to empty between snapshots.
448
- legs: mergeLegs(prev.legs, msg.legs, msg.leg),
449
- errorMessage: (_e = msg.errorMessage) != null ? _e : null,
450
- timestamp: msg.timestamp
451
- };
452
- });
453
- };
454
- }, [withdrawalId]);
455
- useOnWithdrawalLifecycle(handler);
456
- useEffect2(() => {
457
- if (!withdrawalId) return;
458
- if (!state.terminal) return;
459
- if (balanceRefetchedForRef.current === withdrawalId) return;
460
- balanceRefetchedForRef.current = withdrawalId;
461
- invalidateUserMoneyState(queryClient);
462
- client.syncManagedBalances().catch(() => {
463
- });
464
- }, [client, queryClient, state.terminal, withdrawalId]);
465
- const reset = useCallback2(() => setState(INITIAL_STATE), []);
466
- return { state, reset };
467
- }
468
-
469
- // src/withdraw/use-withdraw-preview.ts
470
- import { useQuery } from "@tanstack/react-query";
471
- function useWithdrawPreview({
472
- amountRaw,
473
- tokenSymbol,
474
- destinationChainId,
475
- destinationAddress,
476
- max
477
- }) {
478
- const client = useAggClient();
479
- const enabled = !!amountRaw && BigInt(amountRaw || "0") > BigInt(0) && !!tokenSymbol && !!destinationChainId && !!destinationAddress;
480
- return useQuery({
481
- queryKey: [
482
- "withdraw-preview",
483
- tokenSymbol,
484
- amountRaw,
485
- destinationChainId,
486
- destinationAddress,
487
- max != null ? max : false
488
- ],
489
- enabled,
490
- staleTime: 15e3,
491
- queryFn: () => client.withdrawPreview(__spreadValues({
492
- amountRaw,
493
- tokenSymbol,
494
- destinationChainId,
495
- destinationAddress
496
- }, max ? { max: true } : {}))
497
- });
498
- }
499
-
500
- export {
501
- useWithdrawFlow,
502
- useWithdrawEstimate,
503
- useWithdrawalLifecycle,
504
- useWithdrawPreview
505
- };
@@ -1,31 +0,0 @@
1
- import {
2
- __async,
3
- useAggClient
4
- } from "./chunk-JFJNW2PD.mjs";
5
-
6
- // src/use-ramp-quotes.ts
7
- import { useMutation } from "@tanstack/react-query";
8
- function useRampQuotes() {
9
- const client = useAggClient();
10
- return useMutation({
11
- mutationFn: (params) => __async(null, null, function* () {
12
- return client.getRampQuotes(params);
13
- })
14
- });
15
- }
16
-
17
- // src/use-ramp-session.ts
18
- import { useMutation as useMutation2 } from "@tanstack/react-query";
19
- function useRampSession() {
20
- const client = useAggClient();
21
- return useMutation2({
22
- mutationFn: (params) => __async(null, null, function* () {
23
- return client.createRampSession(params);
24
- })
25
- });
26
- }
27
-
28
- export {
29
- useRampQuotes,
30
- useRampSession
31
- };