diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index ce4f54add..c4903b4d8 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -63,47 +63,28 @@ export default () => { }, []); const checkTheWalletIsActive = useCallback(() => { - const isWalletAvailable = () => - window.cardano && walletName && Object.keys(window.cardano).includes(walletName); + const hrefCondition = + window.location.pathname === PATHS.home || + window.location.pathname === PATHS.governanceActions || + window.location.pathname === PATHS.governanceActionsAction; - const cleanUpWalletData = () => { - removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`); - removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`); - }; - - const waitForWalletExtension = async () => { - const timeout = 5000; - const interval = 100; - const startTime = Date.now(); - - while (Date.now() - startTime < timeout) { - if (isWalletAvailable()) { - enable(walletName); - return; - } - // eslint-disable-next-line no-await-in-loop - await new Promise((resolve) => { - setTimeout(resolve, interval); - }); + const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); + if (window.cardano) { + const walletExtensions = Object.keys(window.cardano); + if (walletName && walletExtensions.includes(walletName)) { + enable(walletName); + return; } - - if (!isOnAllowedPage) { + } + if ( + (!window.cardano && walletName) || + (walletName && !Object.keys(window.cardano).includes(walletName)) + ) { + if (!hrefCondition) { navigate(PATHS.home); } - cleanUpWalletData(); - }; - - const isOnAllowedPage = [PATHS.home, PATHS.governanceActions, PATHS.governanceActionsAction] - .includes(window.location.pathname); - - const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); - - if (!walletName) return; - - if (isWalletAvailable()) { - enable(walletName); - } else { - waitForWalletExtension(); + removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`); + removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`); } }, []); diff --git a/govtool/frontend/src/components/atoms/types.ts b/govtool/frontend/src/components/atoms/types.ts index 3ae4ea5ae..52bf82151 100644 --- a/govtool/frontend/src/components/atoms/types.ts +++ b/govtool/frontend/src/components/atoms/types.ts @@ -1,5 +1,4 @@ import { ChangeEvent } from "react"; -import { LinkProps } from "react-router-dom"; import { ButtonProps as MUIButtonProps, CheckboxProps as MUICheckboxProps, @@ -14,10 +13,6 @@ export type ButtonProps = Omit & { isLoading?: boolean; size?: "small" | "medium" | "large" | "extraLarge"; dataTestId?: string; - to?: LinkProps["to"]; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - state?: any; - component?: React.ElementType; }; export type LoadingButtonProps = ButtonProps & { diff --git a/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx b/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx index 4d091020f..47c98f6be 100644 --- a/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx +++ b/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx @@ -1,6 +1,5 @@ import { FC } from "react"; import { Box, Skeleton } from "@mui/material"; -import { Link, useLocation } from "react-router-dom"; import { Button } from "@atoms"; import { @@ -59,9 +58,6 @@ export const GovernanceActionCard: FC = ({ bech32Prefix: "gov_action", }); - const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions"); - const isCategoryView = useLocation().pathname.includes("category"); - return ( = ({ ) : ( diff --git a/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx b/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx index aa37b32df..4dfe5ae0a 100644 --- a/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx +++ b/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx @@ -1,8 +1,8 @@ import { useState, useEffect } from "react"; -import { GovernanceActionCard } from "@molecules"; import { useValidateMutation } from "@/hooks/mutations"; import { MetadataStandard, ProposalData } from "@/models"; +import { GovernanceActionCard } from "../molecules"; type ActionTypeProps = Omit< ProposalData, diff --git a/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx b/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx index a4316ed2b..fb366fc67 100644 --- a/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx +++ b/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx @@ -1,5 +1,5 @@ import { useMemo, useRef } from "react"; -import { useNavigate, useParams } from "react-router-dom"; +import { generatePath, useNavigate, useParams } from "react-router-dom"; import { Box, CircularProgress, Link } from "@mui/material"; import { Background, Typography } from "@atoms"; @@ -18,6 +18,7 @@ import { useTranslation, } from "@hooks"; import { + getFullGovActionId, getProposalTypeLabel, removeDuplicatedProposals, } from "@utils"; @@ -140,6 +141,18 @@ export const DashboardGovernanceActionsCategory = () => { } onClick={() => { saveScrollPosition(); + + navigate( + generatePath(PATHS.dashboardGovernanceActionsAction, { + proposalId: getFullGovActionId(item.txHash, item.index), + }), + { + state: { + proposal: item, + openedFromCategoryPage: true, + }, + }, + ); }} txHash={item.txHash} /> diff --git a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx index ace4a0125..7eda23034 100644 --- a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx +++ b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx @@ -20,6 +20,7 @@ import { } from "@hooks"; import { WALLET_LS_KEY, + getFullGovActionId, getItemFromLocalStorage, getProposalTypeLabel, removeDuplicatedProposals, @@ -141,6 +142,19 @@ export const GovernanceActionsCategory = () => { {...item} onClick={() => { saveScrollPosition(); + + navigate( + PATHS.governanceActionsAction.replace( + ":proposalId", + getFullGovActionId(item.txHash, item.index), + ), + { + state: { + proposal: item, + openedFromCategoryPage: true, + }, + }, + ); }} /> diff --git a/govtool/frontend/src/stories/Slider.stories.tsx b/govtool/frontend/src/stories/Slider.stories.tsx index 16ca0e518..578d8c391 100644 --- a/govtool/frontend/src/stories/Slider.stories.tsx +++ b/govtool/frontend/src/stories/Slider.stories.tsx @@ -58,6 +58,6 @@ export const SliderComponentOverflow: Story = { await expect(canvas.getByText("Slider title")).toBeInTheDocument(); await expect(canvas.getAllByTestId("slider")).toHaveLength(6); - await expect(canvas.getByRole("link")).toBeEnabled(); + await expect(canvas.getByRole("button")).toBeEnabled(); }, };