@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/index.js CHANGED
@@ -95,6 +95,18 @@ function useChipiContext() {
95
95
  }
96
96
  return context;
97
97
  }
98
+
99
+ // src/utils/with-error-code.ts
100
+ function withErrorCode(wrapped, original) {
101
+ const code = original.code;
102
+ if (typeof code === "string") {
103
+ Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
104
+ }
105
+ Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
106
+ return wrapped;
107
+ }
108
+
109
+ // src/hooks/useCreateWallet.ts
98
110
  function useCreateWallet() {
99
111
  const { chipiSDK } = useChipiContext();
100
112
  const mutation = reactQuery.useMutation({
@@ -125,7 +137,7 @@ function useCreateWallet() {
125
137
  }
126
138
  } catch (error) {
127
139
  if (error instanceof Error) {
128
- throw new Error(`Passkey creation failed: ${error.message}`);
140
+ throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
129
141
  }
130
142
  throw new Error("Failed to create passkey for wallet");
131
143
  }
@@ -374,18 +386,21 @@ function useChipiSession(config3) {
374
386
  staleTime: 3e4
375
387
  // 30 seconds
376
388
  });
389
+ const [revokedSessionKey, setRevokedSessionKey] = React.useState(null);
377
390
  const sessionState = React.useMemo(() => {
378
391
  if (!localSession) return "none";
392
+ if (revokedSessionKey === localSession.publicKey) return "revoked";
393
+ if (localSession.validUntil * 1e3 < Date.now()) return "expired";
379
394
  const status = sessionStatusQuery.data;
380
395
  if (status) {
381
- if (!status.isActive) return "revoked";
396
+ if (status.validUntil === 0) return "created";
382
397
  if (status.validUntil * 1e3 < Date.now()) return "expired";
383
398
  if (status.remainingCalls <= 0) return "expired";
399
+ if (!status.isActive) return "revoked";
384
400
  return "active";
385
401
  }
386
- if (localSession.validUntil * 1e3 < Date.now()) return "expired";
387
402
  return "created";
388
- }, [localSession, sessionStatusQuery.data]);
403
+ }, [localSession, revokedSessionKey, sessionStatusQuery.data]);
389
404
  const hasActiveSession = sessionState === "active";
390
405
  const isSessionExpired = sessionState === "expired";
391
406
  const remainingCalls = sessionStatusQuery.data?.remainingCalls;
@@ -440,6 +455,7 @@ function useChipiSession(config3) {
440
455
  },
441
456
  onSuccess: () => {
442
457
  setError(null);
458
+ if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
443
459
  queryClient.invalidateQueries({
444
460
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
445
461
  });
@@ -468,6 +484,7 @@ function useChipiSession(config3) {
468
484
  },
469
485
  onSuccess: () => {
470
486
  setError(null);
487
+ if (localSession) setRevokedSessionKey(localSession.publicKey);
471
488
  queryClient.invalidateQueries({
472
489
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
473
490
  });
@@ -708,7 +725,7 @@ function useMigrateWalletToPasskey() {
708
725
  };
709
726
  } catch (error) {
710
727
  if (error instanceof Error) {
711
- throw new Error(`Migration failed: ${error.message}`);
728
+ throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
712
729
  }
713
730
  throw new Error("Failed to migrate wallet to passkey");
714
731
  }