@rhinestone/deposit-modal 0.4.0 → 0.4.1

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.
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DepositModalInner
3
- } from "./chunk-3PVDRSJ7.mjs";
3
+ } from "./chunk-RTAIW3WW.mjs";
4
4
  import "./chunk-FJWLC4AM.mjs";
5
5
  import {
6
6
  ReownWalletProvider,
7
7
  useReownWallet
8
- } from "./chunk-UFKFSGT3.mjs";
9
- import "./chunk-GKC22JC4.mjs";
8
+ } from "./chunk-43RTPRQY.mjs";
9
+ import "./chunk-A33QFRKD.mjs";
10
10
  import "./chunk-F7P4MV72.mjs";
11
11
  import "./chunk-WJX3TJFK.mjs";
12
12
 
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunk7MP2UWIQcjs = require('./chunk-7MP2UWIQ.cjs');
3
+ var _chunkBTDRUAPJcjs = require('./chunk-BTDRUAPJ.cjs');
4
4
  require('./chunk-NRNJAQUA.cjs');
5
5
 
6
6
 
7
7
 
8
- var _chunk3MXWIYATcjs = require('./chunk-3MXWIYAT.cjs');
9
- require('./chunk-OQVLEVNR.cjs');
8
+ var _chunkULCCXH2Acjs = require('./chunk-ULCCXH2A.cjs');
9
+ require('./chunk-LJJCPDZO.cjs');
10
10
  require('./chunk-UEKPBRBY.cjs');
11
11
  require('./chunk-ABVRVW3P.cjs');
12
12
 
@@ -16,7 +16,7 @@ var _react3 = require('@reown/appkit/react');
16
16
  var _react5 = require('@reown/appkit-adapter-solana/react');
17
17
  var _jsxruntime = require('react/jsx-runtime');
18
18
  function DepositModalWithReown(props) {
19
- const reown = _chunk3MXWIYATcjs.useReownWallet.call(void 0, );
19
+ const reown = _chunkULCCXH2Acjs.useReownWallet.call(void 0, );
20
20
  const enableSolana = _nullishCoalesce(props.enableSolana, () => ( true));
21
21
  const { walletProvider: solanaWalletProvider } = _react3.useAppKitProvider.call(void 0,
22
22
  enableSolana ? "solana" : "eip155"
@@ -37,7 +37,7 @@ function DepositModalWithReown(props) {
37
37
  reown.disconnect();
38
38
  }, [reown.disconnect]);
39
39
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
40
- _chunk7MP2UWIQcjs.DepositModalInner,
40
+ _chunkBTDRUAPJcjs.DepositModalInner,
41
41
  {
42
42
  ...props,
43
43
  reownWallet: reownWithSolana,
@@ -48,7 +48,7 @@ function DepositModalWithReown(props) {
48
48
  }
49
49
  function DepositModalReown(props) {
50
50
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
51
- _chunk3MXWIYATcjs.ReownWalletProvider,
51
+ _chunkULCCXH2Acjs.ReownWalletProvider,
52
52
  {
53
53
  projectId: props.reownAppId,
54
54
  theme: props.theme,
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkAE5LHTPMcjs = require('./chunk-AE5LHTPM.cjs');
3
+ var _chunkJHT2MJ42cjs = require('./chunk-JHT2MJ42.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunk3MXWIYATcjs = require('./chunk-3MXWIYAT.cjs');
8
- require('./chunk-OQVLEVNR.cjs');
7
+ var _chunkULCCXH2Acjs = require('./chunk-ULCCXH2A.cjs');
8
+ require('./chunk-LJJCPDZO.cjs');
9
9
  require('./chunk-UEKPBRBY.cjs');
10
10
  require('./chunk-ABVRVW3P.cjs');
11
11
 
@@ -13,7 +13,7 @@ require('./chunk-ABVRVW3P.cjs');
13
13
  var _react = require('react');
14
14
  var _jsxruntime = require('react/jsx-runtime');
15
15
  function WithdrawModalWithReown(props) {
16
- const reown = _chunk3MXWIYATcjs.useReownWallet.call(void 0, );
16
+ const reown = _chunkULCCXH2Acjs.useReownWallet.call(void 0, );
17
17
  const handleConnect = _react.useCallback.call(void 0, () => {
18
18
  reown.openConnect();
19
19
  }, [reown.openConnect]);
@@ -21,7 +21,7 @@ function WithdrawModalWithReown(props) {
21
21
  reown.disconnect();
22
22
  }, [reown.disconnect]);
23
23
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
24
- _chunkAE5LHTPMcjs.WithdrawModalInner,
24
+ _chunkJHT2MJ42cjs.WithdrawModalInner,
25
25
  {
26
26
  ...props,
27
27
  reownWallet: reown,
@@ -31,7 +31,7 @@ function WithdrawModalWithReown(props) {
31
31
  );
32
32
  }
33
33
  function WithdrawModalReown(props) {
34
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk3MXWIYATcjs.ReownWalletProvider, { projectId: props.reownAppId, theme: props.theme, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, WithdrawModalWithReown, { ...props }) });
34
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkULCCXH2Acjs.ReownWalletProvider, { projectId: props.reownAppId, theme: props.theme, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, WithdrawModalWithReown, { ...props }) });
35
35
  }
36
36
 
37
37
 
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  WithdrawModalInner
3
- } from "./chunk-WCIGOV34.mjs";
3
+ } from "./chunk-3GLQC2KQ.mjs";
4
4
  import {
5
5
  ReownWalletProvider,
6
6
  useReownWallet
7
- } from "./chunk-UFKFSGT3.mjs";
8
- import "./chunk-GKC22JC4.mjs";
7
+ } from "./chunk-43RTPRQY.mjs";
8
+ import "./chunk-A33QFRKD.mjs";
9
9
  import "./chunk-F7P4MV72.mjs";
