import Tooltip from '@components/shared/Tooltip' import { CheckCircleIcon } from '@heroicons/react/20/solid' import { Governance, ProgramAccount, Proposal } from '@solana/spl-governance' import { RawMint } from '@solana/spl-token' import GovernanceStore from '@store/governanceStore' import { useTranslation } from 'next-i18next' import { getMintMaxVoteWeight } from 'utils/governance/proposals' import { fmtTokenAmount } from 'utils/governance/tools' type Props = { governance: ProgramAccount proposal: ProgramAccount communityMint: RawMint } const QuorumProgress = ({ governance, proposal, communityMint }: Props) => { const { t } = useTranslation(['governance']) const realm = GovernanceStore((s) => s.realm) const voteThresholdPct = governance.account.config.communityVoteThreshold.value || 0 const maxVoteWeight = realm && getMintMaxVoteWeight( communityMint, realm.account.config.communityMintMaxVoteWeightSource ) const minimumYesVotes = fmtTokenAmount(maxVoteWeight!, communityMint.decimals) * (voteThresholdPct / 100) const yesVoteCount = fmtTokenAmount( proposal.account.getYesVoteCount(), communityMint.decimals ) const rawYesVotesRequired = minimumYesVotes - yesVoteCount const votesRequiredInRange = rawYesVotesRequired < 0 ? 0 : rawYesVotesRequired const yesVoteProgress = votesRequiredInRange ? 100 - (votesRequiredInRange / minimumYesVotes) * 100 : 100 const yesVotesRequired = communityMint.decimals == 0 ? Math.ceil(votesRequiredInRange) : votesRequiredInRange return (

{t('approval-q')}

{typeof yesVoteProgress !== 'undefined' && yesVoteProgress < 100 ? (

{`${( yesVotesRequired ?? 0 ).toLocaleString(undefined, { maximumFractionDigits: 0, })} ${(yesVoteProgress ?? 0) > 0 ? 'more' : ''} Yes vote${ (yesVotesRequired ?? 0) > 1 ? 's' : '' } required`}

) : (

{t('required-approval-achieved')}

)}
= 100 ? 'bg-th-up' : 'bg-th-fgd-2' } flex rounded`} >
) } export default QuorumProgress