@rhinestone/deposit-modal 0.1.8 → 0.1.9

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/dist/index.cjs CHANGED
@@ -1058,12 +1058,16 @@ function createDepositService(baseUrl) {
1058
1058
  }
1059
1059
  return { tokens: [], totalUsd: 0 };
1060
1060
  },
1061
- async fetchStatus(address) {
1062
- const response = await fetch(apiUrl(`/status/${address}`), {
1063
- method: "GET",
1064
- headers: { "Content-Type": "application/json" },
1065
- cache: "no-store"
1066
- });
1061
+ async fetchStatus(address, txHash) {
1062
+ const txHashParam = encodeURIComponent(txHash.toLowerCase());
1063
+ const response = await fetch(
1064
+ apiUrl(`/status/${address}?txHash=${txHashParam}`),
1065
+ {
1066
+ method: "GET",
1067
+ headers: { "Content-Type": "application/json" },
1068
+ cache: "no-store"
1069
+ }
1070
+ );
1067
1071
  if (!response.ok) {
1068
1072
  return { lastEvent: void 0 };
1069
1073
  }
@@ -2208,6 +2212,7 @@ function ProcessingStep({
2208
2212
  const [elapsedSeconds, setElapsedSeconds] = (0, import_react6.useState)(0);
2209
2213
  const startTimeRef = (0, import_react6.useRef)(Date.now());
2210
2214
  const intervalRef = (0, import_react6.useRef)(null);
2215
+ const processTriggerKeyRef = (0, import_react6.useRef)(null);
2211
2216
  const sameChainAndToken = targetChain === sourceChain && targetToken.toLowerCase() === sourceToken.toLowerCase();
2212
2217
  (0, import_react6.useEffect)(() => {
2213
2218
  startTimeRef.current = Date.now();
@@ -2227,13 +2232,21 @@ function ProcessingStep({
2227
2232
  }
2228
2233
  }, [state.type]);
2229
2234
  (0, import_react6.useEffect)(() => {
2235
+ const triggerKey = `${smartAccount.toLowerCase()}:${txHash.toLowerCase()}`;
2236
+ if (processTriggerKeyRef.current === triggerKey) {
2237
+ return;
2238
+ }
2239
+ processTriggerKeyRef.current = triggerKey;
2240
+ let cancelled = false;
2230
2241
  async function triggerProcess() {
2231
2242
  if (!publicClient) {
2243
+ if (cancelled) return;
2232
2244
  setState({ type: "error", message: "No client for source chain" });
2233
2245
  return;
2234
2246
  }
2235
2247
  if (!sender) {
2236
2248
  const message = "Wallet address unavailable";
2249
+ if (cancelled) return;
2237
2250
  setState({ type: "error", message });
2238
2251
  onError?.(message, "PROCESS_ERROR");
2239
2252
  return;
@@ -2242,6 +2255,7 @@ function ProcessingStep({
2242
2255
  await publicClient.waitForTransactionReceipt({ hash: txHash });
2243
2256
  } catch (error) {
2244
2257
  const message = error instanceof Error ? error.message : "Transaction not confirmed";
2258
+ if (cancelled) return;
2245
2259
  setState({ type: "error", message });
2246
2260
  onError?.(message, "PROCESS_ERROR");
2247
2261
  return;
@@ -2254,6 +2268,7 @@ function ProcessingStep({
2254
2268
  txHash,
2255
2269
  sender
2256
2270
  });
2271
+ if (cancelled) return;
2257
2272
  if (result.message.includes("Funds are already on the target chain")) {
2258
2273
  if (sameChainAndToken) {
2259
2274
  setState({ type: "complete" });
@@ -2270,11 +2285,15 @@ function ProcessingStep({
2270
2285
  setState({ type: "processing" });
2271
2286
  } catch (error) {
2272
2287
  const message = error instanceof Error ? error.message : "Process failed";
2288
+ if (cancelled) return;
2273
2289
  setState({ type: "processing", warning: message });
2274
2290
  onError?.(message, "PROCESS_FALLBACK");
2275
2291
  }
2276
2292
  }
2277
2293
  triggerProcess();
2294
+ return () => {
2295
+ cancelled = true;
2296
+ };
2278
2297
  }, [
2279
2298
  smartAccount,
2280
2299
  txHash,
@@ -2300,7 +2319,7 @@ function ProcessingStep({
2300
2319
  let isMounted = true;
2301
2320
  async function pollStatus() {
2302
2321
  try {
2303
- const data = await service.fetchStatus(smartAccount);
2322
+ const data = await service.fetchStatus(smartAccount, txHash);
2304
2323
  const lastEvent2 = data.lastEvent;
2305
2324
  const eventMatchesTx = isEventForTx(lastEvent2, txHash);
2306
2325
  const eventForCurrentTx = eventMatchesTx ? lastEvent2 : void 0;
package/dist/index.mjs CHANGED
@@ -1020,12 +1020,16 @@ function createDepositService(baseUrl) {
1020
1020
  }
1021
1021
  return { tokens: [], totalUsd: 0 };
1022
1022
  },
1023
- async fetchStatus(address) {
1024
- const response = await fetch(apiUrl(`/status/${address}`), {
1025
- method: "GET",
1026
- headers: { "Content-Type": "application/json" },
1027
- cache: "no-store"
1028
- });
1023
+ async fetchStatus(address, txHash) {
1024
+ const txHashParam = encodeURIComponent(txHash.toLowerCase());
1025
+ const response = await fetch(
1026
+ apiUrl(`/status/${address}?txHash=${txHashParam}`),
1027
+ {
1028
+ method: "GET",
1029
+ headers: { "Content-Type": "application/json" },
1030
+ cache: "no-store"
1031
+ }
1032
+ );
1029
1033
  if (!response.ok) {
1030
1034
  return { lastEvent: void 0 };
1031
1035
  }
@@ -2170,6 +2174,7 @@ function ProcessingStep({
2170
2174
  const [elapsedSeconds, setElapsedSeconds] = useState5(0);
2171
2175
  const startTimeRef = useRef4(Date.now());
2172
2176
  const intervalRef = useRef4(null);
2177
+ const processTriggerKeyRef = useRef4(null);
2173
2178
  const sameChainAndToken = targetChain === sourceChain && targetToken.toLowerCase() === sourceToken.toLowerCase();
2174
2179
  useEffect5(() => {
2175
2180
  startTimeRef.current = Date.now();
@@ -2189,13 +2194,21 @@ function ProcessingStep({
2189
2194
  }
2190
2195
  }, [state.type]);
2191
2196
  useEffect5(() => {
2197
+ const triggerKey = `${smartAccount.toLowerCase()}:${txHash.toLowerCase()}`;
2198
+ if (processTriggerKeyRef.current === triggerKey) {
2199
+ return;
2200
+ }
2201
+ processTriggerKeyRef.current = triggerKey;
2202
+ let cancelled = false;
2192
2203
  async function triggerProcess() {
2193
2204
  if (!publicClient) {
2205
+ if (cancelled) return;
2194
2206
  setState({ type: "error", message: "No client for source chain" });
2195
2207
  return;
2196
2208
  }
2197
2209
  if (!sender) {
2198
2210
  const message = "Wallet address unavailable";
2211
+ if (cancelled) return;
2199
2212
  setState({ type: "error", message });
2200
2213
  onError?.(message, "PROCESS_ERROR");
2201
2214
  return;
@@ -2204,6 +2217,7 @@ function ProcessingStep({
2204
2217
  await publicClient.waitForTransactionReceipt({ hash: txHash });
2205
2218
  } catch (error) {
2206
2219
  const message = error instanceof Error ? error.message : "Transaction not confirmed";
2220
+ if (cancelled) return;
2207
2221
  setState({ type: "error", message });
2208
2222
  onError?.(message, "PROCESS_ERROR");
2209
2223
  return;
@@ -2216,6 +2230,7 @@ function ProcessingStep({
2216
2230
  txHash,
2217
2231
  sender
2218
2232
  });
2233
+ if (cancelled) return;
2219
2234
  if (result.message.includes("Funds are already on the target chain")) {
2220
2235
  if (sameChainAndToken) {
2221
2236
  setState({ type: "complete" });
@@ -2232,11 +2247,15 @@ function ProcessingStep({
2232
2247
  setState({ type: "processing" });
2233
2248
  } catch (error) {
2234
2249
  const message = error instanceof Error ? error.message : "Process failed";
2250
+ if (cancelled) return;
2235
2251
  setState({ type: "processing", warning: message });
2236
2252
  onError?.(message, "PROCESS_FALLBACK");
2237
2253
  }
2238
2254
  }
2239
2255
  triggerProcess();
2256
+ return () => {
2257
+ cancelled = true;
2258
+ };
2240
2259
  }, [
2241
2260
  smartAccount,
2242
2261
  txHash,
@@ -2262,7 +2281,7 @@ function ProcessingStep({
2262
2281
  let isMounted = true;
2263
2282
  async function pollStatus() {
2264
2283
  try {
2265
- const data = await service.fetchStatus(smartAccount);
2284
+ const data = await service.fetchStatus(smartAccount, txHash);
2266
2285
  const lastEvent2 = data.lastEvent;
2267
2286
  const eventMatchesTx = isEventForTx(lastEvent2, txHash);
2268
2287
  const eventForCurrentTx = eventMatchesTx ? lastEvent2 : void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinestone/deposit-modal",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "React modal component for Rhinestone cross-chain deposits",
5
5
  "author": "Rhinestone <dev@rhinestone.wtf>",
6
6
  "bugs": {