10
10
  import "./chunk-WJX3TJFK.mjs";
11
11
 
@@ -30,7 +30,7 @@ import {
30
30
  saveSessionOwnerToStorage,
31
31
  useLatestRef,
32
32
  useTokenPrices
33
- } from "./chunk-GKC22JC4.mjs";
33
+ } from "./chunk-A33QFRKD.mjs";
34
34
  import {
35
35
  buildSafeTransaction,
36
36
  executeSafeErc20Transfer,
@@ -784,6 +784,7 @@ import { encodeFunctionData, erc20Abi as erc20Abi2, parseUnits as parseUnits2 }
784
784
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
785
785
  var ADDR_REGEX = /^0x[a-fA-F0-9]{40}$/;
786
786
  var REGISTRATION_DEBOUNCE_MS = 600;
787
+ var WITHDRAW_INDEXING_DELAY_MS = 2e3;
787
788
  function resolveSessionOwner(eoaAddress) {
788
789
  const localOwner = loadSessionOwnerFromStorage(eoaAddress);
789
790
  if (localOwner) {
@@ -832,6 +833,14 @@ function WithdrawFlow({
832
833
  const onEventRef = useLatestRef(onEvent);
833
834
  const onLifecycleRef = useLatestRef(onLifecycle);
834
835
  const onErrorRef = useLatestRef(onError);
836
+ const isFlowActiveRef = useRef2(true);
837
+ const submitGenerationRef = useRef2(0);
838
+ useEffect2(() => {
839
+ isFlowActiveRef.current = true;
840
+ return () => {
841
+ isFlowActiveRef.current = false;
842
+ };
843
+ }, []);
835
844
  const logFlow = useCallback2(
836
845
  (message, data) => {
837
846
  debugLog(debug, "withdraw-flow", message, data);
@@ -905,6 +914,7 @@ function WithdrawFlow({
905
914
  const selectedWalletId = useWithdrawStore((s) => s.selectedWalletId);
906
915
  const registration = useWithdrawStore((s) => s.registration);
907
916
  const flowStep = useWithdrawStore((s) => s.step);
917
+ const reviewedRecipient = useWithdrawStore((s) => s.recipient);
908
918
  const setSelectedWalletId = useCallback2(
909
919
  (walletId) => storeApi.dispatch({ type: "wallet/id-selected", walletId }),
910
920
  [storeApi]
@@ -965,7 +975,7 @@ function WithdrawFlow({
965
975
  return ADDR_REGEX.test(recipientInput) ? recipientInput : void 0;
966
976
  }, [recipientInput]);
967
977
  useEffect2(() => {
968
- if (!ownerAddress) return;
978
+ if (!ownerAddress || !recipientForRegistration) return;
969
979
  const desiredTarget = {
970
980
  chain: targetChain,
971
981
  token: targetToken,
@@ -1098,7 +1108,14 @@ function WithdrawFlow({
1098
1108
  }, [sourceChain, sourceToken]);
1099
1109
  const isSourceNative = sourceToken.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase();
1100
1110
  const isSameRoute = targetChain === sourceChain && targetToken.toLowerCase() === sourceToken.toLowerCase();
1111
+ const reviewedTarget = reviewedRecipient ? {
1112
+ chain: targetChain,
1113
+ token: targetToken,
1114
+ recipient: reviewedRecipient
1115
+ } : null;
1116
+ const isReviewedTargetReady = registration.kind === "ready" && reviewedTarget !== null && targetsEqual(registration.registeredTarget, reviewedTarget);
1101
1117
  const reviewBackHandler = useCallback2(() => {
1118
+ submitGenerationRef.current += 1;
1102
1119
  storeApi.dispatch({ type: "review/back" });
1103
1120
  }, [storeApi]);
1104
1121
  useEffect2(() => {
@@ -1173,19 +1190,38 @@ function WithdrawFlow({
1173
1190
  const handleReviewConfirm = useCallback2(
1174
1191
  async () => {
1175
1192
  const state = storeApi.getState();
1176
- if (state.registration.kind !== "ready") {
1177
- throw new Error("Session not ready");
1178
- }
1179
- const smartAccount = state.registration.smartAccount;
1180
1193
  const recipient = state.recipient;
1181
1194
  const amountValue = state.amount;
1182
1195
  if (!recipient || !amountValue) {
1183
1196
  throw new Error("Missing recipient or amount");
1184
1197
  }
1198
+ const desiredTarget = {
1199
+ chain: targetChain,
1200
+ token: targetToken,
1201
+ recipient
1202
+ };
1203
+ const getMatchingRegistration = () => {
1204
+ const current = storeApi.getState().registration;
1205
+ return current.kind === "ready" && targetsEqual(current.registeredTarget, desiredTarget) ? current : null;
1206
+ };
1207
+ const matchingRegistration = getMatchingRegistration();
1208
+ if (!matchingRegistration) {
1209
+ throw new Error("Withdrawal target is still being prepared");
1210
+ }
1211
+ const smartAccount = matchingRegistration.smartAccount;
1185
1212
  if (!onSignTransaction && !signerContext?.walletClient) {
1186
1213
  throw new Error("Wallet not connected");
1187
1214
  }
1215
+ const submitGeneration = submitGenerationRef.current += 1;
1216
+ const isSubmissionLive = () => isFlowActiveRef.current && submitGenerationRef.current === submitGeneration;
1188
1217
  try {
1218
+ await new Promise((resolve) => {
1219
+ setTimeout(resolve, WITHDRAW_INDEXING_DELAY_MS);
1220
+ });
1221
+ if (!isSubmissionLive()) return;
1222
+ if (!getMatchingRegistration()) {
1223
+ throw new Error("Withdrawal target changed before submission");
1224
+ }
1189
1225
  logFlow("submit:start", {
1190
1226
  smartAccount,
1191
1227
  recipient,
@@ -1217,7 +1253,12 @@ function WithdrawFlow({
1217
1253
  data: transferData.data,
1218
1254
  chainId: sourceChain
1219
1255
  });
1256
+ if (!isSubmissionLive()) return;
1220
1257
  const { signature } = await onSignTransaction(request);
1258
+ if (!isSubmissionLive()) return;
1259
+ if (!getMatchingRegistration()) {
1260
+ throw new Error("Withdrawal target changed before submission");
1261
+ }
1221
1262
  const relayResult = await service.relayWithdraw({
1222
1263
  smartAccount,
1223
1264
  chainId: toEvmCaip2(sourceChain),
@@ -1230,6 +1271,9 @@ function WithdrawFlow({
1230
1271
  }
1231
1272
  result = { txHash: relayResult.txHash };
1232
1273
  } else if (isSourceNative) {
1274
+ if (!getMatchingRegistration()) {
1275
+ throw new Error("Withdrawal target changed before submission");
1276
+ }
1233
1277
  result = await executeSafeEthTransfer({
1234
1278
  walletClient: signerContext.walletClient,
1235
1279
  publicClient: pc,
@@ -1239,6 +1283,9 @@ function WithdrawFlow({
1239
1283
  chainId: sourceChain
1240
1284
  });
1241
1285
  } else {
1286
+ if (!getMatchingRegistration()) {
1287
+ throw new Error("Withdrawal target changed before submission");
1288
+ }
1242
1289
  result = await executeSafeErc20Transfer({
1243
1290
  walletClient: signerContext.walletClient,
1244
1291
  publicClient: pc,
@@ -1249,6 +1296,7 @@ function WithdrawFlow({
1249
1296
  chainId: sourceChain
1250
1297
  });
1251
1298
  }
1299
+ if (!isSubmissionLive()) return;
1252
1300
  logFlow("withdraw:submitted", {
1253
1301
  txHash: result.txHash,
1254
1302
  smartAccount,
@@ -1467,7 +1515,7 @@ function WithdrawFlow({
1467
1515
  amount: storeApi.getState().amount ?? "0",
1468
1516
  recipient: storeApi.getState().recipient ?? recipientForRegistration ?? "0x0",
1469
1517
  service,
1470
- registrationPending: registration.kind === "pending" || registration.kind === "stale",
1518
+ registrationPending: registration.kind === "pending" || registration.kind === "stale" || !isReviewedTargetReady,
1471
1519
  registrationError: registration.kind === "failed" ? registration.error : null,
1472
1520
  onConfirm: handleReviewConfirm,
1473
1521
  onError: handleError
@@ -1516,7 +1564,7 @@ function deriveStepView(step, _registration) {
1516
1564
  // src/WithdrawModal.tsx
1517
1565
  import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1518
1566
  var ReownWithdrawInner = lazy(
1519
- () => import("./WithdrawModalReown-BE23LUMT.mjs").then((m) => ({
1567
+ () => import("./WithdrawModalReown-G7EM6HXO.mjs").then((m) => ({
1520
1568
  default: m.WithdrawModalReown
1521
1569
  }))
1522
1570
  );
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isUnsupportedChainSwitchError
3
- } from "./chunk-GKC22JC4.mjs";
3
+ } from "./chunk-A33QFRKD.mjs";
4
4
  import {
5
5
  SUPPORTED_CHAINS,
6
6
  getChainName