Skip to content

Commit

Permalink
Merge pull request #3437 from cardano-foundation/feat/MET-2055-update…
Browse files Browse the repository at this point in the history
…-Governance-votes

fix: MET-2055 disable gov cannot vote
  • Loading branch information
Sotatek-TaiTruong committed May 9, 2024
2 parents 2e909a6 + d5f35e2 commit dbe997a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 36 deletions.
142 changes: 106 additions & 36 deletions src/components/GovernanceVotes/OverallVote.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import {
Box,
Button,
Expand Down Expand Up @@ -60,17 +60,26 @@ const OverallVote: React.FC<{ data: GovernanceVoteDetail | null; voteId: string;
voteId,
index
}) => {
const [selectVote, setSelectVote] = useState<VoteType>("SPOs");
const [selectVote, setSelectVote] = useState<VoteType | "">("");
const [openHistoryVoteModal, setOpenHistoryVoteModal] = useState<boolean>(false);
const [openActionMetadataModal, setOpenActionMetadataModal] = useState<boolean>(false);
const [openModal, setOpenModal] = useState(false);

useEffect(() => {
if (data?.allowedVoteBySPO) {
setSelectVote("SPOs");
} else {
setSelectVote("DReps");
}
}, [data?.allowedVoteBySPO]);
const { data: dataChart, loading: loadingChart } = useFetch<GovernanceVoteChart>(
`${API.POOL_CERTIFICATE.POOL_CHART}?${stringify({
txHash: voteId,
index: index || 0,
voterType: voterType[selectVote]
})}`
selectVote
? `${API.POOL_CERTIFICATE.POOL_CHART}?${stringify({
txHash: voteId,
index: index || 0,
voterType: voterType[selectVote as VoteType]
})}`
: ""
);

const theme = useTheme();
Expand Down Expand Up @@ -117,6 +126,12 @@ const OverallVote: React.FC<{ data: GovernanceVoteDetail | null; voteId: string;
return <></>;
}

const disableButtonSelect = (key: string) => {
if (key === "SPOs" && !data.allowedVoteBySPO) return true;
if (key === "CC" && !data.allowedVoteByCC) return true;
return false;
};

return (
<DataContainer sx={{ boxShadow: "unset" }}>
<Box
Expand Down Expand Up @@ -346,33 +361,46 @@ const OverallVote: React.FC<{ data: GovernanceVoteDetail | null; voteId: string;

<Box display="flex" gap="8px" flexWrap="inherit">
{listVotes.map((i) => (
<Chip
<CustomTooltip
key={i}
sx={{
fontWeight: 500,
fontSize: "12px",
background:
selectVote === i
? theme.palette.primary[200]
: theme.isDark
? theme.palette.primary[500]
: theme.palette.primary[100],
border: `1px solid ${
selectVote === i ? theme.palette.primary.main : theme.palette.secondary[600]
}`,
color:
selectVote === i
? theme.palette.secondary.main
: theme.isDark
? theme.palette.secondary.main
: theme.palette.secondary[600],
"&:hover": {
background: theme.palette.primary[200]
}
}}
label={i}
onClick={() => setSelectVote(i as VoteType)}
/>
title={
disableButtonSelect(i)
? i === "SPOs"
? t("drep.SPODisable")
: t("drep.CCÏDisable")
: undefined
}
>
<Box display={"inline-block"}>
<Chip
disabled={disableButtonSelect(i)}
sx={{
fontWeight: 500,
fontSize: "12px",
background:
selectVote === i
? theme.palette.primary[200]
: theme.isDark
? theme.palette.primary[500]
: theme.palette.primary[100],
border: `1px solid ${
selectVote === i ? theme.palette.primary.main : theme.palette.secondary[600]
}`,
color:
selectVote === i
? theme.palette.secondary.main
: theme.isDark
? theme.palette.secondary.main
: theme.palette.secondary[600],
"&:hover": {
background: theme.palette.primary[200]
}
}}
label={i}
onClick={() => setSelectVote(i as VoteType)}
/>
</Box>
</CustomTooltip>
))}
</Box>
</InfoTitle>
Expand Down Expand Up @@ -596,7 +624,21 @@ const VoteRate = ({ data, selectedVote }: { data: VotingChart | null; selectedVo
</Box>
</CustomTooltip>
</Box>
<CustomTooltip title={t("drep.activeVoteStakeTooltip")}>
<CustomTooltip
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -4]
}
}
]
}
}}
title={t("drep.activeVoteStakeTooltip")}
>
<BlackWarningIcon />
</CustomTooltip>
</Box>
Expand Down Expand Up @@ -625,7 +667,21 @@ const VoteRate = ({ data, selectedVote }: { data: VotingChart | null; selectedVo
</Box>
</CustomTooltip>
</Box>{" "}
<CustomTooltip title={t("drep.thresholdTooltip")}>
<CustomTooltip
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -4]
}
}
]
}
}}
title={t("drep.thresholdTooltip")}
>
<BlackWarningIcon />
</CustomTooltip>
</Box>
Expand Down Expand Up @@ -653,7 +709,21 @@ const VoteRate = ({ data, selectedVote }: { data: VotingChart | null; selectedVo
</Box>
</CustomTooltip>
</Box>{" "}
<CustomTooltip title={t("drep.remainingTooltip")}>
<CustomTooltip
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -4]
}
}
]
}
}}
title={t("drep.remainingTooltip")}
>
<BlackWarningIcon />
</CustomTooltip>
</Box>
Expand Down
2 changes: 2 additions & 0 deletions src/components/GovernanceVotes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ export interface GovernanceVoteDetail {
votingPower: number | null;
submissionDate: string;
poolName: string | null;
allowedVoteByCC: boolean;
allowedVoteBySPO: boolean;
expiryDate: string;
historyVotes: {
no: number | null;
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@
"drep.ccMembers": "CC Members",
"drep.threshold": "Threshold",
"drep.remaining": "Remaining",
"drep.SPODisable": "SPOs cannot cast votes for this governance action",
"drep.CCDisable": "CC cannot cast votes for this governance action",
"drep.activeVoteStakeTooltip": "The active voting stake is the amount of participating stake involved in this governance action.",
"drep.thresholdTooltip": "The threshold is the amount of ADA from yes votes required for this governance action to be ratified.",
"drep.remainingTooltip": "The remaining ADA shows the amount of ADA from participants still left to be voted.",
Expand Down

0 comments on commit dbe997a

Please sign in to comment.