@rhinestone/deposit-modal 0.0.0-dev-20260608080045

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 (40) hide show
  1. package/README.md +134 -0
  2. package/dist/DepositModalReown-6SUEC5IU.mjs +60 -0
  3. package/dist/DepositModalReown-DNW4GH6L.cjs +60 -0
  4. package/dist/QRCode-5DXFNKI2.cjs +58 -0
  5. package/dist/QRCode-WUC652SH.mjs +58 -0
  6. package/dist/WithdrawModalReown-7UAGSOSU.mjs +37 -0
  7. package/dist/WithdrawModalReown-OUWBSKSM.cjs +37 -0
  8. package/dist/caip-CsslyHGL.d.cts +62 -0
  9. package/dist/caip-CsslyHGL.d.ts +62 -0
  10. package/dist/chunk-2SMS542Q.cjs +1654 -0
  11. package/dist/chunk-33H6O5UU.cjs +162 -0
  12. package/dist/chunk-6YRDD462.mjs +614 -0
  13. package/dist/chunk-GPSBM66J.mjs +162 -0
  14. package/dist/chunk-KAWJABTW.mjs +3765 -0
  15. package/dist/chunk-KJ2RR2D4.mjs +7619 -0
  16. package/dist/chunk-MILJQWPT.cjs +614 -0
  17. package/dist/chunk-RABZINV3.cjs +3765 -0
  18. package/dist/chunk-TKQYTBU6.mjs +1654 -0
  19. package/dist/chunk-VVJAIMKB.cjs +7619 -0
  20. package/dist/constants.cjs +70 -0
  21. package/dist/constants.d.cts +21 -0
  22. package/dist/constants.d.ts +21 -0
  23. package/dist/constants.mjs +70 -0
  24. package/dist/deposit.cjs +8 -0
  25. package/dist/deposit.d.cts +11 -0
  26. package/dist/deposit.d.ts +11 -0
  27. package/dist/deposit.mjs +8 -0
  28. package/dist/index.cjs +86 -0
  29. package/dist/index.d.cts +11 -0
  30. package/dist/index.d.ts +11 -0
  31. package/dist/index.mjs +86 -0
  32. package/dist/styles.css +5143 -0
  33. package/dist/styles.d.ts +3 -0
  34. package/dist/types-BMcGO5k_.d.cts +432 -0
  35. package/dist/types-BMcGO5k_.d.ts +432 -0
  36. package/dist/withdraw.cjs +8 -0
  37. package/dist/withdraw.d.cts +11 -0
  38. package/dist/withdraw.d.ts +11 -0
  39. package/dist/withdraw.mjs +8 -0
  40. package/package.json +190 -0
