Show number of votes (#172)

This commit is contained in:
Szymon Szlachtowicz 2021-07-30 08:45:49 +02:00 committed by GitHub
parent 7efa707e3c
commit 3cc6f6873c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import { useContracts } from '../../hooks/useContracts'
import { useVotesAggregate } from '../../hooks/useVotesAggregate'
import { CurrentVoting } from '../../models/community'
import { VoteSendingBtn } from '../Button'
import { BigNumber } from 'ethers'
import { addCommas } from '../../helpers/addCommas'
interface VoteSubmitButtonProps {
vote: CurrentVoting
@ -13,8 +15,11 @@ export function VoteSubmitButton({ vote }: VoteSubmitButtonProps) {
const { votes } = useVotesAggregate(vote.ID)
const { votingContract } = useContracts()
const { send } = useContractFunction(votingContract, 'castVotes')
const voteAmount = votes.reduce((prev, curr) => prev.add(curr[2]), BigNumber.from(0))
if (votes.length > 0) {
return <VoteSendingBtn onClick={() => send(votes)}> {votes.length} votes need saving</VoteSendingBtn>
return (
<VoteSendingBtn onClick={() => send(votes)}> {addCommas(voteAmount.toString())} votes need saving</VoteSendingBtn>
)
}
return null
}