Skip to content

Commit 40bfc2c

Browse files
authored
Merge pull request #2869 from IntersectMBO/staging
GovTool - v2.0.10-patch2
2 parents d1f6b88 + 3a47360 commit 40bfc2c

File tree

5 files changed

+86
-35
lines changed

5 files changed

+86
-35
lines changed

govtool/backend/sql/list-proposals.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ DRepVotingPower AS (
2121
SUM(CASE WHEN drep_hash.view = 'drep_always_abstain' THEN amount ELSE 0 END) AS abstain
2222
FROM
2323
drep_hash
24-
LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id
24+
LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id AND drep_distr.epoch_no = (SELECT MAX(no) FROM epoch)
2525
WHERE drep_hash.view IN ('drep_always_no_confidence', 'drep_always_abstain')
2626
),
2727
CommitteeData AS (

govtool/frontend/src/components/atoms/VotePill.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,60 @@ import { Box, Typography } from "@mui/material";
33

44
import { Vote } from "@models";
55

6+
const borderColorMap = {
7+
yes: "#C0E4BA",
8+
no: "#EDACAC",
9+
abstain: "#99ADDE",
10+
notVoted: "#EAE9F0",
11+
};
12+
13+
const bgColorMap = {
14+
yes: "#F0F9EE",
15+
no: "#FBEBEB",
16+
abstain: "#E6EBF7",
17+
notVoted: "#F5F5F8",
18+
};
19+
20+
const voteLabelKey = {
21+
yes: "votes.yes",
22+
no: "votes.no",
23+
abstain: "votes.abstain",
24+
notVoted: "votes.notVoted",
25+
};
26+
27+
const ccVoteLabelKey = {
28+
yes: "votes.constitutional",
29+
no: "votes.unconstitutional",
30+
abstain: "votes.abstain",
31+
notVoted: "",
32+
};
33+
34+
type VoteExtended = Vote | "notVoted";
35+
636
export const VotePill = ({
737
vote,
838
width,
939
maxWidth,
1040
isCC,
1141
}: {
12-
vote: Vote;
42+
vote: VoteExtended;
1343
width?: number;
1444
maxWidth?: number;
1545
isCC?: boolean;
1646
}) => {
1747
const { t } = useTranslation();
18-
const VOTE = vote.toLowerCase() as "yes" | "no" | "abstain";
48+
49+
const bgColor = bgColorMap[vote];
50+
const borderColor = borderColorMap[vote];
51+
const labelKey = isCC ? ccVoteLabelKey[vote] : voteLabelKey[vote];
52+
1953
return (
2054
<Box
2155
py={0.75}
2256
px={2.25}
2357
border={1}
24-
borderColor={
25-
VOTE === "yes" ? "#C0E4BA" : VOTE === "no" ? "#EDACAC" : "#99ADDE"
26-
}
27-
bgcolor={
28-
VOTE === "yes" ? "#F0F9EE" : VOTE === "no" ? "#FBEBEB" : "#E6EBF7"
29-
}
58+
borderColor={borderColor}
59+
bgcolor={bgColor}
3060
borderRadius={100}
3161
textAlign="center"
3262
minWidth="50px"
@@ -42,17 +72,7 @@ export const VotePill = ({
4272
textOverflow="ellipsis"
4373
overflow="hidden"
4474
>
45-
{t(
46-
`votes.${
47-
isCC
48-
? VOTE === "yes"
49-
? "constitutional"
50-
: vote === "no"
51-
? "unconstitutional"
52-
: VOTE
53-
: VOTE
54-
}`,
55-
)}
75+
{t(labelKey)}
5676
</Typography>
5777
</Box>
5878
);

govtool/frontend/src/components/molecules/VotesSubmitted.tsx

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { Box } from "@mui/material";
44
import { IMAGES, SECURITY_RELEVANT_PARAMS_MAP } from "@consts";
55
import { Typography, VotePill } from "@atoms";
66
import { useTranslation } from "@hooks";
7-
import { correctVoteAdaFormat, getGovActionVotingThresholdKey } from "@utils";
7+
import {
8+
correctDRepDirectoryFormat,
9+
getGovActionVotingThresholdKey,
10+
} from "@utils";
811
import { SubmittedVotesData } from "@models";
912
import { useFeatureFlag, useAppContext } from "@/context";
1013

@@ -42,17 +45,28 @@ export const VotesSubmitted = ({
4245
areCCVoteTotalsDisplayed,
4346
} = useFeatureFlag();
4447
const { t } = useTranslation();
45-
const { epochParams } = useAppContext();
48+
const { epochParams, networkMetrics } = useAppContext();
4649

47-
const dRepYesVotesPercentage =
48-
dRepYesVotes + dRepNoVotes
49-
? (dRepYesVotes / (dRepYesVotes + dRepNoVotes)) * 100
50-
: undefined;
51-
const dRepNoVotesPercentage = dRepYesVotesPercentage
52-
? 100 - dRepYesVotesPercentage
53-
: dRepNoVotes
54-
? 100
50+
const totalStakeControlledByDReps =
51+
networkMetrics?.totalStakeControlledByDReps ?? 0;
52+
53+
const totalDRepVotes = totalStakeControlledByDReps
54+
? totalStakeControlledByDReps - dRepAbstainVotes
55+
: undefined;
56+
const dRepYesVotesPercentage = totalDRepVotes
57+
? (dRepYesVotes / totalDRepVotes) * 100
5558
: undefined;
59+
const dRepNoVotesPercentage = totalDRepVotes
60+
? (dRepNoVotes / totalDRepVotes) * 100
61+
: undefined;
62+
const dRepNotVotedVotes = totalStakeControlledByDReps
63+
? totalStakeControlledByDReps -
64+
dRepYesVotes -
65+
dRepNoVotes -
66+
dRepAbstainVotes
67+
: undefined;
68+
const dRepNotVotedVotesPercentage =
69+
100 - (dRepYesVotesPercentage ?? 0) - (dRepNoVotesPercentage ?? 0);
5670

5771
const poolYesVotesPercentage =
5872
poolYesVotes + poolNoVotes
@@ -123,6 +137,8 @@ export const VotesSubmitted = ({
123137
noVotes={dRepNoVotes}
124138
noVotesPercentage={dRepNoVotesPercentage}
125139
abstainVotes={dRepAbstainVotes}
140+
notVotedVotes={dRepNotVotedVotes}
141+
notVotedPercentage={dRepNotVotedVotesPercentage}
126142
threshold={(() => {
127143
const votingThresholdKey = getGovActionVotingThresholdKey({
128144
govActionType: type,
@@ -174,6 +190,8 @@ type VotesGroupProps = {
174190
yesVotesPercentage?: number;
175191
noVotes: number;
176192
noVotesPercentage?: number;
193+
notVotedVotes?: number;
194+
notVotedPercentage?: number;
177195
abstainVotes: number;
178196
threshold?: number | null;
179197
};
@@ -184,6 +202,8 @@ const VotesGroup = ({
184202
yesVotesPercentage,
185203
noVotes,
186204
noVotesPercentage,
205+
notVotedVotes,
206+
notVotedPercentage,
187207
abstainVotes,
188208
threshold,
189209
}: VotesGroupProps) => {
@@ -219,7 +239,15 @@ const VotesGroup = ({
219239
percentage={noVotesPercentage}
220240
value={noVotes}
221241
/>
222-
{threshold !== undefined && (
242+
{typeof notVotedVotes === "number" && (
243+
<Vote
244+
type={type}
245+
vote="notVoted"
246+
percentage={notVotedPercentage}
247+
value={notVotedVotes}
248+
/>
249+
)}
250+
{threshold !== undefined && threshold !== null && (
223251
<Box
224252
display="flex"
225253
flexDirection="row"
@@ -246,7 +274,7 @@ const VotesGroup = ({
246274
color: "neutralGray",
247275
}}
248276
>
249-
{threshold}
277+
{threshold * 100}%
250278
</Typography>
251279
</Box>
252280
)}
@@ -285,7 +313,9 @@ const Vote = ({ type, vote, value, percentage }: VoteProps) => (
285313
fontWeight: "500",
286314
}}
287315
>
288-
{type !== "ccCommittee" ? `₳ ${correctVoteAdaFormat(value)}` : value}
316+
{type !== "ccCommittee"
317+
? `₳ ${correctDRepDirectoryFormat(value)}`
318+
: value}
289319
</Typography>
290320
{vote !== "abstain" && typeof percentage === "number" && (
291321
<Typography

govtool/frontend/src/i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@
736736
"constitutional": "Constitutional",
737737
"no": "No",
738738
"unconstitutional": "Unconstitutional",
739-
"yes": "Yes"
739+
"yes": "Yes",
740+
"notVoted": "Not voted"
740741
},
741742
"usefulLinks": {
742743
"title": "Useful links",

govtool/frontend/src/types/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare global {
1010
dataLayer: SentryEventDataLayer[];
1111
}
1212

13-
type VoteType = "yes" | "no" | "abstain";
13+
type VoteType = "yes" | "no" | "abstain" | "notVoted";
1414

1515
type ActionTypeFromAPI = {
1616
id: string;

0 commit comments

Comments
 (0)