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

Commit

Permalink
Merge pull request #915 from LiskHQ/911-vote-limit-error-toast
Browse files Browse the repository at this point in the history
Fix incorrectly triggered error toast in voting - Closes #911
  • Loading branch information
gina contrino authored Oct 25, 2017
2 parents d69cc1c + 68f37f0 commit e11bd70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/components/voting/votingBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import grid from 'flexboxgrid/dist/flexboxgrid.css';

import style from './votingBar.css';
import votingConst from '../../constants/voting';
import { getTotalVotesCount, getVoteList, getUnvoteList } from './../../utils/voting';

const VotingBar = ({ votes, t }) => {
const { maxCountOfVotes, maxCountOfVotesInOneTurn } = votingConst;
const votedList = Object.keys(votes).filter(key => votes[key].confirmed);
const voteList = Object.keys(votes).filter(
key => votes[key].unconfirmed && !votes[key].confirmed);
const unvoteList = Object.keys(votes).filter(
key => !votes[key].unconfirmed && votes[key].confirmed);
const totalVotesCount = (votedList.length - unvoteList.length) + voteList.length;
const voteList = getVoteList(votes);
const unvoteList = getUnvoteList(votes);
const totalVotesCount = getTotalVotesCount(votes);
const totalNewVotesCount = voteList.length + unvoteList.length;

return (voteList.length + unvoteList.length ?
Expand Down
4 changes: 2 additions & 2 deletions src/store/middlewares/voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDelegate } from '../../utils/api/delegate';
import { voteLookupStatusUpdated, voteToggled } from '../../actions/voting';
import actionTypes from '../../constants/actions';
import votingConst from '../../constants/voting';
import { getTotalVotesCount } from './../../utils/voting';

const updateLookupStatus = (store, list, username) => {
store.dispatch(voteLookupStatusUpdated({
Expand Down Expand Up @@ -68,8 +69,7 @@ const checkVoteLimits = (store, action) => {
store.dispatch(newAction);
}

const voteCount = Object.keys(votes).filter(
key => (votes[key].confirmed && !votes[key].unconfirmed) || votes[key].unconfirmed).length;
const voteCount = getTotalVotesCount(votes);
if (voteCount === votingConst.maxCountOfVotes + 1 &&
currentVote.unconfirmed !== currentVote.confirmed) {
const label = i18next.t('Maximum of {{n}} votes exceeded.', { n: votingConst.maxCountOfVotes });
Expand Down
13 changes: 13 additions & 0 deletions src/utils/voting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

const getVotedList = votes => (Object.keys(votes).filter(key => votes[key].confirmed));

const getUnvoteList = votes => (Object.keys(votes).filter(
key => !votes[key].unconfirmed && votes[key].confirmed));

const getVoteList = votes => (Object.keys(votes).filter(
key => votes[key].unconfirmed && !votes[key].confirmed));

const getTotalVotesCount = votes => ((getVotedList(votes).length - getUnvoteList(votes).length)
+ getVoteList(votes).length);

export { getTotalVotesCount, getVotedList, getVoteList, getUnvoteList };

0 comments on commit e11bd70

Please sign in to comment.