From 5e149684d90f0515f3f77f87e2abadd9a5b6a7bc Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 27 Oct 2017 13:51:22 +0200 Subject: [PATCH] Fix vote count computation for vote button disable - Closes #932 --- src/components/voteDialog/voteDialog.js | 14 +++++--------- src/utils/voting.js | 6 +++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/voteDialog/voteDialog.js b/src/components/voteDialog/voteDialog.js index 8420226a4..2426210c3 100644 --- a/src/components/voteDialog/voteDialog.js +++ b/src/components/voteDialog/voteDialog.js @@ -8,6 +8,7 @@ import InfoParagraph from '../infoParagraph'; import VoteUrlProcessor from '../voteUrlProcessor'; import styles from './voteDialog.css'; import votingConst from '../../constants/voting'; +import { getTotalVotesCount, getNewVotesCount } from '../../utils/voting'; const { maxCountOfVotes, maxCountOfVotesInOneTurn } = votingConst; @@ -43,12 +44,7 @@ export default class VoteDialog extends React.Component { render() { const { votes } = this.props; - let totalVotes = 0; - const votesList = []; - Object.keys(votes).forEach((item) => { - if (votes[item].confirmed || votes[item].unconfirmed) totalVotes++; - if (votes[item].confirmed !== votes[item].unconfirmed) votesList.push(item); - }); + const countOfVotesInOneTurn = getNewVotesCount(votes); return (
@@ -83,9 +79,9 @@ export default class VoteDialog extends React.Component { fee: Fees.vote, type: 'button', disabled: ( - totalVotes > maxCountOfVotes || - votesList.length === 0 || - votesList.length > maxCountOfVotesInOneTurn || + getTotalVotesCount(votes) > maxCountOfVotes || + countOfVotesInOneTurn === 0 || + countOfVotesInOneTurn > maxCountOfVotesInOneTurn || !authStateIsValid(this.state) ), }} /> diff --git a/src/utils/voting.js b/src/utils/voting.js index 771f3439a..c40bfdf1c 100644 --- a/src/utils/voting.js +++ b/src/utils/voting.js @@ -10,4 +10,8 @@ const getVoteList = votes => (Object.keys(votes).filter( const getTotalVotesCount = votes => ((getVotedList(votes).length - getUnvoteList(votes).length) + getVoteList(votes).length); -export { getTotalVotesCount, getVotedList, getVoteList, getUnvoteList }; +const getNewVotesCount = votes => (Object.keys(votes).filter( + key => ((votes[key].confirmed !== votes[key].unconfirmed)), +)).length; + +export { getNewVotesCount, getTotalVotesCount, getVotedList, getVoteList, getUnvoteList };