diff --git a/example/next/pages/_app.tsx b/example/next/pages/_app.tsx index 7d40684..d3c870a 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 dcde88f..d4acec4 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,