@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 +22 -5
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +22 -5
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -71,6 +71,18 @@ function useChipiContext() {
|
|
|
71
71
|
}
|
|
72
72
|
return context;
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
// src/utils/with-error-code.ts
|
|
76
|
+
function withErrorCode(wrapped, original) {
|
|
77
|
+
const code = original.code;
|
|
78
|
+
if (typeof code === "string") {
|
|
79
|
+
Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
|
|
80
|
+
}
|
|
81
|
+
Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
|
|
82
|
+
return wrapped;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/hooks/useCreateWallet.ts
|
|
74
86
|
function useCreateWallet() {
|
|
75
87
|
const { chipiSDK } = useChipiContext();
|
|
76
88
|
const mutation = useMutation({
|
|
@@ -101,7 +113,7 @@ function useCreateWallet() {
|
|
|
101
113
|
}
|
|
102
114
|
} catch (error) {
|
|
103
115
|
if (error instanceof Error) {
|
|
104
|
-
throw new Error(`Passkey creation failed: ${error.message}`);
|
|
116
|
+
throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
|
|
105
117
|
}
|
|
106
118
|
throw new Error("Failed to create passkey for wallet");
|
|
107
119
|
}
|
|
@@ -350,18 +362,21 @@ function useChipiSession(config3) {
|
|
|
350
362
|
staleTime: 3e4
|
|
351
363
|
// 30 seconds
|
|
352
364
|
});
|
|
365
|
+
const [revokedSessionKey, setRevokedSessionKey] = useState(null);
|
|
353
366
|
const sessionState = useMemo(() => {
|
|
354
367
|
if (!localSession) return "none";
|
|
368
|
+
if (revokedSessionKey === localSession.publicKey) return "revoked";
|
|
369
|
+
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
355
370
|
const status = sessionStatusQuery.data;
|
|
356
371
|
if (status) {
|
|
357
|
-
if (
|
|
372
|
+
if (status.validUntil === 0) return "created";
|
|
358
373
|
if (status.validUntil * 1e3 < Date.now()) return "expired";
|
|
359
374
|
if (status.remainingCalls <= 0) return "expired";
|
|
375
|
+
if (!status.isActive) return "revoked";
|
|
360
376
|
return "active";
|
|
361
377
|
}
|
|
362
|
-
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
363
378
|
return "created";
|
|
364
|
-
}, [localSession, sessionStatusQuery.data]);
|
|
379
|
+
}, [localSession, revokedSessionKey, sessionStatusQuery.data]);
|
|
365
380
|
const hasActiveSession = sessionState === "active";
|
|
366
381
|
const isSessionExpired = sessionState === "expired";
|
|
367
382
|
const remainingCalls = sessionStatusQuery.data?.remainingCalls;
|
|
@@ -416,6 +431,7 @@ function useChipiSession(config3) {
|
|
|
416
431
|
},
|
|
417
432
|
onSuccess: () => {
|
|
418
433
|
setError(null);
|
|
434
|
+
if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
|
|
419
435
|
queryClient.invalidateQueries({
|
|
420
436
|
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
421
437
|
});
|
|
@@ -444,6 +460,7 @@ function useChipiSession(config3) {
|
|
|
444
460
|
},
|
|
445
461
|
onSuccess: () => {
|
|
446
462
|
setError(null);
|
|
463
|
+
if (localSession) setRevokedSessionKey(localSession.publicKey);
|
|
447
464
|
queryClient.invalidateQueries({
|
|
448
465
|
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
449
466
|
});
|
|
@@ -684,7 +701,7 @@ function useMigrateWalletToPasskey() {
|
|
|
684
701
|
};
|
|
685
702
|
} catch (error) {
|
|
686
703
|
if (error instanceof Error) {
|
|
687
|
-
throw new Error(`Migration failed: ${error.message}`);
|
|
704
|
+
throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
|
|
688
705
|
}
|
|
689
706
|
throw new Error("Failed to migrate wallet to passkey");
|
|
690
707
|
}
|