Skip to content

Commit

Permalink
chore: extract RECONNECT_SESSION_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Apr 27, 2023
1 parent 1012820 commit 83d729d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/graz/src/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GasPrice } from "@cosmjs/stargate";
import type { Key } from "@keplr-wallet/types";

import type { GrazChain } from "../chains";
import { RECONNECT_SESSION_KEY } from "../constant";
import { defaultValues, useGrazStore } from "../store";
import type { Maybe } from "../types/core";
import type { WalletType } from "../types/wallet";
Expand Down Expand Up @@ -69,7 +70,7 @@ export const connect = async (args?: ConnectArgs): Promise<Key> => {
_reconnect: Boolean(args?.autoReconnect),
_reconnectConnector: currentWalletType,
});
typeof window !== "undefined" && window.sessionStorage.setItem("graz-reconnect-session", "Active");
typeof window !== "undefined" && window.sessionStorage.setItem(RECONNECT_SESSION_KEY, "Active");

return account;
} catch (error) {
Expand All @@ -81,7 +82,7 @@ export const connect = async (args?: ConnectArgs): Promise<Key> => {
};

export const disconnect = async (clearRecentChain = false): Promise<void> => {
typeof window !== "undefined" && window.sessionStorage.removeItem("graz-reconnect-session");
typeof window !== "undefined" && window.sessionStorage.removeItem(RECONNECT_SESSION_KEY);

useGrazStore.setState((x) => ({
...defaultValues,
Expand Down
1 change: 1 addition & 0 deletions packages/graz/src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const RECONNECT_SESSION_KEY = "graz-reconnect-session";
3 changes: 2 additions & 1 deletion packages/graz/src/provider/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FC } from "react";
import { useEffect } from "react";

import { reconnect } from "../actions/account";
import { RECONNECT_SESSION_KEY } from "../constant";
import { useGrazStore } from "../store";

/**
Expand All @@ -11,7 +12,7 @@ import { useGrazStore } from "../store";
*/
export const useGrazEvents = () => {
const isSessionActive =
typeof window !== "undefined" && window.sessionStorage.getItem("graz-reconnect-session") === "Active";
typeof window !== "undefined" && window.sessionStorage.getItem(RECONNECT_SESSION_KEY) === "Active";
const { activeChain, _reconnect, _onReconnectFailed } = useGrazStore.getState();

useEffect(() => {
Expand Down

0 comments on commit 83d729d

Please sign in to comment.