@rhinestone/deposit-modal 0.1.14 → 0.1.16
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 +46 -21
- package/dist/index.cjs +350 -253
- package/dist/index.d.cts +8 -12
- package/dist/index.d.ts +8 -12
- package/dist/index.mjs +363 -274
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -816,8 +816,10 @@ function buildSession(chain, signerAddress) {
|
|
|
816
816
|
chain
|
|
817
817
|
};
|
|
818
818
|
}
|
|
819
|
-
async function createSmartAccount(userSigner, sessionSigner) {
|
|
820
|
-
const rhinestone = new import_sdk.RhinestoneSDK(
|
|
819
|
+
async function createSmartAccount(userSigner, sessionSigner, sdkApiKey) {
|
|
820
|
+
const rhinestone = new import_sdk.RhinestoneSDK({
|
|
821
|
+
apiKey: sdkApiKey ?? ""
|
|
822
|
+
});
|
|
821
823
|
const ownerAccounts = sessionSigner ? [userSigner, sessionSigner] : [userSigner];
|
|
822
824
|
const config = {
|
|
823
825
|
account: {
|
|
@@ -886,7 +888,10 @@ async function getSessionDetails(rhinestoneAccount, targetChain, signerAddress,
|
|
|
886
888
|
}
|
|
887
889
|
}
|
|
888
890
|
if (targetToken) {
|
|
889
|
-
const targetSymbol = getTokenSymbol(
|
|
891
|
+
const targetSymbol = getTokenSymbol(
|
|
892
|
+
targetToken,
|
|
893
|
+
targetChain.id
|
|
894
|
+
).toUpperCase();
|
|
890
895
|
if (targetSymbol && targetSymbol !== "TOKEN") {
|
|
891
896
|
const chainsForToken = selectedChains.filter(
|
|
892
897
|
(chain) => getSupportedTokenSymbolsForChain(chain.id).includes(targetSymbol)
|
|
@@ -1004,6 +1009,7 @@ function SetupStep({
|
|
|
1004
1009
|
targetChain,
|
|
1005
1010
|
targetChainObj,
|
|
1006
1011
|
targetToken,
|
|
1012
|
+
rhinestoneApiKey,
|
|
1007
1013
|
signerAddress,
|
|
1008
1014
|
sessionChainIds,
|
|
1009
1015
|
recipient,
|
|
@@ -1028,7 +1034,8 @@ function SetupStep({
|
|
|
1028
1034
|
const sessionOwner = await resolveSessionOwner(address);
|
|
1029
1035
|
const account = await createSmartAccount(
|
|
1030
1036
|
signerAccount,
|
|
1031
|
-
sessionOwner.account
|
|
1037
|
+
sessionOwner.account,
|
|
1038
|
+
rhinestoneApiKey
|
|
1032
1039
|
);
|
|
1033
1040
|
const smartAccount = getAccountAddress(account);
|
|
1034
1041
|
setState({ type: "checking" });
|
|
@@ -1082,6 +1089,7 @@ function SetupStep({
|
|
|
1082
1089
|
targetChainObj,
|
|
1083
1090
|
targetChain,
|
|
1084
1091
|
targetToken,
|
|
1092
|
+
rhinestoneApiKey,
|
|
1085
1093
|
signerAddress,
|
|
1086
1094
|
sessionChainIds,
|
|
1087
1095
|
recipient,
|
|
@@ -3496,26 +3504,47 @@ var init_DepositAddressStep = __esm({
|
|
|
3496
3504
|
}
|
|
3497
3505
|
});
|
|
3498
3506
|
|
|
3507
|
+
// src/core/public-client.ts
|
|
3508
|
+
function getPublicClient(chainId) {
|
|
3509
|
+
let client = clientCache.get(chainId);
|
|
3510
|
+
if (!client) {
|
|
3511
|
+
const chain = CHAIN_BY_ID[chainId];
|
|
3512
|
+
client = (0, import_viem7.createPublicClient)({
|
|
3513
|
+
chain,
|
|
3514
|
+
transport: (0, import_viem7.http)()
|
|
3515
|
+
});
|
|
3516
|
+
clientCache.set(chainId, client);
|
|
3517
|
+
}
|
|
3518
|
+
return client;
|
|
3519
|
+
}
|
|
3520
|
+
var import_viem7, clientCache;
|
|
3521
|
+
var init_public_client = __esm({
|
|
3522
|
+
"src/core/public-client.ts"() {
|
|
3523
|
+
"use strict";
|
|
3524
|
+
import_viem7 = require("viem");
|
|
3525
|
+
init_constants();
|
|
3526
|
+
clientCache = /* @__PURE__ */ new Map();
|
|
3527
|
+
}
|
|
3528
|
+
});
|
|
3529
|
+
|
|
3499
3530
|
// src/DepositFlow.tsx
|
|
3500
3531
|
function DepositFlow({
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3532
|
+
dappWalletClient,
|
|
3533
|
+
dappPublicClient,
|
|
3534
|
+
dappAddress,
|
|
3504
3535
|
targetChain,
|
|
3505
3536
|
targetToken,
|
|
3506
3537
|
service,
|
|
3507
|
-
switchChain,
|
|
3508
3538
|
sourceChain: defaultSourceChain,
|
|
3509
3539
|
sourceToken: defaultSourceToken,
|
|
3510
3540
|
amount: defaultAmount,
|
|
3511
3541
|
recipient,
|
|
3542
|
+
rhinestoneApiKey,
|
|
3512
3543
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
3513
3544
|
sessionChainIds,
|
|
3514
3545
|
forceRegister = false,
|
|
3515
3546
|
waitForFinalTx = true,
|
|
3516
|
-
|
|
3517
|
-
selectedConnectAddress,
|
|
3518
|
-
onSelectConnectAddress,
|
|
3547
|
+
reownWallet,
|
|
3519
3548
|
onConnect,
|
|
3520
3549
|
onRequestConnect,
|
|
3521
3550
|
connectButtonLabel,
|
|
@@ -3533,9 +3562,93 @@ function DepositFlow({
|
|
|
3533
3562
|
const [flowMode, setFlowMode] = (0, import_react9.useState)(null);
|
|
3534
3563
|
const [totalBalanceUsd, setTotalBalanceUsd] = (0, import_react9.useState)(0);
|
|
3535
3564
|
const [isConnectSelectionConfirmed, setIsConnectSelectionConfirmed] = (0, import_react9.useState)(false);
|
|
3536
|
-
const
|
|
3537
|
-
const hasConnectedWallet = Boolean(walletClient && publicClient && address);
|
|
3565
|
+
const [selectedConnectAddress, setSelectedConnectAddress] = (0, import_react9.useState)(null);
|
|
3538
3566
|
const targetChainObj = (0, import_react9.useMemo)(() => CHAIN_BY_ID[targetChain], [targetChain]);
|
|
3567
|
+
const dappSwitchChain = (0, import_react9.useMemo)(() => {
|
|
3568
|
+
if (!dappWalletClient?.switchChain) return void 0;
|
|
3569
|
+
return async (chainId) => {
|
|
3570
|
+
await dappWalletClient.switchChain?.({ id: chainId });
|
|
3571
|
+
};
|
|
3572
|
+
}, [dappWalletClient]);
|
|
3573
|
+
const walletOptions = (0, import_react9.useMemo)(() => {
|
|
3574
|
+
const options = [];
|
|
3575
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3576
|
+
if (dappWalletClient?.account && dappAddress) {
|
|
3577
|
+
options.push({
|
|
3578
|
+
address: dappWalletClient.account.address,
|
|
3579
|
+
label: "Connected Wallet",
|
|
3580
|
+
kind: "connected"
|
|
3581
|
+
});
|
|
3582
|
+
seen.add(dappWalletClient.account.address.toLowerCase());
|
|
3583
|
+
}
|
|
3584
|
+
if (reownWallet?.address && reownWallet.isConnected && !seen.has(reownWallet.address.toLowerCase())) {
|
|
3585
|
+
options.push({
|
|
3586
|
+
address: reownWallet.address,
|
|
3587
|
+
label: "External Wallet",
|
|
3588
|
+
kind: "external"
|
|
3589
|
+
});
|
|
3590
|
+
}
|
|
3591
|
+
return options;
|
|
3592
|
+
}, [
|
|
3593
|
+
dappWalletClient,
|
|
3594
|
+
dappAddress,
|
|
3595
|
+
reownWallet?.address,
|
|
3596
|
+
reownWallet?.isConnected
|
|
3597
|
+
]);
|
|
3598
|
+
const canAutoLock = dappWalletClient?.account && dappAddress && !reownWallet;
|
|
3599
|
+
const hasWalletOptions = walletOptions.length > 0;
|
|
3600
|
+
const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
|
|
3601
|
+
const signerContext = (0, import_react9.useMemo)(() => {
|
|
3602
|
+
if (flowMode === "deposit-address") {
|
|
3603
|
+
if (!dappAddress) return null;
|
|
3604
|
+
return {
|
|
3605
|
+
ownerAddress: dappAddress,
|
|
3606
|
+
walletClient: void 0,
|
|
3607
|
+
publicClient: dappPublicClient ?? getPublicClient(targetChain),
|
|
3608
|
+
switchChain: void 0
|
|
3609
|
+
};
|
|
3610
|
+
}
|
|
3611
|
+
if (canAutoLock) {
|
|
3612
|
+
const fallbackChainId = dappWalletClient?.chain?.id ?? targetChain;
|
|
3613
|
+
return {
|
|
3614
|
+
ownerAddress: dappWalletClient.account.address,
|
|
3615
|
+
walletClient: dappWalletClient,
|
|
3616
|
+
publicClient: dappPublicClient ?? getPublicClient(fallbackChainId),
|
|
3617
|
+
switchChain: dappSwitchChain
|
|
3618
|
+
};
|
|
3619
|
+
}
|
|
3620
|
+
if (!isConnectSelectionConfirmed || !selectedConnectAddress) return null;
|
|
3621
|
+
if (dappWalletClient?.account && dappWalletClient.account.address.toLowerCase() === selectedConnectAddress.toLowerCase()) {
|
|
3622
|
+
const fallbackChainId = dappWalletClient?.chain?.id ?? targetChain;
|
|
3623
|
+
return {
|
|
3624
|
+
ownerAddress: dappWalletClient.account.address,
|
|
3625
|
+
walletClient: dappWalletClient,
|
|
3626
|
+
publicClient: dappPublicClient ?? getPublicClient(fallbackChainId),
|
|
3627
|
+
switchChain: dappSwitchChain
|
|
3628
|
+
};
|
|
3629
|
+
}
|
|
3630
|
+
if (reownWallet?.address?.toLowerCase() === selectedConnectAddress.toLowerCase() && reownWallet.walletClient && reownWallet.publicClient) {
|
|
3631
|
+
return {
|
|
3632
|
+
ownerAddress: reownWallet.address,
|
|
3633
|
+
walletClient: reownWallet.walletClient,
|
|
3634
|
+
publicClient: reownWallet.publicClient,
|
|
3635
|
+
switchChain: reownWallet.switchChain
|
|
3636
|
+
};
|
|
3637
|
+
}
|
|
3638
|
+
return null;
|
|
3639
|
+
}, [
|
|
3640
|
+
flowMode,
|
|
3641
|
+
canAutoLock,
|
|
3642
|
+
isConnectSelectionConfirmed,
|
|
3643
|
+
selectedConnectAddress,
|
|
3644
|
+
dappWalletClient,
|
|
3645
|
+
dappPublicClient,
|
|
3646
|
+
dappSwitchChain,
|
|
3647
|
+
dappAddress,
|
|
3648
|
+
reownWallet,
|
|
3649
|
+
targetChain
|
|
3650
|
+
]);
|
|
3651
|
+
const sessionKeyAddress = dappAddress ?? signerContext?.ownerAddress ?? null;
|
|
3539
3652
|
const lastTargetRef = (0, import_react9.useRef)(null);
|
|
3540
3653
|
(0, import_react9.useEffect)(() => {
|
|
3541
3654
|
const prev = lastTargetRef.current;
|
|
@@ -3553,17 +3666,17 @@ function DepositFlow({
|
|
|
3553
3666
|
});
|
|
3554
3667
|
}, []);
|
|
3555
3668
|
const handleBackFromSelectAsset = (0, import_react9.useCallback)(() => {
|
|
3556
|
-
if (
|
|
3669
|
+
if (hasWalletOptions || reownWallet) {
|
|
3557
3670
|
setIsConnectSelectionConfirmed(false);
|
|
3558
3671
|
}
|
|
3559
|
-
}, [
|
|
3672
|
+
}, [hasWalletOptions, reownWallet]);
|
|
3560
3673
|
const handleBackFromDepositAddress = (0, import_react9.useCallback)(() => {
|
|
3561
3674
|
setFlowMode(null);
|
|
3562
3675
|
setStep({ type: "setup" });
|
|
3563
|
-
if (
|
|
3676
|
+
if (hasWalletOptions || reownWallet) {
|
|
3564
3677
|
setIsConnectSelectionConfirmed(false);
|
|
3565
3678
|
}
|
|
3566
|
-
}, [
|
|
3679
|
+
}, [hasWalletOptions, reownWallet]);
|
|
3567
3680
|
const handleBackFromConfirm = (0, import_react9.useCallback)(() => {
|
|
3568
3681
|
setStep((prev) => {
|
|
3569
3682
|
if (prev.type !== "confirm") return prev;
|
|
@@ -3576,7 +3689,7 @@ function DepositFlow({
|
|
|
3576
3689
|
});
|
|
3577
3690
|
}, []);
|
|
3578
3691
|
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;
|
|
3579
|
-
const currentBackHandler = step.type === "deposit-address" ? handleBackFromDepositAddress : step.type === "select-asset" &&
|
|
3692
|
+
const currentBackHandler = step.type === "deposit-address" ? handleBackFromDepositAddress : step.type === "select-asset" && signerContext && !canAutoLock ? handleBackFromSelectAsset : step.type === "amount" ? handleBackFromAmount : step.type === "confirm" ? handleBackFromConfirm : void 0;
|
|
3580
3693
|
(0, import_react9.useEffect)(() => {
|
|
3581
3694
|
onStepChange?.(stepIndex, currentBackHandler);
|
|
3582
3695
|
}, [stepIndex, currentBackHandler, onStepChange]);
|
|
@@ -3701,33 +3814,35 @@ function DepositFlow({
|
|
|
3701
3814
|
}, []);
|
|
3702
3815
|
const selectedConnectAddressEffective = (0, import_react9.useMemo)(() => {
|
|
3703
3816
|
if (selectedConnectAddress) return selectedConnectAddress;
|
|
3704
|
-
if (
|
|
3705
|
-
return
|
|
3817
|
+
if (walletOptions.length === 1) {
|
|
3818
|
+
return walletOptions[0].address;
|
|
3706
3819
|
}
|
|
3707
3820
|
return null;
|
|
3708
|
-
}, [selectedConnectAddress,
|
|
3709
|
-
const
|
|
3710
|
-
() =>
|
|
3711
|
-
[
|
|
3821
|
+
}, [selectedConnectAddress, walletOptions]);
|
|
3822
|
+
const walletOptionsKey = (0, import_react9.useMemo)(
|
|
3823
|
+
() => walletOptions.map((option) => option.address.toLowerCase()).join(","),
|
|
3824
|
+
[walletOptions]
|
|
3712
3825
|
);
|
|
3713
|
-
const showConnectStep = !hasConnectedWallet || hasConnectWalletOptions && !isConnectSelectionConfirmed;
|
|
3714
3826
|
(0, import_react9.useEffect)(() => {
|
|
3715
3827
|
setIsConnectSelectionConfirmed(false);
|
|
3716
|
-
}, [
|
|
3828
|
+
}, [walletOptionsKey, selectedConnectAddressEffective]);
|
|
3717
3829
|
if (showConnectStep) {
|
|
3718
3830
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "rs-modal-body", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3719
3831
|
ConnectStep,
|
|
3720
3832
|
{
|
|
3721
|
-
walletOptions
|
|
3833
|
+
walletOptions,
|
|
3722
3834
|
selectedAddress: selectedConnectAddressEffective,
|
|
3723
|
-
onSelectAddress:
|
|
3724
|
-
onSelectTransferCrypto: () => {
|
|
3835
|
+
onSelectAddress: setSelectedConnectAddress,
|
|
3836
|
+
onSelectTransferCrypto: dappAddress ? () => {
|
|
3725
3837
|
handleSelectTransferCrypto();
|
|
3726
3838
|
setIsConnectSelectionConfirmed(true);
|
|
3727
|
-
},
|
|
3839
|
+
} : void 0,
|
|
3728
3840
|
onRequestConnect,
|
|
3729
3841
|
onConnect,
|
|
3730
3842
|
onContinue: () => {
|
|
3843
|
+
if (selectedConnectAddressEffective) {
|
|
3844
|
+
setSelectedConnectAddress(selectedConnectAddressEffective);
|
|
3845
|
+
}
|
|
3731
3846
|
handleSelectProvider();
|
|
3732
3847
|
setIsConnectSelectionConfirmed(true);
|
|
3733
3848
|
},
|
|
@@ -3735,19 +3850,17 @@ function DepositFlow({
|
|
|
3735
3850
|
}
|
|
3736
3851
|
) });
|
|
3737
3852
|
}
|
|
3738
|
-
if (!walletClient || !publicClient || !address) {
|
|
3739
|
-
return null;
|
|
3740
|
-
}
|
|
3741
3853
|
if (isDepositAddressMode) {
|
|
3854
|
+
if (!dappAddress || !sessionKeyAddress) return null;
|
|
3742
3855
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "rs-modal-body", children: [
|
|
3743
3856
|
step.type === "setup" && targetChainObj && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3744
3857
|
SetupStep,
|
|
3745
3858
|
{
|
|
3746
|
-
|
|
3747
|
-
address,
|
|
3859
|
+
address: sessionKeyAddress,
|
|
3748
3860
|
targetChain,
|
|
3749
3861
|
targetChainObj,
|
|
3750
3862
|
targetToken,
|
|
3863
|
+
rhinestoneApiKey,
|
|
3751
3864
|
signerAddress,
|
|
3752
3865
|
sessionChainIds,
|
|
3753
3866
|
recipient,
|
|
@@ -3788,15 +3901,27 @@ function DepositFlow({
|
|
|
3788
3901
|
)
|
|
3789
3902
|
] });
|
|
3790
3903
|
}
|
|
3904
|
+
if (!signerContext?.walletClient || !signerContext?.publicClient) {
|
|
3905
|
+
return null;
|
|
3906
|
+
}
|
|
3907
|
+
const ownerAddress = signerContext.ownerAddress;
|
|
3908
|
+
const ownerChainId = signerContext.walletClient?.chain?.id ?? signerContext.publicClient.chain?.id ?? targetChain;
|
|
3909
|
+
const getReadClientForChain = (chainId) => {
|
|
3910
|
+
if (signerContext.publicClient.chain?.id === chainId) {
|
|
3911
|
+
return signerContext.publicClient;
|
|
3912
|
+
}
|
|
3913
|
+
return getPublicClient(chainId);
|
|
3914
|
+
};
|
|
3791
3915
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "rs-modal-body", children: [
|
|
3792
3916
|
step.type === "setup" && targetChainObj && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3793
3917
|
SetupStep,
|
|
3794
3918
|
{
|
|
3795
|
-
walletClient,
|
|
3796
|
-
address,
|
|
3919
|
+
walletClient: signerContext.walletClient,
|
|
3920
|
+
address: ownerAddress,
|
|
3797
3921
|
targetChain,
|
|
3798
3922
|
targetChainObj,
|
|
3799
3923
|
targetToken,
|
|
3924
|
+
rhinestoneApiKey,
|
|
3800
3925
|
signerAddress,
|
|
3801
3926
|
sessionChainIds,
|
|
3802
3927
|
recipient,
|
|
@@ -3810,8 +3935,8 @@ function DepositFlow({
|
|
|
3810
3935
|
step.type === "select-asset" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3811
3936
|
AssetSelectStep,
|
|
3812
3937
|
{
|
|
3813
|
-
address,
|
|
3814
|
-
publicClient,
|
|
3938
|
+
address: ownerAddress,
|
|
3939
|
+
publicClient: getReadClientForChain(ownerChainId),
|
|
3815
3940
|
defaultSourceChain,
|
|
3816
3941
|
defaultSourceToken,
|
|
3817
3942
|
service,
|
|
@@ -3822,12 +3947,12 @@ function DepositFlow({
|
|
|
3822
3947
|
step.type === "amount" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3823
3948
|
AmountStep,
|
|
3824
3949
|
{
|
|
3825
|
-
walletClient,
|
|
3826
|
-
publicClient,
|
|
3827
|
-
address,
|
|
3950
|
+
walletClient: signerContext.walletClient,
|
|
3951
|
+
publicClient: getReadClientForChain(step.asset.chainId),
|
|
3952
|
+
address: ownerAddress,
|
|
3828
3953
|
asset: step.asset,
|
|
3829
3954
|
defaultAmount: step.amount ?? defaultAmount,
|
|
3830
|
-
switchChain,
|
|
3955
|
+
switchChain: signerContext.switchChain,
|
|
3831
3956
|
targetChain,
|
|
3832
3957
|
targetToken,
|
|
3833
3958
|
uiConfig,
|
|
@@ -3837,15 +3962,15 @@ function DepositFlow({
|
|
|
3837
3962
|
step.type === "confirm" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3838
3963
|
ConfirmStep,
|
|
3839
3964
|
{
|
|
3840
|
-
walletClient,
|
|
3841
|
-
address,
|
|
3965
|
+
walletClient: signerContext.walletClient,
|
|
3966
|
+
address: ownerAddress,
|
|
3842
3967
|
smartAccount: step.smartAccount,
|
|
3843
3968
|
asset: step.asset,
|
|
3844
3969
|
amount: step.amount,
|
|
3845
3970
|
balance: step.balance,
|
|
3846
3971
|
targetChain,
|
|
3847
3972
|
targetToken,
|
|
3848
|
-
switchChain,
|
|
3973
|
+
switchChain: signerContext.switchChain,
|
|
3849
3974
|
onConfirm: handleDepositSubmitted,
|
|
3850
3975
|
onDepositSubmitted: handleDepositSubmittedCallback,
|
|
3851
3976
|
onError: handleError
|
|
@@ -3885,6 +4010,7 @@ var init_DepositFlow = __esm({
|
|
|
3885
4010
|
init_ProcessingStep();
|
|
3886
4011
|
init_DepositAddressStep();
|
|
3887
4012
|
init_constants();
|
|
4013
|
+
init_public_client();
|
|
3888
4014
|
import_jsx_runtime14 = require("react/jsx-runtime");
|
|
3889
4015
|
}
|
|
3890
4016
|
});
|
|
@@ -3995,72 +4121,6 @@ function useReownWallet() {
|
|
|
3995
4121
|
}
|
|
3996
4122
|
};
|
|
3997
4123
|
}
|
|
3998
|
-
function useResolvedWallet(host, reown) {
|
|
3999
|
-
const [selectedAddress, setSelectedAddress] = (0, import_react10.useState)(null);
|
|
4000
|
-
const walletOptions = (0, import_react10.useMemo)(() => {
|
|
4001
|
-
const options = [];
|
|
4002
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4003
|
-
if (host.address) {
|
|
4004
|
-
options.push({
|
|
4005
|
-
address: host.address,
|
|
4006
|
-
label: "Connected Wallet",
|
|
4007
|
-
kind: "connected"
|
|
4008
|
-
});
|
|
4009
|
-
seen.add(host.address.toLowerCase());
|
|
4010
|
-
}
|
|
4011
|
-
if (reown.address && !seen.has(reown.address.toLowerCase())) {
|
|
4012
|
-
options.push({
|
|
4013
|
-
address: reown.address,
|
|
4014
|
-
label: "External Wallet",
|
|
4015
|
-
kind: "external"
|
|
4016
|
-
});
|
|
4017
|
-
}
|
|
4018
|
-
return options;
|
|
4019
|
-
}, [host.address, reown.address]);
|
|
4020
|
-
const effectiveAddress = (0, import_react10.useMemo)(() => {
|
|
4021
|
-
if (walletOptions.length === 0) return null;
|
|
4022
|
-
if (walletOptions.length === 1) return walletOptions[0].address;
|
|
4023
|
-
if (selectedAddress) {
|
|
4024
|
-
const valid = walletOptions.some(
|
|
4025
|
-
(opt) => opt.address.toLowerCase() === selectedAddress.toLowerCase()
|
|
4026
|
-
);
|
|
4027
|
-
if (valid) return selectedAddress;
|
|
4028
|
-
}
|
|
4029
|
-
return null;
|
|
4030
|
-
}, [walletOptions, selectedAddress]);
|
|
4031
|
-
let walletClient;
|
|
4032
|
-
let publicClient;
|
|
4033
|
-
if (effectiveAddress) {
|
|
4034
|
-
const key = effectiveAddress.toLowerCase();
|
|
4035
|
-
if (host.address?.toLowerCase() === key && host.walletClient && host.publicClient) {
|
|
4036
|
-
walletClient = host.walletClient;
|
|
4037
|
-
publicClient = host.publicClient;
|
|
4038
|
-
} else if (reown.address?.toLowerCase() === key && reown.walletClient && reown.publicClient) {
|
|
4039
|
-
walletClient = reown.walletClient;
|
|
4040
|
-
publicClient = reown.publicClient;
|
|
4041
|
-
}
|
|
4042
|
-
}
|
|
4043
|
-
const handleSwitchChain = (0, import_react10.useCallback)(
|
|
4044
|
-
async (chainId) => {
|
|
4045
|
-
if (host.switchChain && effectiveAddress?.toLowerCase() === host.address?.toLowerCase()) {
|
|
4046
|
-
await host.switchChain(chainId);
|
|
4047
|
-
} else {
|
|
4048
|
-
await reown.switchChain(chainId);
|
|
4049
|
-
}
|
|
4050
|
-
},
|
|
4051
|
-
[host.switchChain, host.address, reown.switchChain, effectiveAddress]
|
|
4052
|
-
);
|
|
4053
|
-
return {
|
|
4054
|
-
walletClient,
|
|
4055
|
-
publicClient,
|
|
4056
|
-
address: effectiveAddress ?? void 0,
|
|
4057
|
-
walletOptions,
|
|
4058
|
-
selectedAddress: effectiveAddress,
|
|
4059
|
-
onSelectAddress: setSelectedAddress,
|
|
4060
|
-
openConnect: reown.openConnect,
|
|
4061
|
-
switchChain: handleSwitchChain
|
|
4062
|
-
};
|
|
4063
|
-
}
|
|
4064
4124
|
var import_react10, import_react_query, import_appkit_adapter_wagmi, import_wagmi, import_react11, import_networks, import_wagmi2, import_jsx_runtime15, NETWORKS, cachedAdapter, cachedProjectId;
|
|
4065
4125
|
var init_reown = __esm({
|
|
4066
4126
|
"src/core/reown.tsx"() {
|
|
@@ -4093,15 +4153,6 @@ __export(DepositModalReown_exports, {
|
|
|
4093
4153
|
});
|
|
4094
4154
|
function DepositModalWithReown(props) {
|
|
4095
4155
|
const reown = useReownWallet();
|
|
4096
|
-
const resolved = useResolvedWallet(
|
|
4097
|
-
{
|
|
4098
|
-
walletClient: props.walletClient,
|
|
4099
|
-
publicClient: props.publicClient,
|
|
4100
|
-
address: props.address,
|
|
4101
|
-
switchChain: props.switchChain
|
|
4102
|
-
},
|
|
4103
|
-
reown
|
|
4104
|
-
);
|
|
4105
4156
|
const handleConnect = (0, import_react12.useCallback)(() => {
|
|
4106
4157
|
reown.openConnect();
|
|
4107
4158
|
}, [reown.openConnect]);
|
|
@@ -4109,15 +4160,8 @@ function DepositModalWithReown(props) {
|
|
|
4109
4160
|
DepositModalInner,
|
|
4110
4161
|
{
|
|
4111
4162
|
...props,
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
address: resolved.address,
|
|
4115
|
-
switchChain: resolved.switchChain,
|
|
4116
|
-
connectWalletOptions: resolved.walletOptions,
|
|
4117
|
-
selectedConnectAddress: resolved.selectedAddress,
|
|
4118
|
-
onSelectConnectAddress: resolved.onSelectAddress,
|
|
4119
|
-
onConnect: handleConnect,
|
|
4120
|
-
onRequestConnect: props.onRequestConnect
|
|
4163
|
+
reownWallet: reown,
|
|
4164
|
+
onConnect: handleConnect
|
|
4121
4165
|
}
|
|
4122
4166
|
);
|
|
4123
4167
|
}
|
|
@@ -4144,27 +4188,25 @@ function DepositModal(props) {
|
|
|
4144
4188
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DepositModalInner, { ...props });
|
|
4145
4189
|
}
|
|
4146
4190
|
function DepositModalInner({
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4191
|
+
dappWalletClient,
|
|
4192
|
+
dappPublicClient,
|
|
4193
|
+
dappAddress,
|
|
4150
4194
|
targetChain: targetChainProp,
|
|
4151
4195
|
targetToken,
|
|
4152
4196
|
isOpen,
|
|
4153
4197
|
onClose,
|
|
4154
4198
|
inline,
|
|
4155
|
-
switchChain,
|
|
4156
4199
|
sourceChain: sourceChainProp,
|
|
4157
4200
|
sourceToken,
|
|
4158
4201
|
defaultAmount,
|
|
4159
4202
|
recipient,
|
|
4160
4203
|
backendUrl = DEFAULT_BACKEND_URL,
|
|
4204
|
+
rhinestoneApiKey,
|
|
4161
4205
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
4162
4206
|
sessionChainIds,
|
|
4163
4207
|
forceRegister = false,
|
|
4164
4208
|
waitForFinalTx = true,
|
|
4165
|
-
|
|
4166
|
-
selectedConnectAddress,
|
|
4167
|
-
onSelectConnectAddress,
|
|
4209
|
+
reownWallet,
|
|
4168
4210
|
onConnect,
|
|
4169
4211
|
onRequestConnect,
|
|
4170
4212
|
connectButtonLabel,
|
|
@@ -4318,24 +4360,22 @@ function DepositModalInner({
|
|
|
4318
4360
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
4319
4361
|
DepositFlow,
|
|
4320
4362
|
{
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4363
|
+
dappWalletClient,
|
|
4364
|
+
dappPublicClient,
|
|
4365
|
+
dappAddress,
|
|
4324
4366
|
targetChain,
|
|
4325
4367
|
targetToken,
|
|
4326
4368
|
service,
|
|
4327
|
-
switchChain,
|
|
4328
4369
|
sourceChain,
|
|
4329
4370
|
sourceToken,
|
|
4330
4371
|
amount: defaultAmount,
|
|
4331
4372
|
recipient,
|
|
4373
|
+
rhinestoneApiKey,
|
|
4332
4374
|
signerAddress,
|
|
4333
4375
|
sessionChainIds,
|
|
4334
4376
|
forceRegister,
|
|
4335
4377
|
waitForFinalTx,
|
|
4336
|
-
|
|
4337
|
-
selectedConnectAddress,
|
|
4338
|
-
onSelectConnectAddress,
|
|
4378
|
+
reownWallet,
|
|
4339
4379
|
onConnect,
|
|
4340
4380
|
onRequestConnect,
|
|
4341
4381
|
connectButtonLabel,
|
|
@@ -4454,7 +4494,7 @@ function WithdrawFormStep({
|
|
|
4454
4494
|
try {
|
|
4455
4495
|
const bal = isNativeAsset(asset) ? await publicClient.getBalance({ address: safeAddress }) : await publicClient.readContract({
|
|
4456
4496
|
address: asset.token,
|
|
4457
|
-
abi:
|
|
4497
|
+
abi: import_viem8.erc20Abi,
|
|
4458
4498
|
functionName: "balanceOf",
|
|
4459
4499
|
args: [safeAddress]
|
|
4460
4500
|
});
|
|
@@ -4482,7 +4522,7 @@ function WithdrawFormStep({
|
|
|
4482
4522
|
const formattedBalance = (0, import_react14.useMemo)(() => {
|
|
4483
4523
|
if (balance === null) return "...";
|
|
4484
4524
|
try {
|
|
4485
|
-
const raw = (0,
|
|
4525
|
+
const raw = (0, import_viem8.formatUnits)(balance, asset.decimals);
|
|
4486
4526
|
const numeric = Number(raw);
|
|
4487
4527
|
if (!Number.isFinite(numeric)) return raw;
|
|
4488
4528
|
return new Intl.NumberFormat("en-US", {
|
|
@@ -4497,7 +4537,7 @@ function WithdrawFormStep({
|
|
|
4497
4537
|
const sym = asset.symbol.toUpperCase();
|
|
4498
4538
|
if (sym !== "USDC" && sym !== "USDT") return;
|
|
4499
4539
|
try {
|
|
4500
|
-
const raw = (0,
|
|
4540
|
+
const raw = (0, import_viem8.formatUnits)(balance, asset.decimals);
|
|
4501
4541
|
const numeric = Number(raw);
|
|
4502
4542
|
if (!Number.isFinite(numeric)) return;
|
|
4503
4543
|
onBalanceUsdChange?.(numeric);
|
|
@@ -4517,7 +4557,7 @@ function WithdrawFormStep({
|
|
|
4517
4557
|
}, [amount, asset.symbol]);
|
|
4518
4558
|
const handleMaxClick = (0, import_react14.useCallback)(() => {
|
|
4519
4559
|
if (balance === null) return;
|
|
4520
|
-
const maxAmount = (0,
|
|
4560
|
+
const maxAmount = (0, import_viem8.formatUnits)(balance, asset.decimals);
|
|
4521
4561
|
setAmount(maxAmount);
|
|
4522
4562
|
setError(null);
|
|
4523
4563
|
}, [balance, asset.decimals]);
|
|
@@ -4538,7 +4578,7 @@ function WithdrawFormStep({
|
|
|
4538
4578
|
}
|
|
4539
4579
|
if (balance !== null) {
|
|
4540
4580
|
try {
|
|
4541
|
-
const amountInUnits = (0,
|
|
4581
|
+
const amountInUnits = (0, import_viem8.parseUnits)(amount, asset.decimals);
|
|
4542
4582
|
if (amountInUnits > balance) {
|
|
4543
4583
|
setError("Insufficient balance");
|
|
4544
4584
|
return;
|
|
@@ -4877,12 +4917,12 @@ function WithdrawFormStep({
|
|
|
4877
4917
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PoweredBy, {})
|
|
4878
4918
|
] });
|
|
4879
4919
|
}
|
|
4880
|
-
var import_react14,
|
|
4920
|
+
var import_react14, import_viem8, import_jsx_runtime18;
|
|
4881
4921
|
var init_WithdrawFormStep = __esm({
|
|
4882
4922
|
"src/components/steps/WithdrawFormStep.tsx"() {
|
|
4883
4923
|
"use strict";
|
|
4884
4924
|
import_react14 = require("react");
|
|
4885
|
-
|
|
4925
|
+
import_viem8 = require("viem");
|
|
4886
4926
|
init_Button();
|
|
4887
4927
|
init_PoweredBy();
|
|
4888
4928
|
init_deposit_service();
|
|
@@ -4928,13 +4968,13 @@ async function executeSafeEthTransfer(params) {
|
|
|
4928
4968
|
safeTxGas: 0n,
|
|
4929
4969
|
baseGas: 0n,
|
|
4930
4970
|
gasPrice: 0n,
|
|
4931
|
-
gasToken:
|
|
4932
|
-
refundReceiver:
|
|
4971
|
+
gasToken: import_viem9.zeroAddress,
|
|
4972
|
+
refundReceiver: import_viem9.zeroAddress
|
|
4933
4973
|
};
|
|
4934
|
-
const signature = (0,
|
|
4935
|
-
(0,
|
|
4936
|
-
(0,
|
|
4937
|
-
(0,
|
|
4974
|
+
const signature = (0, import_viem9.concat)([
|
|
4975
|
+
(0, import_viem9.pad)(account.address, { size: 32 }),
|
|
4976
|
+
(0, import_viem9.pad)((0, import_viem9.toHex)(0), { size: 32 }),
|
|
4977
|
+
(0, import_viem9.toHex)(1, { size: 1 })
|
|
4938
4978
|
]);
|
|
4939
4979
|
const txHash = await walletClient.writeContract({
|
|
4940
4980
|
account,
|
|
@@ -4961,7 +5001,7 @@ async function executeSafeEthTransfer(params) {
|
|
|
4961
5001
|
const safeLogs = receipt.logs.filter(
|
|
4962
5002
|
(log) => log.address.toLowerCase() === safeAddress.toLowerCase()
|
|
4963
5003
|
);
|
|
4964
|
-
const parsed = (0,
|
|
5004
|
+
const parsed = (0, import_viem9.parseEventLogs)({
|
|
4965
5005
|
abi: SAFE_ABI,
|
|
4966
5006
|
logs: safeLogs,
|
|
4967
5007
|
strict: false
|
|
@@ -5003,8 +5043,8 @@ async function executeSafeErc20Transfer(params) {
|
|
|
5003
5043
|
if (!isOwner) {
|
|
5004
5044
|
throw new Error("Connected wallet is not a Safe owner");
|
|
5005
5045
|
}
|
|
5006
|
-
const data = (0,
|
|
5007
|
-
abi:
|
|
5046
|
+
const data = (0, import_viem9.encodeFunctionData)({
|
|
5047
|
+
abi: import_viem9.erc20Abi,
|
|
5008
5048
|
functionName: "transfer",
|
|
5009
5049
|
args: [recipient, amount]
|
|
5010
5050
|
});
|
|
@@ -5016,13 +5056,13 @@ async function executeSafeErc20Transfer(params) {
|
|
|
5016
5056
|
safeTxGas: 0n,
|
|
5017
5057
|
baseGas: 0n,
|
|
5018
5058
|
gasPrice: 0n,
|
|
5019
|
-
gasToken:
|
|
5020
|
-
refundReceiver:
|
|
5059
|
+
gasToken: import_viem9.zeroAddress,
|
|
5060
|
+
refundReceiver: import_viem9.zeroAddress
|
|
5021
5061
|
};
|
|
5022
|
-
const signature = (0,
|
|
5023
|
-
(0,
|
|
5024
|
-
(0,
|
|
5025
|
-
(0,
|
|
5062
|
+
const signature = (0, import_viem9.concat)([
|
|
5063
|
+
(0, import_viem9.pad)(account.address, { size: 32 }),
|
|
5064
|
+
(0, import_viem9.pad)((0, import_viem9.toHex)(0), { size: 32 }),
|
|
5065
|
+
(0, import_viem9.toHex)(1, { size: 1 })
|
|
5026
5066
|
]);
|
|
5027
5067
|
const txHash = await walletClient.writeContract({
|
|
5028
5068
|
account,
|
|
@@ -5049,7 +5089,7 @@ async function executeSafeErc20Transfer(params) {
|
|
|
5049
5089
|
const safeLogs = receipt.logs.filter(
|
|
5050
5090
|
(log) => log.address.toLowerCase() === safeAddress.toLowerCase()
|
|
5051
5091
|
);
|
|
5052
|
-
const parsed = (0,
|
|
5092
|
+
const parsed = (0, import_viem9.parseEventLogs)({
|
|
5053
5093
|
abi: SAFE_ABI,
|
|
5054
5094
|
logs: safeLogs,
|
|
5055
5095
|
strict: false
|
|
@@ -5064,11 +5104,11 @@ async function executeSafeErc20Transfer(params) {
|
|
|
5064
5104
|
}
|
|
5065
5105
|
return { txHash };
|
|
5066
5106
|
}
|
|
5067
|
-
var
|
|
5107
|
+
var import_viem9, SAFE_ABI;
|
|
5068
5108
|
var init_safe = __esm({
|
|
5069
5109
|
"src/core/safe.ts"() {
|
|
5070
5110
|
"use strict";
|
|
5071
|
-
|
|
5111
|
+
import_viem9 = require("viem");
|
|
5072
5112
|
init_constants();
|
|
5073
5113
|
SAFE_ABI = [
|
|
5074
5114
|
{
|
|
@@ -5120,9 +5160,9 @@ var init_safe = __esm({
|
|
|
5120
5160
|
|
|
5121
5161
|
// src/WithdrawFlow.tsx
|
|
5122
5162
|
function WithdrawFlow({
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5163
|
+
dappWalletClient,
|
|
5164
|
+
dappPublicClient,
|
|
5165
|
+
dappAddress,
|
|
5126
5166
|
safeAddress,
|
|
5127
5167
|
sourceChain,
|
|
5128
5168
|
sourceToken,
|
|
@@ -5131,14 +5171,12 @@ function WithdrawFlow({
|
|
|
5131
5171
|
recipient: defaultRecipient,
|
|
5132
5172
|
amount: defaultAmount,
|
|
5133
5173
|
service,
|
|
5134
|
-
|
|
5174
|
+
rhinestoneApiKey,
|
|
5135
5175
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
5136
5176
|
sessionChainIds,
|
|
5137
5177
|
forceRegister = false,
|
|
5138
5178
|
waitForFinalTx = true,
|
|
5139
|
-
|
|
5140
|
-
selectedConnectAddress,
|
|
5141
|
-
onSelectConnectAddress,
|
|
5179
|
+
reownWallet,
|
|
5142
5180
|
onConnect,
|
|
5143
5181
|
onWithdrawSign,
|
|
5144
5182
|
onRequestConnect,
|
|
@@ -5163,12 +5201,87 @@ function WithdrawFlow({
|
|
|
5163
5201
|
setTargetToken(targetTokenProp);
|
|
5164
5202
|
}, [targetChainProp, targetTokenProp]);
|
|
5165
5203
|
const targetChainObj = (0, import_react15.useMemo)(() => CHAIN_BY_ID[targetChain], [targetChain]);
|
|
5166
|
-
const hasCustomSigner = Boolean(
|
|
5167
|
-
const
|
|
5168
|
-
|
|
5169
|
-
() =>
|
|
5170
|
-
|
|
5171
|
-
|
|
5204
|
+
const hasCustomSigner = Boolean(dappAddress && onWithdrawSign);
|
|
5205
|
+
const dappSwitchChain = (0, import_react15.useMemo)(() => {
|
|
5206
|
+
if (!dappWalletClient?.switchChain) return void 0;
|
|
5207
|
+
return async (chainId) => {
|
|
5208
|
+
await dappWalletClient.switchChain?.({ id: chainId });
|
|
5209
|
+
};
|
|
5210
|
+
}, [dappWalletClient]);
|
|
5211
|
+
const walletOptions = (0, import_react15.useMemo)(() => {
|
|
5212
|
+
const options = [];
|
|
5213
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5214
|
+
if (dappWalletClient?.account && dappAddress) {
|
|
5215
|
+
options.push({
|
|
5216
|
+
address: dappWalletClient.account.address,
|
|
5217
|
+
label: "Connected Wallet",
|
|
5218
|
+
kind: "connected"
|
|
5219
|
+
});
|
|
5220
|
+
seen.add(dappWalletClient.account.address.toLowerCase());
|
|
5221
|
+
}
|
|
5222
|
+
if (reownWallet?.address && reownWallet.isConnected && !seen.has(reownWallet.address.toLowerCase())) {
|
|
5223
|
+
options.push({
|
|
5224
|
+
address: reownWallet.address,
|
|
5225
|
+
label: "External Wallet",
|
|
5226
|
+
kind: "external"
|
|
5227
|
+
});
|
|
5228
|
+
}
|
|
5229
|
+
return options;
|
|
5230
|
+
}, [
|
|
5231
|
+
dappWalletClient,
|
|
5232
|
+
dappAddress,
|
|
5233
|
+
reownWallet?.address,
|
|
5234
|
+
reownWallet?.isConnected
|
|
5235
|
+
]);
|
|
5236
|
+
const canAutoLock = (dappWalletClient?.account && dappAddress || hasCustomSigner) && !reownWallet;
|
|
5237
|
+
const [selectedConnectAddress, setSelectedConnectAddress] = (0, import_react15.useState)(null);
|
|
5238
|
+
const signerContext = (0, import_react15.useMemo)(() => {
|
|
5239
|
+
if (canAutoLock) {
|
|
5240
|
+
if (hasCustomSigner) {
|
|
5241
|
+
return {
|
|
5242
|
+
ownerAddress: dappAddress,
|
|
5243
|
+
walletClient: dappWalletClient ?? void 0,
|
|
5244
|
+
publicClient: dappPublicClient ?? getPublicClient(sourceChain),
|
|
5245
|
+
switchChain: dappSwitchChain
|
|
5246
|
+
};
|
|
5247
|
+
}
|
|
5248
|
+
return {
|
|
5249
|
+
ownerAddress: dappWalletClient.account.address,
|
|
5250
|
+
walletClient: dappWalletClient,
|
|
5251
|
+
publicClient: dappPublicClient ?? getPublicClient(sourceChain),
|
|
5252
|
+
switchChain: dappSwitchChain
|
|
5253
|
+
};
|
|
5254
|
+
}
|
|
5255
|
+
if (!isConnectSelectionConfirmed || !selectedConnectAddress) return null;
|
|
5256
|
+
if (dappWalletClient?.account && dappWalletClient.account.address.toLowerCase() === selectedConnectAddress.toLowerCase()) {
|
|
5257
|
+
return {
|
|
5258
|
+
ownerAddress: dappWalletClient.account.address,
|
|
5259
|
+
walletClient: dappWalletClient,
|
|
5260
|
+
publicClient: dappPublicClient ?? getPublicClient(sourceChain),
|
|
5261
|
+
switchChain: dappSwitchChain
|
|
5262
|
+
};
|
|
5263
|
+
}
|
|
5264
|
+
if (reownWallet?.address?.toLowerCase() === selectedConnectAddress.toLowerCase() && reownWallet.walletClient && reownWallet.publicClient) {
|
|
5265
|
+
return {
|
|
5266
|
+
ownerAddress: reownWallet.address,
|
|
5267
|
+
walletClient: reownWallet.walletClient,
|
|
5268
|
+
publicClient: reownWallet.publicClient,
|
|
5269
|
+
switchChain: reownWallet.switchChain
|
|
5270
|
+
};
|
|
5271
|
+
}
|
|
5272
|
+
return null;
|
|
5273
|
+
}, [
|
|
5274
|
+
canAutoLock,
|
|
5275
|
+
hasCustomSigner,
|
|
5276
|
+
isConnectSelectionConfirmed,
|
|
5277
|
+
selectedConnectAddress,
|
|
5278
|
+
dappWalletClient,
|
|
5279
|
+
dappPublicClient,
|
|
5280
|
+
dappSwitchChain,
|
|
5281
|
+
dappAddress,
|
|
5282
|
+
reownWallet,
|
|
5283
|
+
sourceChain
|
|
5284
|
+
]);
|
|
5172
5285
|
const asset = (0, import_react15.useMemo)(() => {
|
|
5173
5286
|
const symbol = getTokenSymbol(sourceToken, sourceChain);
|
|
5174
5287
|
const decimals = getTokenDecimalsByAddress(sourceToken, sourceChain);
|
|
@@ -5219,10 +5332,11 @@ function WithdrawFlow({
|
|
|
5219
5332
|
}, []);
|
|
5220
5333
|
const handleFormSubmit = (0, import_react15.useCallback)(
|
|
5221
5334
|
async (recipient, amountValue) => {
|
|
5222
|
-
|
|
5335
|
+
const ownerAddress2 = signerContext?.ownerAddress;
|
|
5336
|
+
if (!ownerAddress2) {
|
|
5223
5337
|
throw new Error("Wallet not connected");
|
|
5224
5338
|
}
|
|
5225
|
-
if (!onWithdrawSign &&
|
|
5339
|
+
if (!onWithdrawSign && !signerContext?.walletClient) {
|
|
5226
5340
|
throw new Error("Wallet not connected");
|
|
5227
5341
|
}
|
|
5228
5342
|
if (!targetChainObj) {
|
|
@@ -5230,11 +5344,12 @@ function WithdrawFlow({
|
|
|
5230
5344
|
}
|
|
5231
5345
|
setIsSubmitting(true);
|
|
5232
5346
|
try {
|
|
5233
|
-
const signerAccount = walletClient ? (0, import_sdk3.walletClientToAccount)(walletClient) : createViewOnlyAccount(
|
|
5234
|
-
const sessionOwner = await resolveSessionOwner2(
|
|
5347
|
+
const signerAccount = signerContext?.walletClient ? (0, import_sdk3.walletClientToAccount)(signerContext.walletClient) : createViewOnlyAccount(ownerAddress2);
|
|
5348
|
+
const sessionOwner = await resolveSessionOwner2(ownerAddress2);
|
|
5235
5349
|
const account = await createSmartAccount(
|
|
5236
5350
|
signerAccount,
|
|
5237
|
-
sessionOwner.account
|
|
5351
|
+
sessionOwner.account,
|
|
5352
|
+
rhinestoneApiKey
|
|
5238
5353
|
);
|
|
5239
5354
|
const smartAccount = getAccountAddress(account);
|
|
5240
5355
|
const checkResult = await service.checkAccount(smartAccount);
|
|
@@ -5256,7 +5371,7 @@ function WithdrawFlow({
|
|
|
5256
5371
|
factoryData: initData.factoryData,
|
|
5257
5372
|
sessionDetails
|
|
5258
5373
|
},
|
|
5259
|
-
eoaAddress:
|
|
5374
|
+
eoaAddress: ownerAddress2,
|
|
5260
5375
|
sessionOwner: sessionOwner.address,
|
|
5261
5376
|
target: {
|
|
5262
5377
|
chain: targetChain,
|
|
@@ -5265,8 +5380,9 @@ function WithdrawFlow({
|
|
|
5265
5380
|
}
|
|
5266
5381
|
});
|
|
5267
5382
|
}
|
|
5268
|
-
handleConnected(
|
|
5383
|
+
handleConnected(ownerAddress2, smartAccount);
|
|
5269
5384
|
const amountUnits = (0, import_viem10.parseUnits)(amountValue, asset.decimals);
|
|
5385
|
+
const pc = signerContext?.publicClient ?? getPublicClient(sourceChain);
|
|
5270
5386
|
const result = onWithdrawSign ? await onWithdrawSign({
|
|
5271
5387
|
safeAddress,
|
|
5272
5388
|
recipient: smartAccount,
|
|
@@ -5275,15 +5391,15 @@ function WithdrawFlow({
|
|
|
5275
5391
|
chainId: sourceChain,
|
|
5276
5392
|
isNative: isSourceNative
|
|
5277
5393
|
}) : isSourceNative ? await executeSafeEthTransfer({
|
|
5278
|
-
walletClient,
|
|
5279
|
-
publicClient,
|
|
5394
|
+
walletClient: signerContext.walletClient,
|
|
5395
|
+
publicClient: pc,
|
|
5280
5396
|
safeAddress,
|
|
5281
5397
|
recipient: smartAccount,
|
|
5282
5398
|
amount: amountUnits,
|
|
5283
5399
|
chainId: sourceChain
|
|
5284
5400
|
}) : await executeSafeErc20Transfer({
|
|
5285
|
-
walletClient,
|
|
5286
|
-
publicClient,
|
|
5401
|
+
walletClient: signerContext.walletClient,
|
|
5402
|
+
publicClient: pc,
|
|
5287
5403
|
safeAddress,
|
|
5288
5404
|
tokenAddress: sourceToken,
|
|
5289
5405
|
recipient: smartAccount,
|
|
@@ -5313,9 +5429,7 @@ function WithdrawFlow({
|
|
|
5313
5429
|
}
|
|
5314
5430
|
},
|
|
5315
5431
|
[
|
|
5316
|
-
|
|
5317
|
-
publicClient,
|
|
5318
|
-
address,
|
|
5432
|
+
signerContext,
|
|
5319
5433
|
targetChainObj,
|
|
5320
5434
|
resolveSessionOwner2,
|
|
5321
5435
|
signerAddress,
|
|
@@ -5324,6 +5438,7 @@ function WithdrawFlow({
|
|
|
5324
5438
|
targetChain,
|
|
5325
5439
|
targetToken,
|
|
5326
5440
|
service,
|
|
5441
|
+
rhinestoneApiKey,
|
|
5327
5442
|
handleConnected,
|
|
5328
5443
|
asset.decimals,
|
|
5329
5444
|
safeAddress,
|
|
@@ -5384,52 +5499,54 @@ function WithdrawFlow({
|
|
|
5384
5499
|
const handleTargetTokenChange = (0, import_react15.useCallback)((token) => {
|
|
5385
5500
|
setTargetToken(token);
|
|
5386
5501
|
}, []);
|
|
5387
|
-
const hasConnectWalletOptions = (connectWalletOptions?.length ?? 0) > 0;
|
|
5388
5502
|
const selectedConnectAddressEffective = (0, import_react15.useMemo)(() => {
|
|
5389
5503
|
if (selectedConnectAddress) return selectedConnectAddress;
|
|
5390
|
-
if (
|
|
5391
|
-
return
|
|
5504
|
+
if (walletOptions.length === 1) {
|
|
5505
|
+
return walletOptions[0].address;
|
|
5392
5506
|
}
|
|
5393
5507
|
return null;
|
|
5394
|
-
}, [selectedConnectAddress,
|
|
5395
|
-
const
|
|
5396
|
-
() =>
|
|
5397
|
-
[
|
|
5398
|
-
);
|
|
5399
|
-
const hasConnectedWallet = Boolean(
|
|
5400
|
-
walletClient && publicClient && address || hasCustomSigner
|
|
5508
|
+
}, [selectedConnectAddress, walletOptions]);
|
|
5509
|
+
const walletOptionsKey = (0, import_react15.useMemo)(
|
|
5510
|
+
() => walletOptions.map((option) => option.address.toLowerCase()).join(","),
|
|
5511
|
+
[walletOptions]
|
|
5401
5512
|
);
|
|
5402
|
-
const showConnectStep = !
|
|
5513
|
+
const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
|
|
5403
5514
|
(0, import_react15.useEffect)(() => {
|
|
5404
5515
|
setIsConnectSelectionConfirmed(false);
|
|
5405
|
-
}, [
|
|
5516
|
+
}, [walletOptionsKey, selectedConnectAddressEffective]);
|
|
5406
5517
|
if (showConnectStep) {
|
|
5407
5518
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "rs-modal-body", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
5408
5519
|
ConnectStep,
|
|
5409
5520
|
{
|
|
5410
|
-
walletOptions
|
|
5521
|
+
walletOptions,
|
|
5411
5522
|
selectedAddress: selectedConnectAddressEffective,
|
|
5412
|
-
onSelectAddress:
|
|
5523
|
+
onSelectAddress: setSelectedConnectAddress,
|
|
5413
5524
|
onRequestConnect,
|
|
5414
5525
|
onConnect,
|
|
5415
|
-
onContinue: () =>
|
|
5526
|
+
onContinue: () => {
|
|
5527
|
+
if (selectedConnectAddressEffective) {
|
|
5528
|
+
setSelectedConnectAddress(selectedConnectAddressEffective);
|
|
5529
|
+
}
|
|
5530
|
+
setIsConnectSelectionConfirmed(true);
|
|
5531
|
+
},
|
|
5416
5532
|
connectButtonLabel
|
|
5417
5533
|
}
|
|
5418
5534
|
) });
|
|
5419
5535
|
}
|
|
5420
|
-
if (!
|
|
5421
|
-
|
|
5422
|
-
|
|
5536
|
+
if (!signerContext) return null;
|
|
5537
|
+
if (!onWithdrawSign && !signerContext.walletClient) return null;
|
|
5538
|
+
const ownerAddress = signerContext.ownerAddress;
|
|
5539
|
+
const formPublicClient = signerContext.publicClient ?? getPublicClient(sourceChain);
|
|
5423
5540
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "rs-modal-body", children: [
|
|
5424
5541
|
step.type === "form" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
5425
5542
|
WithdrawFormStep,
|
|
5426
5543
|
{
|
|
5427
|
-
walletClient,
|
|
5428
|
-
publicClient:
|
|
5429
|
-
address,
|
|
5544
|
+
walletClient: signerContext.walletClient,
|
|
5545
|
+
publicClient: formPublicClient,
|
|
5546
|
+
address: ownerAddress,
|
|
5430
5547
|
safeAddress,
|
|
5431
5548
|
asset,
|
|
5432
|
-
defaultRecipient: defaultRecipient ??
|
|
5549
|
+
defaultRecipient: defaultRecipient ?? ownerAddress,
|
|
5433
5550
|
defaultAmount,
|
|
5434
5551
|
targetChain,
|
|
5435
5552
|
targetToken,
|
|
@@ -5437,7 +5554,7 @@ function WithdrawFlow({
|
|
|
5437
5554
|
targetTokenOptions,
|
|
5438
5555
|
onTargetChainChange: handleTargetChainChange,
|
|
5439
5556
|
onTargetTokenChange: handleTargetTokenChange,
|
|
5440
|
-
switchChain,
|
|
5557
|
+
switchChain: signerContext.switchChain,
|
|
5441
5558
|
submitting: isSubmitting,
|
|
5442
5559
|
onSubmit: handleFormSubmit,
|
|
5443
5560
|
onBalanceUsdChange: setTotalBalanceUsd
|
|
@@ -5465,13 +5582,13 @@ function WithdrawFlow({
|
|
|
5465
5582
|
)
|
|
5466
5583
|
] });
|
|
5467
5584
|
}
|
|
5468
|
-
var import_react15,
|
|
5585
|
+
var import_react15, import_sdk3, import_viem10, import_jsx_runtime19;
|
|
5469
5586
|
var init_WithdrawFlow = __esm({
|
|
5470
5587
|
"src/WithdrawFlow.tsx"() {
|
|
5471
5588
|
"use strict";
|
|
5472
5589
|
import_react15 = require("react");
|
|
5473
|
-
import_viem9 = require("viem");
|
|
5474
5590
|
init_ConnectStep();
|
|
5591
|
+
init_public_client();
|
|
5475
5592
|
init_WithdrawFormStep();
|
|
5476
5593
|
init_ProcessingStep();
|
|
5477
5594
|
init_constants();
|
|
@@ -5492,15 +5609,6 @@ __export(WithdrawModalReown_exports, {
|
|
|
5492
5609
|
});
|
|
5493
5610
|
function WithdrawModalWithReown(props) {
|
|
5494
5611
|
const reown = useReownWallet();
|
|
5495
|
-
const resolved = useResolvedWallet(
|
|
5496
|
-
{
|
|
5497
|
-
walletClient: props.walletClient,
|
|
5498
|
-
publicClient: props.publicClient,
|
|
5499
|
-
address: props.address,
|
|
5500
|
-
switchChain: props.switchChain
|
|
5501
|
-
},
|
|
5502
|
-
reown
|
|
5503
|
-
);
|
|
5504
5612
|
const handleConnect = (0, import_react16.useCallback)(() => {
|
|
5505
5613
|
reown.openConnect();
|
|
5506
5614
|
}, [reown.openConnect]);
|
|
@@ -5508,15 +5616,8 @@ function WithdrawModalWithReown(props) {
|
|
|
5508
5616
|
WithdrawModalInner,
|
|
5509
5617
|
{
|
|
5510
5618
|
...props,
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
address: resolved.address,
|
|
5514
|
-
switchChain: resolved.switchChain,
|
|
5515
|
-
connectWalletOptions: resolved.walletOptions,
|
|
5516
|
-
selectedConnectAddress: resolved.selectedAddress,
|
|
5517
|
-
onSelectConnectAddress: resolved.onSelectAddress,
|
|
5518
|
-
onConnect: handleConnect,
|
|
5519
|
-
onRequestConnect: props.onRequestConnect
|
|
5619
|
+
reownWallet: reown,
|
|
5620
|
+
onConnect: handleConnect
|
|
5520
5621
|
}
|
|
5521
5622
|
);
|
|
5522
5623
|
}
|
|
@@ -5543,9 +5644,9 @@ function WithdrawModal(props) {
|
|
|
5543
5644
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(WithdrawModalInner, { ...props });
|
|
5544
5645
|
}
|
|
5545
5646
|
function WithdrawModalInner({
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5647
|
+
dappWalletClient,
|
|
5648
|
+
dappPublicClient,
|
|
5649
|
+
dappAddress,
|
|
5549
5650
|
safeAddress,
|
|
5550
5651
|
sourceChain: sourceChainProp,
|
|
5551
5652
|
sourceToken,
|
|
@@ -5556,15 +5657,13 @@ function WithdrawModalInner({
|
|
|
5556
5657
|
isOpen,
|
|
5557
5658
|
onClose,
|
|
5558
5659
|
inline,
|
|
5559
|
-
switchChain,
|
|
5560
5660
|
backendUrl = DEFAULT_BACKEND_URL,
|
|
5661
|
+
rhinestoneApiKey,
|
|
5561
5662
|
signerAddress = DEFAULT_SIGNER_ADDRESS,
|
|
5562
5663
|
sessionChainIds,
|
|
5563
5664
|
forceRegister = false,
|
|
5564
5665
|
waitForFinalTx = true,
|
|
5565
|
-
|
|
5566
|
-
selectedConnectAddress,
|
|
5567
|
-
onSelectConnectAddress,
|
|
5666
|
+
reownWallet,
|
|
5568
5667
|
onConnect,
|
|
5569
5668
|
onWithdrawSign,
|
|
5570
5669
|
onRequestConnect,
|
|
@@ -5716,9 +5815,9 @@ function WithdrawModalInner({
|
|
|
5716
5815
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
5717
5816
|
WithdrawFlow,
|
|
5718
5817
|
{
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5818
|
+
dappWalletClient,
|
|
5819
|
+
dappPublicClient,
|
|
5820
|
+
dappAddress,
|
|
5722
5821
|
safeAddress,
|
|
5723
5822
|
sourceChain,
|
|
5724
5823
|
sourceToken,
|
|
@@ -5727,14 +5826,12 @@ function WithdrawModalInner({
|
|
|
5727
5826
|
recipient,
|
|
5728
5827
|
amount: defaultAmount,
|
|
5729
5828
|
service,
|
|
5730
|
-
|
|
5829
|
+
rhinestoneApiKey,
|
|
5731
5830
|
signerAddress,
|
|
5732
5831
|
sessionChainIds,
|
|
5733
5832
|
forceRegister,
|
|
5734
5833
|
waitForFinalTx,
|
|
5735
|
-
|
|
5736
|
-
selectedConnectAddress,
|
|
5737
|
-
onSelectConnectAddress,
|
|
5834
|
+
reownWallet,
|
|
5738
5835
|
onConnect,
|
|
5739
5836
|
onWithdrawSign,
|
|
5740
5837
|
onRequestConnect,
|