cosmos-explorer/src/views/Governance.vue

279 lines
6.4 KiB
Vue
Raw Normal View History

2021-07-21 14:07:38 +00:00
<template>
<section>
2021-07-28 11:20:30 +00:00
<b-card
v-for="p in proposals"
:key="p.id"
>
<b-card-title class="mb-0">
<b-badge
v-if="p.status == 1"
pill
variant="light-info"
class="text-right"
2021-07-21 14:07:38 +00:00
>
2021-07-28 11:20:30 +00:00
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"
2021-07-21 14:07:38 +00:00
>
2021-07-28 11:20:30 +00:00
Rejected
</b-badge>
2021-07-30 15:24:46 +00:00
#{{ p.id }}. <a :href="`./gov/${p.id}`">{{ p.title }}</a>
2021-07-28 11:20:30 +00:00
</b-card-title>
<b-card-body md="12">
<div class="gov-wrapper">
<div class="gov">
<p class="card-text mb-25">
Start Date
</p>
<h6 class="mb-0">
{{ p.voting_start_time }}
</h6>
</div>
<div class="gov">
<p class="card-text mb-25">
End Date
</p>
<h6 class="mb-0">
{{ p.voting_end_time }}
</h6>
</div>
<div class="gov">
<p class="card-text mb-25">
Deposit
</p>
<h6 class="mb-0">
{{ p.total_deposit }}
</h6>
</div>
<div class="gov">
<p class="card-text mb-25">
Turnout
</p>
<h6 class="mb-0">
{{ p.tally.turnout }}%
</h6>
</div>
</div>
</b-card-body>
2021-07-21 14:07:38 +00:00
2021-07-28 11:20:30 +00:00
<b-progress
:max="100"
height="2rem"
class="mb-2"
show-progress
2021-07-21 14:07:38 +00:00
>
2021-07-28 11:20:30 +00:00
<b-progress-bar
:id="'vote-yes'+p.id"
variant="success"
:value="p.tally.yes"
show-progress
/>
<b-progress-bar
:id="'vote-no'+p.id"
variant="warning"
:value="p.tally.no"
show-progress
/>
<b-progress-bar
:id="'vote-veto'+p.id"
variant="danger"
:value="p.tally.veto"
show-progress
/>
<b-progress-bar
:id="'vote-abstain'+p.id"
variant="info"
:value="p.tally.abstain"
show-progress
/>
</b-progress>
<b-tooltip
:target="'vote-yes'+p.id"
>
{{ p.tally.yes }}% voted Yes
</b-tooltip>
<b-tooltip
:target="'vote-no'+p.id"
>
{{ p.tally.no }}% voted No
</b-tooltip>
<b-tooltip
:target="'vote-veto'+p.id"
>
{{ p.tally.veto }}% voted No With Veta
</b-tooltip>
<b-tooltip
:target="'vote-abstain'+p.id"
>
{{ p.tally.abstain }}% voted Abstain
</b-tooltip>
<b-card-footer>
2021-07-30 15:24:46 +00:00
<router-link
2021-07-28 11:20:30 +00:00
v-ripple.400="'rgba(113, 102, 240, 0.15)'"
2021-07-30 15:24:46 +00:00
:to="`./gov/${p.id}`"
2021-07-28 11:20:30 +00:00
variant="outline-primary"
2021-07-30 15:24:46 +00:00
class="btn"
2021-07-21 14:07:38 +00:00
>
2021-07-30 15:24:46 +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>
2021-07-28 11:20:30 +00:00
<b-button
2021-07-30 15:24:46 +00:00
:disabled="p.status!=2"
2021-07-28 11:20:30 +00:00
variant="primary"
class="btn float-right mg-2"
>
2021-07-30 15:24:46 +00:00
{{ $t('btn_vote') }}
2021-07-28 11:20:30 +00:00
</b-button>
</b-card-footer>
</b-card>
2021-07-21 14:07:38 +00:00
</section>
</template>
<script>
import {
2021-07-28 11:20:30 +00:00
BCard, BCardTitle, BCardBody, BCardFooter, BButton, BProgressBar, BProgress, BBadge, BTooltip,
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-07-21 14:07:38 +00:00
export default {
components: {
BCard,
BButton,
BCardFooter,
BProgressBar,
BProgress,
BBadge,
BCardTitle,
BTooltip,
BCardBody,
},
directives: {
Ripple,
},
data() {
return {
2021-07-30 15:24:46 +00:00
proposals: [new Proposal()],
2021-07-21 14:07:38 +00:00
values: [15, 50, 10, 5],
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: {
getList() {
// this.$http.setup(this.$route)
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-30 15:24:46 +00:00
// asyncComputed: {
// proposals: {
// get() {
// const api = new ChainAPI(this.$route)
// api.setup(this.$route)
// return api.getGovernanceList().then(res => {
// const voting = res.filter(i => i.status === 2)
// if (voting.length > 0) {
// let i = 0
// Promise.all(voting.reverse().map(p => api.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
// })
// })
// }
// return res.reverse()
// })
// },
// // default: 'loading...',
// },
// },
2021-07-28 11:20:30 +00:00
// watch: {
// proposals(val, newdata) {
// console.log('In watch', val, newdata)
// },
// },
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;
align-items:center;
}
.gov-wrapper .gov:not(:last-child) {
margin-right: .7rem;
}
.dark-layout .gov-wrapper .gov {
background-color: #161d31;
}
.gov-wrapper .gov {
padding: .5rem;
margin-bottom: .7rem;
text-align: center;
background-color: #f8f8f8;
border-radius: .357rem;
}
.gov-wrapper .gov {
2021-07-30 15:24:46 +00:00
width: 9.8rem;
2021-07-21 14:07:38 +00:00
}
</style>