diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index c4903b4d8..ce4f54add 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -63,28 +63,47 @@ export default () => { }, []); const checkTheWalletIsActive = useCallback(() => { - const hrefCondition = - window.location.pathname === PATHS.home || - window.location.pathname === PATHS.governanceActions || - window.location.pathname === PATHS.governanceActionsAction; + const isWalletAvailable = () => + window.cardano && walletName && Object.keys(window.cardano).includes(walletName); - const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); - if (window.cardano) { - const walletExtensions = Object.keys(window.cardano); - if (walletName && walletExtensions.includes(walletName)) { - enable(walletName); - return; + 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); + }); } - } - if ( - (!window.cardano && walletName) || - (walletName && !Object.keys(window.cardano).includes(walletName)) - ) { - if (!hrefCondition) { + + if (!isOnAllowedPage) { navigate(PATHS.home); } - removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`); - removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`); + 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(); } }, []); diff --git a/govtool/frontend/src/components/atoms/types.ts b/govtool/frontend/src/components/atoms/types.ts index 52bf82151..3ae4ea5ae 100644 --- a/govtool/frontend/src/components/atoms/types.ts +++ b/govtool/frontend/src/components/atoms/types.ts @@ -1,4 +1,5 @@ import { ChangeEvent } from "react"; +import { LinkProps } from "react-router-dom"; import { ButtonProps as MUIButtonProps, CheckboxProps as MUICheckboxProps, @@ -13,6 +14,10 @@ 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 47c98f6be..d4570c165 100644 --- a/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx +++ b/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx @@ -1,5 +1,6 @@ import { FC } from "react"; import { Box, Skeleton } from "@mui/material"; +import { Link, useLocation } from "react-router-dom"; import { Button } from "@atoms"; import { @@ -19,13 +20,7 @@ import { ProposalData } from "@models"; type ActionTypeProps = Omit< ProposalData, - | "yesVotes" - | "noVotes" - | "abstainVotes" | "id" - | "details" - | "rationale" - | "motivation" > & { onClick?: () => void; inProgress?: boolean; @@ -47,6 +42,7 @@ export const GovernanceActionCard: FC = ({ title, isValidating, metadataStatus, + ...otherProposalData }) => { const { isMobile, screenWidth } = useScreenDimension(); const { t } = useTranslation(); @@ -58,6 +54,9 @@ 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 4dfe5ae0a..aa37b32df 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 fb366fc67..a4316ed2b 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 { generatePath, useNavigate, useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; import { Box, CircularProgress, Link } from "@mui/material"; import { Background, Typography } from "@atoms"; @@ -18,7 +18,6 @@ import { useTranslation, } from "@hooks"; import { - getFullGovActionId, getProposalTypeLabel, removeDuplicatedProposals, } from "@utils"; @@ -141,18 +140,6 @@ 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 7eda23034..ace4a0125 100644 --- a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx +++ b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx @@ -20,7 +20,6 @@ import { } from "@hooks"; import { WALLET_LS_KEY, - getFullGovActionId, getItemFromLocalStorage, getProposalTypeLabel, removeDuplicatedProposals, @@ -142,19 +141,6 @@ 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 578d8c391..16ca0e518 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("button")).toBeEnabled(); + await expect(canvas.getByRole("link")).toBeEnabled(); }, };