diff --git a/packages/DApp/src/components/Card.tsx b/packages/DApp/src/components/Card.tsx index aa29b98..d748e68 100644 --- a/packages/DApp/src/components/Card.tsx +++ b/packages/DApp/src/components/Card.tsx @@ -19,6 +19,7 @@ import { VoteAnimatedModal } from './card/VoteAnimatedModal' import voting from '../helpers/voting' import { DetailedVotingRoom } from '../models/smartContract' import { VoteSubmitButton } from './card/VoteSubmitButton' +import { useRoomAggregateVotes } from '../hooks/useRoomAggregateVotes' interface CardCommunityProps { community: CommunityDetail @@ -122,8 +123,10 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => { const { votingContract } = useContracts() + room = useRoomAggregateVotes(room, showConfirmModal) + const finalizeVoting = useContractFunction(votingContract, 'finalizeVotingRoom') - const community = room.details + const setNext = (val: boolean) => { setShowConfirmModal(val) setShowVoteModal(false) @@ -152,7 +155,7 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => { return ( {showVoteModal && ( - + { Date.now() && showConfirmModal === false) { + const reducedVotes = votes.reduce( + (accumulator, vote) => { + if (vote[1].mod(2).toNumber()) { + return { for: accumulator.for.add(vote[2]), against: accumulator.against } + } + return { for: accumulator.for, against: accumulator.against.add(vote[2]) } + }, + { for: room.totalVotesFor, against: room.totalVotesAgainst } + ) + room = { ...room, totalVotesAgainst: reducedVotes.against, totalVotesFor: reducedVotes.for } + } + return room +}