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

Fix incorrectly triggered error toast in voting - Closes #911 #915

Merged
merged 1 commit into from
Oct 25, 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
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 };