From 0a50bb5e33bb8f6ed7457d485a20cc25fc79314d Mon Sep 17 00:00:00 2001 From: Adam Tomaszczyk Date: Tue, 22 Jul 2025 14:58:17 +0200 Subject: [PATCH 1/2] Allow Opening Governance Actions in New Tab from Live Voting Page --- govtool/frontend/src/App.tsx | 52 ++++++++++++------- .../molecules/GovernanceActionCard.tsx | 7 ++- .../organisms/GovernanceActionsToVote.tsx | 28 +--------- .../src/components/organisms/Slider.tsx | 28 ++++------ .../ValidatedGovernanceActionCard.tsx | 3 +- 5 files changed, 52 insertions(+), 66 deletions(-) diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index c4903b4d8..f5f2fd499 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -63,28 +63,44 @@ 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; + } + 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/molecules/GovernanceActionCard.tsx b/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx index 47c98f6be..263ed05b3 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 { @@ -39,7 +40,6 @@ export const GovernanceActionCard: FC = ({ inProgress = false, expiryDate, expiryEpochNo, - onClick, createdDate, createdEpochNo, txHash, @@ -58,6 +58,8 @@ export const GovernanceActionCard: FC = ({ bech32Prefix: "gov_action", }); + const location = useLocation(); + return ( = ({ ) : ( diff --git a/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx b/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx index 4dfe5ae0a..826dfb3d4 100644 --- a/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx +++ b/govtool/frontend/src/components/organisms/ValidatedGovernanceActionCard.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from "react"; import { useValidateMutation } from "@/hooks/mutations"; import { MetadataStandard, ProposalData } from "@/models"; -import { GovernanceActionCard } from "../molecules"; +import { GovernanceActionCard } from "@molecules"; type ActionTypeProps = Omit< ProposalData, @@ -14,7 +14,6 @@ type ActionTypeProps = Omit< | "rationale" | "motivation" > & { - onClick?: () => void; inProgress?: boolean; }; export const ValidatedGovernanceActionCard = (props: ActionTypeProps) => { From d86def3ddef27c1e6ddba9bd9a90d0a0fcf028a6 Mon Sep 17 00:00:00 2001 From: Adam Tomaszczyk Date: Wed, 23 Jul 2025 12:21:30 +0200 Subject: [PATCH 2/2] Fix Back button on GA category view and tests --- govtool/frontend/src/App.tsx | 5 ++++- .../frontend/src/components/atoms/types.ts | 5 +++++ .../molecules/GovernanceActionCard.tsx | 21 +++++++++++++++++-- .../ValidatedGovernanceActionCard.tsx | 3 ++- .../DashboardGovernanceActionsCategory.tsx | 15 +------------ .../src/pages/GovernanceActionsCategory.tsx | 14 ------------- .../frontend/src/stories/Slider.stories.tsx | 2 +- 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index f5f2fd499..ce4f54add 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -81,7 +81,10 @@ export default () => { enable(walletName); return; } - await new Promise(resolve => setTimeout(resolve, interval)); + // eslint-disable-next-line no-await-in-loop + await new Promise((resolve) => { + setTimeout(resolve, interval); + }); } if (!isOnAllowedPage) { 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 263ed05b3..4d091020f 100644 --- a/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx +++ b/govtool/frontend/src/components/molecules/GovernanceActionCard.tsx @@ -40,6 +40,7 @@ export const GovernanceActionCard: FC = ({ inProgress = false, expiryDate, expiryEpochNo, + onClick, createdDate, createdEpochNo, txHash, @@ -58,7 +59,8 @@ export const GovernanceActionCard: FC = ({ bech32Prefix: "gov_action", }); - const location = useLocation(); + const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions"); + const isCategoryView = useLocation().pathname.includes("category"); return ( = ({ ) : (