From 7fcd7ba4ea0aeade825eba9aa37dc66bcf8f9036 Mon Sep 17 00:00:00 2001 From: Joanna Dyczka Date: Tue, 3 Sep 2024 15:42:24 +0200 Subject: [PATCH] [#1910] fix runtime error when navigating to GA details from Voted on by me tab --- CHANGELOG.md | 1 + .../GovernanceActionDetailsCardVotes.tsx | 19 ++---- .../components/molecules/VoteActionForm.tsx | 66 +++++++------------ .../DashboardGovernanceActionDetails.tsx | 8 +-- .../organisms/GovernanceActionDetailsCard.tsx | 17 ++--- .../src/hooks/forms/useVoteActionForm.tsx | 46 ++++++++----- 6 files changed, 66 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f553d613e..a63725b6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ changes. - Fix displaying wrongly formatted Governance Action ID [Issue 1866](https://github.com/IntersectMBO/govtool/issues/1866) - Fix displaying the proper Governance Action Details on renavigating between pages - Fix displaying protocol params Governance Action details when metadata validation fails [Issue 1889](https://github.com/IntersectMBO/govtool/issues/1889) +- Fix runtime error when navigating to GA details from Voted on by me tab [Issue 1910](https://github.com/IntersectMBO/govtool/issues/1910) ### Changed diff --git a/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx b/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx index f5c23ea31..f56c6d8d9 100644 --- a/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx +++ b/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx @@ -4,18 +4,15 @@ import { Box } from "@mui/material"; import { useScreenDimension } from "@hooks"; import { VoteActionForm, VotesSubmitted } from "@molecules"; import { useFeatureFlag } from "@/context"; -import { ProposalData } from "@/models"; +import { ProposalData, ProposalVote } from "@/models"; type GovernanceActionCardVotesProps = { setIsVoteSubmitted: Dispatch>; isOneColumn: boolean; - isVoter?: boolean; - voteFromEP?: string; - voteUrlFromEP?: string; - voteDateFromEP?: string; - voteEpochNoFromEP?: number; isDashboard?: boolean; isInProgress?: boolean; + isVoter?: boolean; + vote?: ProposalVote; proposal: ProposalData; }; @@ -23,10 +20,7 @@ export const GovernanceActionDetailsCardVotes = ({ setIsVoteSubmitted, isOneColumn, isVoter, - voteFromEP, - voteUrlFromEP, - voteDateFromEP, - voteEpochNoFromEP, + vote, isDashboard, isInProgress, proposal: { @@ -63,10 +57,7 @@ export const GovernanceActionDetailsCardVotes = ({ setIsVoteSubmitted={setIsVoteSubmitted} expiryDate={expiryDate} expiryEpochNo={expiryEpochNo} - voteFromEP={voteFromEP ? voteFromEP.toLowerCase() : undefined} - voteUrlFromEP={voteUrlFromEP} - voteDateFromEP={voteDateFromEP} - voteEpochNoFromEP={voteEpochNoFromEP} + previousVote={vote} dRepAbstainVotes={dRepAbstainVotes} dRepNoVotes={dRepNoVotes} dRepYesVotes={dRepYesVotes} diff --git a/govtool/frontend/src/components/molecules/VoteActionForm.tsx b/govtool/frontend/src/components/molecules/VoteActionForm.tsx index c0a854d5f..964edcf5c 100644 --- a/govtool/frontend/src/components/molecules/VoteActionForm.tsx +++ b/govtool/frontend/src/components/molecules/VoteActionForm.tsx @@ -1,5 +1,4 @@ import { useState, useEffect, useMemo, Dispatch, SetStateAction } from "react"; -import { useLocation } from "react-router-dom"; import { Box } from "@mui/material"; import { Trans } from "react-i18next"; @@ -14,16 +13,14 @@ import { useGetVoteContextTextFromFile, } from "@hooks"; import { formatDisplayDate } from "@utils"; +import { ProposalVote } from "@/models"; type VoteActionFormProps = { setIsVoteSubmitted: Dispatch>; expiryDate: string | undefined; expiryEpochNo: number | undefined; - voteFromEP?: string; - voteUrlFromEP?: string; - voteDateFromEP?: string; - voteEpochNoFromEP?: number; isInProgress?: boolean; + previousVote?: ProposalVote; dRepYesVotes: number; dRepNoVotes: number; dRepAbstainVotes: number; @@ -33,10 +30,7 @@ export const VoteActionForm = ({ setIsVoteSubmitted, expiryDate, expiryEpochNo, - voteFromEP, - voteUrlFromEP, - voteDateFromEP, - voteEpochNoFromEP, + previousVote, dRepAbstainVotes, dRepNoVotes, dRepYesVotes, @@ -50,14 +44,10 @@ export const VoteActionForm = ({ const { voter } = useGetVoterInfo(); const { voteContextText } = useGetVoteContextTextFromFile(voteContextUrl); - const { state } = useLocation(); const { isMobile, screenWidth } = useScreenDimension(); const { openModal } = useModal(); const { t } = useTranslation(); - const voteDate = state ? state.voteDate : voteDateFromEP; - const voteEpochNo = state ? state.voteEpochNo : voteEpochNoFromEP; - const { areFormErrors, confirmVote, @@ -66,7 +56,8 @@ export const VoteActionForm = ({ registerInput, setValue, vote, - } = useVoteActionForm(voteContextHash, voteContextUrl); + canVote, + } = useVoteActionForm({ previousVote, voteContextHash, voteContextUrl }); const setVoteContextData = (url: string, hash: string) => { setVoteContextUrl(url); @@ -74,28 +65,23 @@ export const VoteActionForm = ({ }; useEffect(() => { - if (state && state.vote) { - setValue("vote", state.vote); - setIsVoteSubmitted(true); - } else if (voteFromEP) { - setValue("vote", voteFromEP); + if (previousVote?.vote) { + setValue("vote", previousVote.vote); setIsVoteSubmitted(true); } - }, [state, voteFromEP, setValue]); + }, [previousVote?.vote, setValue, setIsVoteSubmitted]); useEffect(() => { - if (state && state.voteUrl) { - setVoteContextUrl(state.voteUrl); - } else if (voteUrlFromEP) { - setVoteContextUrl(voteUrlFromEP); + if (previousVote?.url) { + setVoteContextUrl(previousVote.url); } - }, [voteUrlFromEP, state]); + }, [previousVote?.url, setVoteContextUrl]); const renderCancelButton = useMemo( () => ( ), - [state], + [previousVote?.vote, setValue], ); const renderChangeVoteButton = useMemo( @@ -113,11 +99,7 @@ export const VoteActionForm = ({