@rhinestone/deposit-modal 0.1.24 → 0.1.25

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.
@@ -0,0 +1,90 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/reown.tsx
2
+ var _react = require('react');
3
+ var _reactquery = require('@tanstack/react-query');
4
+ var _appkitadapterwagmi = require('@reown/appkit-adapter-wagmi');
5
+ var _wagmi = require('wagmi');
6
+ var _react3 = require('@reown/appkit/react');
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _networks = require('@reown/appkit/networks');
15
+
16
+ var _jsxruntime = require('react/jsx-runtime');
17
+ var NETWORKS = [
18
+ _networks.mainnet,
19
+ _networks.base,
20
+ _networks.arbitrum,
21
+ _networks.optimism,
22
+ _networks.polygon,
23
+ _networks.bsc
24
+ ];
25
+ var cachedAdapter = null;
26
+ var cachedProjectId = null;
27
+ function mapTheme(theme) {
28
+ const themeMode = _optionalChain([theme, 'optionalAccess', _ => _.mode]) === "light" ? "light" : "dark";
29
+ const themeVariables = {};
30
+ if (_optionalChain([theme, 'optionalAccess', _2 => _2.ctaColor])) {
31
+ themeVariables["--apkt-accent"] = theme.ctaColor;
32
+ }
33
+ return { themeMode, themeVariables };
34
+ }
35
+ function getOrCreateAdapter(projectId, theme) {
36
+ if (cachedAdapter && cachedProjectId === projectId) return cachedAdapter;
37
+ cachedAdapter = new (0, _appkitadapterwagmi.WagmiAdapter)({
38
+ networks: NETWORKS,
39
+ projectId
40
+ });
41
+ cachedProjectId = projectId;
42
+ const { themeMode, themeVariables } = mapTheme(theme);
43
+ _react3.createAppKit.call(void 0, {
44
+ adapters: [cachedAdapter],
45
+ networks: NETWORKS,
46
+ projectId,
47
+ themeMode,
48
+ themeVariables,
49
+ features: {
50
+ connectMethodsOrder: ["wallet"],
51
+ email: false,
52
+ socials: false
53
+ }
54
+ });
55
+ return cachedAdapter;
56
+ }
57
+ function ReownWalletProvider({
58
+ projectId,
59
+ theme,
60
+ children
61
+ }) {
62
+ const [queryClient] = _react.useState.call(void 0, () => new (0, _reactquery.QueryClient)());
63
+ const adapter = getOrCreateAdapter(projectId, theme);
64
+ const config = adapter.wagmiConfig;
65
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _wagmi.WagmiProvider, { config, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient, children }) });
66
+ }
67
+ function useReownWallet() {
68
+ const { open } = _react3.useAppKit.call(void 0, );
69
+ const { address, isConnected } = _react3.useAppKitAccount.call(void 0, );
70
+ const { data: walletClient } = _wagmi.useWalletClient.call(void 0, );
71
+ const publicClient = _wagmi.usePublicClient.call(void 0, );
72
+ const { switchChainAsync } = _wagmi.useSwitchChain.call(void 0, );
73
+ return {
74
+ walletClient: _nullishCoalesce(walletClient, () => ( void 0)),
75
+ publicClient: _nullishCoalesce(publicClient, () => ( void 0)),
76
+ address,
77
+ isConnected,
78
+ openConnect: () => {
79
+ void open({ view: isConnected ? "Account" : "Connect" });
80
+ },
81
+ switchChain: async (chainId) => {
82
+ await switchChainAsync({ chainId });
83
+ }
84
+ };
85
+ }
86
+
87
+
88
+
89
+
90
+ exports.ReownWalletProvider = ReownWalletProvider; exports.useReownWallet = useReownWallet;
@@ -6,17 +6,21 @@ import {
6
6
  ProcessingStep,
7
7
  accountFromPrivateKey,
8
8
  applyTheme,
9
- buildSessionDetails,
10
9
  createDepositService,
11
10
  createSessionOwnerKey,
11
+ createSmartAccount,
12
+ createViewOnlyAccount,
12
13
  currencyFormatter,
13
14
  formatUserError,
15
+ getAccountAddress,
16
+ getAccountInitData,
14
17
  getAssetId,
15
18
  getPublicClient,
19
+ getSessionDetails,
16
20
  isNativeAsset,
17
21
  loadSessionOwnerFromStorage,
18
22
  saveSessionOwnerToStorage
19
- } from "./chunk-P7SQQAAF.mjs";
23
+ } from "./chunk-GAFLOODV.mjs";
20
24
  import {
21
25
  CHAIN_BY_ID,
22
26
  DEFAULT_BACKEND_URL,
@@ -38,7 +42,9 @@ import {
38
42
  useEffect as useEffect3,
39
43
  useMemo as useMemo3,
40
44
  useRef as useRef2,
41
- useState as useState3
45
+ useState as useState3,
46
+ lazy,
47
+ Suspense
42
48
  } from "react";
43
49
 
44
50
  // src/WithdrawFlow.tsx
@@ -553,6 +559,9 @@ function WithdrawFormStep({
553
559
  }
554
560
  WithdrawFormStep.displayName = "WithdrawFormStep";
555
561
 
562
+ // src/WithdrawFlow.tsx
563
+ import { walletClientToAccount } from "@rhinestone/sdk";
564
+
556
565
  // src/core/safe.ts
557
566
  import {
558
567
  concat,
@@ -853,13 +862,14 @@ function WithdrawFlow({
853
862
  recipient: defaultRecipient,
854
863
  amount: defaultAmount,
855
864
  service,
865
+ rhinestoneApiKey,
856
866
  signerAddress = DEFAULT_SIGNER_ADDRESS,
857
867
  sessionChainIds,
858
868
  forceRegister = false,
859
869
  waitForFinalTx = true,
860
870
  reownWallet,
861
871
  onConnect,
862
- onRelayTransaction,
872
+ onSignTransaction,
863
873
  onRequestConnect,
864
874
  connectButtonLabel,
865
875
  onStepChange,
@@ -883,7 +893,7 @@ function WithdrawFlow({
883
893
  setTargetToken(targetTokenProp);
884
894
  }, [targetChainProp, targetTokenProp]);
885
895
  const targetChainObj = useMemo2(() => CHAIN_BY_ID[targetChain], [targetChain]);
886
- const hasCustomSigner = Boolean(dappAddress && onRelayTransaction);
896
+ const hasCustomSigner = Boolean(dappAddress && onSignTransaction);
887
897
  const dappSwitchChain = useMemo2(() => {
888
898
  if (!dappWalletClient?.switchChain) return void 0;
889
899
  return async (chainId) => {
@@ -1012,23 +1022,13 @@ function WithdrawFlow({
1012
1022
  address: created.address
1013
1023
  };
1014
1024
  }, []);
1015
- const signSessionDetails = useCallback2(
1016
- async (sessionOwnerAccount, typedData) => {
1017
- const signer = sessionOwnerAccount;
1018
- if (!signer.signTypedData) {
1019
- throw new Error("Session owner cannot sign typed data");
1020
- }
1021
- return await signer.signTypedData(typedData);
1022
- },
1023
- []
1024
- );
1025
1025
  const handleFormSubmit = useCallback2(
1026
1026
  async (recipient, amountValue) => {
1027
1027
  const ownerAddress2 = signerContext?.ownerAddress;
1028
1028
  if (!ownerAddress2) {
1029
1029
  throw new Error("Wallet not connected");
1030
1030
  }
1031
- if (!onRelayTransaction && !signerContext?.walletClient) {
1031
+ if (!onSignTransaction && !signerContext?.walletClient) {
1032
1032
  throw new Error("Wallet not connected");
1033
1033
  }
1034
1034
  if (!targetChainObj) {
@@ -1036,32 +1036,31 @@ function WithdrawFlow({
1036
1036
  }
1037
1037
  setIsSubmitting(true);
1038
1038
  try {
1039
+ const signerAccount = signerContext?.walletClient ? walletClientToAccount(signerContext.walletClient) : createViewOnlyAccount(ownerAddress2);
1039
1040
  const sessionOwner = await resolveSessionOwner(ownerAddress2);
1040
- const prepared = await service.prepareAccount({
1041
- ownerAddress: ownerAddress2,
1042
- sessionOwnerAddress: sessionOwner.address,
1043
- targetChain,
1044
- targetToken,
1045
- signerAddress,
1046
- sessionChainIds
1047
- });
1048
- const smartAccount = prepared.smartAccount;
1041
+ const account = await createSmartAccount(
1042
+ signerAccount,
1043
+ sessionOwner.account,
1044
+ rhinestoneApiKey
1045
+ );
1046
+ const smartAccount = getAccountAddress(account);
1049
1047
  const checkResult = await service.checkAccount(smartAccount);
1050
1048
  const targetMatches = checkResult.targetChain === targetChain && checkResult.targetToken?.toLowerCase() === targetToken.toLowerCase();
1051
1049
  if (!checkResult.isRegistered || forceRegister || !targetMatches) {
1052
- const signature = await signSessionDetails(
1050
+ const initData = getAccountInitData(account);
1051
+ const sessionDetails = await getSessionDetails(
1052
+ account,
1053
+ targetChainObj,
1054
+ signerAddress,
1053
1055
  sessionOwner.account,
1054
- prepared.sessionDetailsUnsigned.data
1055
- );
1056
- const sessionDetails = buildSessionDetails(
1057
- prepared.sessionDetailsUnsigned,
1058
- signature
1056
+ targetToken,
1057
+ sessionChainIds
1059
1058
  );
1060
1059
  await service.registerAccount({
1061
1060
  address: smartAccount,
1062
1061
  accountParams: {
1063
- factory: prepared.accountParams.factory,
1064
- factoryData: prepared.accountParams.factoryData,
1062
+ factory: initData.factory,
1063
+ factoryData: initData.factoryData,
1065
1064
  sessionDetails
1066
1065
  },
1067
1066
  eoaAddress: ownerAddress2,
@@ -1077,7 +1076,7 @@ function WithdrawFlow({
1077
1076
  const amountUnits = parseUnits2(amountValue, asset.decimals);
1078
1077
  const pc = signerContext?.publicClient ?? getPublicClient(sourceChain);
1079
1078
  let result;
1080
- if (onRelayTransaction) {
1079
+ if (onSignTransaction) {
1081
1080
  const transferData = isSourceNative ? { to: smartAccount, value: amountUnits, data: "0x" } : {
1082
1081
  to: sourceToken,
1083
1082
  value: 0n,
@@ -1095,7 +1094,18 @@ function WithdrawFlow({
1095
1094
  data: transferData.data,
1096
1095
  chainId: sourceChain
1097
1096
  });
1098
- result = await onRelayTransaction(request);
1097
+ const { signature } = await onSignTransaction(request);
1098
+ const relayResult = await service.relayWithdraw({
1099
+ smartAccount,
1100
+ chainId: sourceChain,
1101
+ safeAddress,
1102
+ safeTransaction: request.typedData.message,
1103
+ signature
1104
+ });
1105
+ if (!relayResult.txHash) {
1106
+ throw new Error("Relay succeeded but no txHash returned");
1107
+ }
1108
+ result = { txHash: relayResult.txHash };
1099
1109
  } else if (isSourceNative) {
1100
1110
  result = await executeSafeEthTransfer({
1101
1111
  walletClient: signerContext.walletClient,
@@ -1148,16 +1158,16 @@ function WithdrawFlow({
1148
1158
  targetChain,
1149
1159
  targetToken,
1150
1160
  service,
1161
+ rhinestoneApiKey,
1151
1162
  handleConnected,
1152
1163
  asset.decimals,
1153
1164
  safeAddress,
1154
1165
  sourceToken,
1155
1166
  sourceChain,
1156
1167
  onWithdrawSubmitted,
1157
- onRelayTransaction,
1168
+ onSignTransaction,
1158
1169
  isSourceNative,
1159
- handleError,
1160
- signSessionDetails
1170
+ handleError
1161
1171
  ]
1162
1172
  );
1163
1173
  const handleWithdrawComplete = useCallback2(
@@ -1244,7 +1254,7 @@ function WithdrawFlow({
1244
1254
  ) });
1245
1255
  }
1246
1256
  if (!signerContext) return null;
1247
- if (!onRelayTransaction && !signerContext.walletClient) return null;
1257
+ if (!onSignTransaction && !signerContext.walletClient) return null;
1248
1258
  const ownerAddress = signerContext.ownerAddress;
1249
1259
  const formPublicClient = signerContext.publicClient ?? getPublicClient(sourceChain);
1250
1260
  return /* @__PURE__ */ jsxs2("div", { className: "rs-modal-body", children: [
@@ -1296,11 +1306,15 @@ function WithdrawFlow({
1296
1306
 
1297
1307
  // src/WithdrawModal.tsx
1298
1308
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1309
+ var ReownWithdrawInner = lazy(
1310
+ () => import("./WithdrawModalReown-HBORIX2O.mjs").then((m) => ({
1311
+ default: m.WithdrawModalReown
1312
+ }))
1313
+ );
1299
1314
  function WithdrawModal(props) {
1300
- if (props.reownAppId) {
1301
- throw new Error(
1302
- 'Reown support moved to "@rhinestone/deposit-modal/reown". Use that entrypoint when passing reownAppId.'
1303
- );
1315
+ const needsReown = !!props.reownAppId;
1316
+ if (needsReown) {
1317
+ return /* @__PURE__ */ jsx3(Suspense, { fallback: null, children: /* @__PURE__ */ jsx3(ReownWithdrawInner, { ...props }) });
1304
1318
  }
1305
1319
  return /* @__PURE__ */ jsx3(WithdrawModalInner, { ...props });
1306
1320
  }
@@ -1320,13 +1334,14 @@ function WithdrawModalInner({
1320
1334
  onClose,
1321
1335
  inline,
1322
1336
  backendUrl = DEFAULT_BACKEND_URL,
1337
+ rhinestoneApiKey,
1323
1338
  signerAddress = DEFAULT_SIGNER_ADDRESS,
1324
1339
  sessionChainIds,
1325
1340
  forceRegister = false,
1326
1341
  waitForFinalTx = true,
1327
1342
  reownWallet,
1328
1343
  onConnect,
1329
- onRelayTransaction,
1344
+ onSignTransaction,
1330
1345
  onRequestConnect,
1331
1346
  connectButtonLabel,
1332
1347
  theme,
@@ -1488,13 +1503,14 @@ function WithdrawModalInner({
1488
1503
  recipient,
1489
1504
  amount: defaultAmount,
1490
1505
  service,
1506
+ rhinestoneApiKey,
1491
1507
  signerAddress,
1492
1508
  sessionChainIds,
1493
1509
  forceRegister,
1494
1510
  waitForFinalTx,
1495
1511
  reownWallet,
1496
1512
  onConnect,
1497
- onRelayTransaction,
1513
+ onSignTransaction,
1498
1514
  onRequestConnect,
1499
1515
  connectButtonLabel,
1500
1516
  onStepChange: handleStepChange,