Skip to content

Commit

Permalink
fix: sessionKey parsing fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jstinhw committed Mar 29, 2024
1 parent 0dab2f8 commit f0bdd11
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/waas/hooks/useSessionPermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import { useValidator } from "..";
import { getEntryPoint } from "../utils/entryPoint";
import { getPermissionId } from "../utils/mock/getPermissionId";

type SessionKeys = {
[permissionId: string]: `0x${string}`;
};

export type SessionPermissionKey = [
key: string,
params: {
Expand Down Expand Up @@ -72,9 +76,13 @@ export function setSessionKey(
permissionId: `0x${string}`,
sessionKey: `0x${string}`
) {
const sessionKeys = JSON.parse(
localStorage.getItem(`kernel_session_key`) || "{}"
);
let sessionKeys: SessionKeys = {};
try {
sessionKeys = JSON.parse(
localStorage.getItem(`kernel_session_key`) || "{}"
);
} catch (err) {}

sessionKeys[permissionId] = sessionKey;
localStorage.setItem(`kernel_session_key`, JSON.stringify(sessionKeys));
}
Expand Down

0 comments on commit f0bdd11

Please sign in to comment.