@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.js CHANGED
@@ -45,6 +45,18 @@ function useChipiContext() {
45
45
  }
46
46
  return context;
47
47
  }
48
+
49
+ // src/utils/with-error-code.ts
50
+ function withErrorCode(wrapped, original) {
51
+ const code = original.code;
52
+ if (typeof code === "string") {
53
+ Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
54
+ }
55
+ Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
56
+ return wrapped;
57
+ }
58
+
59
+ // src/hooks/useCreateWallet.ts
48
60
  function useCreateWallet() {
49
61
  const { chipiSDK } = useChipiContext();
50
62
  const mutation = reactQuery.useMutation({
@@ -75,7 +87,7 @@ function useCreateWallet() {
75
87
  }
76
88
  } catch (error) {
77
89
  if (error instanceof Error) {
78
- throw new Error(`Passkey creation failed: ${error.message}`);
90
+ throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
79
91
  }
80
92
  throw new Error("Failed to create passkey for wallet");
81
93
  }
@@ -324,18 +336,21 @@ function useChipiSession(config3) {
324
336
  staleTime: 3e4
325
337
  // 30 seconds
326
338
  });
339
+ const [revokedSessionKey, setRevokedSessionKey] = react.useState(null);
327
340
  const sessionState = react.useMemo(() => {
328
341
  if (!localSession) return "none";
342
+ if (revokedSessionKey === localSession.publicKey) return "revoked";
343
+ if (localSession.validUntil * 1e3 < Date.now()) return "expired";
329
344
  const status = sessionStatusQuery.data;
330
345
  if (status) {
331
- if (!status.isActive) return "revoked";
346
+ if (status.validUntil === 0) return "created";
332
347
  if (status.validUntil * 1e3 < Date.now()) return "expired";
333
348
  if (status.remainingCalls <= 0) return "expired";
349
+ if (!status.isActive) return "revoked";
334
350
  return "active";
335
351
  }
336
- if (localSession.validUntil * 1e3 < Date.now()) return "expired";
337
352
  return "created";
338
- }, [localSession, sessionStatusQuery.data]);
353
+ }, [localSession, revokedSessionKey, sessionStatusQuery.data]);
339
354
  const hasActiveSession = sessionState === "active";
340
355
  const isSessionExpired = sessionState === "expired";
341
356
  const remainingCalls = sessionStatusQuery.data?.remainingCalls;
@@ -390,6 +405,7 @@ function useChipiSession(config3) {
390
405
  },
391
406
  onSuccess: () => {
392
407
  setError(null);
408
+ if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
393
409
  queryClient.invalidateQueries({
394
410
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
395
411
  });
@@ -418,6 +434,7 @@ function useChipiSession(config3) {
418
434
  },
419
435
  onSuccess: () => {
420
436
  setError(null);
437
+ if (localSession) setRevokedSessionKey(localSession.publicKey);
421
438
  queryClient.invalidateQueries({
422
439
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
423
440
  });
@@ -658,7 +675,7 @@ function useMigrateWalletToPasskey() {
658
675
  };
659
676
  } catch (error) {
660
677
  if (error instanceof Error) {
661
- throw new Error(`Migration failed: ${error.message}`);
678
+ throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
662
679
  }
663
680
  throw new Error("Failed to migrate wallet to passkey");
664
681
  }