@rhinestone/deposit-modal 0.1.25 → 0.1.27

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.
@@ -7,27 +7,22 @@ import {
7
7
  Spinner,
8
8
  accountFromPrivateKey,
9
9
  applyTheme,
10
+ buildSessionDetails,
10
11
  createDepositService,
11
12
  createSessionOwnerKey,
12
- createSmartAccount,
13
- createViewOnlyAccount,
14
13
  currencyFormatter,
15
14
  formatUserError,
16
- getAccountAddress,
17
- getAccountInitData,
18
15
  getAssetId,
19
16
  getEventTxHash,
20
17
  getPublicClient,
21
- getSessionDetails,
22
18
  isDepositEvent,
23
19
  isNativeAsset,
24
20
  loadSessionOwnerFromStorage,
25
21
  portfolioToAssets,
26
22
  saveSessionOwnerToStorage,
27
23
  tokenFormatter
28
- } from "./chunk-GAFLOODV.mjs";
24
+ } from "./chunk-YOFGP4FV.mjs";
29
25
  import {
30
- CHAIN_BY_ID,
31
26
  DEFAULT_BACKEND_URL,
32
27
  DEFAULT_SIGNER_ADDRESS,
33
28
  NATIVE_TOKEN_ADDRESS,
@@ -59,7 +54,6 @@ import { useState as useState7, useCallback as useCallback3, useMemo as useMemo6
59
54
 
60
55
  // src/components/steps/SetupStep.tsx
61
56
  import { useState, useEffect, useRef, useCallback } from "react";
62
- import { walletClientToAccount } from "@rhinestone/sdk";
63
57
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
64
58
  async function resolveSessionOwner(eoaAddress) {
65
59
  const localOwner = loadSessionOwnerFromStorage(eoaAddress);
@@ -80,9 +74,7 @@ function SetupStep({
80
74
  walletClient,
81
75
  address,
82
76
  targetChain,
83
- targetChainObj,
84
77
  targetToken,
85
- rhinestoneApiKey,
86
78
  signerAddress,
87
79
  sessionChainIds,
88
80
  recipient,
@@ -95,7 +87,7 @@ function SetupStep({
95
87
  const [state, setState] = useState({ type: "idle" });
96
88
  const setupInitiatedRef = useRef(false);
97
89
  const runSetup = useCallback(async () => {
98
- if (!address || !targetChainObj) {
90
+ if (!address) {
99
91
  return;
100
92
  }
101
93
  if (walletClient && !walletClient.account) {
@@ -103,14 +95,9 @@ function SetupStep({
103
95
  }
104
96
  try {
105
97
  setState({ type: "creating-account" });
106
- const signerAccount = walletClient ? walletClientToAccount(walletClient) : createViewOnlyAccount(address);
107
98
  const sessionOwner = await resolveSessionOwner(address);
108
- const account = await createSmartAccount(
109
- signerAccount,
110
- sessionOwner.account,
111
- rhinestoneApiKey
112
- );
113
- const smartAccount = getAccountAddress(account);
99
+ const computed = await service.computeAddress(address, sessionOwner.address);
100
+ const smartAccount = computed.smartAccount;
114
101
  setState({ type: "checking" });
115
102
  const checkResult = await service.checkAccount(smartAccount);
116
103
  if (checkResult.isRegistered && !forceRegister) {
@@ -123,21 +110,34 @@ function SetupStep({
123
110
  }
124
111
  }
125
112
  setState({ type: "signing-session" });
126
- const initData = getAccountInitData(account);
127
- const sessionDetails = await getSessionDetails(
128
- account,
129
- targetChainObj,
130
- signerAddress,
131
- sessionOwner.account,
113
+ const prepared = await service.prepareAccount({
114
+ ownerAddress: address,
115
+ sessionOwnerAddress: sessionOwner.address,
116
+ targetChain,
132
117
  targetToken,
118
+ signerAddress,
133
119
  sessionChainIds
120
+ });
121
+ if (!sessionOwner.account.signTypedData) {
122
+ throw new Error("Session owner account does not support signTypedData");
123
+ }
124
+ const typedData = prepared.sessionDetailsUnsigned.data;
125
+ const signature = await sessionOwner.account.signTypedData({
126
+ domain: typedData.domain,
127
+ types: typedData.types,
128
+ primaryType: typedData.primaryType,
129
+ message: typedData.message
130
+ });
131
+ const sessionDetails = buildSessionDetails(
132
+ prepared.sessionDetailsUnsigned,
133
+ signature
134
134
  );
135
135
  setState({ type: "registering" });
136
136
  await service.registerAccount({
137
137
  address: smartAccount,
138
138
  accountParams: {
139
- factory: initData.factory,
140
- factoryData: initData.factoryData,
139
+ factory: prepared.accountParams.factory,
140
+ factoryData: prepared.accountParams.factoryData,
141
141
  sessionDetails
142
142
  },
143
143
  eoaAddress: address,
@@ -159,10 +159,8 @@ function SetupStep({
159
159
  }, [
160
160
  address,
161
161
  walletClient,
162
- targetChainObj,
163
162
  targetChain,
164
163
  targetToken,
165
- rhinestoneApiKey,
166
164
  signerAddress,
167
165
  sessionChainIds,
168
166
  recipient,
@@ -174,11 +172,11 @@ function SetupStep({
174
172
  ]);
175
173
  useEffect(() => {
176
174
  const hasWallet = walletClient ? Boolean(walletClient.account) : true;
177
- if (address && hasWallet && targetChainObj && !setupInitiatedRef.current && state.type === "idle") {
175
+ if (address && hasWallet && !setupInitiatedRef.current && state.type === "idle") {
178
176
  setupInitiatedRef.current = true;
179
177
  runSetup();
180
178
  }
181
- }, [address, walletClient, targetChainObj, state.type, runSetup]);
179
+ }, [address, walletClient, state.type, runSetup]);
182
180
  const handleRetry = () => {
183
181
  setupInitiatedRef.current = false;
184
182
  setState({ type: "idle" });
@@ -1650,7 +1648,6 @@ function DepositFlow({
1650
1648
  sourceToken: defaultSourceToken,
1651
1649
  amount: defaultAmount,
1652
1650
  recipient,
1653
- rhinestoneApiKey,
1654
1651
  signerAddress = DEFAULT_SIGNER_ADDRESS,
1655
1652
  sessionChainIds,
1656
1653
  forceRegister = false,
@@ -1675,7 +1672,6 @@ function DepositFlow({
1675
1672
  const [totalBalanceUsd, setTotalBalanceUsd] = useState7(0);
1676
1673
  const [isConnectSelectionConfirmed, setIsConnectSelectionConfirmed] = useState7(false);
1677
1674
  const [selectedConnectAddress, setSelectedConnectAddress] = useState7(null);
1678
- const targetChainObj = useMemo6(() => CHAIN_BY_ID[targetChain], [targetChain]);
1679
1675
  const dappSwitchChain = useMemo6(() => {
1680
1676
  if (!dappWalletClient?.switchChain) return void 0;
1681
1677
  return async (chainId) => {
@@ -1968,14 +1964,12 @@ function DepositFlow({
1968
1964
  if (isDepositAddressMode) {
1969
1965
  if (!dappAddress || !sessionKeyAddress) return null;
1970
1966
  return /* @__PURE__ */ jsxs7("div", { className: "rs-modal-body", children: [
1971
- step.type === "setup" && targetChainObj && /* @__PURE__ */ jsx7(
1967
+ step.type === "setup" && /* @__PURE__ */ jsx7(
1972
1968
  SetupStep,
1973
1969
  {
1974
1970
  address: sessionKeyAddress,
1975
1971
  targetChain,
1976
- targetChainObj,
1977
1972
  targetToken,
1978
- rhinestoneApiKey,
1979
1973
  signerAddress,
1980
1974
  sessionChainIds,
1981
1975
  recipient,
@@ -2030,15 +2024,13 @@ function DepositFlow({
2030
2024
  return getPublicClient(chainId);
2031
2025
  };
2032
2026
  return /* @__PURE__ */ jsxs7("div", { className: "rs-modal-body", children: [
2033
- step.type === "setup" && targetChainObj && /* @__PURE__ */ jsx7(
2027
+ step.type === "setup" && /* @__PURE__ */ jsx7(
2034
2028
  SetupStep,
2035
2029
  {
2036
2030
  walletClient: signerContext.walletClient,
2037
2031
  address: ownerAddress,
2038
2032
  targetChain,
2039
- targetChainObj,
2040
2033
  targetToken,
2041
- rhinestoneApiKey,
2042
2034
  signerAddress,
2043
2035
  sessionChainIds,
2044
2036
  recipient,
@@ -2120,7 +2112,7 @@ function DepositFlow({
2120
2112
  // src/DepositModal.tsx
2121
2113
  import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
2122
2114
  var ReownDepositInner = lazy(
2123
- () => import("./DepositModalReown-4A5HJK74.mjs").then((m) => ({ default: m.DepositModalReown }))
2115
+ () => import("./DepositModalReown-PFKTSKDS.mjs").then((m) => ({ default: m.DepositModalReown }))
2124
2116
  );
2125
2117
  function DepositModal(props) {
2126
2118
  const needsReown = !!props.reownAppId;
@@ -2144,7 +2136,6 @@ function DepositModalInner({
2144
2136
  defaultAmount,
2145
2137
  recipient,
2146
2138
  backendUrl = DEFAULT_BACKEND_URL,
2147
- rhinestoneApiKey,
2148
2139
  signerAddress = DEFAULT_SIGNER_ADDRESS,
2149
2140
  sessionChainIds,
2150
2141
  forceRegister = false,
@@ -2314,7 +2305,6 @@ function DepositModalInner({
2314
2305
  sourceToken,
2315
2306
  amount: defaultAmount,
2316
2307
  recipient,
2317
- rhinestoneApiKey,
2318
2308
  signerAddress,
2319
2309
  sessionChainIds,
2320
2310
  forceRegister,
@@ -6,23 +6,18 @@ import {
6
6
  ProcessingStep,
7
7
  accountFromPrivateKey,
8
8
  applyTheme,
9
+ buildSessionDetails,
9
10
  createDepositService,
10
11
  createSessionOwnerKey,
11
- createSmartAccount,
12
- createViewOnlyAccount,
13
12
  currencyFormatter,
14
13
  formatUserError,
15
- getAccountAddress,
16
- getAccountInitData,
17
14
  getAssetId,
18
15
  getPublicClient,
19
- getSessionDetails,
20
16
  isNativeAsset,
21
17
  loadSessionOwnerFromStorage,
22
18
  saveSessionOwnerToStorage
23
- } from "./chunk-GAFLOODV.mjs";
19
+ } from "./chunk-YOFGP4FV.mjs";
24
20
  import {
25
- CHAIN_BY_ID,
26
21
  DEFAULT_BACKEND_URL,
27
22
  DEFAULT_SIGNER_ADDRESS,
28
23
  NATIVE_TOKEN_ADDRESS,
@@ -559,9 +554,6 @@ function WithdrawFormStep({
559
554
  }
560
555
  WithdrawFormStep.displayName = "WithdrawFormStep";
561
556
 
562
- // src/WithdrawFlow.tsx
563
- import { walletClientToAccount } from "@rhinestone/sdk";
564
-
565
557
  // src/core/safe.ts
566
558
  import {
567
559
  concat,
@@ -862,7 +854,6 @@ function WithdrawFlow({
862
854
  recipient: defaultRecipient,
863
855
  amount: defaultAmount,
864
856
  service,
865
- rhinestoneApiKey,
866
857
  signerAddress = DEFAULT_SIGNER_ADDRESS,
867
858
  sessionChainIds,
868
859
  forceRegister = false,
@@ -892,7 +883,6 @@ function WithdrawFlow({
892
883
  setTargetChain(targetChainProp);
893
884
  setTargetToken(targetTokenProp);
894
885
  }, [targetChainProp, targetTokenProp]);
895
- const targetChainObj = useMemo2(() => CHAIN_BY_ID[targetChain], [targetChain]);
896
886
  const hasCustomSigner = Boolean(dappAddress && onSignTransaction);
897
887
  const dappSwitchChain = useMemo2(() => {
898
888
  if (!dappWalletClient?.switchChain) return void 0;
@@ -1031,36 +1021,46 @@ function WithdrawFlow({
1031
1021
  if (!onSignTransaction && !signerContext?.walletClient) {
1032
1022
  throw new Error("Wallet not connected");
1033
1023
  }
1034
- if (!targetChainObj) {
1035
- throw new Error("Unsupported target chain");
1036
- }
1037
1024
  setIsSubmitting(true);
1038
1025
  try {
1039
- const signerAccount = signerContext?.walletClient ? walletClientToAccount(signerContext.walletClient) : createViewOnlyAccount(ownerAddress2);
1040
1026
  const sessionOwner = await resolveSessionOwner(ownerAddress2);
1041
- const account = await createSmartAccount(
1042
- signerAccount,
1043
- sessionOwner.account,
1044
- rhinestoneApiKey
1027
+ const computed = await service.computeAddress(
1028
+ ownerAddress2,
1029
+ sessionOwner.address
1045
1030
  );
1046
- const smartAccount = getAccountAddress(account);
1031
+ const smartAccount = computed.smartAccount;
1047
1032
  const checkResult = await service.checkAccount(smartAccount);
1048
1033
  const targetMatches = checkResult.targetChain === targetChain && checkResult.targetToken?.toLowerCase() === targetToken.toLowerCase();
1049
1034
  if (!checkResult.isRegistered || forceRegister || !targetMatches) {
1050
- const initData = getAccountInitData(account);
1051
- const sessionDetails = await getSessionDetails(
1052
- account,
1053
- targetChainObj,
1054
- signerAddress,
1055
- sessionOwner.account,
1035
+ const prepared = await service.prepareAccount({
1036
+ ownerAddress: ownerAddress2,
1037
+ sessionOwnerAddress: sessionOwner.address,
1038
+ targetChain,
1056
1039
  targetToken,
1040
+ signerAddress,
1057
1041
  sessionChainIds
1042
+ });
1043
+ const typedData = prepared.sessionDetailsUnsigned.data;
1044
+ if (!sessionOwner.account.signTypedData) {
1045
+ throw new Error(
1046
+ "Session owner account does not support signTypedData"
1047
+ );
1048
+ }
1049
+ const signature = await sessionOwner.account.signTypedData({
1050
+ domain: typedData.domain,
1051
+ types: typedData.types,
1052
+ primaryType: typedData.primaryType,
1053
+ message: typedData.message
1054
+ });
1055
+ const sessionDetails = buildSessionDetails(
1056
+ prepared.sessionDetailsUnsigned,
1057
+ signature
1058
1058
  );
1059
1059
  await service.registerAccount({
1060
1060
  address: smartAccount,
1061
1061
  accountParams: {
1062
- factory: initData.factory,
1063
- factoryData: initData.factoryData,
1062
+ factory: prepared.accountParams.factory,
1063
+ factoryData: prepared.accountParams.factoryData,
1064
1064
  sessionDetails
1065
1065
  },
1066
1066
  eoaAddress: ownerAddress2,
@@ -1150,7 +1150,6 @@ function WithdrawFlow({
1150
1150
  },
1151
1151
  [
1152
1152
  signerContext,
1153
- targetChainObj,
1154
1153
  resolveSessionOwner,
1155
1154
  signerAddress,
1156
1155
  sessionChainIds,
@@ -1158,7 +1157,6 @@ function WithdrawFlow({
1158
1157
  targetChain,
1159
1158
  targetToken,
1160
1159
  service,
1161
- rhinestoneApiKey,
1162
1160
  handleConnected,
1163
1161
  asset.decimals,
1164
1162
  safeAddress,
@@ -1307,7 +1305,7 @@ function WithdrawFlow({
1307
1305
  // src/WithdrawModal.tsx
1308
1306
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1309
1307
  var ReownWithdrawInner = lazy(
1310
- () => import("./WithdrawModalReown-HBORIX2O.mjs").then((m) => ({
1308
+ () => import("./WithdrawModalReown-6AAWH35J.mjs").then((m) => ({
1311
1309
  default: m.WithdrawModalReown
1312
1310
  }))
1313
1311
  );
@@ -1334,7 +1332,6 @@ function WithdrawModalInner({
1334
1332
  onClose,
1335
1333
  inline,
1336
1334
  backendUrl = DEFAULT_BACKEND_URL,
1337
- rhinestoneApiKey,
1338
1335
  signerAddress = DEFAULT_SIGNER_ADDRESS,
1339
1336
  sessionChainIds,
1340
1337
  forceRegister = false,
@@ -1503,7 +1500,6 @@ function WithdrawModalInner({
1503
1500
  recipient,
1504
1501
  amount: defaultAmount,
1505
1502
  service,
1506
- rhinestoneApiKey,
1507
1503
  signerAddress,
1508
1504
  sessionChainIds,
1509
1505
  forceRegister,