compatible to 0.46.6

This commit is contained in:
liangping 2022-11-25 09:31:34 +08:00
parent 851f7c174e
commit 91c779a7e4
4 changed files with 49 additions and 36 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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)) {

View File

@ -42,6 +42,11 @@
</b-card-title>
</b-card-header>
<b-card-body>
<div>
<object-field-component
:tablefield="proposal.contents"
:small="false"
/></div>
<b-table-simple
stacked="sm"
hover
@ -50,13 +55,6 @@
<tbody>
<b-tr>
<b-td style="text-transform: capitalize; vertical-align: top; width:200px">
{{ $t('proposal_proposer') }}
</b-td><b-td><router-link :to="`../account/${proposer.proposer}`">
{{ formatAddress(proposer.proposer) }}
</router-link> </b-td>
</b-tr>
<b-tr>
<b-td>
{{ $t('proposal_total_deposit') }}
</b-td><b-td>{{ formatToken(proposal.total_deposit) }} </b-td>
</b-tr>
@ -70,13 +68,13 @@
{{ $t('voting_time') }}
</b-td><b-td>{{ formatDate(proposal.voting_start_time) }} - {{ formatDate(proposal.voting_end_time) }}</b-td>
</b-tr>
<b-tr>
<b-td>
Metadata
</b-td><b-td>{{ proposal.metadata }}</b-td>
</b-tr>
</tbody>
</b-table-simple>
<div>
<object-field-component
:tablefield="proposal.contents"
:small="false"
/></div>
<b-table-simple v-if="proposal.type.indexOf('SoftwareUpgrade') > 0">
<b-tr>
<b-td class="text-center">
@ -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(() => {})