From 7f0fc08bd98e06c99e7abf438d9e4d1842df3e70 Mon Sep 17 00:00:00 2001 From: Ryan Goree Date: Thu, 21 Mar 2024 01:48:22 -0500 Subject: [PATCH 1/2] Remove VP col on GSC voting activity table --- apps/council-ui/pages/proposals/details.tsx | 15 ++-- .../VotingActivityTable.tsx | 68 ++++++++++++------- 2 files changed, 53 insertions(+), 30 deletions(-) diff --git a/apps/council-ui/pages/proposals/details.tsx b/apps/council-ui/pages/proposals/details.tsx index f3800a1c..bc093a77 100644 --- a/apps/council-ui/pages/proposals/details.tsx +++ b/apps/council-ui/pages/proposals/details.tsx @@ -47,7 +47,7 @@ export default function ProposalPage(): ReactElement { ); const { gscMembers } = useGscMembers(); - // // voting activity filtering + // voting activity filtering const [gscOnly, setGscOnly] = useState(false); const filteredVotes = useMemo(() => { if (data?.votes && gscOnly && gscMembers) { @@ -58,7 +58,7 @@ export default function ProposalPage(): ReactElement { return dedupeVotes(data?.votes); }, [data, gscOnly, gscMembers]); - // // Redirect to proposals page if the voting contract is not found. + // Redirect to proposals page if the voting contract is not found. if (!usedCoreVoting) { replace("/proposals"); // Returning empty fragment is to remove the undefined type from the query params. @@ -67,8 +67,6 @@ export default function ProposalPage(): ReactElement { const proposalTitle = data?.title ?? `Proposal ${id}`; - // return <>{status}; - return (
@@ -155,6 +153,9 @@ export default function ProposalPage(): ReactElement { ) : ( @@ -181,7 +182,7 @@ export default function ProposalPage(): ReactElement { interface ProposalDetailsPageData { proposalExists: boolean; - type: "core" | "gsc"; + isGsc: boolean; status: ProposalStatus; isActive: boolean; votes?: ReadVote[]; @@ -226,7 +227,7 @@ function useProposalDetailsPageData( const enabled = !!proposal; - const { data, status, error } = useQuery({ + const { data, status } = useQuery({ queryKey: ["proposalDetailsPage", coreVotingAddress, String(proposal?.id)], enabled, queryFn: enabled @@ -272,7 +273,7 @@ function useProposalDetailsPageData( return { proposalExists: !!proposal, - type: isGsc ? "gsc" : "core", + isGsc, votingContractName, status: getProposalStatus({ isExecuted, diff --git a/apps/council-ui/src/ui/proposals/VotingActivityTable/VotingActivityTable.tsx b/apps/council-ui/src/ui/proposals/VotingActivityTable/VotingActivityTable.tsx index a12b0c71..95a2eec2 100644 --- a/apps/council-ui/src/ui/proposals/VotingActivityTable/VotingActivityTable.tsx +++ b/apps/council-ui/src/ui/proposals/VotingActivityTable/VotingActivityTable.tsx @@ -1,8 +1,9 @@ import { Ballot, ReadVote } from "@delvtech/council-viem"; -import { ReactElement, useMemo, useState } from "react"; +import { ReactElement, ReactNode, useMemo, useState } from "react"; import { makeVoterURL } from "src/routes"; import { formatVotingPower } from "src/ui/base/formatting/formatVotingPower"; import { + Column, SortOptions, SortableGridTable, } from "src/ui/base/tables/SortableGridTable"; @@ -15,11 +16,17 @@ type SortField = "votingPower" | "ballot"; interface VotingActivityTableProps { votes: ReadVote[]; voterEnsRecords: EnsRecords; + /** + * Whether to show the voting power used by each voter. + * @default true + */ + showVotingPower?: boolean; } export function VotingActivityTable({ votes, voterEnsRecords, + showVotingPower = true, }: VotingActivityTableProps): ReactElement { const [sortOptions, setSortOptions] = useState>({ key: "votingPower", @@ -31,35 +38,50 @@ export function VotingActivityTable({ [sortOptions, votes], ); + const cols = useMemo(() => { + const cols: Column[] = ["Voter"]; + + if (showVotingPower) { + cols.push({ + cell: "Voting Power", + sortKey: "votingPower", + }); + } + + cols.push({ + cell: "Ballot", + sortKey: "ballot", + }); + + return cols; + }, [showVotingPower]); + return (
{ + const cells: ReactNode[] = [ + , + ]; + if (showVotingPower) { + cells.push(formatVotingPower(power)); + } + cells.push(); return { href: makeVoterURL(voter.address), - cells: [ - , - formatVotingPower(power), - , - ], + cells, }; })} /> From 915dbd4552e8b83c8bd040c3a3a53af8de5faf9b Mon Sep 17 00:00:00 2001 From: Ryan Goree Date: Thu, 21 Mar 2024 01:48:42 -0500 Subject: [PATCH 2/2] Remove non-null assertion --- .../council-core/src/models/coreVoting/ReadCoreVoting.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/council-core/src/models/coreVoting/ReadCoreVoting.ts b/packages/council-core/src/models/coreVoting/ReadCoreVoting.ts index 119c5f3b..b01dd093 100644 --- a/packages/council-core/src/models/coreVoting/ReadCoreVoting.ts +++ b/packages/council-core/src/models/coreVoting/ReadCoreVoting.ts @@ -204,13 +204,18 @@ export class ReadCoreVoting extends Model { }, } of voteEvents) { const proposal = await this.getProposal({ id: proposalId }); + if (!proposal) { + throw new Error( + `Vote event for proposal ${proposalId} from voter ${voter} references a non-existent proposal.`, + ); + } votes.push( new ReadVote({ ballot: BALLOTS[castBallot], contractFactory: this.contractFactory, network: this.network, power: votingPower, - proposal: proposal!, + proposal, voter, }), );