diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e68c9352..4cd1e8549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ changes. ### Fixed -- +- Fix typescript bug leading to runtime error when entering Governance Action details page via direct link [Issue 1801](https://github.com/IntersectMBO/govtool/issues/1801) ### Changed diff --git a/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx b/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx index aa91434a4..f5c23ea31 100644 --- a/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx +++ b/govtool/frontend/src/components/molecules/GovernanceActionDetailsCardVotes.tsx @@ -4,22 +4,11 @@ import { Box } from "@mui/material"; import { useScreenDimension } from "@hooks"; import { VoteActionForm, VotesSubmitted } from "@molecules"; import { useFeatureFlag } from "@/context"; -import { GovernanceActionType } from "@/types/governanceAction"; +import { ProposalData } from "@/models"; type GovernanceActionCardVotesProps = { setIsVoteSubmitted: Dispatch>; - dRepYesVotes: number; - dRepNoVotes: number; - dRepAbstainVotes: number; - poolYesVotes: number; - poolNoVotes: number; - poolAbstainVotes: number; - ccYesVotes: number; - ccNoVotes: number; - ccAbstainVotes: number; isOneColumn: boolean; - expiryDate: string; - expiryEpochNo: number; isVoter?: boolean; voteFromEP?: string; voteUrlFromEP?: string; @@ -27,23 +16,12 @@ type GovernanceActionCardVotesProps = { voteEpochNoFromEP?: number; isDashboard?: boolean; isInProgress?: boolean; - type: GovernanceActionType; + proposal: ProposalData; }; export const GovernanceActionDetailsCardVotes = ({ setIsVoteSubmitted, - dRepAbstainVotes, - dRepNoVotes, - dRepYesVotes, - poolAbstainVotes, - poolNoVotes, - poolYesVotes, - ccAbstainVotes, - ccNoVotes, - ccYesVotes, isOneColumn, - expiryDate, - expiryEpochNo, isVoter, voteFromEP, voteUrlFromEP, @@ -51,7 +29,20 @@ export const GovernanceActionDetailsCardVotes = ({ voteEpochNoFromEP, isDashboard, isInProgress, - type, + proposal: { + dRepAbstainVotes, + dRepNoVotes, + dRepYesVotes, + poolAbstainVotes, + poolNoVotes, + poolYesVotes, + ccAbstainVotes, + ccNoVotes, + ccYesVotes, + expiryDate, + expiryEpochNo, + type, + }, }: GovernanceActionCardVotesProps) => { const { isVotingOnGovernanceActionEnabled } = useFeatureFlag(); const { screenWidth } = useScreenDimension(); diff --git a/govtool/frontend/src/components/molecules/GovernanceVotedOnCard.tsx b/govtool/frontend/src/components/molecules/GovernanceVotedOnCard.tsx index 6888484ad..e47980920 100644 --- a/govtool/frontend/src/components/molecules/GovernanceVotedOnCard.tsx +++ b/govtool/frontend/src/components/molecules/GovernanceVotedOnCard.tsx @@ -132,11 +132,8 @@ export const GovernanceVotedOnCard = ({ votedProposal, inProgress }: Props) => { ), { state: { - ...proposal, - vote: vote.vote.toLowerCase(), - voteUrl: vote.url, - voteDate: vote.date, - voteEpochNo: vote.epochNo, + proposal, + vote, }, }, ) diff --git a/govtool/frontend/src/components/molecules/VoteActionForm.tsx b/govtool/frontend/src/components/molecules/VoteActionForm.tsx index 6f20c1768..c0a854d5f 100644 --- a/govtool/frontend/src/components/molecules/VoteActionForm.tsx +++ b/govtool/frontend/src/components/molecules/VoteActionForm.tsx @@ -17,8 +17,8 @@ import { formatDisplayDate } from "@utils"; type VoteActionFormProps = { setIsVoteSubmitted: Dispatch>; - expiryDate: string; - expiryEpochNo: number; + expiryDate: string | undefined; + expiryEpochNo: number | undefined; voteFromEP?: string; voteUrlFromEP?: string; voteDateFromEP?: string; diff --git a/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx b/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx index 2b31240fd..8fcb99638 100644 --- a/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx +++ b/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx @@ -14,34 +14,39 @@ import { useScreenDimension, useTranslation, } from "@hooks"; -import { getShortenedGovActionId, getProposalTypeLabel } from "@utils"; +import { getFullGovActionId, getShortenedGovActionId } from "@utils"; import { GovernanceActionDetailsCard } from "@organisms"; import { Breadcrumbs } from "@molecules"; +import { ProposalData, ProposalVote } from "@/models"; + +type DashboardGovernanceActionDetailsState = { + proposal?: ProposalData; + vote?: ProposalVote; + openedFromCategoryPage?: boolean; +}; // TODO: Refactor: GovernanceActionDetals and DashboardGovernanceActionDetails are almost identical // and should be unified export const DashboardGovernanceActionDetails = () => { const { voter } = useGetVoterInfo(); const { pendingTransaction, isEnableLoading } = useCardano(); - const { state, hash } = useLocation(); + const { state: untypedState, hash } = useLocation(); + const state = untypedState as DashboardGovernanceActionDetailsState | null; + const index = hash.slice(1); const navigate = useNavigate(); const { isMobile } = useScreenDimension(); const { t } = useTranslation(); - const { proposalId } = useParams(); - const fullProposalId = proposalId + hash; + const { proposalId: txHash } = useParams(); - const { data, isLoading } = useGetProposalQuery(fullProposalId ?? "", !state); - const shortenedGovActionId = getShortenedGovActionId( - state ? state.txHash : data?.proposal.txHash ?? "", - state ? state.index : data?.proposal.index ?? "", - ); + const fullProposalId = txHash && getFullGovActionId(txHash, +index); + const shortenedGovActionId = + txHash && getShortenedGovActionId(txHash, +index); - // TODO: Refactor me - const title = state ? state?.title : data?.proposal?.title; - const label = state - ? getProposalTypeLabel(state.type) - : getProposalTypeLabel(data.proposal.type); - const type = state ? state.type : data.proposal.type; + const { data, isLoading } = useGetProposalQuery( + fullProposalId ?? "", + !state?.proposal || !state?.vote, + ); + const proposal = (data ?? state)?.proposal; return ( { { navigate( state && state.openedFromCategoryPage ? generatePath(PATHS.dashboardGovernanceActionsCategory, { - category: state.type, + category: state?.proposal?.type, }) : PATHS.dashboardGovernanceActions, { @@ -103,67 +106,22 @@ export const DashboardGovernanceActionDetails = () => { > - ) : data || state ? ( + ) : proposal ? ( ) : ( diff --git a/govtool/frontend/src/components/organisms/GovernanceActionDetailsCard.tsx b/govtool/frontend/src/components/organisms/GovernanceActionDetailsCard.tsx index 5f7ba34ca..ab25daf6c 100644 --- a/govtool/frontend/src/components/organisms/GovernanceActionDetailsCard.tsx +++ b/govtool/frontend/src/components/organisms/GovernanceActionDetailsCard.tsx @@ -7,79 +7,30 @@ import { GovernanceActionDetailsCardVotes, } from "@molecules"; import { GovernanceActionDetailsCardData } from "@organisms"; -import { EpochParams, MetadataValidationStatus } from "@models"; -import { GovernanceActionType } from "@/types/governanceAction"; +import { MetadataValidationStatus, ProposalData } from "@models"; type GovernanceActionDetailsCardProps = { - abstract?: string; - ccAbstainVotes: number; - ccNoVotes: number; - ccYesVotes: number; - createdDate: string; - createdEpochNo: number; - dRepAbstainVotes: number; - dRepNoVotes: number; - dRepYesVotes: number; - details?: ActionDetailsType; - expiryDate: string; - expiryEpochNo: number; - govActionId: string; - prevGovActionId: string | null; isDashboard?: boolean; isDataMissing: null | MetadataValidationStatus; isInProgress?: boolean; isVoter?: boolean; - label: string; - links?: string[]; - motivation?: string; - poolAbstainVotes: number; - poolNoVotes: number; - poolYesVotes: number; - protocolParams: EpochParams | null; - rationale?: string; - title?: string; - type: GovernanceActionType; - url: string; voteDateFromEP?: string; voteEpochNoFromEP?: number; voteFromEP?: string; voteUrlFromEP?: string; + proposal: ProposalData; }; export const GovernanceActionDetailsCard = ({ - abstract, - ccAbstainVotes, - ccNoVotes, - ccYesVotes, - createdDate, - createdEpochNo, - dRepAbstainVotes, - dRepNoVotes, - dRepYesVotes, - details, - expiryDate, - expiryEpochNo, - govActionId, - prevGovActionId, isDashboard, isDataMissing, isInProgress, isVoter, - label, - links, - motivation, - poolAbstainVotes, - poolNoVotes, - poolYesVotes, - protocolParams, - rationale, - title, - type, - url, voteDateFromEP, voteEpochNoFromEP, voteFromEP, voteUrlFromEP, + proposal, }: GovernanceActionDetailsCardProps) => { const [isVoteSubmitted, setIsVoteSubmitted] = useState(false); const { screenWidth, isMobile } = useScreenDimension(); @@ -112,41 +63,15 @@ export const GovernanceActionDetailsCard = ({ /> )} ); diff --git a/govtool/frontend/src/components/organisms/GovernanceActionDetailsCardData.tsx b/govtool/frontend/src/components/organisms/GovernanceActionDetailsCardData.tsx index 0f0bf4179..9aa181f14 100644 --- a/govtool/frontend/src/components/organisms/GovernanceActionDetailsCardData.tsx +++ b/govtool/frontend/src/components/organisms/GovernanceActionDetailsCardData.tsx @@ -16,8 +16,9 @@ import { getProposalTypeNoEmptySpaces, testIdFromLabel, replaceNullValues, + getProposalTypeLabel, } from "@utils"; -import { EpochParams, MetadataValidationStatus } from "@models"; +import { MetadataValidationStatus, ProposalData } from "@models"; import { GovernanceActionType } from "@/types/governanceAction"; import { useAppContext } from "@/context"; @@ -50,51 +51,39 @@ const StyledTab = styled((props: StyledTabProps) => ( })); type GovernanceActionDetailsCardDataProps = { - abstract?: string; - createdDate: string; - createdEpochNo: number; - details?: ActionDetailsType; - expiryDate: string; - expiryEpochNo: number; - govActionId: string; - prevGovActionId: string | null; isDashboard?: boolean; isDataMissing: MetadataValidationStatus | null; isInProgress?: boolean; isOneColumn: boolean; isSubmitted?: boolean; - links?: string[]; - motivation?: string; - rationale?: string; - title?: string; - label: string; - url: string; - type: GovernanceActionType; - protocolParams: EpochParams | null; + proposal: ProposalData; }; export const GovernanceActionDetailsCardData = ({ - abstract, - createdDate, - createdEpochNo, - details, - expiryDate, - expiryEpochNo, - govActionId, - prevGovActionId, isDashboard, isDataMissing, isInProgress, isOneColumn, isSubmitted, - links, - motivation, - rationale, - title, - label, - url, - type, - protocolParams, + proposal: { + abstract, + createdDate, + createdEpochNo, + details, + expiryDate, + expiryEpochNo, + index, + motivation, + prevGovActionIndex, + prevGovActionTxHash, + rationale, + references, + title, + txHash, + url, + type, + protocolParams, + }, }: GovernanceActionDetailsCardDataProps) => { const { epochParams } = useAppContext(); const { t } = useTranslation(); @@ -118,6 +107,13 @@ export const GovernanceActionDetailsCardData = ({ setSelectedTab(newValue); }; + const label = getProposalTypeLabel(type); + const govActionId = `${index}${txHash}`; + const prevGovActionId = + prevGovActionIndex && prevGovActionTxHash + ? `${prevGovActionIndex}${prevGovActionTxHash}` + : null; + const tabs = useMemo( () => [ @@ -247,8 +243,12 @@ export const GovernanceActionDetailsCardData = ({ ))} - {tabs.map((tab, index) => ( - + {tabs.map((tab, tabIndex) => ( + {tab.content} ))} @@ -265,7 +265,7 @@ export const GovernanceActionDetailsCardData = ({ dataTestId={testIdFromLabel(detailLabel)} /> ))} - + ); }; @@ -274,10 +274,7 @@ const ReasoningTabContent = ({ abstract, motivation, rationale, -}: Pick< - GovernanceActionDetailsCardDataProps, - "abstract" | "motivation" | "rationale" ->) => { +}: Pick) => { const { t } = useTranslation(); return ( @@ -310,10 +307,7 @@ const ReasoningTabContent = ({ const HardforkDetailsTabContent = ({ details, prevGovActionId, -}: Pick< - GovernanceActionDetailsCardDataProps, - "details" | "prevGovActionId" ->) => { +}: Pick & { prevGovActionId: string | null }) => { const { epochParams } = useAppContext(); const { t } = useTranslation(); diff --git a/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx b/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx index f28fc2be6..2d49e77eb 100644 --- a/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx +++ b/govtool/frontend/src/components/organisms/GovernanceActionsToVote.tsx @@ -75,7 +75,7 @@ export const GovernanceActionsToVote = ({ ), { state: { - ...action, + proposal: action, }, }, ); diff --git a/govtool/frontend/src/hooks/queries/useGetProposalQuery.ts b/govtool/frontend/src/hooks/queries/useGetProposalQuery.ts index e200e48e9..2606d5690 100644 --- a/govtool/frontend/src/hooks/queries/useGetProposalQuery.ts +++ b/govtool/frontend/src/hooks/queries/useGetProposalQuery.ts @@ -17,7 +17,7 @@ export const useGetProposalQuery = (proposalId: string, enabled?: boolean) => { ); return { - data: data!, + data, isLoading, refetch, isFetching: isRefetching, diff --git a/govtool/frontend/src/models/api.ts b/govtool/frontend/src/models/api.ts index 43aadc987..bb3172f5d 100644 --- a/govtool/frontend/src/models/api.ts +++ b/govtool/frontend/src/models/api.ts @@ -1,4 +1,5 @@ import { MetadataValidationStatus } from "@models"; +import { GovernanceActionType } from "@/types/governanceAction"; export type EpochParams = { block_id: number; @@ -121,7 +122,7 @@ export type DRepData = DrepDataDTO & { export type Vote = "yes" | "no" | "abstain"; -type ProposalVote = { +export type ProposalVote = { date: string; drepId: string; epochNo: number; @@ -142,7 +143,7 @@ export type ProposalDataDTO = { index: number; metadataHash: string; txHash: string; - type: string; + type: GovernanceActionType; url: string; dRepYesVotes: number; dRepNoVotes: number; diff --git a/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx b/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx index af847d676..9084bf070 100644 --- a/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx +++ b/govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx @@ -148,7 +148,7 @@ export const DashboardGovernanceActionsCategory = () => { }), { state: { - ...item, + proposal: item, openedFromCategoryPage: true, }, }, diff --git a/govtool/frontend/src/pages/GovernanceActionDetails.tsx b/govtool/frontend/src/pages/GovernanceActionDetails.tsx index 3661df87f..50beb50b4 100644 --- a/govtool/frontend/src/pages/GovernanceActionDetails.tsx +++ b/govtool/frontend/src/pages/GovernanceActionDetails.tsx @@ -17,37 +17,39 @@ import { } from "@hooks"; import { Footer, TopNav, GovernanceActionDetailsCard } from "@organisms"; import { - getProposalTypeLabel, WALLET_LS_KEY, + getFullGovActionId, getItemFromLocalStorage, getShortenedGovActionId, } from "@utils"; import { Breadcrumbs } from "@molecules"; +import { ProposalData } from "@/models"; + +type GovernanceActionDetailsState = { + proposal?: ProposalData; + openedFromCategoryPage?: boolean; +}; // TODO: Refactor: GovernanceActionDetals and DashboardGovernanceActionDetails are almost identical // and should be unified export const GovernanceActionDetails = () => { - const { state, hash } = useLocation(); + const { state: untypedState, hash } = useLocation(); + const state = untypedState as GovernanceActionDetailsState | null; + const index = hash.slice(1); const navigate = useNavigate(); const { pagePadding, isMobile } = useScreenDimension(); const { isEnabled } = useCardano(); const { t } = useTranslation(); - const { proposalId } = useParams(); - const fullProposalId = proposalId + hash; + const { proposalId: txHash } = useParams(); - const { data, isLoading } = useGetProposalQuery(fullProposalId ?? "", !state); + const fullProposalId = txHash && getFullGovActionId(txHash, index); + const shortenedGovActionId = txHash && getShortenedGovActionId(txHash, index); - const shortenedGovActionId = getShortenedGovActionId( - state ? state.txHash : data?.proposal.txHash ?? "", - state ? state.index : data?.proposal.index ?? "", + const { data, isLoading } = useGetProposalQuery( + fullProposalId ?? "", + !state?.proposal, ); - - // TODO: Refactor me - const title = state ? state?.title : data?.proposal?.title; - const label = state - ? getProposalTypeLabel(state.type) - : getProposalTypeLabel(data.proposal.type); - const type = state ? state.type : data.proposal.type; + const proposal = (data ?? state)?.proposal; useEffect(() => { if (isEnabled && getItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`)) { @@ -91,10 +93,8 @@ export const GovernanceActionDetails = () => { { navigate( state && state.openedFromCategoryPage ? generatePath(PATHS.governanceActionsCategory, { - category: state.type, + category: state?.proposal?.type, }) : PATHS.governanceActions, ) @@ -130,74 +130,11 @@ export const GovernanceActionDetails = () => { > - ) : data || state ? ( + ) : proposal ? ( ) : ( diff --git a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx index 2060ba16e..51d982f79 100644 --- a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx +++ b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx @@ -151,7 +151,7 @@ export const GovernanceActionsCategory = () => { ), { state: { - ...item, + proposal: item, openedFromCategoryPage: true, }, }, diff --git a/govtool/frontend/src/stories/GovernanceAction.stories.ts b/govtool/frontend/src/stories/GovernanceAction.stories.ts index 337a06510..706bc6626 100644 --- a/govtool/frontend/src/stories/GovernanceAction.stories.ts +++ b/govtool/frontend/src/stories/GovernanceAction.stories.ts @@ -4,6 +4,7 @@ import type { Meta, StoryObj } from "@storybook/react"; import { screen, userEvent, waitFor, within } from "@storybook/testing-library"; import { formatDisplayDate } from "@utils"; import { GovernanceActionCard } from "@/components/molecules"; +import { GovernanceActionType } from "@/types/governanceAction"; const meta = { title: "Example/GovernanceActionCard", @@ -29,7 +30,7 @@ const commonArgs = { onClick: jest.fn(), title: "Example title", txHash: "sad78afdsf7jasd98d", - type: "exampleType", + type: GovernanceActionType.InfoAction, metadataValid: true, metadataStatus: null, dRepYesVotes: 1, @@ -51,7 +52,7 @@ export const GovernanceActionCardComponent: Story = { play: async ({ canvasElement, args }) => { const canvas = within(canvasElement); - expect(canvas.getByTestId("exampleType-type")).toBeInTheDocument(); + expect(canvas.getByTestId(GovernanceActionType.InfoAction)).toBeInTheDocument(); expect(canvas.getByTestId("sad78afdsf7jasd98d#2-id")).toBeInTheDocument(); expect( canvas.getByText(formatDisplayDate("1970-01-01T00:00:00Z")), diff --git a/govtool/frontend/src/stories/GovernanceActionDetailsCard.stories.ts b/govtool/frontend/src/stories/GovernanceActionDetailsCard.stories.ts index e1e26b3f3..15bbbc6b7 100644 --- a/govtool/frontend/src/stories/GovernanceActionDetailsCard.stories.ts +++ b/govtool/frontend/src/stories/GovernanceActionDetailsCard.stories.ts @@ -1,4 +1,4 @@ -import { MetadataValidationStatus } from "@models"; +import { MetadataValidationStatus, ProposalData } from "@models"; import { GovernanceActionDetailsCard } from "@organisms"; import { expect, jest } from "@storybook/jest"; import type { Meta, StoryObj } from "@storybook/react"; @@ -20,31 +20,38 @@ export default meta; type Story = StoryObj; const commonArgs = { - abstainVotes: 1000000, - createdDate: new Date().toISOString(), - createdEpochNo: 1000000, - expiryEpochNo: 1000001, - expiryDate: new Date().toISOString(), - noVotes: 1000000, - label: "Info Action", - type: GovernanceActionType.InfoAction, - url: "https://exampleurl.com", - govActionId: "exampleId1232312312312", isDataMissing: null, - title: "Example title", - dRepYesVotes: 1000000, - dRepNoVotes: 302, - dRepAbstainVotes: 350, - poolYesVotes: 1, - poolNoVotes: 0, - poolAbstainVotes: 2, - ccYesVotes: 1, - ccNoVotes: 0, - ccAbstainVotes: 2, - protocolParams: null, - prevGovActionId: null, + proposal: { + id: '1', + index: 1, + txHash: "exampleTxHash", + createdDate: new Date().toISOString(), + createdEpochNo: 1000000, + expiryEpochNo: 1000001, + expiryDate: new Date().toISOString(), + type: GovernanceActionType.InfoAction, + url: "https://exampleurl.com", + title: "Example title", + dRepYesVotes: 1000000, + dRepNoVotes: 302, + dRepAbstainVotes: 350, + poolYesVotes: 1, + poolNoVotes: 0, + poolAbstainVotes: 2, + ccYesVotes: 1, + ccNoVotes: 0, + ccAbstainVotes: 2, + protocolParams: null, + prevGovActionIndex: null, + prevGovActionTxHash: null, + metadataHash: "exampleMetadataHash", + metadataStatus: null, + metadataValid: true, + } satisfies ProposalData, }; +const govActionId = commonArgs.proposal.index + commonArgs.proposal.txHash; + async function assertTooltip(tooltip: HTMLElement, expectedText: RegExp) { await userEvent.hover(tooltip); await waitFor(async () => { @@ -61,25 +68,28 @@ async function assertGovActionDetails( const todayDate = formatDisplayDate(new Date()); await expect(canvas.getAllByText(todayDate)).toHaveLength(2); await expect( - canvas.getByTestId(`${getProposalTypeNoEmptySpaces(args.type)}-type`), - ).toHaveTextContent(args.label); - await expect(canvas.getByTestId(`${args.govActionId}-id`)).toHaveTextContent( - args.govActionId, + canvas.getByTestId(`${getProposalTypeNoEmptySpaces(args.proposal.type)}-type`), + ).toHaveTextContent(args.proposal.type); + await expect(canvas.getByTestId(`${govActionId}-id`)).toHaveTextContent( + govActionId, ); } export const GovernanceActionDetailsCardComponent: Story = { args: { ...commonArgs, + proposal: { + ...commonArgs.proposal, abstract: "Example about section", rationale: "Example rationale section", motivation: "Example motivation section", + } }, play: async ({ canvasElement, args }) => { const canvas = within(canvasElement); - await expect(canvas.getByText(args.title!)).toBeInTheDocument(); + await expect(canvas.getByText(args.proposal.title!)).toBeInTheDocument(); await assertGovActionDetails(canvas, args); const [tooltip1, tooltip2] = canvas.getAllByTestId("InfoOutlinedIcon"); @@ -98,14 +108,17 @@ export const GovernanceActionDetailsDrep: Story = { ...commonArgs, isDashboard: true, isVoter: true, - abstract: "Example about section", - rationale: "Example rationale section", - motivation: "Example motivation section", + proposal: { + ...commonArgs.proposal, + abstract: "Example about section", + rationale: "Example rationale section", + motivation: "Example motivation section", + }, }, play: async ({ canvasElement, args }) => { const canvas = within(canvasElement); - await expect(canvas.getByText(args.title!)).toBeInTheDocument(); + await expect(canvas.getByText(args.proposal.title!)).toBeInTheDocument(); await assertGovActionDetails(canvas, args); const [tooltip1, tooltip2] = canvas.getAllByTestId("InfoOutlinedIcon"); diff --git a/govtool/frontend/src/stories/GovernanceActionVoted.stories.ts b/govtool/frontend/src/stories/GovernanceActionVoted.stories.ts index 49563fb99..55c97fc1b 100644 --- a/govtool/frontend/src/stories/GovernanceActionVoted.stories.ts +++ b/govtool/frontend/src/stories/GovernanceActionVoted.stories.ts @@ -4,6 +4,7 @@ import { GovernanceVotedOnCard } from "@molecules"; import { userEvent, waitFor, within, screen } from "@storybook/testing-library"; import { expect } from "@storybook/jest"; import { formatDisplayDate } from "@/utils"; +import { GovernanceActionType } from "@/types/governanceAction"; const meta = { title: "Example/GovernanceVotedOnCard", @@ -19,7 +20,7 @@ export default meta; type Story = StoryObj; async function checkGovActionVisibility(canvas: ReturnType) { - expect(canvas.getByTestId("exampleType-type")).toBeInTheDocument(); + expect(canvas.getByTestId(GovernanceActionType.InfoAction)).toBeInTheDocument(); expect(canvas.getByTestId("exampleHash#1-id")).toBeInTheDocument(); expect(canvas.getByText(/vote submitted/i)).toBeInTheDocument(); @@ -69,7 +70,7 @@ export const GovernanceVotedOnCardComponent: Story = { createdDate: "1970-01-01T00:00:00Z", expiryDate: "1970-02-01T00:00:00Z", id: "exampleId", - type: "exampleType", + type: GovernanceActionType.InfoAction, index: 1, txHash: "exampleHash", url: "https://example.com", @@ -116,7 +117,7 @@ export const GovernanceVotedOnCardAbstain: Story = { createdDate: "1970-01-01T00:00:00Z", expiryDate: "1970-02-01T00:00:00Z", id: "exampleId", - type: "exampleType", + type: GovernanceActionType.InfoAction, index: 1, txHash: "exampleHash", url: "https://example.com", @@ -164,7 +165,7 @@ export const GovernanceVotedOnCardYes: Story = { createdDate: "1970-01-01T00:00:00Z", expiryDate: "1970-02-01T00:00:00Z", id: "exampleId", - type: "exampleType", + type: GovernanceActionType.InfoAction, index: 1, txHash: "exampleHash", url: "https://example.com", @@ -212,7 +213,7 @@ export const GovernanceVotedOnCardNo: Story = { createdDate: "1970-01-01T00:00:00Z", expiryDate: "1970-02-01T00:00:00Z", id: "exampleId", - type: "exampleType", + type: GovernanceActionType.InfoAction, index: 1, txHash: "exampleHash", url: "https://example.com", diff --git a/govtool/frontend/src/utils/getGovActionId.ts b/govtool/frontend/src/utils/getGovActionId.ts index 135c0b704..8a1dcef5b 100644 --- a/govtool/frontend/src/utils/getGovActionId.ts +++ b/govtool/frontend/src/utils/getGovActionId.ts @@ -1,4 +1,4 @@ -export const getShortenedGovActionId = (txHash: string, index: number) => { +export const getShortenedGovActionId = (txHash: string, index: number | string) => { if (txHash.length <= 6) { return `${txHash}#${index}`; } @@ -9,5 +9,5 @@ export const getShortenedGovActionId = (txHash: string, index: number) => { return `${firstPart}...${lastPart}#${index}`; }; -export const getFullGovActionId = (txHash: string, index: number) => +export const getFullGovActionId = (txHash: string, index: number | string) => `${txHash}#${index}`; diff --git a/govtool/frontend/src/utils/tests/removeDuplicatedProposals.test.ts b/govtool/frontend/src/utils/tests/removeDuplicatedProposals.test.ts index c42ef87d9..29260ed57 100644 --- a/govtool/frontend/src/utils/tests/removeDuplicatedProposals.test.ts +++ b/govtool/frontend/src/utils/tests/removeDuplicatedProposals.test.ts @@ -1,12 +1,13 @@ import { ProposalData } from "@models"; import { removeDuplicatedProposals } from ".."; +import { GovernanceActionType } from "@/types/governanceAction"; const uniqueProposals: ProposalData[] = [ { id: "1322", txHash: "2bca7756ba6c998518c1bccbcdd5165e32d3c8e0bfdf930d34359c98354e85a0", index: 0, - type: "InfoAction", + type: GovernanceActionType.InfoAction, details: { description: "Info about InfoAction 1", additionalInfo: "Additional information for InfoAction 1", @@ -41,7 +42,7 @@ const uniqueProposals: ProposalData[] = [ id: "1338", txHash: "5e37f4d48182c4d8ff8e8ee7472c066501459b7bc8aaf6ca2f93a522ae12b0ea", index: 0, - type: "InfoAction", + type: GovernanceActionType.InfoAction, details: { description: "Info about InfoAction 2", additionalInfo: "Additional information for InfoAction 2", @@ -76,7 +77,7 @@ const uniqueProposals: ProposalData[] = [ id: "1335", txHash: "e88ddff921de8b7f6079a1c25a301c034de6b3ec8a906ad75463f0f5b3597672", index: 0, - type: "InfoAction", + type: GovernanceActionType.InfoAction, details: { description: "Info about InfoAction 3", additionalInfo: "Additional information for InfoAction 3",