-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dao 721 Implemented quorum part in the Votes Column (#242)
* DAO-721 Implemented quorum column * Implemented memoized latest proposals table to speed up UI. * Quorum will have no decimals place per Product. * Quorum percentage will be integer only, no decimals.
- Loading branch information
1 parent
6f83201
commit ce48345
Showing
3 changed files
with
44 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
import { useProposalContext } from '@/app/proposals/ProposalsContext' | ||
import { toFixed } from '@/lib/utils' | ||
import { useReadContract } from 'wagmi' | ||
import { GovernorAbi } from '@/lib/abis/Governor' | ||
import { GOVERNOR_ADDRESS } from '@/lib/constants' | ||
import { formatBalanceToHuman } from '@/app/user/Balances/balanceUtils' | ||
|
||
export const VotesColumn = () => { | ||
const { proposalVotes } = useProposalContext() | ||
|
||
const { proposalVotes, blockNumber } = useProposalContext() | ||
const votes = proposalVotes.reduce((prev, next) => Number(next) + prev, 0) | ||
return <p>{toFixed(votes)}</p> | ||
|
||
const { data: quorumAtSnapshot } = useReadContract({ | ||
abi: GovernorAbi, | ||
address: GOVERNOR_ADDRESS, | ||
functionName: 'quorum', | ||
args: [BigInt(blockNumber)], | ||
}) | ||
let quorum = '-' | ||
let percentage = 0 | ||
|
||
if (quorumAtSnapshot) { | ||
quorum = formatBalanceToHuman(quorumAtSnapshot) | ||
// Calculate percentage of votes relative to quorum | ||
percentage = (votes / Number(quorum)) * 100 | ||
} | ||
|
||
// Determine the color based on percentage | ||
let colorClass = 'text-st-error' // Default to RED (0-49%) | ||
if (percentage >= 100) { | ||
colorClass = 'text-st-success' | ||
} else if (percentage >= 50) { | ||
colorClass = 'text-st-info' | ||
} | ||
return ( | ||
<> | ||
<p className={colorClass}> | ||
{toFixed(votes)} ({Math.floor(percentage)}%) | ||
</p> | ||
<p>Quorum: {Math.floor(Number(quorum))}</p> | ||
</> | ||
) | ||
} |
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