From ad220615776ee58f31d09a14f5744c2b380b8730 Mon Sep 17 00:00:00 2001 From: SrikanthSoparla Date: Thu, 1 Feb 2024 21:05:32 +0530 Subject: [PATCH] proposal id, tally calculation fixes. --- src/actions/proposals.js | 2 +- src/containers/NavBar/index.js | 10 +++---- src/containers/Proposals/Cards.js | 26 +++++++++++++------ .../Proposals/ProposalDialog/index.js | 18 ++++++++++--- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/actions/proposals.js b/src/actions/proposals.js index 947e36a..9ca2d02 100644 --- a/src/actions/proposals.js +++ b/src/actions/proposals.js @@ -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( diff --git a/src/containers/NavBar/index.js b/src/containers/NavBar/index.js index 38c11f9..d7e73f5 100644 --- a/src/containers/NavBar/index.js +++ b/src/containers/NavBar/index.js @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/src/containers/Proposals/Cards.js b/src/containers/Proposals/Cards.js index 948b899..5f9bb91 100644 --- a/src/containers/Proposals/Cards.js +++ b/src/containers/Proposals/Cards.js @@ -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 && @@ -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); }; @@ -91,7 +101,7 @@ const Cards = (props) => { className="card" onClick={() => handleProposal(proposal)}> - {proposal.proposal_id} + {proposal.id}

props.handleShow(proposal)}> { diff --git a/src/containers/Proposals/ProposalDialog/index.js b/src/containers/Proposals/ProposalDialog/index.js index 095fbd4..4aba443 100644 --- a/src/containers/Proposals/ProposalDialog/index.js +++ b/src/containers/Proposals/ProposalDialog/index.js @@ -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 &&