import { Proposal } from '@solana/spl-governance' import VoteResultsBar from './VoteResultBar' import { fmtTokenAmount } from 'utils/governance/tools' import { RawMint } from '@solana/spl-token' import { useTranslation } from 'next-i18next' import { BN } from '@coral-xyz/anchor' type VoteResultsProps = { proposal: Proposal communityMint: RawMint } const VoteResults = ({ proposal, communityMint }: VoteResultsProps) => { const { t } = useTranslation(['governance']) const yesVoteCount = fmtTokenAmount( proposal.getYesVoteCount() as BN, communityMint.decimals, ) const noVoteCount = fmtTokenAmount( proposal.getNoVoteCount() as BN, communityMint.decimals, ) const totalVoteCount = yesVoteCount + noVoteCount const getRelativeVoteCount = (voteCount: number) => totalVoteCount === 0 ? 0 : (voteCount / totalVoteCount) * 100 const relativeYesVotes = getRelativeVoteCount(yesVoteCount) const relativeNoVotes = getRelativeVoteCount(noVoteCount) return (
{proposal ? (

{t('yes-votes')}

{(yesVoteCount ?? 0).toLocaleString()} {relativeYesVotes?.toFixed(1)}%

{t('no-votes')}

{(noVoteCount ?? 0).toLocaleString()} {relativeNoVotes?.toFixed(1)}%

) : ( <>
)}
) } export default VoteResults