From c24341332395f3d21f79129d8686df9cce8b3b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Wed, 28 Aug 2024 17:23:36 +0200 Subject: [PATCH] fix(#1838): fix counting CC and SPO votes --- CHANGELOG.md | 1 + govtool/backend/sql/list-proposals.sql | 51 ++++++- .../components/molecules/VotesSubmitted.tsx | 141 ++++-------------- 3 files changed, 77 insertions(+), 116 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6abd66b6a..c45c04b02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ changes. - Delete duplicate text on DRep registration form [Issue 1847](https://github.com/IntersectMBO/govtool/issues/1847) - Fix modal content invisible on ios [Issue 1842](https://github.com/IntersectMBO/govtool/issues/1842) +- Fix counting votes by CC committee members and SPOs [Issue 1838](https://github.com/IntersectMBO/govtool/issues/1838) ### Changed diff --git a/govtool/backend/sql/list-proposals.sql b/govtool/backend/sql/list-proposals.sql index d917766c0..7926fd6ba 100644 --- a/govtool/backend/sql/list-proposals.sql +++ b/govtool/backend/sql/list-proposals.sql @@ -78,12 +78,12 @@ SELECT always_no_confidence_voting_power.amount END) "no_votes", coalesce(Sum(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0) + always_abstain_voting_power.amount "abstain_votes", - coalesce(Sum(ldd_pool.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0), - coalesce(Sum(ldd_pool.amount) FILTER (WHERE voting_procedure.vote::text = 'No'), 0), - coalesce(Sum(ldd_pool.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0), - coalesce(Sum(ldd_cc.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0), - coalesce(Sum(ldd_cc.amount) FILTER (WHERE voting_procedure.vote::text = 'No'), 0), - coalesce(Sum(ldd_cc.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0), + coalesce(vp_by_pool.poolYesVotes, 0), + coalesce(vp_by_pool.poolNoVotes, 0), + coalesce(vp_by_pool.poolAbstainVotes, 0), + coalesce(vp_by_cc.ccYesVotes, 0), + coalesce(vp_by_cc.ccNoVotes, 0), + coalesce(vp_by_cc.ccAbstainVotes, 0), prev_gov_action.index as prev_gov_action_index, encode(prev_gov_action_tx.hash, 'hex') as prev_gov_action_tx_hash FROM @@ -104,8 +104,37 @@ FROM LEFT JOIN voting_procedure ON voting_procedure.gov_action_proposal_id = gov_action_proposal.id LEFT JOIN LatestDrepDistr ldd_drep ON ldd_drep.hash_id = voting_procedure.drep_voter AND ldd_drep.rn = 1 - LEFT JOIN LatestDrepDistr ldd_pool ON ldd_pool.hash_id = voting_procedure.pool_voter - AND ldd_pool.rn = 1 + LEFT JOIN + ( + SELECT + gov_action_proposal_id, + SUM(CASE WHEN vote = 'Yes' THEN 1 ELSE 0 END) AS poolYesVotes, + SUM(CASE WHEN vote = 'No' THEN 1 ELSE 0 END) AS poolNoVotes, + SUM(CASE WHEN vote = 'Abstain' THEN 1 ELSE 0 END) AS poolAbstainVotes + FROM + voting_procedure + WHERE + pool_voter IS NOT NULL + GROUP BY + gov_action_proposal_id + ) vp_by_pool + ON gov_action_proposal.id = vp_by_pool.gov_action_proposal_id + LEFT JOIN + ( + SELECT + gov_action_proposal_id, + SUM(CASE WHEN vote = 'Yes' THEN 1 ELSE 0 END) AS ccYesVotes, + SUM(CASE WHEN vote = 'No' THEN 1 ELSE 0 END) AS ccNoVotes, + SUM(CASE WHEN vote = 'Abstain' THEN 1 ELSE 0 END) AS ccAbstainVotes + FROM + voting_procedure + WHERE + committee_voter IS NOT NULL + GROUP BY + gov_action_proposal_id + ) vp_by_cc + ON gov_action_proposal.id = vp_by_cc.gov_action_proposal_id + LEFT JOIN LatestDrepDistr ldd_cc ON ldd_cc.hash_id = voting_procedure.committee_voter AND ldd_cc.rn = 1 LEFT JOIN gov_action_proposal AS prev_gov_action ON gov_action_proposal.prev_gov_action_proposal = prev_gov_action.id @@ -130,6 +159,12 @@ GROUP BY off_chain_vote_gov_action_data.abstract, off_chain_vote_gov_action_data.motivation, off_chain_vote_gov_action_data.rationale, + vp_by_pool.poolYesVotes, + vp_by_pool.poolNoVotes, + vp_by_pool.poolAbstainVotes, + vp_by_cc.ccYesVotes, + vp_by_cc.ccNoVotes, + vp_by_cc.ccAbstainVotes, gov_action_proposal.index, creator_tx.hash, creator_block.time, diff --git a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx index f67dff54d..d148a49a9 100644 --- a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx +++ b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx @@ -17,6 +17,27 @@ type Props = { ccAbstainVotes: number; }; +const Vote = ({ + vote, + value, +}: { + vote: "yes" | "no" | "abstain"; + value: string | number; +}) => ( + + + + {value} + + +); + export const VotesSubmitted = ({ dRepAbstainVotes, dRepNoVotes, @@ -79,40 +100,12 @@ export const VotesSubmitted = ({ > {t("govActions.dReps")} - - - - ₳ {correctAdaFormat(dRepYesVotes)} - - - - - - ₳ {correctAdaFormat(dRepAbstainVotes)} - - - - - - ₳ {correctAdaFormat(dRepNoVotes)} - - + + + {t("govActions.sPos")} - - - - ₳ {correctAdaFormat(poolYesVotes)} - - - - - - ₳ {correctAdaFormat(poolAbstainVotes)} - - - - - - ₳ {correctAdaFormat(poolNoVotes)} - - + + + {t("govActions.ccCommittee")} - - - - ₳ {correctAdaFormat(ccYesVotes)} - - - - - - ₳ {correctAdaFormat(ccAbstainVotes)} - - - - - - ₳ {correctAdaFormat(ccNoVotes)} - - + + +