diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 4b6e965b..9011d56d 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -252,23 +252,33 @@ export default class ChainFetch { return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}`) } - async getGovernanceList() { - const url = this.config.chain_name === 'certik' ? '/shentu/gov/v1alpha1/proposals?pagination.limit=500' : '/cosmos/gov/v1beta1/proposals?pagination.limit=500' - return Promise.all([this.get(url), this.get('/staking/pool')]).then(data => { - const pool = new StakingPool().init(commonProcess(data[1])) - let proposals = commonProcess(data[0]) + async getGovernanceListByStatus(status) { + const url = this.config.chain_name === 'certik' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=100&proposal_status=${status}` : `/cosmos/gov/v1beta1/proposals?pagination.limit=100&proposal_status=${status}` + return this.get(url) + } + + async getGovernanceList(next = '') { + const url = this.config.chain_name === 'certik' + ? `/shentu/gov/v1alpha1/proposals?pagination.limit=50&pagination.reverse=true&pagination.key=${next}` + : `/cosmos/gov/v1beta1/proposals?pagination.limit=50&pagination.reverse=true&pagination.key=${next}` + return this.get(url).then(data => { + // const pool = new StakingPool().init(commonProcess(data[1])) + let proposals = commonProcess(data) if (Array.isArray(proposals.proposals)) { proposals = proposals.proposals } const ret = [] if (proposals) { proposals.forEach(e => { - const g = new Proposal().init(e, pool.bondedToken) + const g = new Proposal().init(e, 0) g.versionFixed(this.config.sdk_version) ret.push(g) }) } - return ret + return { + proposals: ret, + pagination: data.pagination, + } }) } diff --git a/src/views/Governance.vue b/src/views/Governance.vue index 945b0c59..e770850a 100644 --- a/src/views/Governance.vue +++ b/src/views/Governance.vue @@ -51,6 +51,14 @@
+
+

+ Type +

+
+ {{ formatType(p.contents['@type']) }} +
+

Start Date @@ -75,14 +83,6 @@ {{ formatToken(p.total_deposit) || '-' }}

-
-

- Turnout -

-
- {{ percent(p.tally.turnout) }}% -
-
@@ -177,6 +177,18 @@ + + + + Load More + + + 0 ? txt.substring(index + 1) : txt + }, percent: v => percent(v), formatDate: v => dayjs(v).format('YYYY-MM-DD'), formatToken: v => tokenFormatter(v, {}), @@ -236,25 +253,31 @@ export default { this.selectedTitle = title }, getList() { - this.$http.getGovernanceList().then(res => { - const voting = res.filter(i => i.status === 2) - if (voting.length > 0) { - let i = 0 - Promise.all(voting.reverse().map(p => this.$http.getGovernanceTally(p.id, p.tally.total))).then(update => { - this.proposals.map(x => { - if (x.status === 2) { - const xh = x - xh.tally = update[i] - i += 1 - return xh - } - return x - }) - }) - } - this.proposals = res.reverse() + this.loading = true + this.$http.getGovernanceList(this.next).then(res => { + this.proposals = this.proposals.concat(res.proposals) + this.updateTally(this.proposals) + this.next = res.pagination.next_key + this.loading = false }) }, + updateTally(res) { + const voting = res.filter(i => i.status === 2) + if (voting.length > 0) { + let i = 0 + Promise.all(voting.reverse().map(p => this.$http.getGovernanceTally(p.id, 0))).then(update => { + this.proposals.map(x => { + if (x.status === 2) { + const xh = x + xh.tally = update[i] + i += 1 + return xh + } + return x + }) + }) + } + }, }, }