From c99c2ce89ad355ab9b09c7b5d3a136bc5f5711d4 Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Tue, 13 Feb 2024 00:56:29 +0700 Subject: [PATCH] feat: voting overview veto alert --- CHANGELOG.md | 1 + .../VotingOverviewThreshold.tsx | 150 +++++++++++++----- 2 files changed, 113 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe39ea32..6fd11dfea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features +- [#779](https://github.com/alleslabs/celatone-frontend/pull/779) Proposal period overview voting - no with veto alert - [#778](https://github.com/alleslabs/celatone-frontend/pull/778) Proposal period overview voting - [#775](https://github.com/alleslabs/celatone-frontend/pull/775) Proposal period overview deposit - [#766](https://github.com/alleslabs/celatone-frontend/pull/766) Proposal status summary body diff --git a/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverviewThreshold.tsx b/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverviewThreshold.tsx index dad7dc72a..6d8c88163 100644 --- a/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverviewThreshold.tsx +++ b/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverviewThreshold.tsx @@ -7,6 +7,7 @@ import { CustomIcon } from "lib/components/icon"; import { StatusChip } from "lib/components/table"; import { extractParams, + formatPrettyPercent, getVoteResult, normalizeVotesInfo, } from "lib/pages/proposal-details/utils"; @@ -16,6 +17,7 @@ import { type ProposalParams, type ProposalVotesInfo, } from "lib/types"; +import { divWithDefault } from "lib/utils"; interface VotingOverviewThresholdProps { proposalData: ProposalData; @@ -32,7 +34,8 @@ export const VotingOverviewThreshold = ({ params, proposalData.isExpedited ); - const { totalVotes } = normalizeVotesInfo(votesInfo); + const { noWithVeto, totalVotes } = normalizeVotesInfo(votesInfo); + const noWithVetoRatio = divWithDefault(noWithVeto, totalVotes, 0); const { result, resultColor } = getVoteResult( threshold, @@ -41,46 +44,117 @@ export const VotingOverviewThreshold = ({ ); return ( - - {(proposalData.status === ProposalStatus.VOTING_PERIOD || - totalVotes.gte(quorum)) && ( - - - {proposalData.status === ProposalStatus.VOTING_PERIOD ? ( - - Current Voting Result - - ) : ( - + <> + + {(proposalData.status === ProposalStatus.VOTING_PERIOD || + totalVotes.gte(quorum)) && ( + + + {proposalData.status === ProposalStatus.VOTING_PERIOD ? ( - Final Vote Result: + Current Voting Result - {proposalData.status === ProposalStatus.FAILED ? ( - - ) : ( - <> - - - {result} - - - )} - - )} + ) : ( + + + Final Vote Result: + + {proposalData.status === ProposalStatus.FAILED ? ( + + ) : ( + <> + + + {result} + + + )} + + )} + + )} + + + + {noWithVetoRatio.gte(vetoThreshold) && ( + + + + {proposalData.status === ProposalStatus.VOTING_PERIOD ? ( + <> + Currently, the “No with veto” vote proportion + constitutes{" "} + + {formatPrettyPercent(noWithVetoRatio.toNumber())}{" "} + + of the total votes, including “Abstain”, which + exceeds the{" "} + + {formatPrettyPercent(vetoThreshold)} threshold + + . If the proposal concludes with this voting outcome, it will be + regardless of “Yes” votes. + + ) : ( + <> + Due to the “No with veto” vote proportion + constitutes{" "} + + {formatPrettyPercent(noWithVetoRatio.toNumber())}{" "} + + of the total votes including “Abstain”, which + exceeds the{" "} + + {formatPrettyPercent(vetoThreshold)} threshold + + , the proposal is rejected regardless of “Yes” + votes. + + )} + )} - - - + ); };