Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Fix vote count computation for vote button disable - Closes #932 #933

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/components/voteDialog/voteDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 (
<article>
<form id='voteform'>
Expand Down Expand Up @@ -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)
),
}} />
Expand Down
6 changes: 5 additions & 1 deletion src/utils/voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };