Skip to content

Commit

Permalink
Merge pull request #66 from AudiusProject/jowlee-quorum-req
Browse files Browse the repository at this point in the history
Add quorum to proposal
  • Loading branch information
jowlee authored and michellebrier committed Oct 9, 2023
1 parent 5b84ff8 commit 0727bc2
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/protocol-dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/protocol-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"3box": "^1.22.2",
"@apollo/client": "^3.3.7",
"@audius/libs": "1.1.13",
"@audius/libs": "^1.1.14",
"@audius/stems": "0.3.4",
"@reduxjs/toolkit": "^1.4.0",
"chart.js": "^2.9.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,54 @@
justify-content: center;
min-height: 400px;
}

.quorumContainer {
margin-top: 8px;
display: inline-flex;
justify-content: center;
align-items: center;
text-transform: uppercase;
font-weight: var(--font-bold);
font-size: var(--font-xs);
line-height: 15px;
text-align: center;
letter-spacing: 1px;
}

.quorumValue {
margin: 0px 8px;
}


.quorumStatusContainer {
font-weight: var(--font-demi-bold);
font-size: var(--font-l);
line-height: 22px;
color: var(--neutral);
text-transform: capitalize;
display: inline-flex;
margin-top: 16px;
align-items: center;
}

.circle {
height: 24px;
width: 24px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 8px;
}

.circle.met {
background-color: #6BCF63;
}

.circle.notMet {
background-color: var(--neutral-light-4);
}

.icon path {
fill: var(--static-white);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
import { useAccountUser } from 'store/account/hooks'
import Tooltip, { Position } from 'components/Tooltip'
import { createStyles } from 'utils/mobile'
import { IconCheck, IconRemove } from '@audius/stems'

import desktopStyles from './ProposalHero.module.css'
import mobileStyles from './ProposalHeroMobile.module.css'
import Loading from 'components/Loading'
import getActiveStake from 'utils/activeStake'
import clsx from 'clsx'

const styles = createStyles({ desktopStyles, mobileStyles })

Expand All @@ -39,7 +41,11 @@ const messages = {
voteAgainst: 'Vote Against',
timeRemaining: 'Est. Time Remaining',
targetBlock: 'Target Block',
notVoted: 'NOT-VOTED'
notVoted: 'NOT-VOTED',
voted: 'VOTED',
quorum: 'QUORUM',
quorumMet: 'Quorum Met',
quorumNotMet: 'Quorum Not Met'
}

type VoteCTAProps = {
Expand Down Expand Up @@ -183,6 +189,13 @@ const ProposalHero: React.FC<ProposalHeroProps> = ({
</StandaloneBox>
)

const totalMagnitudeVoted = proposal
? proposal?.voteMagnitudeYes.add(proposal?.voteMagnitudeNo)
: Utils.toBN('0')
const hasMetQuorum = proposal
? totalMagnitudeVoted.gte(proposal.quorum)
: false

return (
<Paper className={styles.container}>
{proposal && proposal.proposer ? (
Expand Down Expand Up @@ -210,6 +223,22 @@ const ProposalHero: React.FC<ProposalHeroProps> = ({
</div>
)}
</div>
{isActive && hasMetQuorum && (
<div className={styles.quorumStatusContainer}>
<div className={clsx(styles.circle, styles.met)}>
<IconCheck className={styles.icon} />
</div>
{messages.quorumMet}
</div>
)}
{isActive && !hasMetQuorum && (
<div className={styles.quorumStatusContainer}>
<div className={clsx(styles.circle, styles.notMet)}>
<IconRemove className={styles.icon} />
</div>
{messages.quorumNotMet}
</div>
)}
</div>
<div className={styles.stats}>
<VoteMeter
Expand All @@ -223,6 +252,25 @@ const ProposalHero: React.FC<ProposalHeroProps> = ({
>
{`${formatShortAud(amountAbstained)} ${messages.notVoted}`}
</Tooltip>
{isActive && (
<div className={styles.quorumContainer}>
<Tooltip
text={formatWei(totalMagnitudeVoted)}
position={Position.BOTTOM}
className={styles.quorumValue}
>
{`${formatShortAud(totalMagnitudeVoted)} ${messages.voted}`}
</Tooltip>
{' / '}
<Tooltip
text={formatWei(proposal.quorum)}
position={Position.BOTTOM}
className={styles.quorumValue}
>
{`${formatShortAud(proposal.quorum)} ${messages.quorum}`}
</Tooltip>
</div>
)}
</div>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ export default class Governance {
}))
}

async getProposalQuorum(proposalId: number): Promise<BN> {
await this.aud.hasPermissions()
const quorumAmount: BN = await this.getContract().calculateQuorum(
proposalId
)
return quorumAmount
}

/* -------------------- Governance Write -------------------- */

async submitProposal(args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ export function fetchActiveProposals(): ThunkAction<
await Promise.all(
proposalIds.map(async id => {
const proposal = await aud.Governance.getProposalById(id)
const quorum = await aud.Governance.getProposalQuorum(id)
const {
name,
description
} = await aud.Governance.getProposalSubmissionById(id)
proposal.name = name
proposal.description = description
proposal.quorum = quorum
return proposal
})
)
Expand All @@ -87,8 +89,10 @@ export function fetchAllProposals(): ThunkAction<
proposalEvents.map(async (p: ProposalEvent) => {
const { proposalId, description, name } = p
const proposal = await aud.Governance.getProposalById(proposalId)
const quorum = await aud.Governance.getProposalQuorum(proposalId)
proposal.description = description
proposal.name = name
proposal.quorum = quorum
if (proposal.outcome !== Outcome.InProgress) {
const evaluationBlockNumber = await aud.Governance.getProposalEvaluationBlock(
proposalId
Expand All @@ -108,12 +112,14 @@ export function fetchProposal(
): ThunkAction<void, AppState, Audius, Action<string>> {
return async (dispatch, getState, aud) => {
const proposal = await aud.Governance.getProposalById(proposalId)
const quorum = await aud.Governance.getProposalQuorum(proposalId)
const {
name,
description
} = await aud.Governance.getProposalSubmissionById(proposalId)
proposal.name = name
proposal.description = description
proposal.quorum = quorum
if (proposal.outcome !== Outcome.InProgress) {
const evaluationBlockNumber = await aud.Governance.getProposalEvaluationBlock(
proposalId
Expand Down
1 change: 1 addition & 0 deletions packages/protocol-dashboard/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export type Proposal = {
name?: string
description?: string
evaluatedBlock?: Block
quorum: BigNumber
}

export type ProposalEvent = {
Expand Down

0 comments on commit 0727bc2

Please sign in to comment.