Skip to content

Commit

Permalink
correctly calculate vote progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Aug 28, 2021
1 parent 88930c3 commit 170b393
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
11 changes: 4 additions & 7 deletions components/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ import { ChevronRightIcon } from '@heroicons/react/solid'
import StatusBadge from './StatusBadge'
import Link from 'next/link'
import { Proposal, ProposalState } from '../models/accounts'
import { calculatePct, fmtUnixTime } from '../utils/formatting'
import { fmtUnixTime } from '../utils/formatting'
import ApprovalProgress from './ApprovalProgress'
import useRealm from '../hooks/useRealm'
import useProposalVotes from '../hooks/useProposalVotes'

type ProposalCardProps = {
id: string
proposal: Proposal
}

const ProposalCard = ({ id, proposal }: ProposalCardProps) => {
const { symbol, mint } = useRealm()

const yesVotePct = calculatePct(proposal.yesVotesCount, mint.supply)

const yesVoteProgress =
(yesVotePct / proposal.voteThresholdPercentage?.value) * 100
const { symbol } = useRealm()
const { yesVoteProgress } = useProposalVotes(proposal)

return (
<div>
Expand Down
28 changes: 7 additions & 21 deletions pages/dao/[symbol]/proposal/[pk].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import DiscussionPanel from '../../../../components/DiscussionPanel'
import VotePanel from '../../../../components/VotePanel'
import { ProposalState } from '../../../../models/accounts'

import { calculatePct, fmtTokenAmount } from '../../../../utils/formatting'
import ApprovalProgress from '../../../../components/ApprovalProgress'
import useRealm from '../../../../hooks/useRealm'
import useProposalVotes from '../../../../hooks/useProposalVotes'

const Proposal = () => {
const { symbol, mint } = useRealm()
const { symbol } = useRealm()
const { proposal, description, instructions } = useProposal()

const yesVotePct = proposal
? calculatePct(proposal.info.yesVotesCount, mint?.supply)
: null

const yesVoteProgress =
(yesVotePct / proposal?.info.voteThresholdPercentage?.value) * 100
const { yesVoteProgress, yesVoteCount, noVoteCount } = useProposalVotes(
proposal?.info
)

console.log('proposal data', { proposal, instructions })

Expand Down Expand Up @@ -60,21 +56,11 @@ const Proposal = () => {
<>
<div className="bg-bkg-1 px-4 py-2 rounded w-full">
<p className="text-fgd-3 text-xs">Approve</p>
<div className="font-bold">
{fmtTokenAmount(
proposal?.info.yesVotesCount,
mint?.decimals
)}
</div>
<div className="font-bold">{yesVoteCount}</div>
</div>
<div className="bg-bkg-1 px-4 py-2 rounded w-full">
<p className="text-fgd-3 text-xs">Deny</p>
<div className="font-bold">
{fmtTokenAmount(
proposal?.info.noVotesCount,
mint?.decimals
)}
</div>
<div className="font-bold">{noVoteCount}</div>
</div>
</>
) : (
Expand Down

0 comments on commit 170b393

Please sign in to comment.