-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix votes breakdown visualization for weighted voting
- Loading branch information
Showing
9 changed files
with
132 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 5 additions & 11 deletions
16
src/components/Proposals/SnapshotProposalDetails/hooks/useTotalVotes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { useState, useEffect } from 'react'; | ||
import useSnapshotProposal from '../../../../hooks/DAO/loaders/snapshot/useSnapshotProposal'; | ||
import { ExtendedSnapshotProposal } from '../../../../types'; | ||
|
||
export default function useTotalVotes({ proposal }: { proposal?: ExtendedSnapshotProposal }) { | ||
const [totalVotesCasted, setTotalVotesCasted] = useState(0); | ||
const { getVoteWeight } = useSnapshotProposal(proposal); | ||
|
||
useEffect(() => { | ||
if (proposal) { | ||
let newTotalVotesCasted = 0; | ||
if (proposal.votesBreakdown) { | ||
Object.keys(proposal.votesBreakdown).forEach(voteChoice => { | ||
const voteChoiceBreakdown = proposal.votesBreakdown[voteChoice]; | ||
newTotalVotesCasted += voteChoiceBreakdown.total; | ||
}); | ||
|
||
if (newTotalVotesCasted !== totalVotesCasted) { | ||
setTotalVotesCasted(newTotalVotesCasted); | ||
} | ||
} | ||
proposal.votes.forEach(vote => (newTotalVotesCasted += getVoteWeight(vote))); | ||
setTotalVotesCasted(newTotalVotesCasted); | ||
} | ||
}, [proposal, totalVotesCasted]); | ||
}, [proposal, totalVotesCasted, getVoteWeight]); | ||
|
||
return { totalVotesCasted }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters