Update gov module

This commit is contained in:
liangping 2021-12-22 16:55:58 +08:00
parent 4ea72891e5
commit 7d9618653c
5 changed files with 54 additions and 48 deletions

View File

@ -1,5 +1,3 @@
import { percent } from '../utils'
export default class ProposalTally {
constructor() {
this.total = 0
@ -17,11 +15,11 @@ export default class ProposalTally {
} else {
this.total = total
}
this.yes = percent(Number(element.yes) / this.total)
this.no = percent(Number(element.no) / this.total)
this.veto = percent(Number(element.no_with_veto) / this.total)
this.abstain = percent(Number(element.abstain) / this.total)
this.turnout = percent(subtotal / this.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.turnout = subtotal / this.total
return this
}

View File

@ -1,5 +1,4 @@
import compareVersions from 'compare-versions'
import { toDay, formatToken } from '../utils'
import ProposalTally from './proposal-tally'
export default class Proposal {
@ -28,10 +27,11 @@ export default class Proposal {
this.title = element.content.value.title
this.description = element.content.value.description
this.tally = new ProposalTally().init(element.final_tally_result, total)
this.submit_time = toDay(element.submit_time, 'date')
this.voting_end_time = toDay(element.voting_end_time, 'date')
this.voting_start_time = toDay(element.voting_start_time, 'date')
this.total_deposit = formatToken(element.total_deposit[0])
this.submit_time = element.submit_time
this.voting_end_time = element.voting_end_time
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
return this
}

View File

@ -1,5 +1,3 @@
import { percent } from '../utils'
export default class StakingPool {
constructor() {
this.element = null
@ -19,6 +17,6 @@ export default class StakingPool {
}
bondedRatio() {
return percent((this.bondedToken * 100) / this.total())
return (this.bondedToken * 100) / this.total()
}
}

View File

@ -56,7 +56,7 @@
Start Date
</p>
<h6 class="mb-0">
{{ p.voting_start_time }}
{{ formatDate(p.voting_start_time) }}
</h6>
</div>
<div class="gov">
@ -64,7 +64,7 @@
End Date
</p>
<h6 class="mb-0">
{{ p.voting_end_time }}
{{ formatDate(p.voting_end_time) }}
</h6>
</div>
<div class="gov">
@ -72,7 +72,7 @@
Deposit
</p>
<h6 class="mb-0">
{{ p.total_deposit || '-' }}
{{ formatToken(p.total_deposit) || '-' }}
</h6>
</div>
<div class="gov">
@ -80,7 +80,7 @@
Turnout
</p>
<h6 class="mb-0">
{{ p.tally.turnout }}%
{{ percent(p.tally.turnout) }}%
</h6>
</div>
</div>
@ -95,51 +95,51 @@
<b-progress-bar
:id="'vote-yes'+p.id"
variant="success"
:value="p.tally.yes"
:value="percent(p.tally.yes)"
show-progress
:label="`${p.tally.yes.toFixed()}%`"
:label="`${percent(p.tally.yes).toFixed()}%`"
/>
<b-progress-bar
:id="'vote-no'+p.id"
variant="warning"
:value="p.tally.no"
:label="`${p.tally.no.toFixed()}%`"
:value="percent(p.tally.no)"
:label="`${percent(p.tally.no).toFixed()}%`"
show-progress
/>
<b-progress-bar
:id="'vote-veto'+p.id"
variant="danger"
:value="p.tally.veto"
:label="`${p.tally.veto.toFixed()}%`"
:value="percent(p.tally.veto)"
:label="`${percent(p.tally.veto).toFixed()}%`"
show-progress
/>
<b-progress-bar
:id="'vote-abstain'+p.id"
variant="info"
:value="p.tally.abstain"
:label="`${p.tally.abstain.toFixed()}%`"
:value="percent(p.tally.abstain)"
:label="`${percent(p.tally.abstain).toFixed()}%`"
show-progress
/>
</b-progress>
<b-tooltip
:target="'vote-yes'+p.id"
>
{{ p.tally.yes }}% voted Yes
{{ percent(p.tally.yes) }}% voted Yes
</b-tooltip>
<b-tooltip
:target="'vote-no'+p.id"
>
{{ p.tally.no }}% voted No
{{ percent(p.tally.no) }}% voted No
</b-tooltip>
<b-tooltip
:target="'vote-veto'+p.id"
>
{{ p.tally.veto }}% voted No With Veta
{{ percent(p.tally.veto) }}% voted No With Veta
</b-tooltip>
<b-tooltip
:target="'vote-abstain'+p.id"
>
{{ p.tally.abstain }}% voted Abstain
{{ percent(p.tally.abstain) }}% voted Abstain
</b-tooltip>
<b-card-footer class="pb-0">
<router-link
@ -194,6 +194,8 @@ import {
} from 'bootstrap-vue'
import Ripple from 'vue-ripple-directive'
import { Proposal } from '@/libs/data'
import { percent, tokenFormatter } from '@/libs/utils'
import dayjs from 'dayjs'
import OperationVoteComponent from './OperationVoteComponent.vue'
import OperationGovDepositComponent from './OperationGovDepositComponent.vue'
@ -229,6 +231,9 @@ export default {
this.getList()
},
methods: {
percent: v => percent(v),
formatDate: v => dayjs(v).format('YYYY-MM-DD'),
formatToken: v => tokenFormatter(v, {}),
selectProposal(pid, title) {
this.selectedProposalId = Number(pid)
this.selectedTitle = title

View File

@ -65,17 +65,17 @@
<b-tr>
<b-td>
{{ $t('proposal_total_deposit') }}
</b-td><b-td>{{ proposal.total_deposit }} </b-td>
</b-td><b-td>{{ formatToken(proposal.total_deposit) }} </b-td>
</b-tr>
<b-tr>
<b-td>
{{ $t('proposal_submit_time') }}
</b-td><b-td>{{ proposal.submit_time }}</b-td>
</b-td><b-td>{{ formatDate(proposal.submit_time) }}</b-td>
</b-tr>
<b-tr>
<b-td>
{{ $t('voting_time') }}
</b-td><b-td>{{ proposal.voting_start_time }} - {{ proposal.voting_end_time }}</b-td>
</b-td><b-td>{{ formatDate(proposal.voting_start_time) }} - {{ formatDate(proposal.voting_end_time) }}</b-td>
</b-tr>
<b-tr>
<b-td>
@ -134,51 +134,51 @@
<b-progress-bar
:id="'vote-yes'+proposal.id"
variant="success"
:value="proposal.tally.yes"
:label="`${proposal.tally.yes.toFixed()}%`"
:value="percent(proposal.tally.yes)"
:label="`${percent(proposal.tally.yes).toFixed()}%`"
show-progress
/>
<b-progress-bar
:id="'vote-no'+proposal.id"
variant="warning"
:value="proposal.tally.no"
:label="`${proposal.tally.no.toFixed()}%`"
:value="percent(proposal.tally.no)"
:label="`${percent(proposal.tally.no).toFixed()}%`"
show-progress
/>
<b-progress-bar
:id="'vote-veto'+proposal.id"
variant="danger"
:value="proposal.tally.veto"
:label="`${proposal.tally.veto.toFixed()}%`"
:value="percent(proposal.tally.veto)"
:label="`${percent(proposal.tally.veto).toFixed()}%`"
show-progress
/>
<b-progress-bar
:id="'vote-abstain'+proposal.id"
variant="info"
:value="proposal.tally.abstain"
:label="`${proposal.tally.abstain.toFixed()}%`"
:value="percent(proposal.tally.abstain)"
:label="`${percent(proposal.tally.abstain).toFixed()}%`"
show-progress
/>
</b-progress>
<b-tooltip
:target="'vote-yes'+proposal.id"
>
{{ proposal.tally.yes }}% voted Yes
{{ percent(proposal.tally.yes) }}% voted Yes
</b-tooltip>
<b-tooltip
:target="'vote-no'+proposal.id"
>
{{ proposal.tally.no }}% voted No
{{ percent(proposal.tally.no) }}% voted No
</b-tooltip>
<b-tooltip
:target="'vote-veto'+proposal.id"
>
{{ proposal.tally.veto }}% voted No With Veta
{{ percent(proposal.tally.veto) }}% voted No With Veta
</b-tooltip>
<b-tooltip
:target="'vote-abstain'+proposal.id"
>
{{ proposal.tally.abstain }}% voted Abstain
{{ percent(proposal.tally.abstain) }}% voted Abstain
</b-tooltip>
<b-table
v-if="votes.votes && votes.votes.length > 0"
@ -206,7 +206,7 @@
<b-card no-body>
<b-card-header>
<b-card-title>
Deposits ({{ proposal.total_deposit }})
Deposits ({{ formatToken(proposal.total_deposit) }})
</b-card-title>
</b-card-header>
<b-card-body>
@ -268,7 +268,9 @@ import {
import FlipCountdown from 'vue2-flip-countdown'
// import fetch from 'node-fetch'
import { getCachedValidators, getStakingValidatorByAccount, tokenFormatter } from '@/libs/utils'
import {
getCachedValidators, getStakingValidatorByAccount, percent, tokenFormatter,
} from '@/libs/utils'
import { Proposal, Proposer } from '@/libs/data'
import dayjs from 'dayjs'
import ObjectFieldComponent from './ObjectFieldComponent.vue'
@ -392,6 +394,9 @@ export default {
})
},
methods: {
percent: v => percent(v),
formatDate: v => dayjs(v).format('YYYY-MM-DD HH:mm'),
formatToken: v => tokenFormatter(v, {}),
loadVotes() {
if (this.next) {
const pid = this.$route.params.proposalid