-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from aragon/fix/accurate-proposal-status-info
Accurate proposal status
- Loading branch information
Showing
6 changed files
with
71 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Proposal, VotingMode } from "@/plugins/tokenVoting/utils/types"; | ||
export const RATIO_BASE = 1_000_000; | ||
|
||
export function getProposalStatusVariant( | ||
proposal: Proposal, | ||
tokenSupply: bigint | ||
) { | ||
// Terminal cases | ||
if (!proposal?.tally) return { variant: "info", label: "(Loading)" }; | ||
else if (proposal.executed) return { variant: "primary", label: "Executed" }; | ||
|
||
const supportThreshold = proposal.parameters.supportThreshold; | ||
|
||
if (!proposal.active) { | ||
// Defeated or executable? | ||
const yesNoVotes = proposal.tally.no + proposal.tally.yes; | ||
if (!yesNoVotes) return { variant: "critical", label: "Defeated" }; | ||
|
||
const totalVotes = proposal.tally.abstain + yesNoVotes; | ||
if (totalVotes < proposal.parameters.minVotingPower) { | ||
return { variant: "critical", label: "Low turnout" }; | ||
} | ||
|
||
const finalRatio = (BigInt(RATIO_BASE) * proposal.tally.yes) / yesNoVotes; | ||
|
||
if (finalRatio > BigInt(supportThreshold)) { | ||
return { variant: "success", label: "Executable" }; | ||
} | ||
return { variant: "critical", label: "Defeated" }; | ||
} | ||
|
||
// Active or early execution? | ||
const noVotesWorstCase = | ||
tokenSupply - proposal.tally.yes - proposal.tally.abstain; | ||
const totalYesNoWc = proposal.tally.yes + noVotesWorstCase; | ||
|
||
if (proposal.parameters.votingMode == VotingMode.EarlyExecution) { | ||
const currentRatio = | ||
(BigInt(RATIO_BASE) * proposal.tally.yes) / totalYesNoWc; | ||
if (currentRatio > BigInt(supportThreshold)) { | ||
return { variant: "success", label: "Executable" }; | ||
} | ||
} | ||
return { variant: "info", label: "Active" }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters