Return nay flag from votes (#8805)

* Return nay flag from votes

* Add comments around calcs
This commit is contained in:
Jaco 2023-01-14 22:42:43 +02:00 committed by GitHub
parent 5fe877fd73
commit a4c9706c29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -27,6 +27,7 @@ interface Props {
interface VoterState {
hasVoted: boolean;
hasVotedAye: boolean;
hasVotedNay: boolean;
}
function Motion ({ className = '', isMember, members, motion: { hash, proposal, votes }, prime }: Props): React.ReactElement<Props> | null {
@ -37,15 +38,17 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal,
const { hasVoted, hasVotedAye } = useMemo(
(): VoterState => {
if (votes) {
const hasVotedAye = allAccounts.some((address) => votes.ayes.some((accountId) => accountId.eq(address)));
const hasVotedAye = allAccounts.some((a) => votes.ayes.some((accountId) => accountId.eq(a)));
const hasVotedNay = allAccounts.some((a) => votes.nays.some((accountId) => accountId.eq(a)));
return {
hasVoted: hasVotedAye || allAccounts.some((address) => votes.nays.some((accountId) => accountId.eq(address))),
hasVotedAye
hasVoted: hasVotedAye || hasVotedNay,
hasVotedAye,
hasVotedNay
};
}
return { hasVoted: false, hasVotedAye: false };
return { hasVoted: false, hasVotedAye: false, hasVotedNay: false };
},
[allAccounts, votes]
);

View File

@ -41,7 +41,9 @@ function getStatus (api: ApiPromise, bestNumber: BlockNumber, votes: Votes, numM
}
const isEnd = bestNumber.gte(votes.end);
// let approved = yes_votes >= voting.threshold;
const hasPassed = votes.threshold.lten(votes.ayes.length);
// let disapproved = seats.saturating_sub(no_votes) < voting.threshold;
const hasFailed = votes.threshold.gtn(Math.abs(numMembers - votes.nays.length));
return {