mirror of
https://github.com/status-im/community-dapp.git
synced 2025-02-23 19:48:27 +00:00
Show aggregated votes (#95)
This commit is contained in:
parent
3e7c27cff8
commit
abe8dd749b
@ -19,6 +19,7 @@ import { VoteAnimatedModal } from './card/VoteAnimatedModal'
|
|||||||
import voting from '../helpers/voting'
|
import voting from '../helpers/voting'
|
||||||
import { DetailedVotingRoom } from '../models/smartContract'
|
import { DetailedVotingRoom } from '../models/smartContract'
|
||||||
import { VoteSubmitButton } from './card/VoteSubmitButton'
|
import { VoteSubmitButton } from './card/VoteSubmitButton'
|
||||||
|
import { useRoomAggregateVotes } from '../hooks/useRoomAggregateVotes'
|
||||||
|
|
||||||
interface CardCommunityProps {
|
interface CardCommunityProps {
|
||||||
community: CommunityDetail
|
community: CommunityDetail
|
||||||
@ -122,8 +123,10 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => {
|
|||||||
|
|
||||||
const { votingContract } = useContracts()
|
const { votingContract } = useContracts()
|
||||||
|
|
||||||
|
room = useRoomAggregateVotes(room, showConfirmModal)
|
||||||
|
|
||||||
const finalizeVoting = useContractFunction(votingContract, 'finalizeVotingRoom')
|
const finalizeVoting = useContractFunction(votingContract, 'finalizeVotingRoom')
|
||||||
const community = room.details
|
|
||||||
const setNext = (val: boolean) => {
|
const setNext = (val: boolean) => {
|
||||||
setShowConfirmModal(val)
|
setShowConfirmModal(val)
|
||||||
setShowVoteModal(false)
|
setShowVoteModal(false)
|
||||||
@ -152,7 +155,7 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => {
|
|||||||
return (
|
return (
|
||||||
<CardVoteBlock>
|
<CardVoteBlock>
|
||||||
{showVoteModal && (
|
{showVoteModal && (
|
||||||
<Modal heading={`${vote?.type} ${community.name}?`} setShowModal={setShowVoteModal}>
|
<Modal heading={`${vote?.type} ${room.details.name}?`} setShowModal={setShowVoteModal}>
|
||||||
<VoteModal
|
<VoteModal
|
||||||
vote={vote}
|
vote={vote}
|
||||||
room={room.roomNumber}
|
room={room.roomNumber}
|
||||||
@ -168,7 +171,7 @@ export const CardVote = ({ room, hideModalFunction }: CardVoteProps) => {
|
|||||||
<Modal setShowModal={hideConfirm}>
|
<Modal setShowModal={hideConfirm}>
|
||||||
<VoteAnimatedModal
|
<VoteAnimatedModal
|
||||||
vote={vote}
|
vote={vote}
|
||||||
community={community}
|
community={room.details}
|
||||||
selectedVote={selectedVoted}
|
selectedVote={selectedVoted}
|
||||||
setShowModal={hideConfirm}
|
setShowModal={hideConfirm}
|
||||||
proposingAmount={proposingAmount}
|
proposingAmount={proposingAmount}
|
||||||
|
19
packages/DApp/src/hooks/useRoomAggregateVotes.ts
Normal file
19
packages/DApp/src/hooks/useRoomAggregateVotes.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { DetailedVotingRoom } from '../models/smartContract'
|
||||||
|
import { useVotesAggregate } from './useVotesAggregate'
|
||||||
|
|
||||||
|
export function useRoomAggregateVotes(room: DetailedVotingRoom, showConfirmModal: boolean) {
|
||||||
|
const { votes } = useVotesAggregate(room.roomNumber)
|
||||||
|
if (room.endAt.toNumber() * 1000 > 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user