@rhinestone/deposit-modal 0.1.14 → 0.1.15
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 +45 -21
- package/dist/index.cjs +327 -248
- package/dist/index.d.cts +6 -12
- package/dist/index.d.ts +6 -12
- package/dist/index.mjs +340 -269
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3479,17 +3479,39 @@ var init_DepositAddressStep = __esm({
|
|
|
3479
3479
|
}
|
|
3480
3480
|
});
|
|
3481
3481
|
|
|
3482
|
+
// src/core/public-client.ts
|
|
3483
|
+
import { createPublicClient, http } from "viem";
|
|
3484
|
+
function getPublicClient(chainId) {
|
|
3485
|
+
let client = clientCache.get(chainId);
|
|
3486
|
+
if (!client) {
|
|
3487
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
3488
|
+
client = createPublicClient({
|
|
3489
|
+
chain,
|
|
3490
|
+
transport: http()
|
|
3491
|
+
});
|
|
3492
|
+
clientCache.set(chainId, client);
|
|
3493
|
+
}
|
|
3494
|
+
return client;
|
|
3495
|
+
}
|
|
3496
|
+
var clientCache;
|
|
3497
|
+
var init_public_client = __esm({
|
|
3498
|
+
"src/core/public-client.ts"() {
|
|
3499
|
+
"use strict";
|
|
3500
|
+
init_constants();
|
|
3501
|
+
clientCache = /* @__PURE__ */ new Map();
|
|
3502
|
+
}
|
|
3503
|
+
});
|
|
3504
|
+
|
|
3482
3505
|
// src/DepositFlow.tsx
|
|
3483
3506
|
import { useState as useState7, useCallback as useCallback4, useMemo as useMemo6, useEffect as useEffect7, useRef as useRef6 } from "react";
|
|
3484
3507
|
import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
3485
3508
|
function DepositFlow({
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3509
|
+
dappWalletClient,
|
|
3510
|
+
dappPublicClient,
|
|
3511
|
+
dappAddress,
|
|
3489
3512
|
targetChain,
|
|
3490
3513
|
targetToken,
|
|
3491
3514
|
service,
|
|
3492
|
-
switchChain,
|
|
3493
3515
|
sourceChain: defaultSourceChain,
|
|
3494
3516
|
sourceToken: defaultSourceToken,
|
|
3495
3517
|
amount: defaultAmount,
|
|
@@ -3498,9 +3520,7 @@ function DepositFlow({
|
|
|
3498
3520
|
sessionChainIds,
|
|
3499
3521
|
forceRegister = false,
|
|
3500
3522
|
waitForFinalTx = true,
|
|
3501
|
-
|
|
3502
|
-
selectedConnectAddress,
|
|
3503
|
-
onSelectConnectAddress,
|
|
3523
|
+
reownWallet,
|
|
3504
3524
|
onConnect,
|
|
3505
3525
|
onRequestConnect,
|
|
3506
3526
|
connectButtonLabel,
|
|
@@ -3518,9 +3538,93 @@ function DepositFlow({
|
|
|
3518
3538
|
const [flowMode, setFlowMode] = useState7(null);
|
|
3519
3539
|
const [totalBalanceUsd, setTotalBalanceUsd] = useState7(0);
|
|
3520
3540
|
const [isConnectSelectionConfirmed, setIsConnectSelectionConfirmed] = useState7(false);
|
|
3521
|
-
const
|
|
3522
|
-
const hasConnectedWallet = Boolean(walletClient && publicClient && address);
|
|
3541
|
+
const [selectedConnectAddress, setSelectedConnectAddress] = useState7(null);
|
|
3523
3542
|
const targetChainObj = useMemo6(() => CHAIN_BY_ID[targetChain], [targetChain]);
|
|
3543
|
+
const dappSwitchChain = useMemo6(() => {
|
|
3544
|
+
if (!dappWalletClient?.switchChain) return void 0;
|
|
3545
|
+
return async (chainId) => {
|
|
3546
|
+
await dappWalletClient.switchChain?.({ id: chainId });
|
|
3547
|
+
};
|
|
3548
|
+
}, [dappWalletClient]);
|
|
3549
|
+
const walletOptions = useMemo6(() => {
|
|
3550
|
+
const options = [];
|
|
3551
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3552
|
+
if (dappWalletClient?.account && dappAddress) {
|
|
3553
|
+
options.push({
|
|
3554
|
+
address: dappWalletClient.account.address,
|
|
3555
|
+
label: "Connected Wallet",
|
|
3556
|
+
kind: "connected"
|
|
3557
|
+
});
|
|
3558
|
+
seen.add(dappWalletClient.account.address.toLowerCase());
|
|
3559
|
+
}
|
|
3560
|
+
if (reownWallet?.address && reownWallet.isConnected && !seen.has(reownWallet.address.toLowerCase())) {
|
|
3561
|
+
options.push({
|
|
3562
|
+
address: reownWallet.address,
|
|
3563
|
+
label: "External Wallet",
|
|
3564
|
+
kind: "external"
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
return options;
|
|
3568
|
+
}, [
|
|
3569
|
+
dappWalletClient,
|
|
3570
|
+
dappAddress,
|
|
3571
|
+
reownWallet?.address,
|
|
3572
|
+
reownWallet?.isConnected
|
|
3573
|
+
]);
|
|
3574
|
+
const canAutoLock = dappWalletClient?.account && dappAddress && !reownWallet;
|
|
3575
|
+
const hasWalletOptions = walletOptions.length > 0;
|
|
3576
|
+
const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
|
|
3577
|
+
const signerContext = useMemo6(() => {
|
|
3578
|
+
if (flowMode === "deposit-address") {
|
|
3579
|
+
if (!dappAddress) return null;
|
|
3580
|
+
return {
|
|
3581
|
+
ownerAddress: dappAddress,
|
|
3582
|
+
walletClient: void 0,
|
|
3583
|
+
publicClient: dappPublicClient ?? getPublicClient(targetChain),
|
|
3584
|
+
switchChain: void 0
|
|
3585
|
+
};
|
|
3586
|
+
}
|
|
3587
|
+
if (canAutoLock) {
|
|
3588
|
+
const fallbackChainId = dappWalletClient?.chain?.id ?? targetChain;
|
|
3589
|
+
return {
|
|
3590
|
+
ownerAddress: dappWalletClient.account.address,
|
|
3591
|
+
walletClient: dappWalletClient,
|
|
3592
|
+
publicClient: dappPublicClient ?? getPublicClient(fallbackChainId),
|
|
3593
|
+
switchChain: dappSwitchChain
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
if (!isConnectSelectionConfirmed || !selectedConnectAddress) return null;
|
|
3597
|
+
if (dappWalletClient?.account && dappWalletClient.account.address.toLowerCase() === selectedConnectAddress.toLowerCase()) {
|
|
3598
|
+
const fallbackChainId = dappWalletClient?.chain?.id ?? targetChain;
|
|
3599
|
+
return {
|
|
3600
|
+
ownerAddress: dappWalletClient.account.address,
|
|
3601
|
+
walletClient: dappWalletClient,
|
|
3602
|
+
publicClient: dappPublicClient ?? getPublicClient(fallbackChainId),
|
|
3603
|
+
switchChain: dappSwitchChain
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
if (reownWallet?.address?.toLowerCase() === selectedConnectAddress.toLowerCase() && reownWallet.walletClient && reownWallet.publicClient) {
|
|
3607
|
+
return {
|
|
3608
|
+
ownerAddress: reownWallet.address,
|
|
3609
|
+
walletClient: reownWallet.walletClient,
|
|
3610
|
+
publicClient: reownWallet.publicClient,
|
|
3611
|
+
switchChain: reownWallet.switchChain
|
|
3612
|
+
};
|
|
3613
|
+
}
|
|
3614
|
+
return null;
|
|
3615
|
+
}, [
|
|
3616
|
+
flowMode,
|
|
3617
|
+
canAutoLock,
|
|
3618
|
+
isConnectSelectionConfirmed,
|
|
3619
|
+
selectedConnectAddress,
|
|
3620
|
+
dappWalletClient,
|
|
3621
|
+
dappPublicClient,
|
|
3622
|
+
dappSwitchChain,
|
|
3623
|
+
dappAddress,
|
|
3624
|
+
reownWallet,
|
|
3625
|
+
targetChain
|
|
3626
|
+
]);
|
|
3627
|
+
const sessionKeyAddress = dappAddress ?? signerContext?.ownerAddress ?? null;
|
|
3524
3628
|
const lastTargetRef = useRef6(null);
|
|
3525
3629
|
useEffect7(() => {
|
|
3526
3630
|
const prev = lastTargetRef.current;
|
|
@@ -3538,17 +3642,17 @@ function DepositFlow({
|
|
|
3538
3642
|
});
|
|
3539
3643
|
}, []);
|
|
3540
3644
|
const handleBackFromSelectAsset = useCallback4(() => {
|
|
3541
|
-
if (
|
|
3645
|
+
if (hasWalletOptions || reownWallet) {
|
|
3542
3646
|
setIsConnectSelectionConfirmed(false);
|
|
3543
3647
|
}
|
|
3544
|
-
}, [
|
|
3648
|
+
}, [hasWalletOptions, reownWallet]);
|
|
3545
3649
|
const handleBackFromDepositAddress = useCallback4(() => {
|
|
3546
3650
|
setFlowMode(null);
|
|
3547
3651
|
setStep({ type: "setup" });
|
|
3548
|
-
if (
|
|
3652
|
+
if (hasWalletOptions || reownWallet) {
|
|
3549
3653
|
setIsConnectSelectionConfirmed(false);
|
|
3550
3654
|
}
|
|
3551
|
-
}, [
|
|
3655
|
+
}, [hasWalletOptions, reownWallet]);
|
|
3552
3656
|
const handleBackFromConfirm = useCallback4(() => {
|
|
3553
3657
|
setStep((prev) => {
|
|
3554
3658
|
if (prev.type !== "confirm") return prev;
|
|
@@ -3561,7 +3665,7 @@ function DepositFlow({
|
|
|
3561
3665
|
});
|
|
3562
3666
|
}, []);
|
|
3563
3667
|
const stepIndex = step.type === "setup" ? 0 : step.type === "deposit-address" ? 1 : step.type === "select-asset" ? 1 : step.type === "amount" ? 2 : step.type === "confirm" ? 3 : 4;
|
|
3564
|
-
const currentBackHandler = step.type === "deposit-address" ? handleBackFromDepositAddress : step.type === "select-asset" &&
|
|
3668
|
+
const currentBackHandler = step.type === "deposit-address" ? handleBackFromDepositAddress : step.type === "select-asset" && signerContext && !canAutoLock ? handleBackFromSelectAsset : step.type === "amount" ? handleBackFromAmount : step.type === "confirm" ? handleBackFromConfirm : void 0;
|
|
3565
3669
|
useEffect7(() => {
|
|
3566
3670
|
onStepChange?.(stepIndex, currentBackHandler);
|
|
3567
3671
|
}, [stepIndex, currentBackHandler, onStepChange]);
|
|
@@ -3686,33 +3790,35 @@ function DepositFlow({
|
|
|
3686
3790
|
}, []);
|
|
3687
3791
|
const selectedConnectAddressEffective = useMemo6(() => {
|
|
3688
3792
|
if (selectedConnectAddress) return selectedConnectAddress;
|
|
3689
|
-
if (
|
|
3690
|
-
return
|
|
3793
|
+
if (walletOptions.length === 1) {
|
|
3794
|
+
return walletOptions[0].address;
|
|
3691
3795
|
}
|
|
3692
3796
|
return null;
|
|
3693
|
-
}, [selectedConnectAddress,
|
|
3694
|
-
const
|
|
3695
|
-
() =>
|
|
3696
|
-
[
|
|
3797
|
+
}, [selectedConnectAddress, walletOptions]);
|
|
3798
|
+
const walletOptionsKey = useMemo6(
|
|
3799
|
+
() => walletOptions.map((option) => option.address.toLowerCase()).join(","),
|
|
3800
|
+
[walletOptions]
|
|
3697
3801
|
);
|
|
3698
|
-
const showConnectStep = !hasConnectedWallet || hasConnectWalletOptions && !isConnectSelectionConfirmed;
|
|
3699
3802
|
useEffect7(() => {
|
|
3700
3803
|
setIsConnectSelectionConfirmed(false);
|
|
3701
|
-
}, [
|
|
3804
|
+
}, [walletOptionsKey, selectedConnectAddressEffective]);
|
|
3702
3805
|
if (showConnectStep) {
|
|
3703
3806
|
return /* @__PURE__ */ jsx14("div", { className: "rs-modal-body", children: /* @__PURE__ */ jsx14(
|
|
3704
3807
|
ConnectStep,
|
|
3705
3808
|
{
|
|
3706
|
-
walletOptions
|
|
3809
|
+
walletOptions,
|
|
3707
3810
|
selectedAddress: selectedConnectAddressEffective,
|
|
3708
|
-
onSelectAddress:
|
|
3709
|
-
onSelectTransferCrypto: () => {
|
|
3811
|
+
onSelectAddress: setSelectedConnectAddress,
|
|
3812
|
+
onSelectTransferCrypto: dappAddress ? () => {
|
|
3710
3813
|
handleSelectTransferCrypto();
|
|
3711
3814
|
setIsConnectSelectionConfirmed(true);
|
|
3712
|
-
},
|
|
3815
|
+
} : void 0,
|
|
3713
3816
|
onRequestConnect,
|
|
3714
3817
|
onConnect,
|
|
3715
3818
|
onContinue: () => {
|
|
3819
|
+
if (selectedConnectAddressEffective) {
|
|
3820
|
+
setSelectedConnectAddress(selectedConnectAddressEffective);
|
|
3821
|
+
}
|
|
3716
3822
|
handleSelectProvider();
|
|
3717
3823
|
setIsConnectSelectionConfirmed(true);
|
|
3718
3824
|
},
|
|
@@ -3720,16 +3826,13 @@ function DepositFlow({
|
|
|
3720
3826
|
}
|
|
3721
3827
|
) });
|
|
3722
3828
|
}
|
|
3723
|
-
if (!walletClient || !publicClient || !address) {
|
|
3724
|
-
return null;
|
|
3725
|
-
}
|
|
3726
3829
|
if (isDepositAddressMode) {
|
|
3830
|
+
if (!dappAddress || !sessionKeyAddress) return null;
|
|
3727
3831
|
return /* @__PURE__ */ jsxs13("div", { className: "rs-modal-body", children: [
|
|
3728
3832
|
step.type === "setup" && targetChainObj && /* @__PURE__ */ jsx14(
|
|
3729
3833
|
SetupStep,
|
|
3730
3834
|
{
|
|
3731
|
-
|
|
3732
|
-
address,
|
|
3835
|
+
address: sessionKeyAddress,
|
|
3733
3836
|
targetChain,
|
|
3734
3837
|
targetChainObj,
|
|
3735
3838
|
targetToken,
|
|
@@ -3773,12 +3876,23 @@ function DepositFlow({
|
|
|
3773
3876
|
)
|
|
3774
3877
|
] });
|
|
3775
3878
|
}
|
|
3879
|
+
if (!signerContext?.walletClient || !signerContext?.publicClient) {
|
|
3880
|
+
return null;
|
|
3881
|
+
}
|
|
3882
|
+
const ownerAddress = signerContext.ownerAddress;
|
|
3883
|
+
const ownerChainId = signerContext.walletClient?.chain?.id ?? signerContext.publicClient.chain?.id ?? targetChain;
|
|
3884
|
+
const getReadClientForChain = (chainId) => {
|
|
3885
|
+
if (signerContext.publicClient.chain?.id === chainId) {
|
|
3886
|
+
return signerContext.publicClient;
|
|
3887
|
+
}
|
|
3888
|
+
return getPublicClient(chainId);
|
|
3889
|
+
};
|
|
3776
3890
|
return /* @__PURE__ */ jsxs13("div", { className: "rs-modal-body", children: [
|
|
3777
3891
|
step.type === "setup" && targetChainObj && /* @__PURE__ */ jsx14(
|
|
3778
3892
|
SetupStep,
|
|
3779
3893
|
{
|
|
3780
|
-
walletClient,
|
|
3781
|
-
address,
|
|
3894
|
+
walletClient: signerContext.walletClient,
|
|
3895
|
+
address: ownerAddress,
|
|
3782
3896
|
targetChain,
|
|
3783
3897
|
targetChainObj,
|
|
3784
3898
|
targetToken,
|
|
@@ -3795,8 +3909,8 @@ function DepositFlow({
|
|
|
3795
3909
|
step.type === "select-asset" && /* @__PURE__ */ jsx14(
|
|
3796
3910
|
AssetSelectStep,
|
|
3797
3911
|
{
|
|
3798
|
-
address,
|
|
3799
|
-
publicClient,
|
|
3912
|
+
address: ownerAddress,
|
|
3913
|
+
publicClient: getReadClientForChain(ownerChainId),
|
|
3800
3914
|
defaultSourceChain,
|
|
3801
3915
|
defaultSourceToken,
|
|
3802
3916
|
service,
|
|
@@ -3807,12 +3921,12 @@ function DepositFlow({
|
|
|
3807
3921
|
step.type === "amount" && /* @__PURE__ */ jsx14(
|
|
3808
3922
|
AmountStep,
|
|
3809
3923
|
{
|
|
3810
|
-
walletClient,
|
|
3811
|
-
publicClient,
|
|
3812
|
-
address,
|
|
3924
|
+
walletClient: signerContext.walletClient,
|
|
3925
|
+
publicClient: getReadClientForChain(step.asset.chainId),
|
|
3926
|
+
address: ownerAddress,
|
|
3813
3927
|
asset: step.asset,
|
|
3814
3928
|
defaultAmount: step.amount ?? defaultAmount,
|
|
3815
|
-
switchChain,
|
|
3929
|
+
switchChain: signerContext.switchChain,
|
|
3816
3930
|
targetChain,
|
|
3817
3931
|
targetToken,
|
|
3818
3932
|
uiConfig,
|
|
@@ -3822,15 +3936,15 @@ function DepositFlow({
|
|
|
3822
3936
|
step.type === "confirm" && /* @__PURE__ */ jsx14(
|
|
3823
3937
|
ConfirmStep,
|
|
3824
3938
|
{
|
|
3825
|
-
walletClient,
|
|
3826
|
-
address,
|
|
3939
|
+
walletClient: signerContext.walletClient,
|
|
3940
|
+
address: ownerAddress,
|
|
3827
3941
|
smartAccount: step.smartAccount,
|
|
3828
3942
|
asset: step.asset,
|
|
3829
3943
|
amount: step.amount,
|
|
3830
3944
|
balance: step.balance,
|
|
3831
3945
|
targetChain,
|
|
3832
3946
|
targetToken,
|
|
3833
|
-
switchChain,
|
|
3947
|
+
switchChain: signerContext.switchChain,
|
|
3834
3948
|
onConfirm: handleDepositSubmitted,
|
|
3835
3949
|
onDepositSubmitted: handleDepositSubmittedCallback,
|
|
3836
3950
|
onError: handleError
|
|
@@ -3868,6 +3982,7 @@ var init_DepositFlow = __esm({
|
|
|
3868
3982
|
init_ProcessingStep();
|
|
3869
3983
|
init_DepositAddressStep();
|
|
3870
3984
|
init_constants();
|
|
3985
|
+
init_public_client();
|
|
3871
3986
|
}
|
|
3872
3987
|
});
|
|
3873
3988
|
|
|
@@ -3918,15 +4033,11 @@ var init_theme = __esm({
|
|
|
3918
4033
|
});
|
|
3919
4034
|
|
|
3920
4035
|
// src/core/reown.tsx
|
|
3921
|
-
import { useState as useState8
|
|
4036
|
+
import { useState as useState8 } from "react";
|
|
3922
4037
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3923
4038
|
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
|
|
3924
4039
|
import { WagmiProvider } from "wagmi";
|
|
3925
|
-
import {
|
|
3926
|
-
createAppKit,
|
|
3927
|
-
useAppKit,
|
|
3928
|
-
useAppKitAccount
|
|
3929
|
-
} from "@reown/appkit/react";
|
|
4040
|
+
import { createAppKit, useAppKit, useAppKitAccount } from "@reown/appkit/react";
|
|
3930
4041
|
import {
|
|
3931
4042
|
mainnet as mainnet2,
|
|
3932
4043
|
base as base2,
|
|
@@ -3935,11 +4046,7 @@ import {
|
|
|
3935
4046
|
polygon as polygon2,
|
|
3936
4047
|
bsc as bsc2
|
|
3937
4048
|
} from "@reown/appkit/networks";
|
|
3938
|
-
import {
|
|
3939
|
-
useWalletClient,
|
|
3940
|
-
usePublicClient,
|
|
3941
|
-
useSwitchChain
|
|
3942
|
-
} from "wagmi";
|
|
4049
|
+
import { useWalletClient, usePublicClient, useSwitchChain } from "wagmi";
|
|
3943
4050
|
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
3944
4051
|
function mapTheme(theme) {
|
|
3945
4052
|
const themeMode = theme?.mode === "light" ? "light" : "dark";
|
|
@@ -4000,72 +4107,6 @@ function useReownWallet() {
|
|
|
4000
4107
|
}
|
|
4001
4108
|
};
|
|
4002
4109
|
}
|
|
4003
|
-
function useResolvedWallet(host, reown) {
|
|
4004
|
-
const [selectedAddress, setSelectedAddress] = useState8(null);
|
|
4005
|
-
const walletOptions = useMemo7(() => {
|
|
4006
|
-
const options = [];
|
|
4007
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4008
|
-
if (host.address) {
|
|
4009
|
-
options.push({
|
|
4010
|
-
address: host.address,
|
|
4011
|
-
label: "Connected Wallet",
|
|
4012
|
-
kind: "connected"
|
|
4013
|
-
});
|
|
4014
|
-
seen.add(host.address.toLowerCase());
|
|
4015
|
-
}
|
|
4016
|
-
if (reown.address && !seen.has(reown.address.toLowerCase())) {
|
|
4017
|
-
options.push({
|
|
4018
|
-
address: reown.address,
|
|
4019
|
-
label: "External Wallet",
|
|
4020
|
-
kind: "external"
|
|
4021
|
-
});
|
|
4022
|
-
}
|
|
4023
|
-
return options;
|
|
4024
|
-
}, [host.address, reown.address]);
|
|
4025
|
-
const effectiveAddress = useMemo7(() => {
|
|
4026
|
-
if (walletOptions.length === 0) return null;
|
|
4027
|
-
if (walletOptions.length === 1) return walletOptions[0].address;
|
|
4028
|
-
if (selectedAddress) {
|
|
4029
|
-
const valid = walletOptions.some(
|
|
4030
|
-
(opt) => opt.address.toLowerCase() === selectedAddress.toLowerCase()
|
|
4031
|
-
);
|
|
4032
|
-
if (valid) return selectedAddress;
|
|
4033
|
-
}
|
|
4034
|
-
return null;
|
|
4035
|
-
}, [walletOptions, selectedAddress]);
|
|
4036
|
-
let walletClient;
|
|
4037
|
-
let publicClient;
|
|
4038
|
-
if (effectiveAddress) {
|
|
4039
|
-
const key = effectiveAddress.toLowerCase();
|
|
4040
|
-
if (host.address?.toLowerCase() === key && host.walletClient && host.publicClient) {
|
|
4041
|
-
walletClient = host.walletClient;
|
|
4042
|
-
publicClient = host.publicClient;
|
|
4043
|
-
} else if (reown.address?.toLowerCase() === key && reown.walletClient && reown.publicClient) {
|
|
4044
|
-
walletClient = reown.walletClient;
|
|
4045
|
-
publicClient = reown.publicClient;
|
|
4046
|
-
}
|
|
4047
|
-
}
|
|
4048
|
-
const handleSwitchChain = useCallback5(
|
|
4049
|
-
async (chainId) => {
|
|
4050
|
-
if (host.switchChain && effectiveAddress?.toLowerCase() === host.address?.toLowerCase()) {
|
|
4051
|
-
await host.switchChain(chainId);
|
|
4052
|
-
} else {
|
|
4053
|
-
await reown.switchChain(chainId);
|
|
4054
|
-
}
|
|
4055
|
-
},
|
|
4056
|
-
[host.switchChain, host.address, reown.switchChain, effectiveAddress]
|
|
4057
|
-
);
|
|
4058
|
-
return {
|
|
4059
|
-
walletClient,
|
|
4060
|
-
publicClient,
|
|
4061
|
-
address: effectiveAddress ?? void 0,
|
|
4062
|
-
walletOptions,
|
|
4063
|
-
selectedAddress: effectiveAddress,
|
|
4064
|
-
onSelectAddress: setSelectedAddress,
|
|
4065
|
-
openConnect: reown.openConnect,
|
|
4066
|
-
switchChain: handleSwitchChain
|
|
4067
|
-
};
|
|
4068
|
-
}
|
|
4069
4110
|
var NETWORKS, cachedAdapter, cachedProjectId;
|
|
4070
4111
|
var init_reown = __esm({
|
|
4071
4112
|
"src/core/reown.tsx"() {
|
|
@@ -4088,35 +4129,19 @@ var DepositModalReown_exports = {};
|
|
|
4088
4129
|
__export(DepositModalReown_exports, {
|
|
4089
4130
|
DepositModalReown: () => DepositModalReown
|
|
4090
4131
|
});
|
|
4091
|
-
import { useCallback as
|
|
4132
|
+
import { useCallback as useCallback5 } from "react";
|
|
4092
4133
|
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
4093
4134
|
function DepositModalWithReown(props) {
|
|
4094
4135
|
const reown = useReownWallet();
|
|
4095
|
-
const
|
|
4096
|
-
{
|
|
4097
|
-
walletClient: props.walletClient,
|
|
4098
|
-
publicClient: props.publicClient,
|
|
4099
|
-
address: props.address,
|
|
4100
|
-
switchChain: props.switchChain
|
|
4101
|
-
},
|
|
4102
|
-
reown
|
|
4103
|
-
);
|
|
4104
|
-
const handleConnect = useCallback6(() => {
|
|
4136
|
+
const handleConnect = useCallback5(() => {
|
|
4105
4137
|
reown.openConnect();
|
|
4106
4138
|
}, [reown.openConnect]);
|
|
4107
4139
|
return /* @__PURE__ */ jsx16(
|
|
4108
4140
|
DepositModalInner,
|
|
4109
4141
|
{
|
|
4110
4142
|
...props,
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
address: resolved.address,
|
|
4114
|
-
switchChain: resolved.switchChain,
|
|
4115
|
-
connectWalletOptions: resolved.walletOptions,
|
|
4116
|
-
selectedConnectAddress: resolved.selectedAddress,
|
|
4117
|
-
onSelectConnectAddress: resolved.onSelectAddress,
|
|
4118
|
-
onConnect: handleConnect,
|
|
4119
|
-
onRequestConnect: props.onRequestConnect
|
|
4143
|
+
reownWallet: reown,
|
|
4144
|
+
onConnect: handleConnect
|
|
4120
4145
|
}
|
|
4121
4146
|
);
|
|
4122
4147
|
}
|
|
@@ -4133,11 +4158,11 @@ var init_DepositModalReown = __esm({
|
|
|
4133
4158
|
|
|
4134
4159
|
// src/DepositModal.tsx
|
|
4135
4160
|
import {
|
|
4136
|
-
useMemo as
|
|
4161
|
+
useMemo as useMemo7,
|
|
4137
4162
|
useEffect as useEffect8,
|
|
4138
4163
|
useRef as useRef7,
|
|
4139
4164
|
useState as useState9,
|
|
4140
|
-
useCallback as
|
|
4165
|
+
useCallback as useCallback6,
|
|
4141
4166
|
lazy,
|
|
4142
4167
|
Suspense
|
|
4143
4168
|
} from "react";
|
|
@@ -4150,15 +4175,14 @@ function DepositModal(props) {
|
|
|
4150
4175
|
return /* @__PURE__ */ jsx17(DepositModalInner, { ...props });
|
|
4151
4176
|
}
|
|
4152
4177
|
function DepositModalInner({
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4178
|
+
dappWalletClient,
|
|
4179
|
+
dappPublicClient,
|
|
4180
|
+
dappAddress,
|
|
4156
4181
|
targetChain: targetChainProp,
|
|
4157
4182
|
targetToken,
|
|
4158
4183
|
isOpen,
|
|
4159
4184
|
onClose,
|
|
4160
4185
|
inline,
|
|
4161
|
-
switchChain,
|
|
4162
4186
|
sourceChain: sourceChainProp,
|
|
4163
4187
|
sourceToken,
|
|
4164
4188
|
defaultAmount,
|
|
@@ -4168,9 +4192,7 @@ function DepositModalInner({
|
|
|
4168
4192
|
sessionChainIds,
|
|
4169
4193
|
forceRegister = false,
|
|
4170
4194
|
waitForFinalTx = true,
|
|
4171
|
-
|
|
4172
|
-
selectedConnectAddress,
|
|
4173
|
-
onSelectConnectAddress,
|
|
4195
|
+
reownWallet,
|
|
4174
4196
|
onConnect,
|
|
4175
4197
|
onRequestConnect,
|
|
4176
4198
|
connectButtonLabel,
|
|
@@ -4191,7 +4213,7 @@ function DepositModalInner({
|
|
|
4191
4213
|
const backHandlerRef = useRef7(void 0);
|
|
4192
4214
|
const targetChain = getChainId(targetChainProp);
|
|
4193
4215
|
const sourceChain = sourceChainProp ? getChainId(sourceChainProp) : void 0;
|
|
4194
|
-
const service =
|
|
4216
|
+
const service = useMemo7(() => createDepositService(backendUrl), [backendUrl]);
|
|
4195
4217
|
useEffect8(() => {
|
|
4196
4218
|
if (isOpen && modalRef.current) {
|
|
4197
4219
|
applyTheme(modalRef.current, theme);
|
|
@@ -4209,17 +4231,17 @@ function DepositModalInner({
|
|
|
4209
4231
|
setCurrentStepIndex(0);
|
|
4210
4232
|
}
|
|
4211
4233
|
}, [isOpen]);
|
|
4212
|
-
const handleStepChange =
|
|
4234
|
+
const handleStepChange = useCallback6(
|
|
4213
4235
|
(stepIndex, onBack) => {
|
|
4214
4236
|
setCurrentStepIndex(stepIndex);
|
|
4215
4237
|
backHandlerRef.current = onBack;
|
|
4216
4238
|
},
|
|
4217
4239
|
[]
|
|
4218
4240
|
);
|
|
4219
|
-
const handleTotalBalanceChange =
|
|
4241
|
+
const handleTotalBalanceChange = useCallback6((balance) => {
|
|
4220
4242
|
setTotalBalanceUsd(balance);
|
|
4221
4243
|
}, []);
|
|
4222
|
-
const handleBack =
|
|
4244
|
+
const handleBack = useCallback6(() => {
|
|
4223
4245
|
backHandlerRef.current?.();
|
|
4224
4246
|
}, []);
|
|
4225
4247
|
const showLogo = uiConfig?.showLogo ?? false;
|
|
@@ -4324,13 +4346,12 @@ function DepositModalInner({
|
|
|
4324
4346
|
/* @__PURE__ */ jsx17(
|
|
4325
4347
|
DepositFlow,
|
|
4326
4348
|
{
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4349
|
+
dappWalletClient,
|
|
4350
|
+
dappPublicClient,
|
|
4351
|
+
dappAddress,
|
|
4330
4352
|
targetChain,
|
|
4331
4353
|
targetToken,
|
|
4332
4354
|
service,
|
|
4333
|
-
switchChain,
|
|
4334
4355
|
sourceChain,
|
|
4335
4356
|
sourceToken,
|
|
4336
4357
|
amount: defaultAmount,
|
|
@@ -4339,9 +4360,7 @@ function DepositModalInner({
|
|
|
4339
4360
|
sessionChainIds,
|
|
4340
4361
|
forceRegister,
|
|
4341
4362
|
waitForFinalTx,
|
|
4342
|
-
|
|
4343
|
-
selectedConnectAddress,
|
|
4344
|
-
onSelectConnectAddress,
|
|
4363
|
+
reownWallet,
|
|
4345
4364
|
onConnect,
|
|
4346
4365
|
onRequestConnect,
|
|
4347
4366
|
connectButtonLabel,
|
|
@@ -4378,7 +4397,7 @@ var init_DepositModal = __esm({
|
|
|
4378
4397
|
});
|
|
4379
4398
|
|
|
4380
4399
|
// src/components/steps/WithdrawFormStep.tsx
|
|
4381
|
-
import { useCallback as
|
|
4400
|
+
import { useCallback as useCallback7, useEffect as useEffect9, useMemo as useMemo8, useRef as useRef8, useState as useState10 } from "react";
|
|
4382
4401
|
import { erc20Abi as erc20Abi3, formatUnits as formatUnits5, parseUnits as parseUnits3 } from "viem";
|
|
4383
4402
|
import { jsx as jsx18, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
4384
4403
|
function useClickOutside(ref, onClose) {
|
|
@@ -4486,7 +4505,7 @@ function WithdrawFormStep({
|
|
|
4486
4505
|
unwatch();
|
|
4487
4506
|
};
|
|
4488
4507
|
}, [safeAddress, publicClient, publicClientChainId, asset]);
|
|
4489
|
-
const formattedBalance =
|
|
4508
|
+
const formattedBalance = useMemo8(() => {
|
|
4490
4509
|
if (balance === null) return "...";
|
|
4491
4510
|
try {
|
|
4492
4511
|
const raw = formatUnits5(balance, asset.decimals);
|
|
@@ -4512,7 +4531,7 @@ function WithdrawFormStep({
|
|
|
4512
4531
|
return;
|
|
4513
4532
|
}
|
|
4514
4533
|
}, [balance, asset.decimals, asset.symbol, onBalanceUsdChange]);
|
|
4515
|
-
const amountUsd =
|
|
4534
|
+
const amountUsd = useMemo8(() => {
|
|
4516
4535
|
if (!amount) return null;
|
|
4517
4536
|
const parsed = Number(amount);
|
|
4518
4537
|
if (!Number.isFinite(parsed) || parsed <= 0) return null;
|
|
@@ -4522,18 +4541,18 @@ function WithdrawFormStep({
|
|
|
4522
4541
|
}
|
|
4523
4542
|
return null;
|
|
4524
4543
|
}, [amount, asset.symbol]);
|
|
4525
|
-
const handleMaxClick =
|
|
4544
|
+
const handleMaxClick = useCallback7(() => {
|
|
4526
4545
|
if (balance === null) return;
|
|
4527
4546
|
const maxAmount = formatUnits5(balance, asset.decimals);
|
|
4528
4547
|
setAmount(maxAmount);
|
|
4529
4548
|
setError(null);
|
|
4530
4549
|
}, [balance, asset.decimals]);
|
|
4531
|
-
const handleUseConnected =
|
|
4550
|
+
const handleUseConnected = useCallback7(() => {
|
|
4532
4551
|
if (!address) return;
|
|
4533
4552
|
setRecipient(address);
|
|
4534
4553
|
setError(null);
|
|
4535
4554
|
}, [address]);
|
|
4536
|
-
const handleWithdraw =
|
|
4555
|
+
const handleWithdraw = useCallback7(async () => {
|
|
4537
4556
|
if (!recipient || !/^0x[a-fA-F0-9]{40}$/.test(recipient)) {
|
|
4538
4557
|
setError("Enter a valid recipient address");
|
|
4539
4558
|
return;
|
|
@@ -5130,15 +5149,14 @@ var init_safe = __esm({
|
|
|
5130
5149
|
});
|
|
5131
5150
|
|
|
5132
5151
|
// src/WithdrawFlow.tsx
|
|
5133
|
-
import { useCallback as
|
|
5134
|
-
import { createPublicClient, http } from "viem";
|
|
5152
|
+
import { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo9, useState as useState11 } from "react";
|
|
5135
5153
|
import { walletClientToAccount as walletClientToAccount2 } from "@rhinestone/sdk";
|
|
5136
5154
|
import { parseUnits as parseUnits4 } from "viem";
|
|
5137
5155
|
import { jsx as jsx19, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
5138
5156
|
function WithdrawFlow({
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5157
|
+
dappWalletClient,
|
|
5158
|
+
dappPublicClient,
|
|
5159
|
+
dappAddress,
|
|
5142
5160
|
safeAddress,
|
|
5143
5161
|
sourceChain,
|
|
5144
5162
|
sourceToken,
|
|
@@ -5147,14 +5165,11 @@ function WithdrawFlow({
|
|
|
5147
5165
|
recipient: defaultRecipient,
|
|
5148
5166
|
amount: defaultAmount,
|
|
5149
5167
|
service,
|
|
5150
|
-
switchChain,
|
|
5151
5168
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
5152
5169
|
sessionChainIds,
|
|
5153
5170
|
forceRegister = false,
|
|
5154
5171
|
waitForFinalTx = true,
|
|
5155
|
-
|
|
5156
|
-
selectedConnectAddress,
|
|
5157
|
-
onSelectConnectAddress,
|
|
5172
|
+
reownWallet,
|
|
5158
5173
|
onConnect,
|
|
5159
5174
|
onWithdrawSign,
|
|
5160
5175
|
onRequestConnect,
|
|
@@ -5178,14 +5193,89 @@ function WithdrawFlow({
|
|
|
5178
5193
|
setTargetChain(targetChainProp);
|
|
5179
5194
|
setTargetToken(targetTokenProp);
|
|
5180
5195
|
}, [targetChainProp, targetTokenProp]);
|
|
5181
|
-
const targetChainObj =
|
|
5182
|
-
const hasCustomSigner = Boolean(
|
|
5183
|
-
const
|
|
5184
|
-
|
|
5185
|
-
() =>
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5196
|
+
const targetChainObj = useMemo9(() => CHAIN_BY_ID[targetChain], [targetChain]);
|
|
5197
|
+
const hasCustomSigner = Boolean(dappAddress && onWithdrawSign);
|
|
5198
|
+
const dappSwitchChain = useMemo9(() => {
|
|
5199
|
+
if (!dappWalletClient?.switchChain) return void 0;
|
|
5200
|
+
return async (chainId) => {
|
|
5201
|
+
await dappWalletClient.switchChain?.({ id: chainId });
|
|
5202
|
+
};
|
|
5203
|
+
}, [dappWalletClient]);
|
|
5204
|
+
const walletOptions = useMemo9(() => {
|
|
5205
|
+
const options = [];
|
|
5206
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5207
|
+
if (dappWalletClient?.account && dappAddress) {
|
|
5208
|
+
options.push({
|
|
5209
|
+
address: dappWalletClient.account.address,
|
|
5210
|
+
label: "Connected Wallet",
|
|
5211
|
+
kind: "connected"
|
|
5212
|
+
});
|
|
5213
|
+
seen.add(dappWalletClient.account.address.toLowerCase());
|
|
5214
|
+
}
|
|
5215
|
+
if (reownWallet?.address && reownWallet.isConnected && !seen.has(reownWallet.address.toLowerCase())) {
|
|
5216
|
+
options.push({
|
|
5217
|
+
address: reownWallet.address,
|
|
5218
|
+
label: "External Wallet",
|
|
5219
|
+
kind: "external"
|
|
5220
|
+
});
|
|
5221
|
+
}
|
|
5222
|
+
return options;
|
|
5223
|
+
}, [
|
|
5224
|
+
dappWalletClient,
|
|
5225
|
+
dappAddress,
|
|
5226
|
+
reownWallet?.address,
|
|
5227
|
+
reownWallet?.isConnected
|
|
5228
|
+
]);
|
|
5229
|
+
const canAutoLock = (dappWalletClient?.account && dappAddress || hasCustomSigner) && !reownWallet;
|
|
5230
|
+
const [selectedConnectAddress, setSelectedConnectAddress] = useState11(null);
|
|
5231
|
+
const signerContext = useMemo9(() => {
|
|
5232
|
+
if (canAutoLock) {
|
|
5233
|
+
if (hasCustomSigner) {
|
|
5234
|
+
return {
|
|
5235
|
+
ownerAddress: dappAddress,
|
|
5236
|
+
walletClient: dappWalletClient ?? void 0,
|
|
5237
|
+
publicClient: dappPublicClient ?? getPublicClient(sourceChain),
|
|
5238
|
+
switchChain: dappSwitchChain
|
|
5239
|
+
};
|
|
5240
|
+
}
|
|
5241
|
+
return {
|
|
5242
|
+
ownerAddress: dappWalletClient.account.address,
|
|
5243
|
+
walletClient: dappWalletClient,
|
|
5244
|
+
publicClient: dappPublicClient ?? getPublicClient(sourceChain),
|
|
5245
|
+
switchChain: dappSwitchChain
|
|
5246
|
+
};
|
|
5247
|
+
}
|
|
5248
|
+
if (!isConnectSelectionConfirmed || !selectedConnectAddress) return null;
|
|
5249
|
+
if (dappWalletClient?.account && dappWalletClient.account.address.toLowerCase() === selectedConnectAddress.toLowerCase()) {
|
|
5250
|
+
return {
|
|
5251
|
+
ownerAddress: dappWalletClient.account.address,
|
|
5252
|
+
walletClient: dappWalletClient,
|
|
5253
|
+
publicClient: dappPublicClient ?? getPublicClient(sourceChain),
|
|
5254
|
+
switchChain: dappSwitchChain
|
|
5255
|
+
};
|
|
5256
|
+
}
|
|
5257
|
+
if (reownWallet?.address?.toLowerCase() === selectedConnectAddress.toLowerCase() && reownWallet.walletClient && reownWallet.publicClient) {
|
|
5258
|
+
return {
|
|
5259
|
+
ownerAddress: reownWallet.address,
|
|
5260
|
+
walletClient: reownWallet.walletClient,
|
|
5261
|
+
publicClient: reownWallet.publicClient,
|
|
5262
|
+
switchChain: reownWallet.switchChain
|
|
5263
|
+
};
|
|
5264
|
+
}
|
|
5265
|
+
return null;
|
|
5266
|
+
}, [
|
|
5267
|
+
canAutoLock,
|
|
5268
|
+
hasCustomSigner,
|
|
5269
|
+
isConnectSelectionConfirmed,
|
|
5270
|
+
selectedConnectAddress,
|
|
5271
|
+
dappWalletClient,
|
|
5272
|
+
dappPublicClient,
|
|
5273
|
+
dappSwitchChain,
|
|
5274
|
+
dappAddress,
|
|
5275
|
+
reownWallet,
|
|
5276
|
+
sourceChain
|
|
5277
|
+
]);
|
|
5278
|
+
const asset = useMemo9(() => {
|
|
5189
5279
|
const symbol = getTokenSymbol(sourceToken, sourceChain);
|
|
5190
5280
|
const decimals = getTokenDecimalsByAddress(sourceToken, sourceChain);
|
|
5191
5281
|
return {
|
|
@@ -5206,19 +5296,19 @@ function WithdrawFlow({
|
|
|
5206
5296
|
useEffect10(() => {
|
|
5207
5297
|
onTotalBalanceChange?.(totalBalanceUsd);
|
|
5208
5298
|
}, [totalBalanceUsd, onTotalBalanceChange]);
|
|
5209
|
-
const handleConnected =
|
|
5299
|
+
const handleConnected = useCallback8(
|
|
5210
5300
|
(addr, smartAccount) => {
|
|
5211
5301
|
onConnected?.({ address: addr, smartAccount });
|
|
5212
5302
|
},
|
|
5213
5303
|
[onConnected]
|
|
5214
5304
|
);
|
|
5215
|
-
const handleError =
|
|
5305
|
+
const handleError = useCallback8(
|
|
5216
5306
|
(message, code) => {
|
|
5217
5307
|
onError?.({ message, code });
|
|
5218
5308
|
},
|
|
5219
5309
|
[onError]
|
|
5220
5310
|
);
|
|
5221
|
-
const resolveSessionOwner2 =
|
|
5311
|
+
const resolveSessionOwner2 = useCallback8(async (eoaAddress) => {
|
|
5222
5312
|
const localOwner = loadSessionOwnerFromStorage(eoaAddress);
|
|
5223
5313
|
if (localOwner) {
|
|
5224
5314
|
return {
|
|
@@ -5233,12 +5323,13 @@ function WithdrawFlow({
|
|
|
5233
5323
|
address: created.address
|
|
5234
5324
|
};
|
|
5235
5325
|
}, []);
|
|
5236
|
-
const handleFormSubmit =
|
|
5326
|
+
const handleFormSubmit = useCallback8(
|
|
5237
5327
|
async (recipient, amountValue) => {
|
|
5238
|
-
|
|
5328
|
+
const ownerAddress2 = signerContext?.ownerAddress;
|
|
5329
|
+
if (!ownerAddress2) {
|
|
5239
5330
|
throw new Error("Wallet not connected");
|
|
5240
5331
|
}
|
|
5241
|
-
if (!onWithdrawSign &&
|
|
5332
|
+
if (!onWithdrawSign && !signerContext?.walletClient) {
|
|
5242
5333
|
throw new Error("Wallet not connected");
|
|
5243
5334
|
}
|
|
5244
5335
|
if (!targetChainObj) {
|
|
@@ -5246,8 +5337,8 @@ function WithdrawFlow({
|
|
|
5246
5337
|
}
|
|
5247
5338
|
setIsSubmitting(true);
|
|
5248
5339
|
try {
|
|
5249
|
-
const signerAccount = walletClient ? walletClientToAccount2(walletClient) : createViewOnlyAccount(
|
|
5250
|
-
const sessionOwner = await resolveSessionOwner2(
|
|
5340
|
+
const signerAccount = signerContext?.walletClient ? walletClientToAccount2(signerContext.walletClient) : createViewOnlyAccount(ownerAddress2);
|
|
5341
|
+
const sessionOwner = await resolveSessionOwner2(ownerAddress2);
|
|
5251
5342
|
const account = await createSmartAccount(
|
|
5252
5343
|
signerAccount,
|
|
5253
5344
|
sessionOwner.account
|
|
@@ -5272,7 +5363,7 @@ function WithdrawFlow({
|
|
|
5272
5363
|
factoryData: initData.factoryData,
|
|
5273
5364
|
sessionDetails
|
|
5274
5365
|
},
|
|
5275
|
-
eoaAddress:
|
|
5366
|
+
eoaAddress: ownerAddress2,
|
|
5276
5367
|
sessionOwner: sessionOwner.address,
|
|
5277
5368
|
target: {
|
|
5278
5369
|
chain: targetChain,
|
|
@@ -5281,8 +5372,9 @@ function WithdrawFlow({
|
|
|
5281
5372
|
}
|
|
5282
5373
|
});
|
|
5283
5374
|
}
|
|
5284
|
-
handleConnected(
|
|
5375
|
+
handleConnected(ownerAddress2, smartAccount);
|
|
5285
5376
|
const amountUnits = parseUnits4(amountValue, asset.decimals);
|
|
5377
|
+
const pc = signerContext?.publicClient ?? getPublicClient(sourceChain);
|
|
5286
5378
|
const result = onWithdrawSign ? await onWithdrawSign({
|
|
5287
5379
|
safeAddress,
|
|
5288
5380
|
recipient: smartAccount,
|
|
@@ -5291,15 +5383,15 @@ function WithdrawFlow({
|
|
|
5291
5383
|
chainId: sourceChain,
|
|
5292
5384
|
isNative: isSourceNative
|
|
5293
5385
|
}) : isSourceNative ? await executeSafeEthTransfer({
|
|
5294
|
-
walletClient,
|
|
5295
|
-
publicClient,
|
|
5386
|
+
walletClient: signerContext.walletClient,
|
|
5387
|
+
publicClient: pc,
|
|
5296
5388
|
safeAddress,
|
|
5297
5389
|
recipient: smartAccount,
|
|
5298
5390
|
amount: amountUnits,
|
|
5299
5391
|
chainId: sourceChain
|
|
5300
5392
|
}) : await executeSafeErc20Transfer({
|
|
5301
|
-
walletClient,
|
|
5302
|
-
publicClient,
|
|
5393
|
+
walletClient: signerContext.walletClient,
|
|
5394
|
+
publicClient: pc,
|
|
5303
5395
|
safeAddress,
|
|
5304
5396
|
tokenAddress: sourceToken,
|
|
5305
5397
|
recipient: smartAccount,
|
|
@@ -5329,9 +5421,7 @@ function WithdrawFlow({
|
|
|
5329
5421
|
}
|
|
5330
5422
|
},
|
|
5331
5423
|
[
|
|
5332
|
-
|
|
5333
|
-
publicClient,
|
|
5334
|
-
address,
|
|
5424
|
+
signerContext,
|
|
5335
5425
|
targetChainObj,
|
|
5336
5426
|
resolveSessionOwner2,
|
|
5337
5427
|
signerAddress,
|
|
@@ -5351,24 +5441,24 @@ function WithdrawFlow({
|
|
|
5351
5441
|
handleError
|
|
5352
5442
|
]
|
|
5353
5443
|
);
|
|
5354
|
-
const handleWithdrawComplete =
|
|
5444
|
+
const handleWithdrawComplete = useCallback8(
|
|
5355
5445
|
(txHash, destinationTxHash) => {
|
|
5356
5446
|
onWithdrawComplete?.({ txHash, destinationTxHash });
|
|
5357
5447
|
},
|
|
5358
5448
|
[onWithdrawComplete]
|
|
5359
5449
|
);
|
|
5360
|
-
const handleWithdrawFailed =
|
|
5450
|
+
const handleWithdrawFailed = useCallback8(
|
|
5361
5451
|
(txHash, error) => {
|
|
5362
5452
|
onWithdrawFailed?.({ txHash, error });
|
|
5363
5453
|
},
|
|
5364
5454
|
[onWithdrawFailed]
|
|
5365
5455
|
);
|
|
5366
|
-
const targetChainOptions =
|
|
5456
|
+
const targetChainOptions = useMemo9(() => {
|
|
5367
5457
|
return SOURCE_CHAINS.filter(
|
|
5368
5458
|
(chain) => getSupportedTargetTokens(chain.id).length > 0
|
|
5369
5459
|
);
|
|
5370
5460
|
}, []);
|
|
5371
|
-
const targetTokenOptions =
|
|
5461
|
+
const targetTokenOptions = useMemo9(
|
|
5372
5462
|
() => getSupportedTargetTokens(targetChain),
|
|
5373
5463
|
[targetChain]
|
|
5374
5464
|
);
|
|
@@ -5381,7 +5471,7 @@ function WithdrawFlow({
|
|
|
5381
5471
|
setTargetToken(targetTokenOptions[0].address);
|
|
5382
5472
|
}
|
|
5383
5473
|
}, [targetToken, targetTokenOptions]);
|
|
5384
|
-
const handleTargetChainChange =
|
|
5474
|
+
const handleTargetChainChange = useCallback8(
|
|
5385
5475
|
(chainId) => {
|
|
5386
5476
|
setTargetChain(chainId);
|
|
5387
5477
|
const options = getSupportedTargetTokens(chainId);
|
|
@@ -5397,55 +5487,57 @@ function WithdrawFlow({
|
|
|
5397
5487
|
},
|
|
5398
5488
|
[targetToken]
|
|
5399
5489
|
);
|
|
5400
|
-
const handleTargetTokenChange =
|
|
5490
|
+
const handleTargetTokenChange = useCallback8((token) => {
|
|
5401
5491
|
setTargetToken(token);
|
|
5402
5492
|
}, []);
|
|
5403
|
-
const
|
|
5404
|
-
const selectedConnectAddressEffective = useMemo10(() => {
|
|
5493
|
+
const selectedConnectAddressEffective = useMemo9(() => {
|
|
5405
5494
|
if (selectedConnectAddress) return selectedConnectAddress;
|
|
5406
|
-
if (
|
|
5407
|
-
return
|
|
5495
|
+
if (walletOptions.length === 1) {
|
|
5496
|
+
return walletOptions[0].address;
|
|
5408
5497
|
}
|
|
5409
5498
|
return null;
|
|
5410
|
-
}, [selectedConnectAddress,
|
|
5411
|
-
const
|
|
5412
|
-
() =>
|
|
5413
|
-
[
|
|
5414
|
-
);
|
|
5415
|
-
const hasConnectedWallet = Boolean(
|
|
5416
|
-
walletClient && publicClient && address || hasCustomSigner
|
|
5499
|
+
}, [selectedConnectAddress, walletOptions]);
|
|
5500
|
+
const walletOptionsKey = useMemo9(
|
|
5501
|
+
() => walletOptions.map((option) => option.address.toLowerCase()).join(","),
|
|
5502
|
+
[walletOptions]
|
|
5417
5503
|
);
|
|
5418
|
-
const showConnectStep = !
|
|
5504
|
+
const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
|
|
5419
5505
|
useEffect10(() => {
|
|
5420
5506
|
setIsConnectSelectionConfirmed(false);
|
|
5421
|
-
}, [
|
|
5507
|
+
}, [walletOptionsKey, selectedConnectAddressEffective]);
|
|
5422
5508
|
if (showConnectStep) {
|
|
5423
5509
|
return /* @__PURE__ */ jsx19("div", { className: "rs-modal-body", children: /* @__PURE__ */ jsx19(
|
|
5424
5510
|
ConnectStep,
|
|
5425
5511
|
{
|
|
5426
|
-
walletOptions
|
|
5512
|
+
walletOptions,
|
|
5427
5513
|
selectedAddress: selectedConnectAddressEffective,
|
|
5428
|
-
onSelectAddress:
|
|
5514
|
+
onSelectAddress: setSelectedConnectAddress,
|
|
5429
5515
|
onRequestConnect,
|
|
5430
5516
|
onConnect,
|
|
5431
|
-
onContinue: () =>
|
|
5517
|
+
onContinue: () => {
|
|
5518
|
+
if (selectedConnectAddressEffective) {
|
|
5519
|
+
setSelectedConnectAddress(selectedConnectAddressEffective);
|
|
5520
|
+
}
|
|
5521
|
+
setIsConnectSelectionConfirmed(true);
|
|
5522
|
+
},
|
|
5432
5523
|
connectButtonLabel
|
|
5433
5524
|
}
|
|
5434
5525
|
) });
|
|
5435
5526
|
}
|
|
5436
|
-
if (!
|
|
5437
|
-
|
|
5438
|
-
|
|
5527
|
+
if (!signerContext) return null;
|
|
5528
|
+
if (!onWithdrawSign && !signerContext.walletClient) return null;
|
|
5529
|
+
const ownerAddress = signerContext.ownerAddress;
|
|
5530
|
+
const formPublicClient = signerContext.publicClient ?? getPublicClient(sourceChain);
|
|
5439
5531
|
return /* @__PURE__ */ jsxs16("div", { className: "rs-modal-body", children: [
|
|
5440
5532
|
step.type === "form" && /* @__PURE__ */ jsx19(
|
|
5441
5533
|
WithdrawFormStep,
|
|
5442
5534
|
{
|
|
5443
|
-
walletClient,
|
|
5444
|
-
publicClient:
|
|
5445
|
-
address,
|
|
5535
|
+
walletClient: signerContext.walletClient,
|
|
5536
|
+
publicClient: formPublicClient,
|
|
5537
|
+
address: ownerAddress,
|
|
5446
5538
|
safeAddress,
|
|
5447
5539
|
asset,
|
|
5448
|
-
defaultRecipient: defaultRecipient ??
|
|
5540
|
+
defaultRecipient: defaultRecipient ?? ownerAddress,
|
|
5449
5541
|
defaultAmount,
|
|
5450
5542
|
targetChain,
|
|
5451
5543
|
targetToken,
|
|
@@ -5453,7 +5545,7 @@ function WithdrawFlow({
|
|
|
5453
5545
|
targetTokenOptions,
|
|
5454
5546
|
onTargetChainChange: handleTargetChainChange,
|
|
5455
5547
|
onTargetTokenChange: handleTargetTokenChange,
|
|
5456
|
-
switchChain,
|
|
5548
|
+
switchChain: signerContext.switchChain,
|
|
5457
5549
|
submitting: isSubmitting,
|
|
5458
5550
|
onSubmit: handleFormSubmit,
|
|
5459
5551
|
onBalanceUsdChange: setTotalBalanceUsd
|
|
@@ -5485,6 +5577,7 @@ var init_WithdrawFlow = __esm({
|
|
|
5485
5577
|
"src/WithdrawFlow.tsx"() {
|
|
5486
5578
|
"use strict";
|
|
5487
5579
|
init_ConnectStep();
|
|
5580
|
+
init_public_client();
|
|
5488
5581
|
init_WithdrawFormStep();
|
|
5489
5582
|
init_ProcessingStep();
|
|
5490
5583
|
init_constants();
|
|
@@ -5500,35 +5593,19 @@ var WithdrawModalReown_exports = {};
|
|
|
5500
5593
|
__export(WithdrawModalReown_exports, {
|
|
5501
5594
|
WithdrawModalReown: () => WithdrawModalReown
|
|
5502
5595
|
});
|
|
5503
|
-
import { useCallback as
|
|
5596
|
+
import { useCallback as useCallback9 } from "react";
|
|
5504
5597
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
5505
5598
|
function WithdrawModalWithReown(props) {
|
|
5506
5599
|
const reown = useReownWallet();
|
|
5507
|
-
const
|
|
5508
|
-
{
|
|
5509
|
-
walletClient: props.walletClient,
|
|
5510
|
-
publicClient: props.publicClient,
|
|
5511
|
-
address: props.address,
|
|
5512
|
-
switchChain: props.switchChain
|
|
5513
|
-
},
|
|
5514
|
-
reown
|
|
5515
|
-
);
|
|
5516
|
-
const handleConnect = useCallback10(() => {
|
|
5600
|
+
const handleConnect = useCallback9(() => {
|
|
5517
5601
|
reown.openConnect();
|
|
5518
5602
|
}, [reown.openConnect]);
|
|
5519
5603
|
return /* @__PURE__ */ jsx20(
|
|
5520
5604
|
WithdrawModalInner,
|
|
5521
5605
|
{
|
|
5522
5606
|
...props,
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
address: resolved.address,
|
|
5526
|
-
switchChain: resolved.switchChain,
|
|
5527
|
-
connectWalletOptions: resolved.walletOptions,
|
|
5528
|
-
selectedConnectAddress: resolved.selectedAddress,
|
|
5529
|
-
onSelectConnectAddress: resolved.onSelectAddress,
|
|
5530
|
-
onConnect: handleConnect,
|
|
5531
|
-
onRequestConnect: props.onRequestConnect
|
|
5607
|
+
reownWallet: reown,
|
|
5608
|
+
onConnect: handleConnect
|
|
5532
5609
|
}
|
|
5533
5610
|
);
|
|
5534
5611
|
}
|
|
@@ -5545,9 +5622,9 @@ var init_WithdrawModalReown = __esm({
|
|
|
5545
5622
|
|
|
5546
5623
|
// src/WithdrawModal.tsx
|
|
5547
5624
|
import {
|
|
5548
|
-
useCallback as
|
|
5625
|
+
useCallback as useCallback10,
|
|
5549
5626
|
useEffect as useEffect11,
|
|
5550
|
-
useMemo as
|
|
5627
|
+
useMemo as useMemo10,
|
|
5551
5628
|
useRef as useRef9,
|
|
5552
5629
|
useState as useState12,
|
|
5553
5630
|
lazy as lazy2,
|
|
@@ -5562,9 +5639,9 @@ function WithdrawModal(props) {
|
|
|
5562
5639
|
return /* @__PURE__ */ jsx21(WithdrawModalInner, { ...props });
|
|
5563
5640
|
}
|
|
5564
5641
|
function WithdrawModalInner({
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5642
|
+
dappWalletClient,
|
|
5643
|
+
dappPublicClient,
|
|
5644
|
+
dappAddress,
|
|
5568
5645
|
safeAddress,
|
|
5569
5646
|
sourceChain: sourceChainProp,
|
|
5570
5647
|
sourceToken,
|
|
@@ -5575,15 +5652,12 @@ function WithdrawModalInner({
|
|
|
5575
5652
|
isOpen,
|
|
5576
5653
|
onClose,
|
|
5577
5654
|
inline,
|
|
5578
|
-
switchChain,
|
|
5579
5655
|
backendUrl = DEFAULT_BACKEND_URL,
|
|
5580
5656
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
5581
5657
|
sessionChainIds,
|
|
5582
5658
|
forceRegister = false,
|
|
5583
5659
|
waitForFinalTx = true,
|
|
5584
|
-
|
|
5585
|
-
selectedConnectAddress,
|
|
5586
|
-
onSelectConnectAddress,
|
|
5660
|
+
reownWallet,
|
|
5587
5661
|
onConnect,
|
|
5588
5662
|
onWithdrawSign,
|
|
5589
5663
|
onRequestConnect,
|
|
@@ -5605,7 +5679,7 @@ function WithdrawModalInner({
|
|
|
5605
5679
|
const backHandlerRef = useRef9(void 0);
|
|
5606
5680
|
const targetChain = getChainId(targetChainProp);
|
|
5607
5681
|
const sourceChain = getChainId(sourceChainProp);
|
|
5608
|
-
const service =
|
|
5682
|
+
const service = useMemo10(() => createDepositService(backendUrl), [backendUrl]);
|
|
5609
5683
|
useEffect11(() => {
|
|
5610
5684
|
if (isOpen && modalRef.current) {
|
|
5611
5685
|
applyTheme(modalRef.current, theme);
|
|
@@ -5623,17 +5697,17 @@ function WithdrawModalInner({
|
|
|
5623
5697
|
setCurrentStepIndex(0);
|
|
5624
5698
|
}
|
|
5625
5699
|
}, [isOpen]);
|
|
5626
|
-
const handleStepChange =
|
|
5700
|
+
const handleStepChange = useCallback10(
|
|
5627
5701
|
(stepIndex, onBack) => {
|
|
5628
5702
|
setCurrentStepIndex(stepIndex);
|
|
5629
5703
|
backHandlerRef.current = onBack;
|
|
5630
5704
|
},
|
|
5631
5705
|
[]
|
|
5632
5706
|
);
|
|
5633
|
-
const handleTotalBalanceChange =
|
|
5707
|
+
const handleTotalBalanceChange = useCallback10((balance) => {
|
|
5634
5708
|
setTotalBalanceUsd(balance);
|
|
5635
5709
|
}, []);
|
|
5636
|
-
const handleBack =
|
|
5710
|
+
const handleBack = useCallback10(() => {
|
|
5637
5711
|
backHandlerRef.current?.();
|
|
5638
5712
|
}, []);
|
|
5639
5713
|
const showLogo = uiConfig?.showLogo ?? false;
|
|
@@ -5735,9 +5809,9 @@ function WithdrawModalInner({
|
|
|
5735
5809
|
/* @__PURE__ */ jsx21(
|
|
5736
5810
|
WithdrawFlow,
|
|
5737
5811
|
{
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5812
|
+
dappWalletClient,
|
|
5813
|
+
dappPublicClient,
|
|
5814
|
+
dappAddress,
|
|
5741
5815
|
safeAddress,
|
|
5742
5816
|
sourceChain,
|
|
5743
5817
|
sourceToken,
|
|
@@ -5746,14 +5820,11 @@ function WithdrawModalInner({
|
|
|
5746
5820
|
recipient,
|
|
5747
5821
|
amount: defaultAmount,
|
|
5748
5822
|
service,
|
|
5749
|
-
switchChain,
|
|
5750
5823
|
signerAddress,
|
|
5751
5824
|
sessionChainIds,
|
|
5752
5825
|
forceRegister,
|
|
5753
5826
|
waitForFinalTx,
|
|
5754
|
-
|
|
5755
|
-
selectedConnectAddress,
|
|
5756
|
-
onSelectConnectAddress,
|
|
5827
|
+
reownWallet,
|
|
5757
5828
|
onConnect,
|
|
5758
5829
|
onWithdrawSign,
|
|
5759
5830
|
onRequestConnect,
|