@@ -0,0 +1,1654 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ var _chunkRABZINV3cjs = require('./chunk-RABZINV3.cjs');
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ var _chunkMILJQWPTcjs = require('./chunk-MILJQWPT.cjs');
48
+
49
+ // src/WithdrawModal.tsx
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ var _react = require('react');
59
+
60
+ // src/WithdrawFlow.tsx
61
+
62
+
63
+ // src/store/withdraw.ts
64
+
65
+ var _zustand = require('zustand');
66
+ var _vanilla = require('zustand/vanilla');
67
+ function unreachable(action) {
68
+ throw new Error(
69
+ `[deposit-modal/withdraw-store] Unhandled action: ${JSON.stringify(action)}`
70
+ );
71
+ }
72
+ function applyWithdrawAction(state, action) {
73
+ switch (action.type) {
74
+ case "wallet/id-selected":
75
+ return { ...state, selectedWalletId: action.walletId };
76
+ case "registration/started":
77
+ return {
78
+ ...state,
79
+ registration: state.registration.kind === "ready" ? {
80
+ kind: "stale",
81
+ smartAccount: state.registration.smartAccount,
82
+ registeredTarget: state.registration.registeredTarget
83
+ } : { kind: "pending" }
84
+ };
85
+ case "registration/ready":
86
+ return {
87
+ ...state,
88
+ registration: {
89
+ kind: "ready",
90
+ smartAccount: action.smartAccount,
91
+ registeredTarget: action.registeredTarget
92
+ },
93
+ step: state.step === "connect" ? "form" : state.step
94
+ };
95
+ case "registration/failed":
96
+ return {
97
+ ...state,
98
+ registration: { kind: "failed", error: action.error }
99
+ };
100
+ case "form/continue":
101
+ return {
102
+ ...state,
103
+ amount: action.amount,
104
+ recipient: action.recipient,
105
+ step: "review"
106
+ };
107
+ case "review/back":
108
+ return { ...state, step: "form" };
109
+ case "withdraw/submitted":
110
+ return { ...state, txHash: action.txHash, step: "processing" };
111
+ case "withdraw/complete":
112
+ return { ...state, step: "complete" };
113
+ case "withdraw/failed":
114
+ return { ...state, step: "failed" };
115
+ case "flow/reset":
116
+ return {
117
+ ...state,
118
+ step: "form",
119
+ amount: null,
120
+ recipient: null,
121
+ txHash: null
122
+ };
123
+ case "modal/reset":
124
+ return {
125
+ ...state,
126
+ step: "connect",
127
+ selectedWalletId: null,
128
+ registration: { kind: "idle" },
129
+ amount: null,
130
+ recipient: null,
131
+ txHash: null
132
+ };
133
+ default:
134
+ return unreachable(action);
135
+ }
136
+ }
137
+ function createWithdrawStore() {
138
+ const store = _vanilla.createStore.call(void 0, () => ({
139
+ step: "connect",
140
+ selectedWalletId: null,
141
+ registration: { kind: "idle" },
142
+ amount: null,
143
+ recipient: null,
144
+ txHash: null
145
+ }));
146
+ return {
147
+ ...store,
148
+ dispatch(action) {
149
+ store.setState((state) => applyWithdrawAction(state, action));
150
+ }
151
+ };
152
+ }
153
+ var WithdrawStoreContext = _react.createContext.call(void 0, null);
154
+ function WithdrawStoreProvider({
155
+ store,
156
+ children
157
+ }) {
158
+ return _react.createElement.call(void 0,
159
+ WithdrawStoreContext.Provider,
160
+ { value: store },
161
+ children
162
+ );
163
+ }
164
+ function useWithdrawStoreApi() {
165
+ const store = _react.useContext.call(void 0, WithdrawStoreContext);
166
+ if (!store) {
167
+ throw new Error(
168
+ "useWithdrawStore must be called inside <WithdrawStoreProvider>"
169
+ );
170
+ }
171
+ return store;
172
+ }
173
+ function useWithdrawStore(selector) {
174
+ const store = useWithdrawStoreApi();
175
+ return _zustand.useStore.call(void 0, store, selector);
176
+ }
177
+
178
+ // src/components/steps/WithdrawFormStep.tsx
179
+
180
+ var _viem = require('viem');
181
+ var _jsxruntime = require('react/jsx-runtime');
182
+ function useClickOutside(ref, onClose) {
183
+ _react.useEffect.call(void 0, () => {
184
+ function handleClick(e) {
185
+ if (ref.current && !ref.current.contains(e.target)) {
186
+ onClose();
187
+ }
188
+ }
189
+ document.addEventListener("mousedown", handleClick);
190
+ return () => document.removeEventListener("mousedown", handleClick);
191
+ }, [ref, onClose]);
192
+ }
193
+ function WithdrawFormStep({
194
+ walletClient,
195
+ publicClient,
196
+ connectedRecipient,
197
+ safeAddress,
198
+ asset,
199
+ defaultRecipient,
200
+ defaultAmount,
201
+ targetChain,
202
+ targetToken,
203
+ targetChains,
204
+ targetTokenOptions,
205
+ onTargetChainChange,
206
+ onTargetTokenChange,
207
+ switchChain,
208
+ walletIcon,
209
+ submitting = false,
210
+ registrationPending = false,
211
+ registrationError = null,
212
+ onRecipientChange,
213
+ onSubmit,
214
+ onBalanceUsdChange
215
+ }) {
216
+ const [recipient, setRecipient] = _react.useState.call(void 0, _nullishCoalesce(defaultRecipient, () => ( "")));
217
+ const [amount, setAmount] = _react.useState.call(void 0, _nullishCoalesce(defaultAmount, () => ( "")));
218
+ const [balance, setBalance] = _react.useState.call(void 0, null);
219
+ const [isBalanceLoading, setIsBalanceLoading] = _react.useState.call(void 0, true);
220
+ const [error, setError] = _react.useState.call(void 0, null);
221
+ const [isSwitching, setIsSwitching] = _react.useState.call(void 0, false);
222
+ const [showChainDropdown, setShowChainDropdown] = _react.useState.call(void 0, false);
223
+ const [showTokenDropdown, setShowTokenDropdown] = _react.useState.call(void 0, false);
224
+ const [isSubmitting, setIsSubmitting] = _react.useState.call(void 0, false);
225
+ const hasAttemptedSwitch = _react.useRef.call(void 0, false);
226
+ const chainDropdownRef = _react.useRef.call(void 0, null);
227
+ const tokenDropdownRef = _react.useRef.call(void 0, null);
228
+ const publicClientChainId = _optionalChain([publicClient, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]);
229
+ useClickOutside(chainDropdownRef, () => setShowChainDropdown(false));
230
+ useClickOutside(tokenDropdownRef, () => setShowTokenDropdown(false));
231
+ const preferredConnectedRecipient = _nullishCoalesce(connectedRecipient, () => ( ""));
232
+ const isRecipientConnected = Boolean(
233
+ preferredConnectedRecipient && recipient && recipient.toLowerCase() === preferredConnectedRecipient.toLowerCase()
234
+ );
235
+ const chainMismatch = Boolean(
236
+ _optionalChain([walletClient, 'optionalAccess', _3 => _3.chain, 'optionalAccess', _4 => _4.id]) && walletClient.chain.id !== asset.chainId
237
+ );
238
+ const targetSymbol = _chunkMILJQWPTcjs.getTokenSymbol.call(void 0, targetToken, targetChain);
239
+ const targetChainName = _chunkMILJQWPTcjs.getChainName.call(void 0, targetChain);
240
+ const isBusy = submitting || isSubmitting;
241
+ const seededRecipientRef = _react.useRef.call(void 0, _nullishCoalesce(defaultRecipient, () => ( "")));
242
+ _react.useEffect.call(void 0, () => {
243
+ const nextSeed = _nullishCoalesce(defaultRecipient, () => ( ""));
244
+ setRecipient((current) => {
245
+ if (current === seededRecipientRef.current || current === "") {
246
+ return nextSeed;
247
+ }
248
+ return current;
249
+ });
250
+ seededRecipientRef.current = nextSeed;
251
+ }, [defaultRecipient]);
252
+ _react.useEffect.call(void 0, () => {
253
+ if (chainMismatch && switchChain && !hasAttemptedSwitch.current) {
254
+ hasAttemptedSwitch.current = true;
255
+ setIsSwitching(true);
256
+ switchChain(asset.chainId).catch((err) => {
257
+ const raw = err instanceof Error ? err.message : "Failed to switch chain";
258
+ setError(_chunkRABZINV3cjs.formatUserError.call(void 0, raw));
259
+ }).finally(() => {
260
+ setIsSwitching(false);
261
+ });
262
+ }
263
+ }, [chainMismatch, switchChain, asset.chainId]);
264
+ _react.useEffect.call(void 0, () => {
265
+ hasAttemptedSwitch.current = false;
266
+ }, [asset.chainId]);
267
+ _react.useEffect.call(void 0, () => {
268
+ let active = true;
269
+ let timeoutId;
270
+ let retryDelayMs = 5e3;
271
+ async function fetchBalance() {
272
+ if (!safeAddress || !publicClient) return;
273
+ if (publicClientChainId && publicClientChainId !== asset.chainId) {
274
+ timeoutId = setTimeout(fetchBalance, 1e3);
275
+ return;
276
+ }
277
+ try {
278
+ const bal = _chunkRABZINV3cjs.isNativeAsset.call(void 0, asset) ? await publicClient.getBalance({ address: safeAddress }) : await publicClient.readContract({
279
+ address: asset.token,
280
+ abi: _viem.erc20Abi,
281
+ functionName: "balanceOf",
282
+ args: [safeAddress]
283
+ });
284
+ if (active) {
285
+ setBalance(bal);
286
+ setIsBalanceLoading(false);
287
+ }
288
+ } catch (e2) {
289
+ if (active) {
290
+ setBalance(null);
291
+ timeoutId = setTimeout(fetchBalance, retryDelayMs);
292
+ retryDelayMs = Math.min(Math.round(retryDelayMs * 1.5), 3e4);
293
+ }
294
+ }
295
+ }
296
+ setBalance(null);
297
+ setIsBalanceLoading(true);
298
+ void fetchBalance();
299
+ return () => {
300
+ active = false;
301
+ if (timeoutId) {
302
+ clearTimeout(timeoutId);
303
+ }
304
+ };
305
+ }, [safeAddress, publicClient, publicClientChainId, asset]);
306
+ const formattedBalance = _react.useMemo.call(void 0, () => {
307
+ if (balance === null) return "...";
308
+ try {
309
+ const raw = _viem.formatUnits.call(void 0, balance, asset.decimals);
310
+ const numeric = Number(raw);
311
+ if (!Number.isFinite(numeric)) return raw;
312
+ return new Intl.NumberFormat("en-US", {
313
+ maximumFractionDigits: 2
314
+ }).format(numeric);
315
+ } catch (e3) {
316
+ return "...";
317
+ }
318
+ }, [balance, asset.decimals]);
319
+ _react.useEffect.call(void 0, () => {
320
+ if (balance === null) return;
321
+ const sym = asset.symbol.toUpperCase();
322
+ if (sym !== "USDC" && sym !== "USDT" && sym !== "USDT0") return;
323
+ try {
324
+ const raw = _viem.formatUnits.call(void 0, balance, asset.decimals);
325
+ const numeric = Number(raw);
326
+ if (!Number.isFinite(numeric)) return;
327
+ _optionalChain([onBalanceUsdChange, 'optionalCall', _5 => _5(numeric)]);
328
+ } catch (e4) {
329
+ return;
330
+ }
331
+ }, [balance, asset.decimals, asset.symbol, onBalanceUsdChange]);
332
+ const amountUsd = _react.useMemo.call(void 0, () => {
333
+ if (!amount) return null;
334
+ const parsed = Number(amount);
335
+ if (!Number.isFinite(parsed) || parsed <= 0) return null;
336
+ const sym = asset.symbol.toUpperCase();
337
+ if (sym === "USDC" || sym === "USDT" || sym === "USDT0") {
338
+ return parsed;
339
+ }
340
+ return null;
341
+ }, [amount, asset.symbol]);
342
+ const handleMaxClick = _react.useCallback.call(void 0, () => {
343
+ if (balance === null) return;
344
+ const maxAmount = _viem.formatUnits.call(void 0, balance, asset.decimals);
345
+ setAmount(maxAmount);
346
+ setError(null);
347
+ }, [balance, asset.decimals]);
348
+ const handleUseConnected = _react.useCallback.call(void 0, () => {
349
+ if (!preferredConnectedRecipient) return;
350
+ setRecipient(preferredConnectedRecipient);
351
+ _optionalChain([onRecipientChange, 'optionalCall', _6 => _6(preferredConnectedRecipient)]);
352
+ setError(null);
353
+ }, [preferredConnectedRecipient, onRecipientChange]);
354
+ const handleWithdraw = _react.useCallback.call(void 0, async () => {
355
+ if (!recipient || !/^0x[a-fA-F0-9]{40}$/.test(recipient)) {
356
+ setError("Enter a valid recipient address");
357
+ return;
358
+ }
359
+ const parsed = Number(amount);
360
+ if (!amount || !Number.isFinite(parsed) || parsed <= 0) {
361
+ setError("Enter a valid amount");
362
+ return;
363
+ }
364
+ if (balance !== null) {
365
+ try {
366
+ const amountInUnits = _viem.parseUnits.call(void 0, amount, asset.decimals);
367
+ if (amountInUnits > balance) {
368
+ setError("Insufficient balance");
369
+ return;
370
+ }
371
+ } catch (e5) {
372
+ setError("Invalid amount");
373
+ return;
374
+ }
375
+ }
376
+ setError(null);
377
+ setIsSubmitting(true);
378
+ try {
379
+ await onSubmit(recipient, amount);
380
+ } catch (err) {
381
+ const raw = err instanceof Error ? err.message : "Withdrawal failed";
382
+ setError(_chunkRABZINV3cjs.formatUserError.call(void 0, raw));
383
+ } finally {
384
+ setIsSubmitting(false);
385
+ }
386
+ }, [recipient, amount, balance, asset.decimals, onSubmit]);
387
+ if (isBalanceLoading) {
388
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-screen", children: [
389
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-screen-body rs-withdraw-loading", children: [
390
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.Spinner, { className: "rs-spinner--lg" }),
391
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-withdraw-loading-title", children: "Loading on-chain balance" }),
392
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-withdraw-loading-subtitle", children: chainMismatch ? `Switch to ${_chunkMILJQWPTcjs.getChainName.call(void 0, asset.chainId)} to continue.` : "Please wait before withdrawing." })
393
+ ] }),
394
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.PoweredBy, {})
395
+ ] });
396
+ }
397
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-screen", children: [
398
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-screen-body", children: [
399
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.BodyHeader, { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.CircleArrowOutUpLeftIcon, {}), title: "Withdraw" }),
400
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-section", children: [
401
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
402
+ "label",
403
+ {
404
+ className: "rs-withdraw-label",
405
+ htmlFor: "rs-withdraw-recipient",
406
+ children: "Recipient address"
407
+ }
408
+ ),
409
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-input-row", children: [
410
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
411
+ "input",
412
+ {
413
+ id: "rs-withdraw-recipient",
414
+ type: "text",
415
+ className: "rs-withdraw-input rs-withdraw-input--address",
416
+ placeholder: "0x...",
417
+ value: recipient,
418
+ onChange: (e) => {
419
+ const next = e.target.value.trim();
420
+ setRecipient(next);
421
+ _optionalChain([onRecipientChange, 'optionalCall', _7 => _7(next)]);
422
+ if (error) setError(null);
423
+ }
424
+ }
425
+ ),
426
+ preferredConnectedRecipient && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
427
+ "button",
428
+ {
429
+ type: "button",
430
+ className: `rs-withdraw-use-connected ${isRecipientConnected ? "rs-withdraw-use-connected--active" : ""}`,
431
+ onClick: handleUseConnected,
432
+ title: isRecipientConnected ? "Using connected wallet" : "Use connected wallet",
433
+ children: walletIcon ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
434
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
435
+ "img",
436
+ {
437
+ src: walletIcon,
438
+ alt: "Wallet",
439
+ style: { width: 18, height: 18, borderRadius: 4 },
440
+ className: "rs-withdraw-use-connected-icon"
441
+ }
442
+ ),
443
+ isRecipientConnected ? null : "Use connected"
444
+ ] }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
445
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.WalletIcon, { className: "rs-withdraw-use-connected-icon" }),
446
+ isRecipientConnected ? null : "Use connected"
447
+ ] })
448
+ }
449
+ )
450
+ ] })
451
+ ] }),
452
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-section", children: [
453
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "label", { className: "rs-withdraw-label", htmlFor: "rs-withdraw-amount", children: "Amount" }),
454
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-input-row", children: [
455
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
456
+ "input",
457
+ {
458
+ id: "rs-withdraw-amount",
459
+ type: "text",
460
+ inputMode: "decimal",
461
+ className: "rs-withdraw-input rs-withdraw-input--amount",
462
+ placeholder: "0",
463
+ value: amount,
464
+ onChange: (e) => {
465
+ const value = e.target.value.replace(/[^0-9.]/g, "");
466
+ const parts = value.split(".");
467
+ if (parts.length > 2) return;
468
+ setAmount(value);
469
+ if (error) setError(null);
470
+ }
471
+ }
472
+ ),
473
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-withdraw-amount-right", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
474
+ "button",
475
+ {
476
+ type: "button",
477
+ className: "rs-withdraw-max-btn",
478
+ onClick: handleMaxClick,
479
+ disabled: balance === null,
480
+ children: "Max"
481
+ }
482
+ ) })
483
+ ] }),
484
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-amount-info", children: [
485
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-withdraw-usd", children: amountUsd !== null ? _chunkRABZINV3cjs.currencyFormatter.format(amountUsd) : "$0.00" }),
486
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "rs-withdraw-balance", children: [
487
+ "Balance: ",
488
+ formattedBalance,
489
+ " ",
490
+ asset.symbol
491
+ ] })
492
+ ] })
493
+ ] }),
494
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-receive-row", children: [
495
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-receive-col", children: [
496
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-withdraw-label rs-withdraw-label--sm", children: "Receive chain" }),
497
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
498
+ "div",
499
+ {
500
+ className: "rs-withdraw-dropdown-container",
501
+ ref: chainDropdownRef,
502
+ children: [
503
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
504
+ "button",
505
+ {
506
+ type: "button",
507
+ "aria-label": "Receive chain",
508
+ className: "rs-withdraw-dropdown",
509
+ onClick: () => {
510
+ setShowChainDropdown(!showChainDropdown);
511
+ setShowTokenDropdown(false);
512
+ },
513
+ children: [
514
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-dropdown-value", children: [
515
+ _chunkMILJQWPTcjs.getChainIcon.call(void 0, targetChain) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
516
+ "img",
517
+ {
518
+ src: _chunkMILJQWPTcjs.getChainIcon.call(void 0, targetChain),
519
+ alt: targetChainName,
520
+ className: "rs-withdraw-dropdown-icon"
521
+ }
522
+ ),
523
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: targetChainName })
524
+ ] }),
525
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
526
+ _chunkRABZINV3cjs.ChevronDownIcon,
527
+ {
528
+ className: "rs-withdraw-dropdown-arrow",
529
+ style: {
530
+ transform: showChainDropdown ? "rotate(180deg)" : void 0
531
+ }
532
+ }
533
+ )
534
+ ]
535
+ }
536
+ ),
537
+ showChainDropdown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-withdraw-dropdown-menu", children: targetChains.map((chain) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
538
+ "button",
539
+ {
540
+ type: "button",
541
+ className: "rs-withdraw-dropdown-item",
542
+ onClick: () => {
543
+ onTargetChainChange(chain.id);
544
+ setShowChainDropdown(false);
545
+ },
546
+ children: [
547
+ _chunkMILJQWPTcjs.getChainIcon.call(void 0, chain.id) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
548
+ "img",
549
+ {
550
+ src: _chunkMILJQWPTcjs.getChainIcon.call(void 0, chain.id),
551
+ alt: chain.name,
552
+ className: "rs-withdraw-dropdown-icon"
553
+ }
554
+ ),
555
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: chain.name })
556
+ ]
557
+ },
558
+ chain.id
559
+ )) })
560
+ ]
561
+ }
562
+ )
563
+ ] }),
564
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-receive-col", children: [
565
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-withdraw-label rs-withdraw-label--sm", children: "Receive token" }),
566
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
567
+ "div",
568
+ {
569
+ className: "rs-withdraw-dropdown-container",
570
+ ref: tokenDropdownRef,
571
+ children: [
572
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
573
+ "button",
574
+ {
575
+ type: "button",
576
+ "aria-label": "Receive token",
577
+ className: "rs-withdraw-dropdown",
578
+ onClick: () => {
579
+ setShowTokenDropdown(!showTokenDropdown);
580
+ setShowChainDropdown(false);
581
+ },
582
+ children: [
583
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-withdraw-dropdown-value", children: [
584
+ _chunkMILJQWPTcjs.getTokenIcon.call(void 0, targetSymbol) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
585
+ "img",
586
+ {
587
+ src: _chunkMILJQWPTcjs.getTokenIcon.call(void 0, targetSymbol),
588
+ alt: targetSymbol,
589
+ className: "rs-withdraw-dropdown-icon"
590
+ }
591
+ ),
592
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: targetSymbol })
593
+ ] }),
594
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
595
+ _chunkRABZINV3cjs.ChevronDownIcon,
596
+ {
597
+ className: "rs-withdraw-dropdown-arrow",
598
+ style: {
599
+ transform: showTokenDropdown ? "rotate(180deg)" : void 0
600
+ }
601
+ }
602
+ )
603
+ ]
604
+ }
605
+ ),
606
+ showTokenDropdown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-withdraw-dropdown-menu", children: targetTokenOptions.map((option) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
607
+ "button",
608
+ {
609
+ type: "button",
610
+ className: "rs-withdraw-dropdown-item",
611
+ onClick: () => {
612
+ onTargetTokenChange(option.address);
613
+ setShowTokenDropdown(false);
614
+ },
615
+ children: [
616
+ _chunkMILJQWPTcjs.getTokenIcon.call(void 0, option.symbol) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
617
+ "img",
618
+ {
619
+ src: _chunkMILJQWPTcjs.getTokenIcon.call(void 0, option.symbol),
620
+ alt: option.symbol,
621
+ className: "rs-withdraw-dropdown-icon"
622
+ }
623
+ ),
624
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: option.symbol })
625
+ ]
626
+ },
627
+ option.address
628
+ )) })
629
+ ]
630
+ }
631
+ )
632
+ ] })
633
+ ] }),
634
+ chainMismatch && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-chain-switch", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-chain-switch-text", children: isSwitching ? `Switching to ${_chunkMILJQWPTcjs.getChainName.call(void 0, asset.chainId)}...` : `Switch to ${_chunkMILJQWPTcjs.getChainName.call(void 0, asset.chainId)} to continue.` }) }),
635
+ error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.Callout, { variant: "error", children: error }),
636
+ !error && registrationError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.Callout, { variant: "error", children: registrationError }),
637
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
638
+ _chunkRABZINV3cjs.Button,
639
+ {
640
+ onClick: handleWithdraw,
641
+ fullWidth: true,
642
+ loading: isBusy,
643
+ disabled: !recipient || !amount || chainMismatch || isBusy || Boolean(registrationError),
644
+ children: isBusy ? "Preparing..." : registrationPending ? "Preparing session..." : !recipient ? "Enter Recipient Address" : !amount ? "Enter Withdraw Amount" : "Withdraw"
645
+ }
646
+ )
647
+ ] }),
648
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.PoweredBy, {})
649
+ ] });
650
+ }
651
+ WithdrawFormStep.displayName = "WithdrawFormStep";
652
+
653
+ // src/components/steps/WithdrawReviewStep.tsx
654
+
655
+
656
+ function shortenAddress(addr) {
657
+ return addr.length > 12 ? `${addr.slice(0, 6)}\u2026${addr.slice(-4)}` : addr;
658
+ }
659
+ function WithdrawReviewStep({
660
+ sourceChain,
661
+ sourceSymbol,
662
+ targetChain,
663
+ targetToken,
664
+ amount,
665
+ recipient,
666
+ estimatedTime = "< 1 min",
667
+ registrationPending = false,
668
+ registrationError = null,
669
+ onConfirm,
670
+ onError
671
+ }) {
672
+ const [isSubmitting, setIsSubmitting] = _react.useState.call(void 0, false);
673
+ const [error, setError] = _react.useState.call(void 0, null);
674
+ const sourceChainName = _chunkMILJQWPTcjs.getChainName.call(void 0, sourceChain);
675
+ const sourceChainIcon = _chunkMILJQWPTcjs.getChainIcon.call(void 0, sourceChain);
676
+ const targetSymbol = _chunkMILJQWPTcjs.getTokenSymbol.call(void 0, targetToken, targetChain);
677
+ const targetChainName = _chunkMILJQWPTcjs.getChainName.call(void 0, targetChain);
678
+ const targetChainIcon = _chunkMILJQWPTcjs.getChainIcon.call(void 0, targetChain);
679
+ const sourceTokenIcon = _chunkMILJQWPTcjs.getTokenIcon.call(void 0, sourceSymbol);
680
+ const targetTokenIcon = _chunkMILJQWPTcjs.getTokenIcon.call(void 0, targetSymbol);
681
+ const handleConfirm = async () => {
682
+ setError(null);
683
+ setIsSubmitting(true);
684
+ try {
685
+ await onConfirm();
686
+ } catch (err) {
687
+ const raw = err instanceof Error ? err.message : "Withdraw failed";
688
+ const message = _chunkRABZINV3cjs.formatUserError.call(void 0, raw);
689
+ setError(message);
690
+ _optionalChain([onError, 'optionalCall', _8 => _8(message, "WITHDRAW_REVIEW_ERROR")]);
691
+ } finally {
692
+ setIsSubmitting(false);
693
+ }
694
+ };
695
+ const disabled = isSubmitting || registrationPending || Boolean(registrationError);
696
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-screen", children: [
697
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-screen-body rs-screen-body--gap-32", children: [
698
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
699
+ _chunkRABZINV3cjs.BodyHeader,
700
+ {
701
+ icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.CircleArrowOutUpLeftIcon, {}),
702
+ title: "Review withdrawal"
703
+ }
704
+ ),
705
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-details", children: [
706
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-detail-row", children: [
707
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "You send" }),
708
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "rs-review-detail-value", children: [
709
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [
710
+ amount,
711
+ " ",
712
+ sourceSymbol
713
+ ] }),
714
+ sourceTokenIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: sourceTokenIcon, alt: "" }) })
715
+ ] })
716
+ ] }),
717
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-detail-row", children: [
718
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Source chain" }),
719
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "rs-review-detail-value", children: [
720
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: sourceChainName }),
721
+ sourceChainIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: sourceChainIcon, alt: "" }) })
722
+ ] })
723
+ ] }),
724
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-detail-row", children: [
725
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Recipient" }),
726
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-review-detail-value", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: shortenAddress(recipient) }) })
727
+ ] }),
728
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-detail-row", children: [
729
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Receive" }),
730
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "rs-review-detail-value", children: [
731
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [
732
+ amount,
733
+ " ",
734
+ targetSymbol
735
+ ] }),
736
+ targetTokenIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: targetTokenIcon, alt: "" }) })
737
+ ] })
738
+ ] }),
739
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-detail-row", children: [
740
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Destination chain" }),
741
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "rs-review-detail-value", children: [
742
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: targetChainName }),
743
+ targetChainIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: targetChainIcon, alt: "" }) })
744
+ ] })
745
+ ] }),
746
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-review-detail-row", children: [
747
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Estimated time" }),
748
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "rs-review-detail-value", children: estimatedTime })
749
+ ] })
750
+ ] }),
751
+ error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.Callout, { variant: "error", children: error }),
752
+ !error && registrationError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.Callout, { variant: "error", children: registrationError }),
753
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
754
+ _chunkRABZINV3cjs.Button,
755
+ {
756
+ onClick: handleConfirm,
757
+ loading: isSubmitting,
758
+ loadingText: "Submitting transaction...",
759
+ disabled,
760
+ fullWidth: true,
761
+ children: "Continue"
762
+ }
763
+ )
764
+ ] }),
765
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.PoweredBy, {})
766
+ ] });
767
+ }
768
+ WithdrawReviewStep.displayName = "WithdrawReviewStep";
769
+
770
+ // src/WithdrawFlow.tsx
771
+
772
+
773
+ var ADDR_REGEX = /^0x[a-fA-F0-9]{40}$/;
774
+ var REGISTRATION_DEBOUNCE_MS = 600;
775
+ function resolveSessionOwner(eoaAddress) {
776
+ const localOwner = _chunkRABZINV3cjs.loadSessionOwnerFromStorage.call(void 0, eoaAddress);
777
+ if (localOwner) {
778
+ return {
779
+ account: _chunkRABZINV3cjs.accountFromPrivateKey.call(void 0, localOwner.privateKey),
780
+ address: localOwner.address
781
+ };
782
+ }
783
+ const created = _chunkRABZINV3cjs.createSessionOwnerKey.call(void 0, );
784
+ _chunkRABZINV3cjs.saveSessionOwnerToStorage.call(void 0, eoaAddress, created.privateKey, created.address);
785
+ return { account: created.account, address: created.address };
786
+ }
787
+ function targetsEqual(a, b) {
788
+ if (!a) return false;
789
+ return a.chain === b.chain && a.token.toLowerCase() === b.token.toLowerCase() && (_nullishCoalesce(_optionalChain([a, 'access', _9 => _9.recipient, 'optionalAccess', _10 => _10.toLowerCase, 'call', _11 => _11()]), () => ( ""))) === (_nullishCoalesce(_optionalChain([b, 'access', _12 => _12.recipient, 'optionalAccess', _13 => _13.toLowerCase, 'call', _14 => _14()]), () => ( "")));
790
+ }
791
+ function WithdrawFlow({
792
+ dappWalletClient,
793
+ dappPublicClient,
794
+ dappAddress,
795
+ safeAddress,
796
+ sourceChain,
797
+ sourceToken,
798
+ targetChain: targetChainProp,
799
+ targetToken: targetTokenProp,
800
+ recipient: defaultRecipient,
801
+ amount: defaultAmount,
802
+ service,
803
+ allowedRoutes,
804
+ signerAddress = _chunkMILJQWPTcjs.DEFAULT_SIGNER_ADDRESS,
805
+ sessionChainIds,
806
+ forceRegister = false,
807
+ reownWallet,
808
+ onConnect,
809
+ onDisconnect,
810
+ onSignTransaction,
811
+ onRequestConnect,
812
+ onStepChange,
813
+ onClose,
814
+ onLifecycle,
815
+ onEvent,
816
+ onError,
817
+ debug
818
+ }) {
819
+ const onStepChangeRef = _chunkRABZINV3cjs.useLatestRef.call(void 0, onStepChange);
820
+ const onEventRef = _chunkRABZINV3cjs.useLatestRef.call(void 0, onEvent);
821
+ const onLifecycleRef = _chunkRABZINV3cjs.useLatestRef.call(void 0, onLifecycle);
822
+ const onErrorRef = _chunkRABZINV3cjs.useLatestRef.call(void 0, onError);
823
+ const logFlow = _react.useCallback.call(void 0,
824
+ (message, data) => {
825
+ _chunkRABZINV3cjs.debugLog.call(void 0, debug, "withdraw-flow", message, data);
826
+ },
827
+ [debug]
828
+ );
829
+ const logFlowError = _react.useCallback.call(void 0,
830
+ (message, error, data) => {
831
+ _chunkRABZINV3cjs.debugError.call(void 0, debug, "withdraw-flow", message, error, data);
832
+ },
833
+ [debug]
834
+ );
835
+ const [targetChain, setTargetChain] = _react.useState.call(void 0, targetChainProp);
836
+ const [targetToken, setTargetToken] = _react.useState.call(void 0, targetTokenProp);
837
+ const [recipientInput, setRecipientInput] = _react.useState.call(void 0,
838
+ _nullishCoalesce(defaultRecipient, () => ( ""))
839
+ );
840
+ const [totalBalanceUsd, setTotalBalanceUsd] = _react.useState.call(void 0, 0);
841
+ const [isConnectSelectionConfirmed, setIsConnectSelectionConfirmed] = _react.useState.call(void 0, false);
842
+ _react.useEffect.call(void 0, () => {
843
+ setTargetChain(targetChainProp);
844
+ setTargetToken(targetTokenProp);
845
+ }, [targetChainProp, targetTokenProp]);
846
+ _react.useEffect.call(void 0, () => {
847
+ if (defaultRecipient) setRecipientInput(defaultRecipient);
848
+ }, [defaultRecipient]);
849
+ const hasCustomSigner = Boolean(dappAddress && onSignTransaction);
850
+ const dappSwitchChain = _react.useMemo.call(void 0, () => {
851
+ if (!_optionalChain([dappWalletClient, 'optionalAccess', _15 => _15.switchChain])) return void 0;
852
+ return async (chainId) => {
853
+ await _optionalChain([dappWalletClient, 'access', _16 => _16.switchChain, 'optionalCall', _17 => _17({ id: chainId })]);
854
+ };
855
+ }, [dappWalletClient]);
856
+ const walletOptions = _react.useMemo.call(void 0, () => {
857
+ const options = [];
858
+ const seen = /* @__PURE__ */ new Set();
859
+ if (_optionalChain([dappWalletClient, 'optionalAccess', _18 => _18.account]) && dappAddress) {
860
+ const id = `evm:${dappWalletClient.account.address.toLowerCase()}`;
861
+ options.push({
862
+ id,
863
+ address: dappWalletClient.account.address,
864
+ label: "Connected Wallet",
865
+ kind: "connected"
866
+ });
867
+ seen.add(id);
868
+ }
869
+ if (_optionalChain([reownWallet, 'optionalAccess', _19 => _19.address]) && reownWallet.isConnected && reownWallet.walletClient && reownWallet.publicClient) {
870
+ const id = `evm:${reownWallet.address.toLowerCase()}`;
871
+ if (!seen.has(id)) {
872
+ options.push({
873
+ id,
874
+ address: reownWallet.address,
875
+ label: "External Wallet",
876
+ kind: "external",
877
+ icon: reownWallet.icon
878
+ });
879
+ }
880
+ }
881
+ return options;
882
+ }, [
883
+ dappWalletClient,
884
+ dappAddress,
885
+ _optionalChain([reownWallet, 'optionalAccess', _20 => _20.address]),
886
+ _optionalChain([reownWallet, 'optionalAccess', _21 => _21.isConnected]),
887
+ _optionalChain([reownWallet, 'optionalAccess', _22 => _22.walletClient]),
888
+ _optionalChain([reownWallet, 'optionalAccess', _23 => _23.publicClient]),
889
+ _optionalChain([reownWallet, 'optionalAccess', _24 => _24.icon])
890
+ ]);
891
+ const canAutoLock = hasCustomSigner || Boolean(_optionalChain([dappWalletClient, 'optionalAccess', _25 => _25.account]) && dappAddress) && !reownWallet;
892
+ const storeApi = useWithdrawStoreApi();
893
+ const selectedWalletId = useWithdrawStore((s) => s.selectedWalletId);
894
+ const registration = useWithdrawStore((s) => s.registration);
895
+ const flowStep = useWithdrawStore((s) => s.step);
896
+ const setSelectedWalletId = _react.useCallback.call(void 0,
897
+ (walletId) => storeApi.dispatch({ type: "wallet/id-selected", walletId }),
898
+ [storeApi]
899
+ );
900
+ const signerContext = _react.useMemo.call(void 0, () => {
901
+ if (canAutoLock) {
902
+ if (hasCustomSigner) {
903
+ return {
904
+ ownerAddress: dappAddress,
905
+ walletClient: _nullishCoalesce(dappWalletClient, () => ( void 0)),
906
+ publicClient: _nullishCoalesce(dappPublicClient, () => ( _chunkRABZINV3cjs.getPublicClient.call(void 0, sourceChain))),
907
+ switchChain: dappSwitchChain
908
+ };
909
+ }
910
+ return {
911
+ ownerAddress: dappWalletClient.account.address,
912
+ walletClient: dappWalletClient,
913
+ publicClient: _nullishCoalesce(dappPublicClient, () => ( _chunkRABZINV3cjs.getPublicClient.call(void 0, sourceChain))),
914
+ switchChain: dappSwitchChain
915
+ };
916
+ }
917
+ if (!isConnectSelectionConfirmed || !selectedWalletId) return null;
918
+ const selectedOption = walletOptions.find((o) => o.id === selectedWalletId);
919
+ if (!selectedOption || !selectedOption.address) return null;
920
+ if (selectedOption.kind === "connected" && _optionalChain([dappWalletClient, 'optionalAccess', _26 => _26.account]) && dappWalletClient.account.address.toLowerCase() === selectedOption.address.toLowerCase()) {
921
+ return {
922
+ ownerAddress: dappWalletClient.account.address,
923
+ walletClient: dappWalletClient,
924
+ publicClient: _nullishCoalesce(dappPublicClient, () => ( _chunkRABZINV3cjs.getPublicClient.call(void 0, sourceChain))),
925
+ switchChain: dappSwitchChain
926
+ };
927
+ }
928
+ if (selectedOption.kind === "external" && _optionalChain([reownWallet, 'optionalAccess', _27 => _27.address, 'optionalAccess', _28 => _28.toLowerCase, 'call', _29 => _29()]) === selectedOption.address.toLowerCase() && reownWallet.walletClient && reownWallet.publicClient) {
929
+ return {
930
+ ownerAddress: reownWallet.address,
931
+ walletClient: reownWallet.walletClient,
932
+ publicClient: reownWallet.publicClient,
933
+ switchChain: reownWallet.switchChain
934
+ };
935
+ }
936
+ return null;
937
+ }, [
938
+ canAutoLock,
939
+ hasCustomSigner,
940
+ isConnectSelectionConfirmed,
941
+ selectedWalletId,
942
+ walletOptions,
943
+ dappWalletClient,
944
+ dappPublicClient,
945
+ dappSwitchChain,
946
+ dappAddress,
947
+ reownWallet,
948
+ sourceChain
949
+ ]);
950
+ const ownerAddress = _optionalChain([signerContext, 'optionalAccess', _30 => _30.ownerAddress]);
951
+ const recipientForRegistration = _react.useMemo.call(void 0, () => {
952
+ if (!recipientInput) return void 0;
953
+ return ADDR_REGEX.test(recipientInput) ? recipientInput : void 0;
954
+ }, [recipientInput]);
955
+ _react.useEffect.call(void 0, () => {
956
+ if (!ownerAddress) return;
957
+ const desiredTarget = {
958
+ chain: targetChain,
959
+ token: targetToken,
960
+ recipient: recipientForRegistration
961
+ };
962
+ const current = storeApi.getState().registration;
963
+ if (current.kind === "ready" && targetsEqual(current.registeredTarget, desiredTarget)) {
964
+ return;
965
+ }
966
+ let cancelled = false;
967
+ const timeout = setTimeout(async () => {
968
+ try {
969
+ storeApi.dispatch({ type: "registration/started" });
970
+ const sessionOwner = resolveSessionOwner(ownerAddress);
971
+ if (cancelled) return;
972
+ logFlow("auto-register:setup", {
973
+ ownerAddress,
974
+ targetChain,
975
+ targetToken,
976
+ recipient: recipientForRegistration
977
+ });
978
+ const setup = await service.setupAccount({
979
+ ownerAddress,
980
+ sessionOwnerAddress: sessionOwner.address,
981
+ targetChain: _chunkMILJQWPTcjs.toEvmCaip2.call(void 0, targetChain),
982
+ targetToken,
983
+ recipient: recipientForRegistration,
984
+ signerAddress,
985
+ sessionChainIds,
986
+ forceRegister
987
+ });
988
+ if (cancelled) return;
989
+ if (setup.needsRegistration) {
990
+ if (!setup.accountParams || !setup.sessionDetailsUnsigned) {
991
+ throw new Error("Missing registration payload from setup-account");
992
+ }
993
+ const typedData = setup.sessionDetailsUnsigned.data;
994
+ if (!sessionOwner.account.signTypedData) {
995
+ throw new Error(
996
+ "Session owner account does not support signTypedData"
997
+ );
998
+ }
999
+ const signature = await sessionOwner.account.signTypedData({
1000
+ domain: typedData.domain,
1001
+ types: typedData.types,
1002
+ primaryType: typedData.primaryType,
1003
+ message: typedData.message
1004
+ });
1005
+ if (cancelled) return;
1006
+ const sessionDetails = _chunkRABZINV3cjs.buildSessionDetails.call(void 0,
1007
+ setup.sessionDetailsUnsigned,
1008
+ signature
1009
+ );
1010
+ await service.registerAccount({
1011
+ address: setup.smartAccount,
1012
+ accountParams: {
1013
+ factory: setup.accountParams.factory,
1014
+ factoryData: setup.accountParams.factoryData,
1015
+ sessionDetails
1016
+ },
1017
+ eoaAddress: ownerAddress,
1018
+ sessionOwner: sessionOwner.address,
1019
+ target: {
1020
+ chain: _chunkMILJQWPTcjs.toEvmCaip2.call(void 0, targetChain),
1021
+ token: targetToken,
1022
+ recipient: recipientForRegistration
1023
+ }
1024
+ });
1025
+ if (cancelled) return;
1026
+ logFlow("auto-register:registered", {
1027
+ smartAccount: setup.smartAccount
1028
+ });
1029
+ }
1030
+ storeApi.dispatch({
1031
+ type: "registration/ready",
1032
+ smartAccount: setup.smartAccount,
1033
+ registeredTarget: desiredTarget
1034
+ });
1035
+ _optionalChain([onLifecycleRef, 'access', _31 => _31.current, 'optionalCall', _32 => _32({
1036
+ type: "connected",
1037
+ address: ownerAddress,
1038
+ smartAccount: setup.smartAccount
1039
+ })]);
1040
+ } catch (err) {
1041
+ if (cancelled) return;
1042
+ const raw = err instanceof Error ? err.message : "Registration failed";
1043
+ const message = _chunkRABZINV3cjs.formatUserError.call(void 0, raw);
1044
+ logFlowError("auto-register:failed", err, {
1045
+ ownerAddress,
1046
+ targetChain,
1047
+ targetToken
1048
+ });
1049
+ storeApi.dispatch({
1050
+ type: "registration/failed",
1051
+ error: message
1052
+ });
1053
+ _optionalChain([onErrorRef, 'access', _33 => _33.current, 'optionalCall', _34 => _34({ message, code: "WITHDRAW_REGISTER_FAILED" })]);
1054
+ }
1055
+ }, REGISTRATION_DEBOUNCE_MS);
1056
+ return () => {
1057
+ cancelled = true;
1058
+ clearTimeout(timeout);
1059
+ };
1060
+ }, [
1061
+ ownerAddress,
1062
+ targetChain,
1063
+ targetToken,
1064
+ recipientForRegistration,
1065
+ service,
1066
+ signerAddress,
1067
+ sessionChainIds,
1068
+ forceRegister,
1069
+ storeApi,
1070
+ logFlow,
1071
+ logFlowError,
1072
+ onLifecycleRef,
1073
+ onErrorRef
1074
+ ]);
1075
+ const asset = _react.useMemo.call(void 0, () => {
1076
+ const symbol = _chunkMILJQWPTcjs.getTokenSymbol.call(void 0, sourceToken, sourceChain);
1077
+ const decimals = _chunkMILJQWPTcjs.getTokenDecimalsByAddress.call(void 0, sourceToken, sourceChain);
1078
+ return {
1079
+ id: _chunkRABZINV3cjs.getAssetId.call(void 0, { chainId: sourceChain, token: sourceToken }),
1080
+ chainId: sourceChain,
1081
+ token: sourceToken,
1082
+ symbol,
1083
+ name: symbol,
1084
+ decimals
1085
+ };
1086
+ }, [sourceChain, sourceToken]);
1087
+ const isSourceNative = sourceToken.toLowerCase() === _chunkMILJQWPTcjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
1088
+ const isSameRoute = targetChain === sourceChain && targetToken.toLowerCase() === sourceToken.toLowerCase();
1089
+ const reviewBackHandler = _react.useCallback.call(void 0, () => {
1090
+ storeApi.dispatch({ type: "review/back" });
1091
+ }, [storeApi]);
1092
+ _react.useEffect.call(void 0, () => {
1093
+ _optionalChain([onStepChangeRef, 'access', _35 => _35.current, 'optionalCall', _36 => _36(
1094
+ flowStep === "review" ? reviewBackHandler : void 0
1095
+ )]);
1096
+ }, [flowStep, reviewBackHandler, onStepChangeRef]);
1097
+ const lastStepOpenEventKeyRef = _react.useRef.call(void 0, null);
1098
+ _react.useEffect.call(void 0, () => {
1099
+ if (flowStep !== "form") {
1100
+ lastStepOpenEventKeyRef.current = null;
1101
+ return;
1102
+ }
1103
+ if (lastStepOpenEventKeyRef.current === "form") return;
1104
+ lastStepOpenEventKeyRef.current = "form";
1105
+ const tokenSymbol = _chunkMILJQWPTcjs.getTokenSymbol.call(void 0, targetToken, targetChain);
1106
+ const chainName = _chunkMILJQWPTcjs.getChainName.call(void 0, targetChain);
1107
+ _optionalChain([onEventRef, 'access', _37 => _37.current, 'optionalCall', _38 => _38({
1108
+ type: "withdraw_modal_select_amount_open",
1109
+ pred_balance: totalBalanceUsd,
1110
+ default_token: tokenSymbol,
1111
+ default_chain: chainName
1112
+ })]);
1113
+ }, [flowStep, targetToken, targetChain, totalBalanceUsd, onEventRef]);
1114
+ _react.useEffect.call(void 0, () => {
1115
+ logFlow("state:changed", {
1116
+ step: flowStep,
1117
+ sourceChain,
1118
+ sourceToken,
1119
+ targetChain,
1120
+ targetToken,
1121
+ selectedWalletId,
1122
+ registration: registration.kind
1123
+ });
1124
+ }, [
1125
+ logFlow,
1126
+ selectedWalletId,
1127
+ sourceChain,
1128
+ sourceToken,
1129
+ flowStep,
1130
+ targetChain,
1131
+ targetToken,
1132
+ registration.kind
1133
+ ]);
1134
+ const handleError = _react.useCallback.call(void 0,
1135
+ (message, code) => {
1136
+ logFlowError("flow:error", message, { code });
1137
+ _optionalChain([onErrorRef, 'access', _39 => _39.current, 'optionalCall', _40 => _40({ message, code })]);
1138
+ },
1139
+ [logFlowError, onErrorRef]
1140
+ );
1141
+ const handleFormContinue = _react.useCallback.call(void 0,
1142
+ (recipient, amountValue) => {
1143
+ const tokenSymbol = _chunkMILJQWPTcjs.getTokenSymbol.call(void 0, targetToken, targetChain);
1144
+ const chainName = _chunkMILJQWPTcjs.getChainName.call(void 0, targetChain);
1145
+ _optionalChain([onEventRef, 'access', _41 => _41.current, 'optionalCall', _42 => _42({
1146
+ type: "withdraw_modal_select_amount_cta_click",
1147
+ pred_balance: totalBalanceUsd,
1148
+ selected_token: tokenSymbol,
1149
+ selected_chain: chainName,
1150
+ amount: amountValue,
1151
+ cta_name: "withdraw"
1152
+ })]);
1153
+ storeApi.dispatch({
1154
+ type: "form/continue",
1155
+ amount: amountValue,
1156
+ recipient
1157
+ });
1158
+ },
1159
+ [targetToken, targetChain, totalBalanceUsd, onEventRef, storeApi]
1160
+ );
1161
+ const handleReviewConfirm = _react.useCallback.call(void 0,
1162
+ async () => {
1163
+ const state = storeApi.getState();
1164
+ if (state.registration.kind !== "ready") {
1165
+ throw new Error("Session not ready");
1166
+ }
1167
+ const smartAccount = state.registration.smartAccount;
1168
+ const recipient = state.recipient;
1169
+ const amountValue = state.amount;
1170
+ if (!recipient || !amountValue) {
1171
+ throw new Error("Missing recipient or amount");
1172
+ }
1173
+ if (!onSignTransaction && !_optionalChain([signerContext, 'optionalAccess', _43 => _43.walletClient])) {
1174
+ throw new Error("Wallet not connected");
1175
+ }
1176
+ try {
1177
+ logFlow("submit:start", {
1178
+ smartAccount,
1179
+ recipient,
1180
+ amount: amountValue,
1181
+ sourceChain,
1182
+ sourceToken,
1183
+ targetChain,
1184
+ targetToken
1185
+ });
1186
+ const amountUnits = _viem.parseUnits.call(void 0, amountValue, asset.decimals);
1187
+ const pc = _nullishCoalesce(_optionalChain([signerContext, 'optionalAccess', _44 => _44.publicClient]), () => ( _chunkRABZINV3cjs.getPublicClient.call(void 0, sourceChain)));
1188
+ let result;
1189
+ if (onSignTransaction) {
1190
+ const transferTarget = isSameRoute ? recipient : smartAccount;
1191
+ const transferData = isSourceNative ? { to: transferTarget, value: amountUnits, data: "0x" } : {
1192
+ to: sourceToken,
1193
+ value: 0n,
1194
+ data: _viem.encodeFunctionData.call(void 0, {
1195
+ abi: _viem.erc20Abi,
1196
+ functionName: "transfer",
1197
+ args: [transferTarget, amountUnits]
1198
+ })
1199
+ };
1200
+ const request = await _chunkRABZINV3cjs.buildSafeTransaction.call(void 0, {
1201
+ publicClient: pc,
1202
+ safeAddress,
1203
+ to: transferData.to,
1204
+ value: transferData.value,
1205
+ data: transferData.data,
1206
+ chainId: sourceChain
1207
+ });
1208
+ const { signature } = await onSignTransaction(request);
1209
+ const relayResult = await service.relayWithdraw({
1210
+ smartAccount,
1211
+ chainId: _chunkMILJQWPTcjs.toEvmCaip2.call(void 0, sourceChain),
1212
+ safeAddress,
1213
+ safeTransaction: request.typedData.message,
1214
+ signature
1215
+ });
1216
+ if (!relayResult.txHash) {
1217
+ throw new Error("Relay succeeded but no txHash returned");
1218
+ }
1219
+ result = { txHash: relayResult.txHash };
1220
+ } else if (isSourceNative) {
1221
+ result = await _chunkRABZINV3cjs.executeSafeEthTransfer.call(void 0, {
1222
+ walletClient: signerContext.walletClient,
1223
+ publicClient: pc,
1224
+ safeAddress,
1225
+ recipient: isSameRoute ? recipient : smartAccount,
1226
+ amount: amountUnits,
1227
+ chainId: sourceChain
1228
+ });
1229
+ } else {
1230
+ result = await _chunkRABZINV3cjs.executeSafeErc20Transfer.call(void 0, {
1231
+ walletClient: signerContext.walletClient,
1232
+ publicClient: pc,
1233
+ safeAddress,
1234
+ tokenAddress: sourceToken,
1235
+ recipient: isSameRoute ? recipient : smartAccount,
1236
+ amount: amountUnits,
1237
+ chainId: sourceChain
1238
+ });
1239
+ }
1240
+ logFlow("withdraw:submitted", {
1241
+ txHash: result.txHash,
1242
+ smartAccount,
1243
+ amount: amountUnits.toString(),
1244
+ sourceChain,
1245
+ sourceToken
1246
+ });
1247
+ _optionalChain([onLifecycleRef, 'access', _45 => _45.current, 'optionalCall', _46 => _46({
1248
+ type: "submitted",
1249
+ txHash: result.txHash,
1250
+ sourceChain,
1251
+ amount: amountUnits.toString(),
1252
+ safeAddress
1253
+ })]);
1254
+ storeApi.dispatch({ type: "withdraw/submitted", txHash: result.txHash });
1255
+ } catch (err) {
1256
+ const raw = err instanceof Error ? err.message : "Withdraw failed";
1257
+ logFlowError("submit:failed", err, {
1258
+ sourceChain,
1259
+ sourceToken,
1260
+ targetChain,
1261
+ targetToken
1262
+ });
1263
+ handleError(_chunkRABZINV3cjs.formatUserError.call(void 0, raw), "WITHDRAW_FLOW_ERROR");
1264
+ throw err;
1265
+ }
1266
+ },
1267
+ [
1268
+ signerContext,
1269
+ targetChain,
1270
+ targetToken,
1271
+ service,
1272
+ asset.decimals,
1273
+ safeAddress,
1274
+ sourceToken,
1275
+ sourceChain,
1276
+ onSignTransaction,
1277
+ isSourceNative,
1278
+ isSameRoute,
1279
+ handleError,
1280
+ logFlow,
1281
+ logFlowError,
1282
+ onLifecycleRef,
1283
+ storeApi
1284
+ ]
1285
+ );
1286
+ const handleWithdrawComplete = _react.useCallback.call(void 0,
1287
+ (txHash, destinationTxHash, context) => {
1288
+ logFlow("withdraw:complete", { txHash, destinationTxHash, ...context });
1289
+ _optionalChain([onLifecycleRef, 'access', _47 => _47.current, 'optionalCall', _48 => _48({
1290
+ type: "complete",
1291
+ txHash,
1292
+ destinationTxHash,
1293
+ amount: context.amount,
1294
+ // Withdraw targets are always EVM — WithdrawModalProps.targetChain is
1295
+ // Chain | number (never "solana"). The context union is wide only
1296
+ // because ProcessingStep is shared with the deposit flow, so narrow
1297
+ // back here.
1298
+ sourceChain: context.sourceChain,
1299
+ sourceToken: context.sourceToken,
1300
+ targetChain: context.targetChain,
1301
+ targetToken: context.targetToken
1302
+ })]);
1303
+ storeApi.dispatch({ type: "withdraw/complete" });
1304
+ },
1305
+ [logFlow, onLifecycleRef, storeApi]
1306
+ );
1307
+ const handleWithdrawFailed = _react.useCallback.call(void 0,
1308
+ (txHash, error) => {
1309
+ logFlowError("withdraw:failed", error, { txHash });
1310
+ _optionalChain([onLifecycleRef, 'access', _49 => _49.current, 'optionalCall', _50 => _50({
1311
+ type: "failed",
1312
+ txHash,
1313
+ error
1314
+ })]);
1315
+ storeApi.dispatch({ type: "withdraw/failed" });
1316
+ },
1317
+ [logFlowError, onLifecycleRef, storeApi]
1318
+ );
1319
+ const allowedChainSet = _react.useMemo.call(void 0,
1320
+ () => _optionalChain([allowedRoutes, 'optionalAccess', _51 => _51.sourceChains]) ? new Set(allowedRoutes.sourceChains) : null,
1321
+ [_optionalChain([allowedRoutes, 'optionalAccess', _52 => _52.sourceChains])]
1322
+ );
1323
+ const allowedTokenSet = _react.useMemo.call(void 0,
1324
+ () => _optionalChain([allowedRoutes, 'optionalAccess', _53 => _53.sourceTokens]) ? new Set(allowedRoutes.sourceTokens.map((s) => s.toUpperCase())) : null,
1325
+ [_optionalChain([allowedRoutes, 'optionalAccess', _54 => _54.sourceTokens])]
1326
+ );
1327
+ const targetChainOptions = _react.useMemo.call(void 0, () => {
1328
+ return _chunkMILJQWPTcjs.SOURCE_CHAINS.filter((chain) => {
1329
+ if (allowedChainSet && !allowedChainSet.has(chain.id)) return false;
1330
+ const tokens = _chunkMILJQWPTcjs.getSupportedTargetTokens.call(void 0, chain.id);
1331
+ if (allowedTokenSet) {
1332
+ return tokens.some((t) => allowedTokenSet.has(t.symbol.toUpperCase()));
1333
+ }
1334
+ return tokens.length > 0;
1335
+ });
1336
+ }, [allowedChainSet, allowedTokenSet]);
1337
+ const targetTokenOptions = _react.useMemo.call(void 0, () => {
1338
+ const tokens = _chunkMILJQWPTcjs.getSupportedTargetTokens.call(void 0, targetChain);
1339
+ if (!allowedTokenSet) return tokens;
1340
+ return tokens.filter((t) => allowedTokenSet.has(t.symbol.toUpperCase()));
1341
+ }, [targetChain, allowedTokenSet]);
1342
+ _react.useEffect.call(void 0, () => {
1343
+ if (targetTokenOptions.length === 0) return;
1344
+ const matches = targetTokenOptions.some(
1345
+ (option) => option.address.toLowerCase() === targetToken.toLowerCase()
1346
+ );
1347
+ if (!matches) setTargetToken(targetTokenOptions[0].address);
1348
+ }, [targetToken, targetTokenOptions]);
1349
+ const handleTargetChainChange = _react.useCallback.call(void 0,
1350
+ (chainId) => {
1351
+ setTargetChain(chainId);
1352
+ let options = _chunkMILJQWPTcjs.getSupportedTargetTokens.call(void 0, chainId);
1353
+ if (allowedTokenSet) {
1354
+ options = options.filter(
1355
+ (t) => allowedTokenSet.has(t.symbol.toUpperCase())
1356
+ );
1357
+ }
1358
+ if (options.length === 0) return;
1359
+ const currentlySupported = options.some(
1360
+ (option) => option.address.toLowerCase() === targetToken.toLowerCase()
1361
+ );
1362
+ setTargetToken(
1363
+ currentlySupported ? targetToken : options[0].address
1364
+ );
1365
+ },
1366
+ [targetToken, allowedTokenSet]
1367
+ );
1368
+ const handleTargetTokenChange = _react.useCallback.call(void 0, (token) => {
1369
+ setTargetToken(token);
1370
+ }, []);
1371
+ const selectedWalletIdEffective = _react.useMemo.call(void 0, () => {
1372
+ if (selectedWalletId) return selectedWalletId;
1373
+ if (walletOptions.length === 1) return walletOptions[0].id;
1374
+ return null;
1375
+ }, [selectedWalletId, walletOptions]);
1376
+ const walletOptionsKey = _react.useMemo.call(void 0,
1377
+ () => walletOptions.map((o) => o.id).join(","),
1378
+ [walletOptions]
1379
+ );
1380
+ const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
1381
+ _react.useEffect.call(void 0, () => {
1382
+ setIsConnectSelectionConfirmed(false);
1383
+ }, [walletOptionsKey]);
1384
+ const selectedWalletOption = selectedWalletIdEffective ? _nullishCoalesce(walletOptions.find((o) => o.id === selectedWalletIdEffective), () => ( null)) : null;
1385
+ const selectedWalletIcon = _react.useMemo.call(void 0, () => {
1386
+ if (!ownerAddress) return void 0;
1387
+ const selected = walletOptions.find(
1388
+ (o) => _optionalChain([o, 'access', _55 => _55.address, 'optionalAccess', _56 => _56.toLowerCase, 'call', _57 => _57()]) === ownerAddress.toLowerCase()
1389
+ );
1390
+ return _optionalChain([selected, 'optionalAccess', _58 => _58.kind]) === "external" ? _nullishCoalesce(selected.icon, () => ( _optionalChain([reownWallet, 'optionalAccess', _59 => _59.icon]))) : void 0;
1391
+ }, [walletOptions, ownerAddress, _optionalChain([reownWallet, 'optionalAccess', _60 => _60.icon])]);
1392
+ if (showConnectStep) {
1393
+ const withdrawRows = walletOptions.map((option) => ({
1394
+ id: option.id,
1395
+ kind: option.kind,
1396
+ label: option.label,
1397
+ icon: option.icon,
1398
+ address: _nullishCoalesce(_nullishCoalesce(option.address, () => ( option.solanaAddress)), () => ( option.id)),
1399
+ state: "ready"
1400
+ }));
1401
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-modal-body", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1402
+ _chunkRABZINV3cjs.ConnectStep,
1403
+ {
1404
+ walletRows: withdrawRows,
1405
+ onConfirmWallet: (walletId) => {
1406
+ setSelectedWalletId(walletId);
1407
+ setIsConnectSelectionConfirmed(true);
1408
+ },
1409
+ onRequestConnect,
1410
+ onConnect,
1411
+ onDisconnect,
1412
+ title: "Withdraw",
1413
+ subtitle: "Choose a wallet to continue"
1414
+ }
1415
+ ) });
1416
+ }
1417
+ if (!signerContext) return null;
1418
+ if (!onSignTransaction && !signerContext.walletClient) return null;
1419
+ const resolvedConnectedRecipient = _optionalChain([selectedWalletOption, 'optionalAccess', _61 => _61.kind]) === "external" ? selectedWalletOption.address : void 0;
1420
+ const formPublicClient = _nullishCoalesce(signerContext.publicClient, () => ( _chunkRABZINV3cjs.getPublicClient.call(void 0, sourceChain)));
1421
+ const stepView = deriveStepView(flowStep, registration);
1422
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-modal-body", children: [
1423
+ stepView === "form" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1424
+ WithdrawFormStep,
1425
+ {
1426
+ walletClient: signerContext.walletClient,
1427
+ publicClient: formPublicClient,
1428
+ connectedRecipient: resolvedConnectedRecipient,
1429
+ safeAddress,
1430
+ asset,
1431
+ defaultRecipient,
1432
+ defaultAmount,
1433
+ targetChain,
1434
+ targetToken,
1435
+ targetChains: targetChainOptions,
1436
+ targetTokenOptions,
1437
+ onTargetChainChange: handleTargetChainChange,
1438
+ onTargetTokenChange: handleTargetTokenChange,
1439
+ switchChain: signerContext.switchChain,
1440
+ walletIcon: selectedWalletIcon,
1441
+ registrationPending: registration.kind === "pending" || registration.kind === "stale",
1442
+ registrationError: registration.kind === "failed" ? registration.error : null,
1443
+ onRecipientChange: setRecipientInput,
1444
+ onSubmit: async (r, a) => handleFormContinue(r, a),
1445
+ onBalanceUsdChange: setTotalBalanceUsd
1446
+ }
1447
+ ),
1448
+ stepView === "review" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1449
+ WithdrawReviewStep,
1450
+ {
1451
+ sourceChain,
1452
+ sourceSymbol: asset.symbol,
1453
+ targetChain,
1454
+ targetToken,
1455
+ amount: _nullishCoalesce(storeApi.getState().amount, () => ( "0")),
1456
+ recipient: _nullishCoalesce(_nullishCoalesce(storeApi.getState().recipient, () => ( recipientForRegistration)), () => ( "0x0")),
1457
+ registrationPending: registration.kind === "pending" || registration.kind === "stale",
1458
+ registrationError: registration.kind === "failed" ? registration.error : null,
1459
+ onConfirm: handleReviewConfirm,
1460
+ onError: handleError
1461
+ }
1462
+ ),
1463
+ stepView === "processing" && registration.kind !== "idle" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1464
+ _chunkRABZINV3cjs.ProcessingStep,
1465
+ {
1466
+ smartAccount: registration.kind === "ready" || registration.kind === "stale" ? registration.smartAccount : "0x0",
1467
+ txHash: _nullishCoalesce(storeApi.getState().txHash, () => ( "0x0")),
1468
+ sourceChain,
1469
+ sourceToken,
1470
+ targetChain,
1471
+ targetToken,
1472
+ amount: _nullishCoalesce(storeApi.getState().amount, () => ( "0")),
1473
+ directTransfer: isSameRoute,
1474
+ service,
1475
+ flowLabel: "withdraw",
1476
+ onClose,
1477
+ onNewDeposit: () => storeApi.dispatch({ type: "flow/reset" }),
1478
+ onDepositComplete: handleWithdrawComplete,
1479
+ onDepositFailed: handleWithdrawFailed,
1480
+ onError: handleError,
1481
+ debug
1482
+ }
1483
+ )
1484
+ ] });
1485
+ }
1486
+ function deriveStepView(step, _registration) {
1487
+ if (step === "review") return "review";
1488
+ if (step === "processing" || step === "complete" || step === "failed") {
1489
+ return "processing";
1490
+ }
1491
+ return "form";
1492
+ }
1493
+
1494
+ // src/WithdrawModal.tsx
1495
+
1496
+ var ReownWithdrawInner = _react.lazy.call(void 0,
1497
+ () => Promise.resolve().then(() => _interopRequireWildcard(require("./WithdrawModalReown-OUWBSKSM.cjs"))).then((m) => ({
1498
+ default: m.WithdrawModalReown
1499
+ }))
1500
+ );
1501
+ function WithdrawModal(props) {
1502
+ const needsReown = !!props.reownAppId;
1503
+ if (needsReown) {
1504
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, { fallback: null, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ReownWithdrawInner, { ...props }) });
1505
+ }
1506
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, WithdrawModalInner, { ...props });
1507
+ }
1508
+ WithdrawModal.displayName = "WithdrawModal";
1509
+ function WithdrawModalInner({
1510
+ dappWalletClient,
1511
+ dappPublicClient,
1512
+ dappAddress,
1513
+ safeAddress,
1514
+ sourceChain: sourceChainProp,
1515
+ sourceToken,
1516
+ targetChain: targetChainProp,
1517
+ targetToken,
1518
+ recipient,
1519
+ defaultAmount,
1520
+ isOpen,
1521
+ onClose,
1522
+ inline,
1523
+ closeOnOverlayClick,
1524
+ allowedRoutes,
1525
+ backendUrl = _chunkMILJQWPTcjs.DEFAULT_BACKEND_URL,
1526
+ signerAddress = _chunkMILJQWPTcjs.DEFAULT_SIGNER_ADDRESS,
1527
+ sessionChainIds,
1528
+ forceRegister = false,
1529
+ reownWallet,
1530
+ onConnect,
1531
+ onDisconnect,
1532
+ onSignTransaction,
1533
+ onRequestConnect,
1534
+ theme,
1535
+ uiConfig,
1536
+ className,
1537
+ onReady,
1538
+ onLifecycle,
1539
+ onEvent,
1540
+ onError,
1541
+ debug
1542
+ }) {
1543
+ const modalRef = _react.useRef.call(void 0, null);
1544
+ const onReadyRef = _chunkRABZINV3cjs.useLatestRef.call(void 0, onReady);
1545
+ const [backHandler, setBackHandler] = _react.useState.call(void 0,
1546
+ void 0
1547
+ );
1548
+ const targetChain = _chunkMILJQWPTcjs.getChainId.call(void 0, targetChainProp);
1549
+ const sourceChain = _chunkMILJQWPTcjs.getChainId.call(void 0, sourceChainProp);
1550
+ const service = _react.useMemo.call(void 0,
1551
+ () => _chunkRABZINV3cjs.createDepositService.call(void 0, backendUrl, { debug, debugScope: "service:withdraw" }),
1552
+ [backendUrl, debug]
1553
+ );
1554
+ const store = _react.useMemo.call(void 0, () => createWithdrawStore(), []);
1555
+ const onErrorRef = _chunkRABZINV3cjs.useLatestRef.call(void 0, onError);
1556
+ _react.useEffect.call(void 0, () => {
1557
+ if (isOpen && onSignTransaction && !dappAddress) {
1558
+ _optionalChain([onErrorRef, 'access', _62 => _62.current, 'optionalCall', _63 => _63({
1559
+ message: "WithdrawModal requires `dappAddress` when `onSignTransaction` is provided.",
1560
+ code: "WITHDRAW_MISSING_DAPP_ADDRESS"
1561
+ })]);
1562
+ }
1563
+ }, [isOpen, onSignTransaction, dappAddress, onErrorRef]);
1564
+ _react.useEffect.call(void 0, () => {
1565
+ if (isOpen && modalRef.current) {
1566
+ _chunkRABZINV3cjs.applyTheme.call(void 0, modalRef.current, theme);
1567
+ }
1568
+ }, [isOpen, theme]);
1569
+ _react.useEffect.call(void 0, () => {
1570
+ if (isOpen) {
1571
+ _optionalChain([onReadyRef, 'access', _64 => _64.current, 'optionalCall', _65 => _65()]);
1572
+ }
1573
+ }, [isOpen, onReadyRef]);
1574
+ _react.useEffect.call(void 0, () => {
1575
+ if (!isOpen) {
1576
+ store.dispatch({ type: "modal/reset" });
1577
+ }
1578
+ }, [isOpen, store]);
1579
+ const handleStepChange = _react.useCallback.call(void 0, (onBack) => {
1580
+ setBackHandler(() => onBack);
1581
+ }, []);
1582
+ const showBackButton = _nullishCoalesce(_optionalChain([uiConfig, 'optionalAccess', _66 => _66.showBackButton]), () => ( true));
1583
+ const canGoBack = backHandler !== void 0;
1584
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, WithdrawStoreProvider, { store, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1585
+ _chunkRABZINV3cjs.Modal,
1586
+ {
1587
+ isOpen,
1588
+ onClose,
1589
+ className,
1590
+ inline,
1591
+ closeOnOverlayClick,
1592
+ children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref: modalRef, className: "rs-modal", children: [
1593
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "rs-modal-header--redesigned", children: [
1594
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-modal-header-nav-left", children: showBackButton && canGoBack && backHandler && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1595
+ "button",
1596
+ {
1597
+ type: "button",
1598
+ className: "rs-modal-header-back",
1599
+ "aria-label": "Go back",
1600
+ onClick: backHandler,
1601
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.ChevronLeftIcon, {})
1602
+ }
1603
+ ) }),
1604
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rs-modal-header-nav-right", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1605
+ "button",
1606
+ {
1607
+ type: "button",
1608
+ onClick: onClose,
1609
+ className: "rs-modal-close",
1610
+ "aria-label": "Close",
1611
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRABZINV3cjs.CloseIcon, {})
1612
+ }
1613
+ ) })
1614
+ ] }),
1615
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1616
+ WithdrawFlow,
1617
+ {
1618
+ dappWalletClient,
1619
+ dappPublicClient,
1620
+ dappAddress,
1621
+ safeAddress,
1622
+ sourceChain,
1623
+ sourceToken,
1624
+ targetChain,
1625
+ targetToken,
1626
+ recipient,
1627
+ amount: defaultAmount,
1628
+ service,
1629
+ allowedRoutes,
1630
+ signerAddress,
1631
+ sessionChainIds,
1632
+ forceRegister,
1633
+ reownWallet,
1634
+ onConnect,
1635
+ onDisconnect,
1636
+ onSignTransaction,
1637
+ onRequestConnect,
1638
+ onStepChange: handleStepChange,
1639
+ onClose,
1640
+ onLifecycle,
1641
+ onEvent,
1642
+ onError,
1643
+ debug
1644
+ }
1645
+ )
1646
+ ] })
1647
+ }
1648
+ ) });
1649
+ }
1650
+
1651
+
1652
+
1653
+
1654
+ exports.WithdrawModal = WithdrawModal; exports.WithdrawModalInner = WithdrawModalInner;