diff --git a/govtool/frontend/src/pages/CreateGovernanceAction.tsx b/govtool/frontend/src/pages/CreateGovernanceAction.tsx index 3c507874b..323ab7696 100644 --- a/govtool/frontend/src/pages/CreateGovernanceAction.tsx +++ b/govtool/frontend/src/pages/CreateGovernanceAction.tsx @@ -37,7 +37,7 @@ export const CreateGovernanceAction = () => { }); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { navigate(PATHS.home); } }, []); diff --git a/govtool/frontend/src/pages/DRepDirectory.tsx b/govtool/frontend/src/pages/DRepDirectory.tsx index 4d0cd048c..b3f1bc906 100644 --- a/govtool/frontend/src/pages/DRepDirectory.tsx +++ b/govtool/frontend/src/pages/DRepDirectory.tsx @@ -10,9 +10,7 @@ import { checkIsWalletConnected } from "@utils"; export const DRepDirectory = () => { const { t } = useTranslation(); - const isConnected = !checkIsWalletConnected(); - - if (isConnected) { + if (checkIsWalletConnected()) { return ( { }, [pathname, divRef]); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { if (window.location.pathname === PATHS.dashboard) { navigate(PATHS.home); } else { diff --git a/govtool/frontend/src/pages/EditDRepMetadata.tsx b/govtool/frontend/src/pages/EditDRepMetadata.tsx index 15639360c..a269f436e 100644 --- a/govtool/frontend/src/pages/EditDRepMetadata.tsx +++ b/govtool/frontend/src/pages/EditDRepMetadata.tsx @@ -56,7 +56,7 @@ export const EditDRepMetadata = () => { }); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { navigate(PATHS.home); return; } diff --git a/govtool/frontend/src/pages/PublicRoute.tsx b/govtool/frontend/src/pages/PublicRoute.tsx index 8e261f719..3ad54b80e 100644 --- a/govtool/frontend/src/pages/PublicRoute.tsx +++ b/govtool/frontend/src/pages/PublicRoute.tsx @@ -4,12 +4,10 @@ import { useLocation, useNavigate } from "react-router-dom"; import { checkIsWalletConnected } from "../utils"; export const PublicRoute: FC<{ children: ReactNode }> = ({ children }) => { - // checkIsWalletConnected returns true if wallet is NOT connected - const isConnected = !checkIsWalletConnected(); const navigate = useNavigate(); const { pathname } = useLocation(); - if (isConnected && !pathname.startsWith("/connected")) { + if (checkIsWalletConnected() && !pathname.startsWith("/connected")) { navigate(`/connected${pathname}`); } diff --git a/govtool/frontend/src/pages/RegisterAsDirectVoter.tsx b/govtool/frontend/src/pages/RegisterAsDirectVoter.tsx index b00eb8e7b..662ab1b83 100644 --- a/govtool/frontend/src/pages/RegisterAsDirectVoter.tsx +++ b/govtool/frontend/src/pages/RegisterAsDirectVoter.tsx @@ -94,7 +94,7 @@ export const RegisterAsDirectVoter = () => { ); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { navigate(PATHS.home); } }, []); diff --git a/govtool/frontend/src/pages/RegisterAsdRep.tsx b/govtool/frontend/src/pages/RegisterAsdRep.tsx index f5f76d56c..81a0696ac 100644 --- a/govtool/frontend/src/pages/RegisterAsdRep.tsx +++ b/govtool/frontend/src/pages/RegisterAsdRep.tsx @@ -55,7 +55,7 @@ export const RegisterAsdRep = () => { }); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { navigate(PATHS.home); } }, []); diff --git a/govtool/frontend/src/pages/RetireAsDirectVoter.tsx b/govtool/frontend/src/pages/RetireAsDirectVoter.tsx index a75df8054..9939a2e8b 100644 --- a/govtool/frontend/src/pages/RetireAsDirectVoter.tsx +++ b/govtool/frontend/src/pages/RetireAsDirectVoter.tsx @@ -81,7 +81,7 @@ export const RetireAsDirectVoter = () => { ); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { navigate(PATHS.home); } }, []); diff --git a/govtool/frontend/src/pages/RetireAsDrep.tsx b/govtool/frontend/src/pages/RetireAsDrep.tsx index 925b86dcb..337c3f6f6 100644 --- a/govtool/frontend/src/pages/RetireAsDrep.tsx +++ b/govtool/frontend/src/pages/RetireAsDrep.tsx @@ -15,7 +15,7 @@ export const RetireAsDrep = () => { const { isMobile } = useScreenDimension(); useEffect(() => { - if (checkIsWalletConnected()) { + if (!checkIsWalletConnected()) { navigate(PATHS.home); } }, []); diff --git a/govtool/frontend/src/utils/checkIsWalletConnected.ts b/govtool/frontend/src/utils/checkIsWalletConnected.ts index 4c91a1137..1ba31a77a 100644 --- a/govtool/frontend/src/utils/checkIsWalletConnected.ts +++ b/govtool/frontend/src/utils/checkIsWalletConnected.ts @@ -1,5 +1,5 @@ import { WALLET_LS_KEY, getItemFromLocalStorage } from "@/utils/localStorage"; export const checkIsWalletConnected = () => - !getItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`) || - !getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); + getItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`) && + getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); diff --git a/govtool/frontend/src/utils/tests/checkIsWalletConnected.test.ts b/govtool/frontend/src/utils/tests/checkIsWalletConnected.test.ts index 54bb44a4f..afb4393ac 100644 --- a/govtool/frontend/src/utils/tests/checkIsWalletConnected.test.ts +++ b/govtool/frontend/src/utils/tests/checkIsWalletConnected.test.ts @@ -6,20 +6,20 @@ import { } from "@/utils/localStorage"; describe("checkIsWalletConnected function", () => { - it("returns false when wallet information is present in local storage", () => { + it("returns true when wallet information is present in local storage", () => { setItemToLocalStorage(`${WALLET_LS_KEY}_name`, "Nami"); setItemToLocalStorage(`${WALLET_LS_KEY}_stake_key`, "teststakekey"); const isConnected = checkIsWalletConnected(); - expect(isConnected).toBe(false); + expect(isConnected).toBe(true); }); - it("returns true when wallet information is missing in local storage", () => { + it("returns false when wallet information is missing in local storage", () => { removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`); removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`); const isConnected = checkIsWalletConnected(); - expect(isConnected).toBe(true); + expect(isConnected).toBe(false); }); });