cosmos-explorer/src/views/Governance.vue

292 lines
7.6 KiB
Vue
Raw Normal View History

2021-07-21 14:07:38 +00:00
<template>
2021-08-26 13:50:56 +00:00
<div>
<b-row class="match-height">
<b-col
v-for="p in proposals"
:key="p.id"
lg="6"
md="12"
>
<b-card>
<b-card-title
class="mb-0"
2021-08-04 01:28:30 +00:00
>
2021-08-26 13:50:56 +00:00
#{{ p.id }}.
<b-badge
v-if="p.status == 1"
pill
variant="light-info"
class="text-right"
>
Deposit
</b-badge>
<b-badge
v-if="p.status == 2"
pill
variant="light-primary"
class="text-right"
>
Voting
</b-badge>
<b-badge
v-if="p.status == 3"
pill
variant="light-success"
class="text-right"
>
Passed
</b-badge>
<b-badge
v-if="p.status == 4"
pill
variant="light-danger"
class="text-right"
>
Rejected
</b-badge>
<router-link
:to="`./gov/${p.id}`"
>
{{ p.title }}
</router-link></b-card-title>
<b-card-body md="12">
<div class="gov-wrapper d-flex flex-wrap">
<div class="gov">
<p class="card-text mb-25">
Start Date
</p>
<h6 class="mb-0">
2021-12-22 08:55:58 +00:00
{{ formatDate(p.voting_start_time) }}
2021-08-26 13:50:56 +00:00
</h6>
</div>
<div class="gov">
<p class="card-text mb-25">
End Date
</p>
<h6 class="mb-0">
2021-12-22 08:55:58 +00:00
{{ formatDate(p.voting_end_time) }}
2021-08-26 13:50:56 +00:00
</h6>
</div>
<div class="gov">
<p class="card-text mb-25">
Deposit
</p>
<h6 class="mb-0">
2021-12-22 08:55:58 +00:00
{{ formatToken(p.total_deposit) || '-' }}
2021-08-26 13:50:56 +00:00
</h6>
</div>
<div class="gov">
<p class="card-text mb-25">
Turnout
</p>
<h6 class="mb-0">
2021-12-22 08:55:58 +00:00
{{ percent(p.tally.turnout) }}%
2021-08-26 13:50:56 +00:00
</h6>
</div>
</div>
</b-card-body>
<b-progress
:max="100"
height="2rem"
class="mb-2"
show-progress
2021-08-04 01:28:30 +00:00
>
2021-08-26 13:50:56 +00:00
<b-progress-bar
:id="'vote-yes'+p.id"
variant="success"
2021-12-22 08:55:58 +00:00
:value="percent(p.tally.yes)"
2021-08-26 13:50:56 +00:00
show-progress
2021-12-22 08:55:58 +00:00
:label="`${percent(p.tally.yes).toFixed()}%`"
2021-08-26 13:50:56 +00:00
/>
<b-progress-bar
:id="'vote-no'+p.id"
variant="warning"
2021-12-22 08:55:58 +00:00
:value="percent(p.tally.no)"
:label="`${percent(p.tally.no).toFixed()}%`"
2021-08-26 13:50:56 +00:00
show-progress
/>
<b-progress-bar
:id="'vote-veto'+p.id"
variant="danger"
2021-12-22 08:55:58 +00:00
:value="percent(p.tally.veto)"
:label="`${percent(p.tally.veto).toFixed()}%`"
2021-08-26 13:50:56 +00:00
show-progress
/>
<b-progress-bar
:id="'vote-abstain'+p.id"
variant="info"
2021-12-22 08:55:58 +00:00
:value="percent(p.tally.abstain)"
:label="`${percent(p.tally.abstain).toFixed()}%`"
2021-08-26 13:50:56 +00:00
show-progress
/>
</b-progress>
<b-tooltip
:target="'vote-yes'+p.id"
2021-08-04 01:28:30 +00:00
>
2021-12-22 08:55:58 +00:00
{{ percent(p.tally.yes) }}% voted Yes
2021-08-26 13:50:56 +00:00
</b-tooltip>
<b-tooltip
:target="'vote-no'+p.id"
2021-08-04 01:28:30 +00:00
>
2021-12-22 08:55:58 +00:00
{{ percent(p.tally.no) }}% voted No
2021-08-26 13:50:56 +00:00
</b-tooltip>
<b-tooltip
:target="'vote-veto'+p.id"
2021-08-04 01:28:30 +00:00
>
2021-12-22 15:21:58 +00:00
{{ percent(p.tally.veto) }}% voted No With Veto
2021-08-26 13:50:56 +00:00
</b-tooltip>
<b-tooltip
:target="'vote-abstain'+p.id"
2021-07-30 15:24:46 +00:00
>
2021-12-22 08:55:58 +00:00
{{ percent(p.tally.abstain) }}% voted Abstain
2021-08-26 13:50:56 +00:00
</b-tooltip>
<b-card-footer class="pb-0">
<router-link
2021-08-04 01:28:30 +00:00
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
2021-08-26 13:50:56 +00:00
:to="`./gov/${p.id}`"
2021-08-04 01:28:30 +00:00
variant="outline-primary"
>
2021-08-26 13:50:56 +00:00
<b-button
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
:href="`./gov/${p.id}`"
variant="outline-primary"
>
{{ $t('btn_detail') }}
</b-button>
</router-link>
<b-button
2021-10-16 12:19:01 +00:00
v-if="p.status===1"
v-b-modal.deposit-window
variant="primary"
class="btn float-right mg-2"
@click="selectProposal(p.id, p.title)"
>
{{ $t('btn_deposit') }}
</b-button>
<b-button
v-if="p.status===2"
2021-08-26 13:50:56 +00:00
v-b-modal.vote-window
variant="primary"
class="btn float-right mg-2"
@click="selectProposal(p.id, p.title)"
>
{{ $t('btn_vote') }}
2021-08-04 01:28:30 +00:00
</b-button>
2021-08-26 13:50:56 +00:00
</b-card-footer>
</b-card>
</b-col>
</b-row>
<operation-vote-component
:proposal-id="selectedProposalId"
:title="selectedTitle"
/>
2021-10-16 12:19:01 +00:00
<operation-gov-deposit-component
:proposal-id="selectedProposalId"
:title="selectedTitle"
/>
2021-08-26 13:50:56 +00:00
</div>
2021-07-21 14:07:38 +00:00
</template>
<script>
import {
2021-08-26 13:50:56 +00:00
BCard, BCardTitle, BCardBody, BCardFooter, BButton, BProgressBar, BProgress, BBadge, BTooltip, BRow, BCol, VBModal,
2021-07-21 14:07:38 +00:00
} from 'bootstrap-vue'
import Ripple from 'vue-ripple-directive'
2021-07-30 15:24:46 +00:00
import { Proposal } from '@/libs/data'
2021-12-22 08:55:58 +00:00
import { percent, tokenFormatter } from '@/libs/utils'
import dayjs from 'dayjs'
2021-08-26 13:50:56 +00:00
import OperationVoteComponent from './OperationVoteComponent.vue'
2021-10-16 12:19:01 +00:00
import OperationGovDepositComponent from './OperationGovDepositComponent.vue'
2021-07-21 14:07:38 +00:00
export default {
components: {
BCard,
BButton,
BCardFooter,
BProgressBar,
BProgress,
BBadge,
BCardTitle,
BTooltip,
BCardBody,
2021-08-04 01:28:30 +00:00
BRow,
BCol,
2021-08-26 13:50:56 +00:00
OperationVoteComponent,
2021-10-16 12:19:01 +00:00
OperationGovDepositComponent,
2021-07-21 14:07:38 +00:00
},
directives: {
2021-08-26 13:50:56 +00:00
'b-modal': VBModal,
2021-07-21 14:07:38 +00:00
Ripple,
},
data() {
return {
2021-08-26 13:50:56 +00:00
selectedProposalId: 0,
selectedTitle: '',
2021-07-30 15:24:46 +00:00
proposals: [new Proposal()],
2021-07-28 11:20:30 +00:00
max: 1,
2021-07-21 14:07:38 +00:00
}
},
2021-07-30 15:24:46 +00:00
mounted() {
this.getList()
2021-07-28 11:20:30 +00:00
},
2021-07-30 15:24:46 +00:00
methods: {
2021-12-22 08:55:58 +00:00
percent: v => percent(v),
formatDate: v => dayjs(v).format('YYYY-MM-DD'),
formatToken: v => tokenFormatter(v, {}),
2021-08-26 13:50:56 +00:00
selectProposal(pid, title) {
this.selectedProposalId = Number(pid)
this.selectedTitle = title
},
2021-07-30 15:24:46 +00:00
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
2021-07-28 11:20:30 +00:00
})
2021-07-30 15:24:46 +00:00
})
}
this.proposals = res.reverse()
})
2021-07-28 11:20:30 +00:00
},
},
2021-07-21 14:07:38 +00:00
}
</script>
<style scoped>
2021-07-28 11:20:30 +00:00
section {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.card {
flex-basis: 49%;
}
2021-07-21 14:07:38 +00:00
.gov-wrapper {
display: flex;
justify-content:center;
2021-09-04 03:02:12 +00:00
align-items:flex-end;
2021-07-21 14:07:38 +00:00
}
.dark-layout .gov-wrapper .gov {
background-color: #161d31;
}
.gov-wrapper .gov {
padding: .5rem;
2021-08-08 04:07:31 +00:00
margin: .3rem;
2021-09-04 03:02:12 +00:00
min-width: 7.5rem;
2021-07-21 14:07:38 +00:00
text-align: center;
background-color: #f8f8f8;
border-radius: .357rem;
}
</style>