Skip to content

Commit

Permalink
feat: prefix storage key
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Dec 13, 2024
1 parent 6fe388b commit 5c0b3f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/next/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CustomApp: NextPage<AppProps> = ({ Component, pageProps }) => {
<GrazProvider
grazOptions={{
chains,
prefixStorageKey: 'next',
onReconnectFailed: () => {
console.log("reconnect failed");
},
Expand Down
15 changes: 14 additions & 1 deletion packages/graz/src/actions/configure.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 5c0b3f5

Please sign in to comment.