Skip to content

Commit

Permalink
Merge pull request #1857 from IntersectMBO/fix/1838-constitutional-co…
Browse files Browse the repository at this point in the history
…mmittee-votes-not-counted

fix(#1838): fix counting CC and SPO votes
  • Loading branch information
MSzalowski authored Aug 29, 2024
2 parents b66a2ff + c243413 commit 51eaa97
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 116 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 43 additions & 8 deletions govtool/backend/sql/list-proposals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
141 changes: 33 additions & 108 deletions govtool/frontend/src/components/molecules/VotesSubmitted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ type Props = {
ccAbstainVotes: number;
};

const Vote = ({
vote,
value,
}: {
vote: "yes" | "no" | "abstain";
value: string | number;
}) => (
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote={vote} maxWidth={82} />
<Typography
fontSize="16px"
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{value}
</Typography>
</Box>
);

export const VotesSubmitted = ({
dRepAbstainVotes,
dRepNoVotes,
Expand Down Expand Up @@ -79,40 +100,12 @@ export const VotesSubmitted = ({
>
{t("govActions.dReps")}
</Typography>
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote="yes" maxWidth={82} />
<Typography
fontSize="16px"
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(dRepYesVotes)}
</Typography>
</Box>
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote="abstain" maxWidth={82} />
<Typography
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(dRepAbstainVotes)}
</Typography>
</Box>
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote="no" maxWidth={82} />
<Typography
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(dRepNoVotes)}
</Typography>
</Box>
<Vote vote="yes" value={`₳ ${correctAdaFormat(dRepYesVotes)}`} />
<Vote
vote="abstain"
value={`₳ ${correctAdaFormat(dRepAbstainVotes)}`}
/>
<Vote vote="no" value={`₳ ${correctAdaFormat(dRepNoVotes)}`} />
<Box
sx={{
display: "flex",
Expand All @@ -130,40 +123,9 @@ export const VotesSubmitted = ({
>
{t("govActions.sPos")}
</Typography>
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote="yes" maxWidth={82} />
<Typography
fontSize="16px"
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(poolYesVotes)}
</Typography>
</Box>
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote="abstain" maxWidth={82} />
<Typography
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(poolAbstainVotes)}
</Typography>
</Box>
<Box sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}>
<VotePill vote="no" maxWidth={82} />
<Typography
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(poolNoVotes)}
</Typography>
</Box>
<Vote vote="yes" value={poolYesVotes} />
<Vote vote="abstain" value={poolAbstainVotes} />
<Vote vote="no" value={poolNoVotes} />
<Box
sx={{
display: "flex",
Expand All @@ -181,46 +143,9 @@ export const VotesSubmitted = ({
>
{t("govActions.ccCommittee")}
</Typography>
<Box
sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}
>
<VotePill vote="yes" maxWidth={82} />
<Typography
fontSize="16px"
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(ccYesVotes)}
</Typography>
</Box>
<Box
sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}
>
<VotePill vote="abstain" maxWidth={82} />
<Typography
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(ccAbstainVotes)}
</Typography>
</Box>
<Box
sx={{ alignItems: "center", display: "flex", flexWrap: "wrap" }}
>
<VotePill vote="no" maxWidth={82} />
<Typography
sx={{
marginLeft: "12px",
wordBreak: "break-all",
}}
>
{correctAdaFormat(ccNoVotes)}
</Typography>
</Box>
<Vote vote="yes" value={ccYesVotes} />
<Vote vote="abstain" value={ccAbstainVotes} />
<Vote vote="no" value={ccNoVotes} />
</Box>
</Box>
</Box>
Expand Down

0 comments on commit 51eaa97

Please sign in to comment.