Skip to content

Commit

Permalink
proposal id, tally calculation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SrikanthSoparla committed Feb 1, 2024
1 parent dad9276 commit ad22061
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 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 @@ -81,7 +81,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 @@ -104,7 +104,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 @@ -174,7 +174,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 @@ -197,8 +197,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
26 changes: 18 additions & 8 deletions src/containers/Proposals/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ const Cards = (props) => {

const VoteCalculation = (proposal, val) => {
if (proposal.status === 2 || proposal.status === 'PROPOSAL_STATUS_VOTING_PERIOD') {
const value = props.tallyDetails && props.tallyDetails[proposal.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.proposal_id] && props.tallyDetails[proposal.proposal_id][val]
? tally(props.tallyDetails[proposal.proposal_id][val], sum) : '0%');
const value = props.tallyDetails && props.tallyDetails[proposal.id];
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 All @@ -51,7 +61,7 @@ const Cards = (props) => {
};

const handleProposal = (proposal) => {
props.history.push(`/proposals/${proposal.proposal_id}`);
props.history.push(`/proposals/${proposal.id}`);
props.handleShow(proposal);
};

Expand Down Expand Up @@ -91,7 +101,7 @@ const Cards = (props) => {
className="card"
onClick={() => handleProposal(proposal)}>
<span className="number">
{proposal.proposal_id}
{proposal.id}
</span>
<div className="card_heading">
<h2 onClick={() => props.handleShow(proposal)}> {
Expand Down
18 changes: 14 additions & 4 deletions src/containers/Proposals/ProposalDialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,21 @@ class ProposalDialog extends Component {

if (proposal && (proposal.status === 2 || proposal.status === 'PROPOSAL_STATUS_VOTING_PERIOD')) {
const value = this.props.tallyDetails && this.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));
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 (this.props.tallyDetails && this.props.tallyDetails[proposal.id] && this.props.tallyDetails[proposal.id][val]
? tally(this.props.tallyDetails[proposal.id][val], sum) : '0%');
return (this.props.tallyDetails && this.props.tallyDetails[proposal.id] && this.props.tallyDetails[proposal.id][val1]
? tally(this.props.tallyDetails[proposal.id][val1], sum) : '0%');
} else {
const sum = proposal && 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 ad22061

Please sign in to comment.