From 5c0b3f5a6b637b82768bc433479cb2f1055c81b9 Mon Sep 17 00:00:00 2001 From: Nur Fikri Date: Sat, 14 Dec 2024 01:03:51 +0700 Subject: [PATCH] feat: prefix storage key --- example/next/pages/_app.tsx | 1 + packages/graz/src/actions/configure.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/example/next/pages/_app.tsx b/example/next/pages/_app.tsx index 7d406847..d3c870a6 100644 --- a/example/next/pages/_app.tsx +++ b/example/next/pages/_app.tsx @@ -16,6 +16,7 @@ const CustomApp: NextPage = ({ Component, pageProps }) => { { console.log("reconnect failed"); }, diff --git a/packages/graz/src/actions/configure.ts b/packages/graz/src/actions/configure.ts index dcde88f0..d4acec4e 100644 --- a/packages/graz/src/actions/configure.ts +++ b/packages/graz/src/actions/configure.ts @@ -1,7 +1,7 @@ import type { ChainInfo } from "@keplr-wallet/types"; import type { CapsuleConfig, ChainConfig, GrazInternalStore, IframeOptions } from "../store"; -import { useGrazInternalStore } from "../store"; +import { useGrazInternalStore, useGrazSessionStore } from "../store"; import type { WalletType } from "../types/wallet"; export interface ConfigureGrazArgs { @@ -26,9 +26,22 @@ export interface ConfigureGrazArgs { * Options to enable iframe wallet connection. */ iframeOptions?: IframeOptions; + prefixStorageKey?: string; } export const configureGraz = (args: ConfigureGrazArgs): ConfigureGrazArgs => { + if (args.prefixStorageKey) { + useGrazInternalStore.persist.setOptions({ + name: `${args.prefixStorageKey}-graz-internal`, + }); + useGrazSessionStore.persist.setOptions({ + name: `${args.prefixStorageKey}-graz-session`, + }); + useGrazInternalStore.persist.rehydrate(); + useGrazSessionStore.persist.rehydrate(); + localStorage.removeItem("graz-internal"); + sessionStorage.removeItem("graz-session"); + } useGrazInternalStore.setState((prev) => ({ iframeOptions: args.iframeOptions || prev.iframeOptions, walletConnect: args.walletConnect || prev.walletConnect,