From a4c9706c29d10547cd1f4df36aea9678c582c074 Mon Sep 17 00:00:00 2001 From: Jaco Date: Sat, 14 Jan 2023 22:42:43 +0200 Subject: [PATCH] Return nay flag from votes (#8805) * Return nay flag from votes * Add comments around calcs --- packages/page-council/src/Motions/Motion.tsx | 11 +++++++---- packages/react-hooks/src/useVotingStatus.ts | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/page-council/src/Motions/Motion.tsx b/packages/page-council/src/Motions/Motion.tsx index 5e7a1eaf99..8a0c32906f 100644 --- a/packages/page-council/src/Motions/Motion.tsx +++ b/packages/page-council/src/Motions/Motion.tsx @@ -27,6 +27,7 @@ interface Props { interface VoterState { hasVoted: boolean; hasVotedAye: boolean; + hasVotedNay: boolean; } function Motion ({ className = '', isMember, members, motion: { hash, proposal, votes }, prime }: Props): React.ReactElement | null { @@ -37,15 +38,17 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal, const { hasVoted, hasVotedAye } = useMemo( (): VoterState => { if (votes) { - const hasVotedAye = allAccounts.some((address) => votes.ayes.some((accountId) => accountId.eq(address))); + const hasVotedAye = allAccounts.some((a) => votes.ayes.some((accountId) => accountId.eq(a))); + const hasVotedNay = allAccounts.some((a) => votes.nays.some((accountId) => accountId.eq(a))); return { - hasVoted: hasVotedAye || allAccounts.some((address) => votes.nays.some((accountId) => accountId.eq(address))), - hasVotedAye + hasVoted: hasVotedAye || hasVotedNay, + hasVotedAye, + hasVotedNay }; } - return { hasVoted: false, hasVotedAye: false }; + return { hasVoted: false, hasVotedAye: false, hasVotedNay: false }; }, [allAccounts, votes] ); diff --git a/packages/react-hooks/src/useVotingStatus.ts b/packages/react-hooks/src/useVotingStatus.ts index ef00160cbe..5fffb4afb8 100644 --- a/packages/react-hooks/src/useVotingStatus.ts +++ b/packages/react-hooks/src/useVotingStatus.ts @@ -41,7 +41,9 @@ function getStatus (api: ApiPromise, bestNumber: BlockNumber, votes: Votes, numM } const isEnd = bestNumber.gte(votes.end); + // let approved = yes_votes >= voting.threshold; const hasPassed = votes.threshold.lten(votes.ayes.length); + // let disapproved = seats.saturating_sub(no_votes) < voting.threshold; const hasFailed = votes.threshold.gtn(Math.abs(numMembers - votes.nays.length)); return {