@rhinestone/deposit-modal 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -29
- package/dist/{chunk-2JPB3PLB.mjs → DepositModalReown-6KUAO5ZC.mjs} +56 -4
- package/dist/{chunk-Q3W53BKR.cjs → DepositModalReown-XC5RIU7Z.cjs} +62 -10
- package/dist/{caip-C_ZYFIGa.d.cts → caip-523Zrc3r.d.cts} +1 -3
- package/dist/{caip-C_ZYFIGa.d.ts → caip-523Zrc3r.d.ts} +1 -3
- package/dist/{chunk-D3Y7ZBED.cjs → chunk-22RV33LK.cjs} +2170 -1460
- package/dist/chunk-4WB2FHGC.mjs +865 -0
- package/dist/chunk-A223BLVC.mjs +801 -0
- package/dist/{chunk-HQWZCOMS.cjs → chunk-DIX7M3SP.cjs} +232 -601
- package/dist/{chunk-T43VUEJH.mjs → chunk-E4G5BOZP.mjs} +167 -536
- package/dist/chunk-H577RJN5.cjs +801 -0
- package/dist/{chunk-DABKCJVL.mjs → chunk-ILT2PITN.mjs} +60 -3
- package/dist/{chunk-7KHEIMWD.mjs → chunk-KKHLNFSA.mjs} +2436 -1726
- package/dist/chunk-LGVJWVSS.mjs +81 -0
- package/dist/chunk-NEXUCY4B.cjs +11 -0
- package/dist/chunk-NMIMRASD.cjs +1785 -0
- package/dist/chunk-OSI2CFGL.mjs +11 -0
- package/dist/chunk-PAGMU4RQ.cjs +865 -0
- package/dist/chunk-T7LGQFP3.cjs +81 -0
- package/dist/chunk-VN4BLZYC.cjs +2273 -0
- package/dist/chunk-VOGZAZB2.mjs +2273 -0
- package/dist/chunk-WYXBY2MQ.mjs +1785 -0
- package/dist/{chunk-4NN7UTWQ.cjs → chunk-YEBXUUH3.cjs} +63 -6
- package/dist/claim.cjs +10 -0
- package/dist/claim.d.cts +8 -0
- package/dist/claim.d.ts +8 -0
- package/dist/claim.mjs +10 -0
- package/dist/constants.cjs +3 -3
- package/dist/constants.d.cts +4 -2
- package/dist/constants.d.ts +4 -2
- package/dist/constants.mjs +5 -5
- package/dist/deposit.cjs +8 -6
- package/dist/deposit.d.cts +2 -2
- package/dist/deposit.d.ts +2 -2
- package/dist/deposit.mjs +7 -5
- package/dist/index.cjs +22 -12
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.mjs +21 -11
- package/dist/polymarket.cjs +5 -6
- package/dist/polymarket.mjs +2 -3
- package/dist/server.cjs +96 -0
- package/dist/server.d.cts +65 -0
- package/dist/server.d.ts +65 -0
- package/dist/server.mjs +96 -0
- package/dist/styles.css +263 -12
- package/dist/types-C0SGf-21.d.cts +606 -0
- package/dist/types-C0SGf-21.d.ts +606 -0
- package/dist/withdraw.cjs +6 -5
- package/dist/withdraw.d.cts +3 -6
- package/dist/withdraw.d.ts +3 -6
- package/dist/withdraw.mjs +5 -4
- package/package.json +53 -6
- package/dist/DepositModalReown-4BSHOQ5Y.mjs +0 -63
- package/dist/DepositModalReown-UND3DEJH.cjs +0 -63
- package/dist/WithdrawModalReown-FVXSSGY5.mjs +0 -46
- package/dist/WithdrawModalReown-TVZWJKQI.cjs +0 -46
- package/dist/chunk-7OKA6GNA.cjs +0 -4537
- package/dist/chunk-NASHLEVQ.mjs +0 -4537
- package/dist/chunk-O5OKA27M.mjs +0 -800
- package/dist/chunk-U7SVYWVD.cjs +0 -800
- package/dist/chunk-WK5AFRSP.mjs +0 -295
- package/dist/chunk-XRWQMIBY.cjs +0 -295
- package/dist/types--LQWg_4W.d.cts +0 -468
- package/dist/types--LQWg_4W.d.ts +0 -468
|
@@ -1,24 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProcessingStep,
|
|
3
|
+
deriveAccountSalt,
|
|
4
|
+
getPublicClient,
|
|
5
|
+
useTokenPrices,
|
|
6
|
+
warnRemovedProps
|
|
7
|
+
} from "./chunk-WYXBY2MQ.mjs";
|
|
1
8
|
import {
|
|
2
9
|
BodyHeader,
|
|
3
10
|
Button,
|
|
4
11
|
Callout,
|
|
12
|
+
CdnIcon,
|
|
5
13
|
ChevronDownIcon,
|
|
6
14
|
ChevronLeftIcon,
|
|
7
15
|
CircleArrowOutUpLeftIcon,
|
|
8
16
|
CloseIcon,
|
|
9
|
-
ConnectStep,
|
|
10
17
|
Modal,
|
|
11
18
|
PoweredBy,
|
|
12
|
-
ProcessingStep,
|
|
13
19
|
RpcUrlsProvider,
|
|
14
20
|
Spinner,
|
|
15
21
|
TokenIcon,
|
|
16
|
-
WalletIcon,
|
|
17
|
-
accountFromPrivateKey,
|
|
18
22
|
applyTheme,
|
|
19
|
-
|
|
23
|
+
checkBackendUrl,
|
|
20
24
|
createDepositService,
|
|
21
|
-
createSessionOwnerKey,
|
|
22
25
|
currencyFormatter,
|
|
23
26
|
debugError,
|
|
24
27
|
debugLog,
|
|
@@ -26,24 +29,13 @@ import {
|
|
|
26
29
|
formatTokenAmount,
|
|
27
30
|
formatUserError,
|
|
28
31
|
getAssetId,
|
|
29
|
-
getPublicClient,
|
|
30
32
|
isNativeAsset,
|
|
31
33
|
isRecognizedToken,
|
|
32
|
-
loadSessionOwnerFromStorage,
|
|
33
|
-
saveSessionOwnerToStorage,
|
|
34
34
|
useLatestRef,
|
|
35
35
|
useRpcUrls,
|
|
36
|
-
useStableRpcUrls
|
|
37
|
-
|
|
38
|
-
} from "./chunk-NASHLEVQ.mjs";
|
|
39
|
-
import {
|
|
40
|
-
buildSafeTransaction,
|
|
41
|
-
executeSafeErc20Transfer,
|
|
42
|
-
executeSafeEthTransfer
|
|
43
|
-
} from "./chunk-WK5AFRSP.mjs";
|
|
36
|
+
useStableRpcUrls
|
|
37
|
+
} from "./chunk-VOGZAZB2.mjs";
|
|
44
38
|
import {
|
|
45
|
-
DEFAULT_BACKEND_URL,
|
|
46
|
-
DEFAULT_SIGNER_ADDRESS,
|
|
47
39
|
NATIVE_TOKEN_ADDRESS,
|
|
48
40
|
SOURCE_CHAINS,
|
|
49
41
|
getChainIcon,
|
|
@@ -52,19 +44,11 @@ import {
|
|
|
52
44
|
getSupportedTargetTokens,
|
|
53
45
|
getTokenDecimalsByAddress,
|
|
54
46
|
getTokenSymbol,
|
|
55
|
-
|
|
56
|
-
} from "./chunk-
|
|
47
|
+
targetChainToCaip2
|
|
48
|
+
} from "./chunk-A223BLVC.mjs";
|
|
57
49
|
|
|
58
50
|
// src/WithdrawModal.tsx
|
|
59
|
-
import {
|
|
60
|
-
useCallback as useCallback3,
|
|
61
|
-
useEffect as useEffect3,
|
|
62
|
-
useMemo as useMemo3,
|
|
63
|
-
useRef as useRef3,
|
|
64
|
-
useState as useState4,
|
|
65
|
-
lazy,
|
|
66
|
-
Suspense
|
|
67
|
-
} from "react";
|
|
51
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
|
|
68
52
|
|
|
69
53
|
// src/WithdrawFlow.tsx
|
|
70
54
|
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
|
|
@@ -80,8 +64,6 @@ function unreachable(action) {
|
|
|
80
64
|
}
|
|
81
65
|
function applyWithdrawAction(state, action) {
|
|
82
66
|
switch (action.type) {
|
|
83
|
-
case "wallet/id-selected":
|
|
84
|
-
return { ...state, selectedWalletId: action.walletId };
|
|
85
67
|
case "registration/started":
|
|
86
68
|
return {
|
|
87
69
|
...state,
|
|
@@ -99,7 +81,7 @@ function applyWithdrawAction(state, action) {
|
|
|
99
81
|
smartAccount: action.smartAccount,
|
|
100
82
|
registeredTarget: action.registeredTarget
|
|
101
83
|
},
|
|
102
|
-
step: state.step
|
|
84
|
+
step: state.step
|
|
103
85
|
};
|
|
104
86
|
case "registration/failed":
|
|
105
87
|
return {
|
|
@@ -116,7 +98,15 @@ function applyWithdrawAction(state, action) {
|
|
|
116
98
|
case "review/back":
|
|
117
99
|
return { ...state, step: "form" };
|
|
118
100
|
case "withdraw/submitted":
|
|
119
|
-
return {
|
|
101
|
+
return {
|
|
102
|
+
...state,
|
|
103
|
+
txHash: action.txHash,
|
|
104
|
+
processingSmartAccount: action.smartAccount,
|
|
105
|
+
processingTargetChain: action.targetChain,
|
|
106
|
+
processingTargetToken: action.targetToken,
|
|
107
|
+
processingDirectTransfer: action.directTransfer,
|
|
108
|
+
step: "processing"
|
|
109
|
+
};
|
|
120
110
|
case "withdraw/complete":
|
|
121
111
|
return { ...state, step: "complete" };
|
|
122
112
|
case "withdraw/failed":
|
|
@@ -127,17 +117,24 @@ function applyWithdrawAction(state, action) {
|
|
|
127
117
|
step: "form",
|
|
128
118
|
amount: null,
|
|
129
119
|
recipient: null,
|
|
130
|
-
txHash: null
|
|
120
|
+
txHash: null,
|
|
121
|
+
processingSmartAccount: null,
|
|
122
|
+
processingTargetChain: null,
|
|
123
|
+
processingTargetToken: null,
|
|
124
|
+
processingDirectTransfer: null
|
|
131
125
|
};
|
|
132
126
|
case "modal/reset":
|
|
133
127
|
return {
|
|
134
128
|
...state,
|
|
135
|
-
step: "
|
|
136
|
-
selectedWalletId: null,
|
|
129
|
+
step: "form",
|
|
137
130
|
registration: { kind: "idle" },
|
|
138
131
|
amount: null,
|
|
139
132
|
recipient: null,
|
|
140
|
-
txHash: null
|
|
133
|
+
txHash: null,
|
|
134
|
+
processingSmartAccount: null,
|
|
135
|
+
processingTargetChain: null,
|
|
136
|
+
processingTargetToken: null,
|
|
137
|
+
processingDirectTransfer: null
|
|
141
138
|
};
|
|
142
139
|
default:
|
|
143
140
|
return unreachable(action);
|
|
@@ -145,12 +142,15 @@ function applyWithdrawAction(state, action) {
|
|
|
145
142
|
}
|
|
146
143
|
function createWithdrawStore() {
|
|
147
144
|
const store = createStore(() => ({
|
|
148
|
-
step: "
|
|
149
|
-
selectedWalletId: null,
|
|
145
|
+
step: "form",
|
|
150
146
|
registration: { kind: "idle" },
|
|
151
147
|
amount: null,
|
|
152
148
|
recipient: null,
|
|
153
|
-
txHash: null
|
|
149
|
+
txHash: null,
|
|
150
|
+
processingSmartAccount: null,
|
|
151
|
+
processingTargetChain: null,
|
|
152
|
+
processingTargetToken: null,
|
|
153
|
+
processingDirectTransfer: null
|
|
154
154
|
}));
|
|
155
155
|
return {
|
|
156
156
|
...store,
|
|
@@ -187,7 +187,7 @@ function useWithdrawStore(selector) {
|
|
|
187
187
|
// src/components/steps/WithdrawFormStep.tsx
|
|
188
188
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
189
189
|
import { erc20Abi, formatUnits, parseUnits } from "viem";
|
|
190
|
-
import {
|
|
190
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
191
191
|
function useClickOutside(ref, onClose) {
|
|
192
192
|
useEffect(() => {
|
|
193
193
|
function handleClick(e) {
|
|
@@ -200,10 +200,8 @@ function useClickOutside(ref, onClose) {
|
|
|
200
200
|
}, [ref, onClose]);
|
|
201
201
|
}
|
|
202
202
|
function WithdrawFormStep({
|
|
203
|
-
walletClient,
|
|
204
203
|
publicClient,
|
|
205
|
-
|
|
206
|
-
safeAddress,
|
|
204
|
+
accountAddress,
|
|
207
205
|
depositAddress,
|
|
208
206
|
asset,
|
|
209
207
|
defaultRecipient,
|
|
@@ -214,8 +212,6 @@ function WithdrawFormStep({
|
|
|
214
212
|
targetTokenOptions,
|
|
215
213
|
onTargetChainChange,
|
|
216
214
|
onTargetTokenChange,
|
|
217
|
-
switchChain,
|
|
218
|
-
walletIcon,
|
|
219
215
|
submitting = false,
|
|
220
216
|
registrationPending = false,
|
|
221
217
|
registrationError = null,
|
|
@@ -228,23 +224,14 @@ function WithdrawFormStep({
|
|
|
228
224
|
const [balance, setBalance] = useState(null);
|
|
229
225
|
const [isBalanceLoading, setIsBalanceLoading] = useState(true);
|
|
230
226
|
const [error, setError] = useState(null);
|
|
231
|
-
const [isSwitching, setIsSwitching] = useState(false);
|
|
232
227
|
const [showChainDropdown, setShowChainDropdown] = useState(false);
|
|
233
228
|
const [showTokenDropdown, setShowTokenDropdown] = useState(false);
|
|
234
229
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
235
|
-
const hasAttemptedSwitch = useRef(false);
|
|
236
230
|
const chainDropdownRef = useRef(null);
|
|
237
231
|
const tokenDropdownRef = useRef(null);
|
|
238
232
|
const publicClientChainId = publicClient.chain?.id;
|
|
239
233
|
useClickOutside(chainDropdownRef, () => setShowChainDropdown(false));
|
|
240
234
|
useClickOutside(tokenDropdownRef, () => setShowTokenDropdown(false));
|
|
241
|
-
const preferredConnectedRecipient = connectedRecipient ?? "";
|
|
242
|
-
const isRecipientConnected = Boolean(
|
|
243
|
-
preferredConnectedRecipient && recipient && recipient.toLowerCase() === preferredConnectedRecipient.toLowerCase()
|
|
244
|
-
);
|
|
245
|
-
const chainMismatch = Boolean(
|
|
246
|
-
walletClient?.chain?.id && walletClient.chain.id !== asset.chainId
|
|
247
|
-
);
|
|
248
235
|
const targetSymbol = getTokenSymbol(targetToken, targetChain);
|
|
249
236
|
const targetChainName = getChainName(targetChain);
|
|
250
237
|
const isBusy = submitting || isSubmitting;
|
|
@@ -259,37 +246,22 @@ function WithdrawFormStep({
|
|
|
259
246
|
});
|
|
260
247
|
seededRecipientRef.current = nextSeed;
|
|
261
248
|
}, [defaultRecipient]);
|
|
262
|
-
useEffect(() => {
|
|
263
|
-
if (chainMismatch && switchChain && !hasAttemptedSwitch.current) {
|
|
264
|
-
hasAttemptedSwitch.current = true;
|
|
265
|
-
setIsSwitching(true);
|
|
266
|
-
switchChain(asset.chainId).catch((err) => {
|
|
267
|
-
const raw = err instanceof Error ? err.message : "Failed to switch chain";
|
|
268
|
-
setError(formatUserError(raw));
|
|
269
|
-
}).finally(() => {
|
|
270
|
-
setIsSwitching(false);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}, [chainMismatch, switchChain, asset.chainId]);
|
|
274
|
-
useEffect(() => {
|
|
275
|
-
hasAttemptedSwitch.current = false;
|
|
276
|
-
}, [asset.chainId]);
|
|
277
249
|
useEffect(() => {
|
|
278
250
|
let active = true;
|
|
279
251
|
let timeoutId;
|
|
280
252
|
let retryDelayMs = 5e3;
|
|
281
253
|
async function fetchBalance() {
|
|
282
|
-
if (!
|
|
254
|
+
if (!accountAddress || !publicClient) return;
|
|
283
255
|
if (publicClientChainId && publicClientChainId !== asset.chainId) {
|
|
284
256
|
timeoutId = setTimeout(fetchBalance, 1e3);
|
|
285
257
|
return;
|
|
286
258
|
}
|
|
287
259
|
try {
|
|
288
|
-
const bal = isNativeAsset(asset) ? await publicClient.getBalance({ address:
|
|
260
|
+
const bal = isNativeAsset(asset) ? await publicClient.getBalance({ address: accountAddress }) : await publicClient.readContract({
|
|
289
261
|
address: asset.token,
|
|
290
262
|
abi: erc20Abi,
|
|
291
263
|
functionName: "balanceOf",
|
|
292
|
-
args: [
|
|
264
|
+
args: [accountAddress]
|
|
293
265
|
});
|
|
294
266
|
if (active) {
|
|
295
267
|
setBalance(bal);
|
|
@@ -312,7 +284,7 @@ function WithdrawFormStep({
|
|
|
312
284
|
clearTimeout(timeoutId);
|
|
313
285
|
}
|
|
314
286
|
};
|
|
315
|
-
}, [
|
|
287
|
+
}, [accountAddress, publicClient, publicClientChainId, asset]);
|
|
316
288
|
const formattedBalance = useMemo(() => {
|
|
317
289
|
if (balance === null) return "...";
|
|
318
290
|
try {
|
|
@@ -355,19 +327,13 @@ function WithdrawFormStep({
|
|
|
355
327
|
setAmount(maxAmount);
|
|
356
328
|
setError(null);
|
|
357
329
|
}, [balance, asset.decimals]);
|
|
358
|
-
const handleUseConnected = useCallback(() => {
|
|
359
|
-
if (!preferredConnectedRecipient) return;
|
|
360
|
-
setRecipient(preferredConnectedRecipient);
|
|
361
|
-
onRecipientChange?.(preferredConnectedRecipient);
|
|
362
|
-
setError(null);
|
|
363
|
-
}, [preferredConnectedRecipient, onRecipientChange]);
|
|
364
330
|
const handleWithdraw = useCallback(async () => {
|
|
365
331
|
if (!recipient || !/^0x[a-fA-F0-9]{40}$/.test(recipient)) {
|
|
366
332
|
setError("Enter a valid recipient address");
|
|
367
333
|
return;
|
|
368
334
|
}
|
|
369
335
|
const lowerRecipient = recipient.toLowerCase();
|
|
370
|
-
if (lowerRecipient ===
|
|
336
|
+
if (lowerRecipient === accountAddress.toLowerCase() || lowerRecipient === depositAddress?.toLowerCase()) {
|
|
371
337
|
setError(
|
|
372
338
|
"Recipient can't be your own account. Send to a different wallet."
|
|
373
339
|
);
|
|
@@ -405,7 +371,7 @@ function WithdrawFormStep({
|
|
|
405
371
|
amount,
|
|
406
372
|
balance,
|
|
407
373
|
asset.decimals,
|
|
408
|
-
|
|
374
|
+
accountAddress,
|
|
409
375
|
depositAddress,
|
|
410
376
|
onSubmit
|
|
411
377
|
]);
|
|
@@ -414,7 +380,7 @@ function WithdrawFormStep({
|
|
|
414
380
|
/* @__PURE__ */ jsxs("div", { className: "rs-screen-body rs-withdraw-loading", children: [
|
|
415
381
|
/* @__PURE__ */ jsx(Spinner, { className: "rs-spinner--lg" }),
|
|
416
382
|
/* @__PURE__ */ jsx("div", { className: "rs-withdraw-loading-title", children: "Loading on-chain balance" }),
|
|
417
|
-
/* @__PURE__ */ jsx("div", { className: "rs-withdraw-loading-subtitle", children:
|
|
383
|
+
/* @__PURE__ */ jsx("div", { className: "rs-withdraw-loading-subtitle", children: "Please wait before withdrawing." })
|
|
418
384
|
] }),
|
|
419
385
|
/* @__PURE__ */ jsx(PoweredBy, {})
|
|
420
386
|
] });
|
|
@@ -431,48 +397,22 @@ function WithdrawFormStep({
|
|
|
431
397
|
children: "Recipient address"
|
|
432
398
|
}
|
|
433
399
|
),
|
|
434
|
-
/* @__PURE__ */
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
if (error) setError(null);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
),
|
|
451
|
-
preferredConnectedRecipient && /* @__PURE__ */ jsx(
|
|
452
|
-
"button",
|
|
453
|
-
{
|
|
454
|
-
type: "button",
|
|
455
|
-
className: `rs-withdraw-use-connected ${isRecipientConnected ? "rs-withdraw-use-connected--active" : ""}`,
|
|
456
|
-
onClick: handleUseConnected,
|
|
457
|
-
title: isRecipientConnected ? "Using connected wallet" : "Use connected wallet",
|
|
458
|
-
children: walletIcon ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
459
|
-
/* @__PURE__ */ jsx(
|
|
460
|
-
"img",
|
|
461
|
-
{
|
|
462
|
-
src: walletIcon,
|
|
463
|
-
alt: "Wallet",
|
|
464
|
-
style: { width: 18, height: 18, borderRadius: 4 },
|
|
465
|
-
className: "rs-withdraw-use-connected-icon"
|
|
466
|
-
}
|
|
467
|
-
),
|
|
468
|
-
isRecipientConnected ? null : "Use connected"
|
|
469
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
470
|
-
/* @__PURE__ */ jsx(WalletIcon, { className: "rs-withdraw-use-connected-icon" }),
|
|
471
|
-
isRecipientConnected ? null : "Use connected"
|
|
472
|
-
] })
|
|
400
|
+
/* @__PURE__ */ jsx("div", { className: "rs-withdraw-input-row", children: /* @__PURE__ */ jsx(
|
|
401
|
+
"input",
|
|
402
|
+
{
|
|
403
|
+
id: "rs-withdraw-recipient",
|
|
404
|
+
type: "text",
|
|
405
|
+
className: "rs-withdraw-input rs-withdraw-input--address",
|
|
406
|
+
placeholder: "0x...",
|
|
407
|
+
value: recipient,
|
|
408
|
+
onChange: (e) => {
|
|
409
|
+
const next = e.target.value.trim();
|
|
410
|
+
setRecipient(next);
|
|
411
|
+
onRecipientChange?.(next);
|
|
412
|
+
if (error) setError(null);
|
|
473
413
|
}
|
|
474
|
-
|
|
475
|
-
|
|
414
|
+
}
|
|
415
|
+
) })
|
|
476
416
|
] }),
|
|
477
417
|
/* @__PURE__ */ jsxs("div", { className: "rs-withdraw-section", children: [
|
|
478
418
|
/* @__PURE__ */ jsx("label", { className: "rs-withdraw-label", htmlFor: "rs-withdraw-amount", children: "Amount" }),
|
|
@@ -507,7 +447,7 @@ function WithdrawFormStep({
|
|
|
507
447
|
) })
|
|
508
448
|
] }),
|
|
509
449
|
/* @__PURE__ */ jsxs("div", { className: "rs-withdraw-amount-info", children: [
|
|
510
|
-
/* @__PURE__ */ jsx("span", { className: "rs-withdraw-usd", children: amountUsd !== null ? currencyFormatter.format(amountUsd) : "$0.00" }),
|
|
450
|
+
/* @__PURE__ */ jsx("span", { className: "rs-withdraw-usd", children: amountUsd !== null ? `~${currencyFormatter.format(amountUsd)}` : "$0.00" }),
|
|
511
451
|
/* @__PURE__ */ jsxs("span", { className: "rs-withdraw-balance", children: [
|
|
512
452
|
"Balance: ",
|
|
513
453
|
formattedBalance,
|
|
@@ -537,8 +477,8 @@ function WithdrawFormStep({
|
|
|
537
477
|
},
|
|
538
478
|
children: [
|
|
539
479
|
/* @__PURE__ */ jsxs("div", { className: "rs-withdraw-dropdown-value", children: [
|
|
540
|
-
|
|
541
|
-
|
|
480
|
+
/* @__PURE__ */ jsx(
|
|
481
|
+
CdnIcon,
|
|
542
482
|
{
|
|
543
483
|
src: getChainIcon(targetChain),
|
|
544
484
|
alt: targetChainName,
|
|
@@ -569,8 +509,8 @@ function WithdrawFormStep({
|
|
|
569
509
|
setShowChainDropdown(false);
|
|
570
510
|
},
|
|
571
511
|
children: [
|
|
572
|
-
|
|
573
|
-
|
|
512
|
+
/* @__PURE__ */ jsx(
|
|
513
|
+
CdnIcon,
|
|
574
514
|
{
|
|
575
515
|
src: getChainIcon(chain.id),
|
|
576
516
|
alt: chain.name,
|
|
@@ -654,7 +594,6 @@ function WithdrawFormStep({
|
|
|
654
594
|
)
|
|
655
595
|
] })
|
|
656
596
|
] }),
|
|
657
|
-
chainMismatch && /* @__PURE__ */ jsx("div", { className: "rs-chain-switch", children: /* @__PURE__ */ jsx("div", { className: "rs-chain-switch-text", children: isSwitching ? `Switching to ${getChainName(asset.chainId)}...` : `Switch to ${getChainName(asset.chainId)} to continue.` }) }),
|
|
658
597
|
error && /* @__PURE__ */ jsx(Callout, { variant: "error", children: error }),
|
|
659
598
|
!error && registrationError && /* @__PURE__ */ jsx(Callout, { variant: "error", children: registrationError }),
|
|
660
599
|
/* @__PURE__ */ jsx(
|
|
@@ -663,7 +602,7 @@ function WithdrawFormStep({
|
|
|
663
602
|
onClick: handleWithdraw,
|
|
664
603
|
fullWidth: true,
|
|
665
604
|
loading: isBusy,
|
|
666
|
-
disabled: !recipient || !amount ||
|
|
605
|
+
disabled: !recipient || !amount || isBusy || Boolean(registrationError),
|
|
667
606
|
children: isBusy ? "Preparing..." : registrationPending ? "Preparing session..." : !recipient ? "Enter Recipient Address" : !amount ? "Enter Withdraw Amount" : "Withdraw"
|
|
668
607
|
}
|
|
669
608
|
)
|
|
@@ -755,7 +694,7 @@ function WithdrawReviewStep({
|
|
|
755
694
|
/* @__PURE__ */ jsx2("span", { children: "Source chain" }),
|
|
756
695
|
/* @__PURE__ */ jsxs2("span", { className: "rs-review-detail-value", children: [
|
|
757
696
|
/* @__PURE__ */ jsx2("span", { children: sourceChainName }),
|
|
758
|
-
sourceChainIcon && /* @__PURE__ */ jsx2("span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ jsx2(
|
|
697
|
+
sourceChainIcon && /* @__PURE__ */ jsx2("span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ jsx2(CdnIcon, { src: sourceChainIcon }) })
|
|
759
698
|
] })
|
|
760
699
|
] }),
|
|
761
700
|
/* @__PURE__ */ jsxs2("div", { className: "rs-review-detail-row", children: [
|
|
@@ -773,7 +712,7 @@ function WithdrawReviewStep({
|
|
|
773
712
|
/* @__PURE__ */ jsx2("span", { children: "Destination chain" }),
|
|
774
713
|
/* @__PURE__ */ jsxs2("span", { className: "rs-review-detail-value", children: [
|
|
775
714
|
/* @__PURE__ */ jsx2("span", { children: targetChainName }),
|
|
776
|
-
targetChainIcon && /* @__PURE__ */ jsx2("span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ jsx2(
|
|
715
|
+
targetChainIcon && /* @__PURE__ */ jsx2("span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ jsx2(CdnIcon, { src: targetChainIcon }) })
|
|
777
716
|
] })
|
|
778
717
|
] }),
|
|
779
718
|
/* @__PURE__ */ jsxs2("div", { className: "rs-review-detail-row", children: [
|
|
@@ -801,32 +740,17 @@ function WithdrawReviewStep({
|
|
|
801
740
|
WithdrawReviewStep.displayName = "WithdrawReviewStep";
|
|
802
741
|
|
|
803
742
|
// src/WithdrawFlow.tsx
|
|
804
|
-
import {
|
|
743
|
+
import { parseUnits as parseUnits2 } from "viem";
|
|
805
744
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
806
745
|
var ADDR_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
807
746
|
var REGISTRATION_DEBOUNCE_MS = 600;
|
|
808
747
|
var WITHDRAW_INDEXING_DELAY_MS = 2e3;
|
|
809
|
-
function resolveSessionOwner(eoaAddress) {
|
|
810
|
-
const localOwner = loadSessionOwnerFromStorage(eoaAddress);
|
|
811
|
-
if (localOwner) {
|
|
812
|
-
return {
|
|
813
|
-
account: accountFromPrivateKey(localOwner.privateKey),
|
|
814
|
-
address: localOwner.address
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
const created = createSessionOwnerKey();
|
|
818
|
-
saveSessionOwnerToStorage(eoaAddress, created.privateKey, created.address);
|
|
819
|
-
return { account: created.account, address: created.address };
|
|
820
|
-
}
|
|
821
748
|
function targetsEqual(a, b) {
|
|
822
749
|
if (!a) return false;
|
|
823
750
|
return a.chain === b.chain && a.token.toLowerCase() === b.token.toLowerCase() && (a.recipient?.toLowerCase() ?? "") === (b.recipient?.toLowerCase() ?? "");
|
|
824
751
|
}
|
|
825
752
|
function WithdrawFlow({
|
|
826
|
-
|
|
827
|
-
dappPublicClient,
|
|
828
|
-
dappAddress,
|
|
829
|
-
safeAddress,
|
|
753
|
+
accountAddress,
|
|
830
754
|
sourceChain,
|
|
831
755
|
sourceToken,
|
|
832
756
|
targetChain: targetChainProp,
|
|
@@ -834,15 +758,8 @@ function WithdrawFlow({
|
|
|
834
758
|
recipient: defaultRecipient,
|
|
835
759
|
amount: defaultAmount,
|
|
836
760
|
service,
|
|
837
|
-
allowedRoutes,
|
|
838
|
-
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
839
|
-
sessionChainIds,
|
|
840
761
|
forceRegister = false,
|
|
841
|
-
|
|
842
|
-
onConnect,
|
|
843
|
-
onDisconnect,
|
|
844
|
-
onSignTransaction,
|
|
845
|
-
onRequestConnect,
|
|
762
|
+
onSendTransaction,
|
|
846
763
|
onStepChange,
|
|
847
764
|
onClose,
|
|
848
765
|
onLifecycle,
|
|
@@ -881,213 +798,81 @@ function WithdrawFlow({
|
|
|
881
798
|
defaultRecipient ?? ""
|
|
882
799
|
);
|
|
883
800
|
const [totalBalanceUsd, setTotalBalanceUsd] = useState3(0);
|
|
884
|
-
const [isConnectSelectionConfirmed, setIsConnectSelectionConfirmed] = useState3(false);
|
|
885
801
|
useEffect2(() => {
|
|
886
802
|
setTargetChain(targetChainProp);
|
|
803
|
+
}, [targetChainProp]);
|
|
804
|
+
useEffect2(() => {
|
|
887
805
|
setTargetToken(targetTokenProp);
|
|
888
|
-
}, [
|
|
806
|
+
}, [targetTokenProp]);
|
|
889
807
|
useEffect2(() => {
|
|
890
808
|
if (defaultRecipient) setRecipientInput(defaultRecipient);
|
|
891
809
|
}, [defaultRecipient]);
|
|
892
|
-
const hasCustomSigner = Boolean(dappAddress && onSignTransaction);
|
|
893
|
-
const dappSwitchChain = useMemo2(() => {
|
|
894
|
-
if (!dappWalletClient?.switchChain) return void 0;
|
|
895
|
-
return async (chainId) => {
|
|
896
|
-
await dappWalletClient.switchChain?.({ id: chainId });
|
|
897
|
-
};
|
|
898
|
-
}, [dappWalletClient]);
|
|
899
|
-
const walletOptions = useMemo2(() => {
|
|
900
|
-
const options = [];
|
|
901
|
-
const seen = /* @__PURE__ */ new Set();
|
|
902
|
-
if (dappWalletClient?.account && dappAddress) {
|
|
903
|
-
const id = `evm:${dappWalletClient.account.address.toLowerCase()}`;
|
|
904
|
-
options.push({
|
|
905
|
-
id,
|
|
906
|
-
address: dappWalletClient.account.address,
|
|
907
|
-
label: "Connected Wallet",
|
|
908
|
-
kind: "connected"
|
|
909
|
-
});
|
|
910
|
-
seen.add(id);
|
|
911
|
-
}
|
|
912
|
-
if (reownWallet?.address && reownWallet.isConnected && reownWallet.walletClient && reownWallet.publicClient) {
|
|
913
|
-
const id = `evm:${reownWallet.address.toLowerCase()}`;
|
|
914
|
-
if (!seen.has(id)) {
|
|
915
|
-
options.push({
|
|
916
|
-
id,
|
|
917
|
-
address: reownWallet.address,
|
|
918
|
-
label: "External Wallet",
|
|
919
|
-
kind: "external",
|
|
920
|
-
icon: reownWallet.icon
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
return options;
|
|
925
|
-
}, [
|
|
926
|
-
dappWalletClient,
|
|
927
|
-
dappAddress,
|
|
928
|
-
reownWallet?.address,
|
|
929
|
-
reownWallet?.isConnected,
|
|
930
|
-
reownWallet?.walletClient,
|
|
931
|
-
reownWallet?.publicClient,
|
|
932
|
-
reownWallet?.icon
|
|
933
|
-
]);
|
|
934
|
-
const canAutoLock = hasCustomSigner || Boolean(dappWalletClient?.account && dappAddress) && !reownWallet;
|
|
935
810
|
const storeApi = useWithdrawStoreApi();
|
|
936
|
-
const selectedWalletId = useWithdrawStore((s) => s.selectedWalletId);
|
|
937
811
|
const registration = useWithdrawStore((s) => s.registration);
|
|
938
812
|
const flowStep = useWithdrawStore((s) => s.step);
|
|
939
813
|
const reviewedRecipient = useWithdrawStore((s) => s.recipient);
|
|
940
|
-
const
|
|
941
|
-
(
|
|
942
|
-
[
|
|
814
|
+
const publicClient = useMemo2(
|
|
815
|
+
() => getPublicClient(sourceChain, rpcUrls),
|
|
816
|
+
[sourceChain, rpcUrls]
|
|
943
817
|
);
|
|
944
|
-
const signerContext = useMemo2(() => {
|
|
945
|
-
if (canAutoLock) {
|
|
946
|
-
if (hasCustomSigner) {
|
|
947
|
-
return {
|
|
948
|
-
ownerAddress: dappAddress,
|
|
949
|
-
walletClient: dappWalletClient ?? void 0,
|
|
950
|
-
publicClient: dappPublicClient ?? getPublicClient(sourceChain, rpcUrls),
|
|
951
|
-
switchChain: dappSwitchChain
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
return {
|
|
955
|
-
ownerAddress: dappWalletClient.account.address,
|
|
956
|
-
walletClient: dappWalletClient,
|
|
957
|
-
publicClient: dappPublicClient ?? getPublicClient(sourceChain, rpcUrls),
|
|
958
|
-
switchChain: dappSwitchChain
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
if (!isConnectSelectionConfirmed || !selectedWalletId) return null;
|
|
962
|
-
const selectedOption = walletOptions.find((o) => o.id === selectedWalletId);
|
|
963
|
-
if (!selectedOption || !selectedOption.address) return null;
|
|
964
|
-
if (selectedOption.kind === "connected" && dappWalletClient?.account && dappWalletClient.account.address.toLowerCase() === selectedOption.address.toLowerCase()) {
|
|
965
|
-
return {
|
|
966
|
-
ownerAddress: dappWalletClient.account.address,
|
|
967
|
-
walletClient: dappWalletClient,
|
|
968
|
-
publicClient: dappPublicClient ?? getPublicClient(sourceChain, rpcUrls),
|
|
969
|
-
switchChain: dappSwitchChain
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
if (selectedOption.kind === "external" && reownWallet?.address?.toLowerCase() === selectedOption.address.toLowerCase() && reownWallet.walletClient && reownWallet.publicClient) {
|
|
973
|
-
return {
|
|
974
|
-
ownerAddress: reownWallet.address,
|
|
975
|
-
walletClient: reownWallet.walletClient,
|
|
976
|
-
publicClient: reownWallet.publicClient,
|
|
977
|
-
switchChain: reownWallet.switchChain
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
return null;
|
|
981
|
-
}, [
|
|
982
|
-
canAutoLock,
|
|
983
|
-
hasCustomSigner,
|
|
984
|
-
isConnectSelectionConfirmed,
|
|
985
|
-
selectedWalletId,
|
|
986
|
-
walletOptions,
|
|
987
|
-
dappWalletClient,
|
|
988
|
-
dappPublicClient,
|
|
989
|
-
dappSwitchChain,
|
|
990
|
-
dappAddress,
|
|
991
|
-
reownWallet,
|
|
992
|
-
sourceChain,
|
|
993
|
-
rpcUrls
|
|
994
|
-
]);
|
|
995
|
-
const ownerAddress = signerContext?.ownerAddress;
|
|
996
818
|
const recipientForRegistration = useMemo2(() => {
|
|
997
819
|
if (!recipientInput) return void 0;
|
|
998
820
|
return ADDR_REGEX.test(recipientInput) ? recipientInput : void 0;
|
|
999
821
|
}, [recipientInput]);
|
|
1000
822
|
useEffect2(() => {
|
|
1001
|
-
if (!
|
|
823
|
+
if (!recipientForRegistration) return;
|
|
1002
824
|
const desiredTarget = {
|
|
1003
825
|
chain: targetChain,
|
|
1004
826
|
token: targetToken,
|
|
1005
827
|
recipient: recipientForRegistration
|
|
1006
828
|
};
|
|
1007
829
|
const current = storeApi.getState().registration;
|
|
1008
|
-
if (current.kind === "ready" && targetsEqual(current.registeredTarget, desiredTarget)) {
|
|
830
|
+
if (!forceRegister && current.kind === "ready" && targetsEqual(current.registeredTarget, desiredTarget)) {
|
|
1009
831
|
return;
|
|
1010
832
|
}
|
|
1011
833
|
let cancelled = false;
|
|
1012
834
|
const timeout = setTimeout(async () => {
|
|
1013
835
|
try {
|
|
1014
836
|
storeApi.dispatch({ type: "registration/started" });
|
|
1015
|
-
const sessionOwner = resolveSessionOwner(ownerAddress);
|
|
1016
|
-
if (cancelled) return;
|
|
1017
837
|
logFlow("auto-register:setup", {
|
|
1018
|
-
|
|
838
|
+
accountAddress,
|
|
1019
839
|
targetChain,
|
|
1020
840
|
targetToken,
|
|
1021
841
|
recipient: recipientForRegistration
|
|
1022
842
|
});
|
|
1023
|
-
const
|
|
1024
|
-
ownerAddress,
|
|
1025
|
-
sessionOwnerAddress: sessionOwner.address,
|
|
1026
|
-
targetChain: toEvmCaip2(targetChain),
|
|
1027
|
-
targetToken,
|
|
843
|
+
const salt = deriveAccountSalt({
|
|
1028
844
|
recipient: recipientForRegistration,
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
forceRegister
|
|
845
|
+
targetChain,
|
|
846
|
+
targetToken
|
|
1032
847
|
});
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
if (!sessionOwner.account.signTypedData) {
|
|
1040
|
-
throw new Error(
|
|
1041
|
-
"Session owner account does not support signTypedData"
|
|
1042
|
-
);
|
|
848
|
+
const { evmDepositAddress } = await service.registerManagedAccount({
|
|
849
|
+
salt,
|
|
850
|
+
target: {
|
|
851
|
+
chain: targetChainToCaip2(targetChain),
|
|
852
|
+
token: targetToken,
|
|
853
|
+
recipient: recipientForRegistration
|
|
1043
854
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
});
|
|
1050
|
-
if (cancelled) return;
|
|
1051
|
-
const sessionDetails = buildSessionDetails(
|
|
1052
|
-
setup.sessionDetailsUnsigned,
|
|
1053
|
-
signature
|
|
1054
|
-
);
|
|
1055
|
-
await service.registerAccount({
|
|
1056
|
-
address: setup.smartAccount,
|
|
1057
|
-
accountParams: {
|
|
1058
|
-
factory: setup.accountParams.factory,
|
|
1059
|
-
factoryData: setup.accountParams.factoryData,
|
|
1060
|
-
sessionDetails
|
|
1061
|
-
},
|
|
1062
|
-
eoaAddress: ownerAddress,
|
|
1063
|
-
sessionOwner: sessionOwner.address,
|
|
1064
|
-
target: {
|
|
1065
|
-
chain: toEvmCaip2(targetChain),
|
|
1066
|
-
token: targetToken,
|
|
1067
|
-
recipient: recipientForRegistration
|
|
1068
|
-
}
|
|
1069
|
-
});
|
|
1070
|
-
if (cancelled) return;
|
|
1071
|
-
logFlow("auto-register:registered", {
|
|
1072
|
-
smartAccount: setup.smartAccount
|
|
1073
|
-
});
|
|
1074
|
-
}
|
|
855
|
+
});
|
|
856
|
+
if (cancelled) return;
|
|
857
|
+
logFlow("auto-register:registered", {
|
|
858
|
+
smartAccount: evmDepositAddress
|
|
859
|
+
});
|
|
1075
860
|
storeApi.dispatch({
|
|
1076
861
|
type: "registration/ready",
|
|
1077
|
-
smartAccount:
|
|
862
|
+
smartAccount: evmDepositAddress,
|
|
1078
863
|
registeredTarget: desiredTarget
|
|
1079
864
|
});
|
|
1080
865
|
onLifecycleRef.current?.({
|
|
1081
866
|
type: "connected",
|
|
1082
|
-
address:
|
|
1083
|
-
smartAccount:
|
|
867
|
+
address: accountAddress,
|
|
868
|
+
smartAccount: evmDepositAddress
|
|
1084
869
|
});
|
|
1085
870
|
} catch (err) {
|
|
1086
871
|
if (cancelled) return;
|
|
1087
872
|
const raw = err instanceof Error ? err.message : "Registration failed";
|
|
1088
873
|
const message = formatUserError(raw);
|
|
1089
874
|
logFlowError("auto-register:failed", err, {
|
|
1090
|
-
|
|
875
|
+
accountAddress,
|
|
1091
876
|
targetChain,
|
|
1092
877
|
targetToken
|
|
1093
878
|
});
|
|
@@ -1103,13 +888,11 @@ function WithdrawFlow({
|
|
|
1103
888
|
clearTimeout(timeout);
|
|
1104
889
|
};
|
|
1105
890
|
}, [
|
|
1106
|
-
|
|
891
|
+
accountAddress,
|
|
1107
892
|
targetChain,
|
|
1108
893
|
targetToken,
|
|
1109
894
|
recipientForRegistration,
|
|
1110
895
|
service,
|
|
1111
|
-
signerAddress,
|
|
1112
|
-
sessionChainIds,
|
|
1113
896
|
forceRegister,
|
|
1114
897
|
storeApi,
|
|
1115
898
|
logFlow,
|
|
@@ -1170,12 +953,10 @@ function WithdrawFlow({
|
|
|
1170
953
|
sourceToken,
|
|
1171
954
|
targetChain,
|
|
1172
955
|
targetToken,
|
|
1173
|
-
selectedWalletId,
|
|
1174
956
|
registration: registration.kind
|
|
1175
957
|
});
|
|
1176
958
|
}, [
|
|
1177
959
|
logFlow,
|
|
1178
|
-
selectedWalletId,
|
|
1179
960
|
sourceChain,
|
|
1180
961
|
sourceToken,
|
|
1181
962
|
flowStep,
|
|
@@ -1233,14 +1014,11 @@ function WithdrawFlow({
|
|
|
1233
1014
|
}
|
|
1234
1015
|
const smartAccount = matchingRegistration.smartAccount;
|
|
1235
1016
|
const lowerRecipient = recipient.toLowerCase();
|
|
1236
|
-
if (lowerRecipient ===
|
|
1017
|
+
if (lowerRecipient === accountAddress.toLowerCase() || lowerRecipient === smartAccount.toLowerCase()) {
|
|
1237
1018
|
throw new Error(
|
|
1238
1019
|
"Recipient can't be your own account. Send to a different wallet."
|
|
1239
1020
|
);
|
|
1240
1021
|
}
|
|
1241
|
-
if (!onSignTransaction && !signerContext?.walletClient) {
|
|
1242
|
-
throw new Error("Wallet not connected");
|
|
1243
|
-
}
|
|
1244
1022
|
const submitGeneration = submitGenerationRef.current += 1;
|
|
1245
1023
|
const isSubmissionLive = () => isFlowActiveRef.current && submitGenerationRef.current === submitGeneration;
|
|
1246
1024
|
try {
|
|
@@ -1261,71 +1039,19 @@ function WithdrawFlow({
|
|
|
1261
1039
|
targetToken
|
|
1262
1040
|
});
|
|
1263
1041
|
const amountUnits = parseUnits2(amountValue, asset.decimals);
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
value: 0n,
|
|
1271
|
-
data: encodeFunctionData({
|
|
1272
|
-
abi: erc20Abi2,
|
|
1273
|
-
functionName: "transfer",
|
|
1274
|
-
args: [transferTarget, amountUnits]
|
|
1275
|
-
})
|
|
1276
|
-
};
|
|
1277
|
-
const request = await buildSafeTransaction({
|
|
1278
|
-
publicClient: pc,
|
|
1279
|
-
safeAddress,
|
|
1280
|
-
to: transferData.to,
|
|
1281
|
-
value: transferData.value,
|
|
1282
|
-
data: transferData.data,
|
|
1283
|
-
chainId: sourceChain
|
|
1284
|
-
});
|
|
1285
|
-
if (!isSubmissionLive()) return;
|
|
1286
|
-
const { signature } = await onSignTransaction(request);
|
|
1287
|
-
if (!isSubmissionLive()) return;
|
|
1288
|
-
if (!getMatchingRegistration()) {
|
|
1289
|
-
throw new Error("Withdrawal target changed before submission");
|
|
1290
|
-
}
|
|
1291
|
-
const relayResult = await service.relayWithdraw({
|
|
1292
|
-
smartAccount,
|
|
1293
|
-
chainId: toEvmCaip2(sourceChain),
|
|
1294
|
-
safeAddress,
|
|
1295
|
-
safeTransaction: request.typedData.message,
|
|
1296
|
-
signature
|
|
1297
|
-
});
|
|
1298
|
-
if (!relayResult.txHash) {
|
|
1299
|
-
throw new Error("Relay succeeded but no txHash returned");
|
|
1300
|
-
}
|
|
1301
|
-
result = { txHash: relayResult.txHash };
|
|
1302
|
-
} else if (isSourceNative) {
|
|
1303
|
-
if (!getMatchingRegistration()) {
|
|
1304
|
-
throw new Error("Withdrawal target changed before submission");
|
|
1305
|
-
}
|
|
1306
|
-
result = await executeSafeEthTransfer({
|
|
1307
|
-
walletClient: signerContext.walletClient,
|
|
1308
|
-
publicClient: pc,
|
|
1309
|
-
safeAddress,
|
|
1310
|
-
recipient: isSameRoute ? recipient : smartAccount,
|
|
1311
|
-
amount: amountUnits,
|
|
1312
|
-
chainId: sourceChain
|
|
1313
|
-
});
|
|
1314
|
-
} else {
|
|
1315
|
-
if (!getMatchingRegistration()) {
|
|
1316
|
-
throw new Error("Withdrawal target changed before submission");
|
|
1317
|
-
}
|
|
1318
|
-
result = await executeSafeErc20Transfer({
|
|
1319
|
-
walletClient: signerContext.walletClient,
|
|
1320
|
-
publicClient: pc,
|
|
1321
|
-
safeAddress,
|
|
1322
|
-
tokenAddress: sourceToken,
|
|
1323
|
-
recipient: isSameRoute ? recipient : smartAccount,
|
|
1324
|
-
amount: amountUnits,
|
|
1325
|
-
chainId: sourceChain
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1042
|
+
const result = await onSendTransaction({
|
|
1043
|
+
chainId: sourceChain,
|
|
1044
|
+
token: sourceToken,
|
|
1045
|
+
amount: amountUnits,
|
|
1046
|
+
to: isSameRoute ? recipient : smartAccount
|
|
1047
|
+
});
|
|
1328
1048
|
if (!isSubmissionLive()) return;
|
|
1049
|
+
if (!getMatchingRegistration()) {
|
|
1050
|
+
throw new Error("Withdrawal target changed before submission");
|
|
1051
|
+
}
|
|
1052
|
+
if (!result?.txHash) {
|
|
1053
|
+
throw new Error("onSendTransaction did not return a txHash");
|
|
1054
|
+
}
|
|
1329
1055
|
logFlow("withdraw:submitted", {
|
|
1330
1056
|
txHash: result.txHash,
|
|
1331
1057
|
smartAccount,
|
|
@@ -1338,9 +1064,18 @@ function WithdrawFlow({
|
|
|
1338
1064
|
txHash: result.txHash,
|
|
1339
1065
|
sourceChain,
|
|
1340
1066
|
amount: amountUnits.toString(),
|
|
1341
|
-
|
|
1067
|
+
accountAddress
|
|
1068
|
+
});
|
|
1069
|
+
storeApi.dispatch({
|
|
1070
|
+
type: "withdraw/submitted",
|
|
1071
|
+
txHash: result.txHash,
|
|
1072
|
+
smartAccount,
|
|
1073
|
+
targetChain,
|
|
1074
|
+
targetToken,
|
|
1075
|
+
// Pin the routing decision this submit actually made — it chose the
|
|
1076
|
+
// transfer target above.
|
|
1077
|
+
directTransfer: isSameRoute
|
|
1342
1078
|
});
|
|
1343
|
-
storeApi.dispatch({ type: "withdraw/submitted", txHash: result.txHash });
|
|
1344
1079
|
} catch (err) {
|
|
1345
1080
|
const raw = err instanceof Error ? err.message : "Withdraw failed";
|
|
1346
1081
|
logFlowError("submit:failed", err, {
|
|
@@ -1354,23 +1089,19 @@ function WithdrawFlow({
|
|
|
1354
1089
|
}
|
|
1355
1090
|
},
|
|
1356
1091
|
[
|
|
1357
|
-
signerContext,
|
|
1358
1092
|
targetChain,
|
|
1359
1093
|
targetToken,
|
|
1360
|
-
service,
|
|
1361
1094
|
asset.decimals,
|
|
1362
|
-
|
|
1095
|
+
accountAddress,
|
|
1363
1096
|
sourceToken,
|
|
1364
1097
|
sourceChain,
|
|
1365
|
-
|
|
1366
|
-
isSourceNative,
|
|
1098
|
+
onSendTransaction,
|
|
1367
1099
|
isSameRoute,
|
|
1368
1100
|
handleError,
|
|
1369
1101
|
logFlow,
|
|
1370
1102
|
logFlowError,
|
|
1371
1103
|
onLifecycleRef,
|
|
1372
|
-
storeApi
|
|
1373
|
-
rpcUrls
|
|
1104
|
+
storeApi
|
|
1374
1105
|
]
|
|
1375
1106
|
);
|
|
1376
1107
|
const handleWithdrawComplete = useCallback2(
|
|
@@ -1406,29 +1137,16 @@ function WithdrawFlow({
|
|
|
1406
1137
|
},
|
|
1407
1138
|
[logFlowError, onLifecycleRef, storeApi]
|
|
1408
1139
|
);
|
|
1409
|
-
const
|
|
1410
|
-
() =>
|
|
1411
|
-
|
|
1140
|
+
const targetChainOptions = useMemo2(
|
|
1141
|
+
() => SOURCE_CHAINS.filter(
|
|
1142
|
+
(chain) => getSupportedTargetTokens(chain.id).length > 0
|
|
1143
|
+
),
|
|
1144
|
+
[]
|
|
1412
1145
|
);
|
|
1413
|
-
const
|
|
1414
|
-
() =>
|
|
1415
|
-
[
|
|
1146
|
+
const targetTokenOptions = useMemo2(
|
|
1147
|
+
() => getSupportedTargetTokens(targetChain),
|
|
1148
|
+
[targetChain]
|
|
1416
1149
|
);
|
|
1417
|
-
const targetChainOptions = useMemo2(() => {
|
|
1418
|
-
return SOURCE_CHAINS.filter((chain) => {
|
|
1419
|
-
if (allowedChainSet && !allowedChainSet.has(chain.id)) return false;
|
|
1420
|
-
const tokens = getSupportedTargetTokens(chain.id);
|
|
1421
|
-
if (allowedTokenSet) {
|
|
1422
|
-
return tokens.some((t) => allowedTokenSet.has(t.symbol.toUpperCase()));
|
|
1423
|
-
}
|
|
1424
|
-
return tokens.length > 0;
|
|
1425
|
-
});
|
|
1426
|
-
}, [allowedChainSet, allowedTokenSet]);
|
|
1427
|
-
const targetTokenOptions = useMemo2(() => {
|
|
1428
|
-
const tokens = getSupportedTargetTokens(targetChain);
|
|
1429
|
-
if (!allowedTokenSet) return tokens;
|
|
1430
|
-
return tokens.filter((t) => allowedTokenSet.has(t.symbol.toUpperCase()));
|
|
1431
|
-
}, [targetChain, allowedTokenSet]);
|
|
1432
1150
|
useEffect2(() => {
|
|
1433
1151
|
if (targetTokenOptions.length === 0) return;
|
|
1434
1152
|
const matches = targetTokenOptions.some(
|
|
@@ -1439,12 +1157,7 @@ function WithdrawFlow({
|
|
|
1439
1157
|
const handleTargetChainChange = useCallback2(
|
|
1440
1158
|
(chainId) => {
|
|
1441
1159
|
setTargetChain(chainId);
|
|
1442
|
-
|
|
1443
|
-
if (allowedTokenSet) {
|
|
1444
|
-
options = options.filter(
|
|
1445
|
-
(t) => allowedTokenSet.has(t.symbol.toUpperCase())
|
|
1446
|
-
);
|
|
1447
|
-
}
|
|
1160
|
+
const options = getSupportedTargetTokens(chainId);
|
|
1448
1161
|
if (options.length === 0) return;
|
|
1449
1162
|
const currentlySupported = options.some(
|
|
1450
1163
|
(option) => option.address.toLowerCase() === targetToken.toLowerCase()
|
|
@@ -1453,71 +1166,19 @@ function WithdrawFlow({
|
|
|
1453
1166
|
currentlySupported ? targetToken : options[0].address
|
|
1454
1167
|
);
|
|
1455
1168
|
},
|
|
1456
|
-
[targetToken
|
|
1169
|
+
[targetToken]
|
|
1457
1170
|
);
|
|
1458
1171
|
const handleTargetTokenChange = useCallback2((token) => {
|
|
1459
1172
|
setTargetToken(token);
|
|
1460
1173
|
}, []);
|
|
1461
|
-
const selectedWalletIdEffective = useMemo2(() => {
|
|
1462
|
-
if (selectedWalletId) return selectedWalletId;
|
|
1463
|
-
if (walletOptions.length === 1) return walletOptions[0].id;
|
|
1464
|
-
return null;
|
|
1465
|
-
}, [selectedWalletId, walletOptions]);
|
|
1466
|
-
const walletOptionsKey = useMemo2(
|
|
1467
|
-
() => walletOptions.map((o) => o.id).join(","),
|
|
1468
|
-
[walletOptions]
|
|
1469
|
-
);
|
|
1470
|
-
const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
|
|
1471
|
-
useEffect2(() => {
|
|
1472
|
-
setIsConnectSelectionConfirmed(false);
|
|
1473
|
-
}, [walletOptionsKey]);
|
|
1474
|
-
const selectedWalletOption = selectedWalletIdEffective ? walletOptions.find((o) => o.id === selectedWalletIdEffective) ?? null : null;
|
|
1475
|
-
const selectedWalletIcon = useMemo2(() => {
|
|
1476
|
-
if (!ownerAddress) return void 0;
|
|
1477
|
-
const selected = walletOptions.find(
|
|
1478
|
-
(o) => o.address?.toLowerCase() === ownerAddress.toLowerCase()
|
|
1479
|
-
);
|
|
1480
|
-
return selected?.kind === "external" ? selected.icon ?? reownWallet?.icon : void 0;
|
|
1481
|
-
}, [walletOptions, ownerAddress, reownWallet?.icon]);
|
|
1482
|
-
if (showConnectStep) {
|
|
1483
|
-
const withdrawRows = walletOptions.map((option) => ({
|
|
1484
|
-
id: option.id,
|
|
1485
|
-
kind: option.kind,
|
|
1486
|
-
label: option.label,
|
|
1487
|
-
icon: option.icon,
|
|
1488
|
-
address: option.address ?? option.solanaAddress ?? option.id,
|
|
1489
|
-
state: "ready"
|
|
1490
|
-
}));
|
|
1491
|
-
return /* @__PURE__ */ jsx3("div", { className: "rs-modal-body", children: /* @__PURE__ */ jsx3(
|
|
1492
|
-
ConnectStep,
|
|
1493
|
-
{
|
|
1494
|
-
walletRows: withdrawRows,
|
|
1495
|
-
onConfirmWallet: (walletId) => {
|
|
1496
|
-
setSelectedWalletId(walletId);
|
|
1497
|
-
setIsConnectSelectionConfirmed(true);
|
|
1498
|
-
},
|
|
1499
|
-
onRequestConnect,
|
|
1500
|
-
onConnect,
|
|
1501
|
-
onDisconnect,
|
|
1502
|
-
title: "Withdraw",
|
|
1503
|
-
subtitle: "Choose a wallet to continue"
|
|
1504
|
-
}
|
|
1505
|
-
) });
|
|
1506
|
-
}
|
|
1507
|
-
if (!signerContext) return null;
|
|
1508
|
-
if (!onSignTransaction && !signerContext.walletClient) return null;
|
|
1509
|
-
const resolvedConnectedRecipient = selectedWalletOption?.kind === "external" ? selectedWalletOption.address : void 0;
|
|
1510
|
-
const formPublicClient = signerContext.publicClient ?? getPublicClient(sourceChain, rpcUrls);
|
|
1511
1174
|
const depositAddress = registration.kind === "ready" || registration.kind === "stale" ? registration.smartAccount : void 0;
|
|
1512
1175
|
const stepView = deriveStepView(flowStep, registration);
|
|
1513
1176
|
return /* @__PURE__ */ jsxs3("div", { className: "rs-modal-body", children: [
|
|
1514
1177
|
stepView === "form" && /* @__PURE__ */ jsx3(
|
|
1515
1178
|
WithdrawFormStep,
|
|
1516
1179
|
{
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
connectedRecipient: resolvedConnectedRecipient,
|
|
1520
|
-
safeAddress,
|
|
1180
|
+
publicClient,
|
|
1181
|
+
accountAddress,
|
|
1521
1182
|
depositAddress,
|
|
1522
1183
|
asset,
|
|
1523
1184
|
defaultRecipient,
|
|
@@ -1528,8 +1189,6 @@ function WithdrawFlow({
|
|
|
1528
1189
|
targetTokenOptions,
|
|
1529
1190
|
onTargetChainChange: handleTargetChainChange,
|
|
1530
1191
|
onTargetTokenChange: handleTargetTokenChange,
|
|
1531
|
-
switchChain: signerContext.switchChain,
|
|
1532
|
-
walletIcon: selectedWalletIcon,
|
|
1533
1192
|
registrationPending: registration.kind === "pending" || registration.kind === "stale",
|
|
1534
1193
|
registrationError: registration.kind === "failed" ? registration.error : null,
|
|
1535
1194
|
onRecipientChange: setRecipientInput,
|
|
@@ -1557,16 +1216,16 @@ function WithdrawFlow({
|
|
|
1557
1216
|
stepView === "processing" && registration.kind !== "idle" && /* @__PURE__ */ jsx3(
|
|
1558
1217
|
ProcessingStep,
|
|
1559
1218
|
{
|
|
1560
|
-
smartAccount: registration.kind === "ready" || registration.kind === "stale" ? registration.smartAccount : "0x0",
|
|
1219
|
+
smartAccount: storeApi.getState().processingSmartAccount ?? (registration.kind === "ready" || registration.kind === "stale" ? registration.smartAccount : "0x0"),
|
|
1561
1220
|
txHash: storeApi.getState().txHash ?? "0x0",
|
|
1562
1221
|
sourceChain,
|
|
1563
1222
|
sourceToken,
|
|
1564
|
-
targetChain,
|
|
1565
|
-
targetToken,
|
|
1223
|
+
targetChain: storeApi.getState().processingTargetChain ?? targetChain,
|
|
1224
|
+
targetToken: storeApi.getState().processingTargetToken ?? targetToken,
|
|
1566
1225
|
amount: toBaseUnits(storeApi.getState().amount ?? "0", asset.decimals),
|
|
1567
1226
|
sourceSymbol: asset.symbol,
|
|
1568
1227
|
sourceDecimals: asset.decimals,
|
|
1569
|
-
directTransfer: isSameRoute,
|
|
1228
|
+
directTransfer: storeApi.getState().processingDirectTransfer ?? isSameRoute,
|
|
1570
1229
|
service,
|
|
1571
1230
|
flowLabel: "withdraw",
|
|
1572
1231
|
onClose,
|
|
@@ -1596,24 +1255,8 @@ function deriveStepView(step, _registration) {
|
|
|
1596
1255
|
|
|
1597
1256
|
// src/WithdrawModal.tsx
|
|
1598
1257
|
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
default: m.WithdrawModalReown
|
|
1602
|
-
}))
|
|
1603
|
-
);
|
|
1604
|
-
function WithdrawModal(props) {
|
|
1605
|
-
const needsReown = !!props.reownAppId;
|
|
1606
|
-
if (needsReown) {
|
|
1607
|
-
return /* @__PURE__ */ jsx4(Suspense, { fallback: null, children: /* @__PURE__ */ jsx4(ReownWithdrawInner, { ...props }) });
|
|
1608
|
-
}
|
|
1609
|
-
return /* @__PURE__ */ jsx4(WithdrawModalInner, { ...props });
|
|
1610
|
-
}
|
|
1611
|
-
WithdrawModal.displayName = "WithdrawModal";
|
|
1612
|
-
function WithdrawModalInner({
|
|
1613
|
-
dappWalletClient,
|
|
1614
|
-
dappPublicClient,
|
|
1615
|
-
dappAddress,
|
|
1616
|
-
safeAddress,
|
|
1258
|
+
function WithdrawModal({
|
|
1259
|
+
accountAddress,
|
|
1617
1260
|
sourceChain: sourceChainProp,
|
|
1618
1261
|
sourceToken,
|
|
1619
1262
|
targetChain: targetChainProp,
|
|
@@ -1624,17 +1267,10 @@ function WithdrawModalInner({
|
|
|
1624
1267
|
onClose,
|
|
1625
1268
|
inline,
|
|
1626
1269
|
closeOnOverlayClick,
|
|
1627
|
-
|
|
1628
|
-
backendUrl = DEFAULT_BACKEND_URL,
|
|
1270
|
+
backendUrl,
|
|
1629
1271
|
rpcUrls: rpcUrlsProp,
|
|
1630
|
-
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
1631
|
-
sessionChainIds,
|
|
1632
1272
|
forceRegister = false,
|
|
1633
|
-
|
|
1634
|
-
onConnect,
|
|
1635
|
-
onDisconnect,
|
|
1636
|
-
onSignTransaction,
|
|
1637
|
-
onRequestConnect,
|
|
1273
|
+
onSendTransaction,
|
|
1638
1274
|
theme,
|
|
1639
1275
|
uiConfig,
|
|
1640
1276
|
className,
|
|
@@ -1642,14 +1278,20 @@ function WithdrawModalInner({
|
|
|
1642
1278
|
onLifecycle,
|
|
1643
1279
|
onEvent,
|
|
1644
1280
|
onError,
|
|
1645
|
-
debug
|
|
1281
|
+
debug,
|
|
1282
|
+
// Every prop 0.9.0 removed lands here, since none of them is named above.
|
|
1283
|
+
// `uiConfig` is destructured, so its removed nested key isn't scanned — that
|
|
1284
|
+
// one only ever applied to the deposit flow.
|
|
1285
|
+
...removedProps
|
|
1646
1286
|
}) {
|
|
1287
|
+
warnRemovedProps("WithdrawModal", removedProps);
|
|
1288
|
+
checkBackendUrl("WithdrawModal", backendUrl);
|
|
1647
1289
|
const modalRef = useRef3(null);
|
|
1648
1290
|
const onReadyRef = useLatestRef(onReady);
|
|
1649
1291
|
const [backHandler, setBackHandler] = useState4(
|
|
1650
1292
|
void 0
|
|
1651
1293
|
);
|
|
1652
|
-
const targetChain = getChainId(targetChainProp);
|
|
1294
|
+
const targetChain = getChainId(targetChainProp ?? sourceChainProp);
|
|
1653
1295
|
const sourceChain = getChainId(sourceChainProp);
|
|
1654
1296
|
const rpcUrls = useStableRpcUrls(rpcUrlsProp);
|
|
1655
1297
|
const service = useMemo3(
|
|
@@ -1659,13 +1301,13 @@ function WithdrawModalInner({
|
|
|
1659
1301
|
const store = useMemo3(() => createWithdrawStore(), []);
|
|
1660
1302
|
const onErrorRef = useLatestRef(onError);
|
|
1661
1303
|
useEffect3(() => {
|
|
1662
|
-
if (isOpen &&
|
|
1304
|
+
if (isOpen && typeof onSendTransaction !== "function") {
|
|
1663
1305
|
onErrorRef.current?.({
|
|
1664
|
-
message: "WithdrawModal requires
|
|
1665
|
-
code: "
|
|
1306
|
+
message: "WithdrawModal requires an `onSendTransaction` function.",
|
|
1307
|
+
code: "WITHDRAW_MISSING_SEND_TRANSACTION"
|
|
1666
1308
|
});
|
|
1667
1309
|
}
|
|
1668
|
-
}, [isOpen,
|
|
1310
|
+
}, [isOpen, onSendTransaction, onErrorRef]);
|
|
1669
1311
|
useEffect3(() => {
|
|
1670
1312
|
if (isOpen && modalRef.current) {
|
|
1671
1313
|
applyTheme(modalRef.current, theme);
|
|
@@ -1720,26 +1362,16 @@ function WithdrawModalInner({
|
|
|
1720
1362
|
/* @__PURE__ */ jsx4(
|
|
1721
1363
|
WithdrawFlow,
|
|
1722
1364
|
{
|
|
1723
|
-
|
|
1724
|
-
dappPublicClient,
|
|
1725
|
-
dappAddress,
|
|
1726
|
-
safeAddress,
|
|
1365
|
+
accountAddress,
|
|
1727
1366
|
sourceChain,
|
|
1728
1367
|
sourceToken,
|
|
1729
1368
|
targetChain,
|
|
1730
|
-
targetToken,
|
|
1369
|
+
targetToken: targetToken ?? sourceToken,
|
|
1731
1370
|
recipient,
|
|
1732
1371
|
amount: defaultAmount,
|
|
1733
1372
|
service,
|
|
1734
|
-
allowedRoutes,
|
|
1735
|
-
signerAddress,
|
|
1736
|
-
sessionChainIds,
|
|
1737
1373
|
forceRegister,
|
|
1738
|
-
|
|
1739
|
-
onConnect,
|
|
1740
|
-
onDisconnect,
|
|
1741
|
-
onSignTransaction,
|
|
1742
|
-
onRequestConnect,
|
|
1374
|
+
onSendTransaction,
|
|
1743
1375
|
onStepChange: handleStepChange,
|
|
1744
1376
|
onClose,
|
|
1745
1377
|
onLifecycle,
|
|
@@ -1754,6 +1386,5 @@ function WithdrawModalInner({
|
|
|
1754
1386
|
}
|
|
1755
1387
|
|
|
1756
1388
|
export {
|
|
1757
|
-
WithdrawModal
|
|
1758
|
-
WithdrawModalInner
|
|
1389
|
+
WithdrawModal
|
|
1759
1390
|
};
|