Skip to content

Commit

Permalink
proposal tally count updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
SrikanthSoparla committed Jan 24, 2024
1 parent d0642cd commit f41aea8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/actions/proposals.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const fetchProposalTally = (id) => (dispatch) => {
},
})
.then((res) => {
dispatch(fetchProposalTallySuccess(res.data && res.data.result, id));
dispatch(fetchProposalTallySuccess(res.data && res.data.tally, id));
})
.catch((error) => {
dispatch(fetchProposalTallyError(
Expand Down
10 changes: 5 additions & 5 deletions src/containers/NavBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class NavBar extends Component {
array.push(val.proposal_id);
}
if (val.status === 2 || val.status === 'PROPOSAL_STATUS_VOTING_PERIOD') {
this.props.fetchProposalTally(val.proposal_id);
this.props.fetchProposalTally(val.id);
}

return null;
Expand All @@ -102,7 +102,7 @@ class NavBar extends Component {
array.push(val.proposal_id);
}
if (val.status === 2 || val.status === 'PROPOSAL_STATUS_VOTING_PERIOD') {
this.props.fetchProposalTally(val.proposal_id);
this.props.fetchProposalTally(val.id);
}

return null;
Expand Down Expand Up @@ -154,7 +154,7 @@ class NavBar extends Component {

if ((val.status === 2 || val.status === 'PROPOSAL_STATUS_VOTING_PERIOD') &&
!votedOption && this.props.address) {
this.props.fetchVoteDetails(val.proposal_id, this.props.address);
this.props.fetchVoteDetails(val.id, this.props.address);
}

return null;
Expand All @@ -177,8 +177,8 @@ class NavBar extends Component {
array.push(val.proposal_id);
}
if (val.status === 2 || val.status === 'PROPOSAL_STATUS_VOTING_PERIOD') {
this.props.fetchProposalTally(val.proposal_id);
this.props.fetchVoteDetails(val.proposal_id, this.props.address);
this.props.fetchProposalTally(val.id);
this.props.fetchVoteDetails(val.id, this.props.address);
}

return null;
Expand Down
20 changes: 15 additions & 5 deletions src/containers/Proposals/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ const Cards = (props) => {
const VoteCalculation = (proposal, val) => {
if (proposal.status === 2 || proposal.status === 'PROPOSAL_STATUS_VOTING_PERIOD') {
const value = props.tallyDetails && props.tallyDetails[proposal.id];
const sum = value && value.yes_count && value.no_count && value.no_with_veto_count && value.abstain_count &&
(parseInt(value.yes_count) + parseInt(value.no_count) + parseInt(value.no_with_veto_count) + parseInt(value.abstain_count));

return (props.tallyDetails && props.tallyDetails[proposal.id] && props.tallyDetails[proposal.id][val]
? tally(props.tallyDetails[proposal.id][val], sum) : '0%');
const sum = value && value.yes && value.no && value.no_with_veto && value.abstain &&
(parseInt(value.yes) + parseInt(value.no) + parseInt(value.no_with_veto) + parseInt(value.abstain));
let val1 = null;
if (val === 'yes_count') {
val1 = 'yes';
} else if (val === 'no_count') {
val1 = 'no';
} else if (val === 'no_with_veto_count') {
val1 = 'no_with_veto';
} else if (val === 'abstain_count') {
val1 = 'abstain';
}

return (props.tallyDetails && props.tallyDetails[proposal.id] && props.tallyDetails[proposal.id][val1]
? tally(props.tallyDetails[proposal.id][val1], sum) : '0%');
} else {
const sum = proposal.final_tally_result && proposal.final_tally_result.yes_count &&
proposal.final_tally_result.no_count && proposal.final_tally_result.no_with_veto_count &&
Expand Down

0 comments on commit f41aea8

Please sign in to comment.