@chipi-stack/chipi-react 14.13.0 → 14.13.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.
package/dist/hooks.mjs CHANGED
@@ -23,6 +23,18 @@ function useChipiContext() {
23
23
  }
24
24
  return context;
25
25
  }
26
+
27
+ // src/utils/with-error-code.ts
28
+ function withErrorCode(wrapped, original) {
29
+ const code = original.code;
30
+ if (typeof code === "string") {
31
+ Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
32
+ }
33
+ Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
34
+ return wrapped;
35
+ }
36
+
37
+ // src/hooks/useCreateWallet.ts
26
38
  function useCreateWallet() {
27
39
  const { chipiSDK } = useChipiContext();
28
40
  const mutation = useMutation({
@@ -53,7 +65,7 @@ function useCreateWallet() {
53
65
  }
54
66
  } catch (error) {
55
67
  if (error instanceof Error) {
56
- throw new Error(`Passkey creation failed: ${error.message}`);
68
+ throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
57
69
  }
58
70
  throw new Error("Failed to create passkey for wallet");
59
71
  }
@@ -302,18 +314,21 @@ function useChipiSession(config3) {
302
314
  staleTime: 3e4
303
315
  // 30 seconds
304
316
  });
317
+ const [revokedSessionKey, setRevokedSessionKey] = useState(null);
305
318
  const sessionState = useMemo(() => {
306
319
  if (!localSession) return "none";
320
+ if (revokedSessionKey === localSession.publicKey) return "revoked";
321
+ if (localSession.validUntil * 1e3 < Date.now()) return "expired";
307
322
  const status = sessionStatusQuery.data;
308
323
  if (status) {
309
- if (!status.isActive) return "revoked";
324
+ if (status.validUntil === 0) return "created";
310
325
  if (status.validUntil * 1e3 < Date.now()) return "expired";
311
326
  if (status.remainingCalls <= 0) return "expired";
327
+ if (!status.isActive) return "revoked";
312
328
  return "active";
313
329
  }
314
- if (localSession.validUntil * 1e3 < Date.now()) return "expired";
315
330
  return "created";
316
- }, [localSession, sessionStatusQuery.data]);
331
+ }, [localSession, revokedSessionKey, sessionStatusQuery.data]);
317
332
  const hasActiveSession = sessionState === "active";
318
333
  const isSessionExpired = sessionState === "expired";
319
334
  const remainingCalls = sessionStatusQuery.data?.remainingCalls;
@@ -368,6 +383,7 @@ function useChipiSession(config3) {
368
383
  },
369
384
  onSuccess: () => {
370
385
  setError(null);
386
+ if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
371
387
  queryClient.invalidateQueries({
372
388
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
373
389
  });
@@ -396,6 +412,7 @@ function useChipiSession(config3) {
396
412
  },
397
413
  onSuccess: () => {
398
414
  setError(null);
415
+ if (localSession) setRevokedSessionKey(localSession.publicKey);
399
416
  queryClient.invalidateQueries({
400
417
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
401
418
  });
@@ -636,7 +653,7 @@ function useMigrateWalletToPasskey() {
636
653
  };
637
654
  } catch (error) {
638
655
  if (error instanceof Error) {
639
- throw new Error(`Migration failed: ${error.message}`);
656
+ throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
640
657
  }
641
658
  throw new Error("Failed to migrate wallet to passkey");
642
659
  }