From 04e152c1fbbe387f6ecb7d1c1cc179c794ec9f3d Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Tue, 14 Dec 2021 15:18:41 +0800 Subject: [PATCH] add upgrade count down --- package.json | 1 + src/lang/locales/en.json | 1 + src/views/GovernanceProposalView.vue | 29 +++++++++++++++++++++++++++- yarn.lock | 7 +++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d1d43a86..9bde2a07 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "vue-toastification": "1.7.8", "vue-tour": "1.5.0", "vue-tree-halower": "1.8.3", + "vue2-flip-countdown": "^0.12.1", "vue2-leaflet": "2.5.2", "vuedraggable": "2.24.3", "vuex": "3.6.0" diff --git a/src/lang/locales/en.json b/src/lang/locales/en.json index 564235a7..50fe6739 100644 --- a/src/lang/locales/en.json +++ b/src/lang/locales/en.json @@ -53,6 +53,7 @@ "proposal_content": "Content", "proposal_total_deposit": "Total Deposit", "voting_time": "Voting Time", + "upgrade_time": "Estimated Upgrade Time:", "btn_vote": "Vote", "btn_deposit": "Deposit", diff --git a/src/views/GovernanceProposalView.vue b/src/views/GovernanceProposalView.vue index 94c921cd..47aed3ec 100644 --- a/src/views/GovernanceProposalView.vue +++ b/src/views/GovernanceProposalView.vue @@ -77,6 +77,11 @@ {{ $t('voting_time') }} {{ proposal.voting_start_time }} - {{ proposal.voting_end_time }} + + + {{ $t('upgrade_time') }} + + {{ $t('proposal_type') }} @@ -257,10 +262,12 @@ import { BCard, BCardBody, BCardFooter, BButton, BTable, BTableSimple, BTr, BTd, BCardTitle, BCardHeader, BProgressBar, BProgress, BTooltip, BBadge, } from 'bootstrap-vue' +import FlipCountdown from 'vue2-flip-countdown' // import fetch from 'node-fetch' import { getCachedValidators, getStakingValidatorByAccount, tokenFormatter } from '@/libs/data/data' import { Proposal, Proposer } from '@/libs/data' +import dayjs from 'dayjs' import ObjectFieldComponent from './ObjectFieldComponent.vue' import OperationVoteComponent from './OperationVoteComponent.vue' import OperationGovDepositComponent from './OperationGovDepositComponent.vue' @@ -285,9 +292,11 @@ export default { ObjectFieldComponent, OperationVoteComponent, OperationGovDepositComponent, + FlipCountdown, }, data() { return { + latest: {}, next: null, proposal: new Proposal(), proposer: new Proposer(), @@ -335,10 +344,28 @@ export default { ], } }, - + computed: { + upgradeTime() { + if (this.proposal.type === 'cosmos-sdk/SoftwareUpgradeProposal') { + if (Number(this.proposal?.contents.plan.height || 0) > 0 && this.latest) { + const blocks = Number(this.proposal.contents.plan.height) - Number(this.latest.block?.header?.height || 0) + if (blocks > 0) { + const endtime = dayjs().add(blocks * 6, 'second').format('YYYY-MM-DD HH:mm:ss') + return endtime + } + } + return dayjs(this.proposal.contents.plan.time).format('YYYY-MM-DD HH:mm:ss') + } + return '0001-01-01 00:00:00' + }, + }, created() { const pid = this.$route.params.proposalid + this.$http.getLatestBlock().then(res => { + this.latest = res + }) + this.$http.getGovernance(pid).then(p => { if (p.status === 2) { this.$http.getGovernanceTally(pid, 0).then(t => p.updateTally(t)) diff --git a/yarn.lock b/yarn.lock index 53f6977c..a5573350 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11896,6 +11896,13 @@ vue-tree-halower@1.8.3: dependencies: vue "^2.4.4" +vue2-flip-countdown@^0.12.1: + version "0.12.1" + resolved "https://registry.yarnpkg.com/vue2-flip-countdown/-/vue2-flip-countdown-0.12.1.tgz#67d115634df1fbcf789be07e2674b1a6aefb4e7f" + integrity sha512-kS3A86VMUjsG2FGnqv/AO4UTLKAAwutqh1dOTPfjSRiUfsgLO+9gmhLSeo+qSBoQYpCxccq44G/IsoRef8kywQ== + dependencies: + uuid "^3.3.2" + vue2-leaflet@2.5.2: version "2.5.2" resolved "https://registry.npmjs.org/vue2-leaflet/-/vue2-leaflet-2.5.2.tgz"