From 91c779a7e4cb7ca07bc5b3b23213921934d23d38 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 25 Nov 2022 09:31:34 +0800 Subject: [PATCH] compatible to 0.46.6 --- src/libs/data/proposal-tally.js | 10 ++++----- src/libs/data/proposal.js | 13 ++++++----- src/libs/fetch.js | 33 +++++++++++++++++++--------- src/views/GovernanceProposalView.vue | 29 +++++++++++------------- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/libs/data/proposal-tally.js b/src/libs/data/proposal-tally.js index 0bbb0b44..578436c7 100644 --- a/src/libs/data/proposal-tally.js +++ b/src/libs/data/proposal-tally.js @@ -9,16 +9,16 @@ export default class ProposalTally { } init(element, total) { - const subtotal = Number(element.yes) + Number(element.no) + Number(element.abstain) + Number(element.no_with_veto) + const subtotal = Number(element.yes || element.yes_count) + Number(element.no || element.no_count) + Number(element.abstain || element.abstain_count) + Number(element.no_with_veto || element.no_with_veto_count) if (total < 1) { this.total = subtotal + 1 } else { this.total = total } - this.yes = Number(element.yes) / this.total - this.no = Number(element.no) / this.total - this.veto = Number(element.no_with_veto) / this.total - this.abstain = Number(element.abstain) / this.total + this.yes = Number(element.yes || element.yes_count) / this.total + this.no = Number(element.no || element.no_count) / this.total + this.veto = Number(element.no_with_veto || element.no_with_veto_count) / this.total + this.abstain = Number(element.abstain || element.abstain_count) / this.total this.turnout = subtotal / this.total return this } diff --git a/src/libs/data/proposal.js b/src/libs/data/proposal.js index 6efe3cfc..056007a7 100644 --- a/src/libs/data/proposal.js +++ b/src/libs/data/proposal.js @@ -16,6 +16,7 @@ export default class Proposal { this.voting_start_time = '0000-00-00' this.total_deposit = '-' this.contents = null + this.metadata = {} } init(element, total) { @@ -29,15 +30,12 @@ export default class Proposal { this.voting_start_time = element.voting_start_time // eslint-disable-next-line prefer-destructuring this.total_deposit = element.total_deposit[0] - this.contents = element.content.value || element.content + if (element.content) this.contents = element.content.value || element.content if (this.contents) { this.title = this.contents.title this.description = this.contents.description - this.type = element.content.type - if (element.content['@type']) { - this.type = element.content['@type'] - } } + this.metadata = element.metadata return this } @@ -51,6 +49,11 @@ export default class Proposal { versionFixed(ver) { if (compareVersions(ver, '0.46') >= 0) { + [this.contents] = this.element.messages + if (this.contents['@type'] === '/cosmos.gov.v1.MsgExecLegacyContent') { + this.title = this.contents.content.title + this.description = this.contents.content.description + } if (this.element.metadata) { this.title = this.element.metadata.title || this.element.metadata this.description = this.element.metadata.description || this.element.metadata diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 16bc1de5..979b8fe6 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -281,19 +281,23 @@ export default class ChainFetch { } async getGovernanceParameterDeposit() { - return this.get('/cosmos/gov/v1beta1/params/deposit').then(data => commonProcess(data.deposit_params)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/params/deposit`).then(data => commonProcess(data.deposit_params)) } async getGovernanceParameterTallying() { - return this.get('/cosmos/gov/v1beta1/params/tallying').then(data => commonProcess(data.tally_params)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/params/tallying`).then(data => commonProcess(data.tally_params)) } async getGovernanceParameterVoting() { - return this.get('/cosmos/gov/v1beta1/params/voting').then(data => commonProcess(data.voting_params)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/params/voting`).then(data => commonProcess(data.voting_params)) } async getGovernanceTally(pid, total, conf) { - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/tally`, conf).then(data => new ProposalTally().init(commonProcess(data).tally, total)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}/tally`, conf).then(data => new ProposalTally().init(commonProcess(data).tally, total)) } getGovernance(pid) { @@ -303,7 +307,9 @@ export default class ChainFetch { return p }) } - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}`).then(data => { + + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}`).then(data => { const p = new Proposal().init(commonProcess(data).proposal, 0) p.versionFixed(this.config.sdk_version) return p @@ -324,7 +330,9 @@ export default class ChainFetch { return Array.isArray(result) ? result.reverse().map(d => new Deposit().init(d)) : result }) } - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/deposits`).then(data => { + + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}/deposits`).then(data => { const result = commonProcess(data) return Array.isArray(result) ? result.reverse().map(d => new Deposit().init(d)) : result }) @@ -340,12 +348,15 @@ export default class ChainFetch { if (this.config.chain_name === 'shentu') { return this.get(`/shentu/gov/v1alpha1/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}&pagination.reverse=true`) } - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}&pagination.reverse=true`) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}&pagination.reverse=true`) } async getGovernanceListByStatus(status, chain = null) { const conf = chain || this.config - const url = conf.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=100&proposal_status=${status}` : `/cosmos/gov/v1beta1/proposals?pagination.limit=100&proposal_status=${status}` + + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + const url = conf.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=100&proposal_status=${status}` : `/cosmos/gov/${ver}/proposals?pagination.limit=100&proposal_status=${status}` return this.get(url, conf).then(data => { let proposals = commonProcess(data) if (Array.isArray(proposals.proposals)) { @@ -367,9 +378,10 @@ export default class ChainFetch { } async getGovernanceProposalVote(pid, voter, chain) { + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' const url = this.config.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals/${pid}/votes/${voter}` - : `/cosmos/gov/v1beta1/proposals/${pid}/votes/${voter}` + : `/cosmos/gov/${ver}/proposals/${pid}/votes/${voter}` return this.get(url, chain).then(data => { if (data.code === 3) { throw new Error('not found') @@ -385,9 +397,10 @@ export default class ChainFetch { async getGovernanceList(next = '', chain = null) { const key = next || '' + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' const url = this.config.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=20&pagination.reverse=true&pagination.key=${key}` - : `/cosmos/gov/v1beta1/proposals?pagination.limit=20&pagination.reverse=true&pagination.key=${key}` + : `/cosmos/gov/${ver}/proposals?pagination.limit=20&pagination.reverse=true&pagination.key=${key}` return this.get(url, chain).then(data => { let proposals = commonProcess(data) if (Array.isArray(proposals.proposals)) { diff --git a/src/views/GovernanceProposalView.vue b/src/views/GovernanceProposalView.vue index ead05968..d0807b78 100644 --- a/src/views/GovernanceProposalView.vue +++ b/src/views/GovernanceProposalView.vue @@ -42,6 +42,11 @@ +
+
- {{ $t('proposal_proposer') }} - - {{ formatAddress(proposer.proposer) }} - - - - {{ $t('proposal_total_deposit') }} {{ formatToken(proposal.total_deposit) }} @@ -70,13 +68,13 @@ {{ $t('voting_time') }} {{ formatDate(proposal.voting_start_time) }} - {{ formatDate(proposal.voting_end_time) }} + + + Metadata + {{ proposal.metadata }} + -
-
@@ -395,10 +393,9 @@ export default { if (!getCachedValidators()) { this.$http.getValidatorList() } - - this.$http.getGovernanceProposer(pid).then(res => { - this.proposer = res - }) + // this.$http.getGovernanceProposer(pid).then(res => { + // this.proposer = res + // }) this.$http.getGovernanceDeposits(pid).then(res => { this.deposits = res }).catch(() => {})