Skip to content

Commit

Permalink
proposal api updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
SrikanthSoparla committed May 16, 2024
1 parent 9aed2e8 commit 7dd4202
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/constants/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const urlFetchVoteDetails = (proposalId, address) => `${REST_URL}/cosmos/

export const VALIDATORS_LIST_URL = `${REST_URL}/cosmos/staking/v1beta1/validators?pagination.limit=1000`;
export const getValidatorURL = (address) => `${REST_URL}/cosmos/staking/v1beta1/validators/${address}`;
export const PROPOSALS_LIST_URL = `${REST_URL}/cosmos/gov/v1beta1/proposals?pagination.limit=1000`;
export const PROPOSALS_LIST_URL = `${REST_URL}/cosmos/gov/v1/proposals?pagination.limit=1000`;
export const INACTIVE_VALIDATORS_URL = `${REST_URL}/cosmos/staking/v1beta1/validators?pagination.limit=1000&status=BOND_STATUS_UNBONDED`;
export const INACTIVE_VALIDATORS_UNBONDING_URL = `${REST_URL}/cosmos/staking/v1beta1/validators?pagination.limit=1000&status=BOND_STATUS_UNBONDING`;
export const getDelegatedValidatorsURL = (address) => `${REST_URL}/cosmos/staking/v1beta1/delegators/${address}/validators`;
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
64 changes: 30 additions & 34 deletions src/containers/Proposals/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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 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;
Expand All @@ -45,33 +45,24 @@ const Cards = (props) => {
val1 = 'abstain';
}

return (props.tallyDetails && props.tallyDetails[proposal.proposal_id] && props.tallyDetails[proposal.proposal_id][val1]
? tally(props.tallyDetails[proposal.proposal_id][val1], sum) : '0%');
console.log('55555', sum, val, val1, value, props.tallyDetails, proposal.id);
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 &&
proposal.final_tally_result.no && proposal.final_tally_result.no_with_veto &&
proposal.final_tally_result.abstain &&
(parseInt(proposal.final_tally_result.yes) + parseInt(proposal.final_tally_result.no) +
parseInt(proposal.final_tally_result.no_with_veto) + parseInt(proposal.final_tally_result.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';
}
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 &&
proposal.final_tally_result.abstain_count &&
(parseInt(proposal.final_tally_result.yes_count) + parseInt(proposal.final_tally_result.no_count) +
parseInt(proposal.final_tally_result.no_with_veto_count) + parseInt(proposal.final_tally_result.abstain_count));

return (proposal && proposal.final_tally_result &&
proposal.final_tally_result[val1]
? tally(proposal.final_tally_result[val1], sum) : '0%');
proposal.final_tally_result[val]
? tally(proposal.final_tally_result[val], sum) : '0%');
}
};

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

Expand All @@ -82,22 +73,23 @@ const Cards = (props) => {
reversedItems.map((proposal, index) => {
if (index < (page * rowsPerPage) && index >= (page - 1) * rowsPerPage) {
let votedOption = props.voteDetails && props.voteDetails.length &&
proposal && proposal.proposal_id &&
props.voteDetails.filter((vote) => vote && (vote.proposal_id === proposal.proposal_id))[0];
proposal && proposal.id &&
props.voteDetails.filter((vote) => vote && vote.proposal_id === proposal.id)[0];
if (votedOption && votedOption.options && votedOption.options.length && votedOption.options[0]) {
votedOption = votedOption.options[0];
}
let proposer = proposal.proposer;
props.proposalDetails && Object.keys(props.proposalDetails).length &&
Object.keys(props.proposalDetails).filter((key) => {
if (key === proposal.proposal_id) {
if (key === proposal.id) {
if (props.proposalDetails[key] &&
props.proposalDetails[key][0] &&
props.proposalDetails[key][0].body &&
props.proposalDetails[key][0].body.messages &&
props.proposalDetails[key][0].body.messages.length &&
props.proposalDetails[key][0].body.messages[0].proposer) {
proposer = props.proposalDetails[key][0].body.messages[0].proposer;
props.proposalDetails[key][0].tx &&
props.proposalDetails[key][0].tx.value &&
props.proposalDetails[key][0].tx.value.msg[0] &&
props.proposalDetails[key][0].tx.value.msg[0].value &&
props.proposalDetails[key][0].tx.value.msg[0].value.proposer) {
proposer = props.proposalDetails[key][0].tx.value.msg[0].value.proposer;
}
}

Expand All @@ -107,17 +99,19 @@ const Cards = (props) => {
Object.keys(props.proposalDetails).find((key) => key === proposal.proposal_id);
inProgress = !inProgress && props.proposalDetailsInProgress;

const content = proposal && proposal.messages && proposal.messages[0] && proposal.messages[0].content;

return (
<div
key={index}
className="card"
onClick={() => handleProposal(proposal)}>
<span className="number">
{proposal.proposal_id}
{proposal.id}
</span>
<div className="card_heading">
<h2 onClick={() => props.handleShow(proposal)}> {
proposal.title || (proposal.content && proposal.content.title)
proposal.title || (content && content.title)
}</h2>
{proposal.status === 3 || proposal.status === 'PROPOSAL_STATUS_PASSED'
? <Icon className="success" icon="success"/>
Expand Down Expand Up @@ -146,7 +140,7 @@ const Cards = (props) => {
</Button>
: null}
</div>
<p className="description">{proposal.summary || (proposal.content && proposal.content.description)}</p>
<p className="description">{proposal.summary || (content && content.description)}</p>
<div className="row">
<div className="icon_info">
<Icon className="person" icon="person"/>
Expand Down Expand Up @@ -179,7 +173,9 @@ const Cards = (props) => {
proposal.status === 'PROPOSAL_STATUS_VOTING_PERIOD')
? 'voting_period'
: (proposal.status === 4 ||
proposal.status === 'PROPOSAL_STATUS_REJECTED' || proposal.status === 'PROPOSAL_STATUS_FAILED')
proposal.status === 5 ||
proposal.status === 'PROPOSAL_STATUS_FAILED' ||
proposal.status === 'PROPOSAL_STATUS_REJECTED')
? 'rejected'
: null)}>
<p>Proposal Status: {
Expand All @@ -190,7 +186,7 @@ const Cards = (props) => {
: proposal.status === 2 ||
proposal.status === 'PROPOSAL_STATUS_VOTING_PERIOD' ? 'VotingPeriod'
: proposal.status === 3 ||
proposal.status === 'PROPOSAL_STATUS_PASSED' ? 'Passed'
proposal.status === 'PROPOSAL_STATUS_PASSED' ? 'Passed'
: proposal.status === 4 ||
proposal.status === 'PROPOSAL_STATUS_REJECTED' ? 'Rejected'
: proposal.status === 5 ||
Expand Down
Loading

0 comments on commit 7dd4202

Please sign in to comment.