Update UI

This commit is contained in:
liangping 2021-08-08 11:42:12 +08:00
parent 3286700201
commit 9dd7f22cda
9 changed files with 81 additions and 46 deletions

View File

@ -1,12 +1,30 @@
import dayjs from 'dayjs' import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { import {
Bech32, fromBase64, fromHex, toHex, Bech32, fromBase64, fromHex, toHex,
} from '@cosmjs/encoding' } from '@cosmjs/encoding'
import { sha256 } from '@cosmjs/crypto' import { sha256 } from '@cosmjs/crypto'
export function toDay(time) { dayjs.extend(relativeTime)
export function toDay(time, format = 'long') {
if (format === 'long') {
return dayjs(time).format('YYYY-MM-DD HH:mm') return dayjs(time).format('YYYY-MM-DD HH:mm')
} }
if (format === 'date') {
return dayjs(time).format('YYYY-MM-DD')
}
if (format === 'time') {
return dayjs(time).format('HH:mm:ss')
}
if (format === 'from') {
return dayjs(time).fromNow()
}
if (format === 'to') {
return dayjs(time).toNow()
}
return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
}
export function percent(num) { export function percent(num) {
return parseFloat((num * 100).toFixed(2)) return parseFloat((num * 100).toFixed(2))

View File

@ -28,9 +28,9 @@ export default class Proposal {
this.title = element.content.value.title this.title = element.content.value.title
this.description = element.content.value.description this.description = element.content.value.description
this.tally = new ProposalTally().init(element.final_tally_result, total) this.tally = new ProposalTally().init(element.final_tally_result, total)
this.submit_time = toDay(element.submit_time) this.submit_time = toDay(element.submit_time, 'date')
this.voting_end_time = toDay(element.voting_end_time) this.voting_end_time = toDay(element.voting_end_time, 'date')
this.voting_start_time = toDay(element.voting_start_time) this.voting_start_time = toDay(element.voting_start_time, 'date')
this.total_deposit = formatToken(element.total_deposit[0]) this.total_deposit = formatToken(element.total_deposit[0])
this.contents = element.content.value this.contents = element.content.value
return this return this

View File

@ -7,7 +7,7 @@ export default class StdTx {
this.fee = [new Token()] this.fee = [new Token()]
this.gas = 0 this.gas = 0
this.memo = '' this.memo = ''
this.messages = [] this.messages = null
this.signatures = [] this.signatures = []
this.timeout_height = 0 this.timeout_height = 0
} }

View File

@ -3,6 +3,7 @@ import StdTx from './stdtx'
export default class WrapStdTx { export default class WrapStdTx {
constructor() { constructor() {
this.std = true
this.code = 0 this.code = 0
this.txhash = '' this.txhash = ''
this.data = '' this.data = ''
@ -19,6 +20,7 @@ export default class WrapStdTx {
static create(element, version = '0.40') { static create(element, version = '0.40') {
const self = new WrapStdTx() const self = new WrapStdTx()
if (compareVersions(version, '0.40') < 1) { if (compareVersions(version, '0.40') < 1) {
if (element.txhash) {
self.txhash = element.txhash self.txhash = element.txhash
self.data = element.data self.data = element.data
self.gas_used = element.gas_used self.gas_used = element.gas_used
@ -27,6 +29,10 @@ export default class WrapStdTx {
self.logs = element.logs self.logs = element.logs
self.timestamp = element.timestamp self.timestamp = element.timestamp
self.tx = StdTx.create(element.tx) self.tx = StdTx.create(element.tx)
} else {
self.std = false
self.raw = element
}
} else { } else {
self.code = element.tx_response.code self.code = element.tx_response.code
self.txhash = element.tx_response.txhash self.txhash = element.tx_response.txhash

View File

@ -82,16 +82,18 @@ export default {
this.$http.getBlockByHeight(height).then(res => { this.$http.getBlockByHeight(height).then(res => {
this.block = res this.block = res
const { txs } = res.block.data const { txs } = res.block.data
if (txs === null) return
const array = [] const array = []
for (let i = 0; i <= txs.length; i += 1) { for (let i = 0; i < txs.length; i += 1) {
let tx = new Tx()
try { try {
const origin = decodeTxRaw(fromBase64(txs[i])) const origin = decodeTxRaw(fromBase64(txs[i]))
const tx = Tx.create(origin) tx = Tx.create(origin)
tx.setHash(txs[i])
array.push(tx)
} catch (e) { } catch (e) {
// catch errors // catch errors
} }
tx.setHash(txs[i])
array.push(tx)
} }
if (array.length > 0) this.txs = array if (array.length > 0) this.txs = array
}) })

View File

@ -20,11 +20,11 @@
<!-- Column: Height --> <!-- Column: Height -->
<template #cell(height)="data"> <template #cell(height)="data">
<router-link :to="`./blocks/${data.item.block.header.height}`"> <router-link :to="`./blocks/${data.item.block.header.height}`">
#{{ data.item.block.header.height }} {{ data.item.block.header.height }}
</router-link> </router-link>
</template> </template>
<template #cell(hash)="data"> <template #cell(hash)="data">
{{ data.item.block_id.hash }} <small>{{ data.item.block_id.hash }}</small>
</template> </template>
<template #cell(time)="data"> <template #cell(time)="data">
{{ formatTime(data.item.block.header.time) }} {{ formatTime(data.item.block.header.time) }}
@ -65,10 +65,14 @@ export default {
islive: true, islive: true,
blocks: [], blocks: [],
list_fields: [ list_fields: [
{ key: 'height', sortable: true }, {
key: 'height',
sortable: true,
},
{ {
key: 'hash', key: 'hash',
tdClass: 'text-truncate', thClass: 'd-none d-lg-block',
tdClass: 'd-none d-lg-block',
}, },
{ {
key: 'proposer', key: 'proposer',
@ -80,7 +84,11 @@ export default {
tdClass: 'text-right', tdClass: 'text-right',
thClass: 'text-right', thClass: 'text-right',
}, },
{ key: 'time' }, {
key: 'time',
thClass: 'd-none d-md-block',
tdClass: 'd-none d-md-block',
},
], ],
} }
}, },
@ -111,7 +119,7 @@ export default {
}, },
methods: { methods: {
length: v => (Array.isArray(v) ? v.length : 0), length: v => (Array.isArray(v) ? v.length : 0),
formatTime: v => toDay(v), formatTime: v => toDay(v, 'time'),
fetch() { fetch() {
this.$http.getLatestBlock().then(b => { this.$http.getLatestBlock().then(b => {
const has = this.blocks.findIndex(x => x.block.header.height === b.block.header.height) const has = this.blocks.findIndex(x => x.block.header.height === b.block.header.height)

View File

@ -250,7 +250,4 @@ section {
border-radius: .357rem; border-radius: .357rem;
} }
.gov-wrapper .gov {
width: 9.8rem;
}
</style> </style>

View File

@ -3,10 +3,8 @@
<b-card <b-card
no-body no-body
> >
<b-card-header> <b-card-header class="d-flex justify-content-between">
<b-card-title> <small>
Validators (Max:{{ stakingParameters.max_validators }})
<small class="text-muted">
<b-badge variant="danger"> <b-badge variant="danger">
&nbsp; &nbsp;
</b-badge> </b-badge>
@ -16,6 +14,8 @@
</b-badge> </b-badge>
Top 67% of Voting Power Top 67% of Voting Power
</small> </small>
<b-card-title>
<span><small> {{ validators.length }}/{{ stakingParameters.max_validators }}</small> Validators</span>
</b-card-title> </b-card-title>
</b-card-header> </b-card-header>
<b-table <b-table
@ -108,7 +108,7 @@ export default {
return { return {
islive: true, islive: true,
mintInflation: 0, mintInflation: 0,
stakingPool: {}, stakingPool: 1,
stakingParameters: new StakingParameters(), stakingParameters: new StakingParameters(),
validators: [new Validator()], validators: [new Validator()],
delegations: [new Validator()], delegations: [new Validator()],
@ -135,16 +135,15 @@ export default {
} }
}, },
created() { created() {
this.$http.getStakingPool().then(res => {
this.stakingPool = res
})
this.$http.getStakingParameters().then(res => { this.$http.getStakingParameters().then(res => {
this.stakingParameters = res this.stakingParameters = res
}) })
this.$http.getValidatorList().then(res => { this.$http.getValidatorList().then(res => {
const identities = [] const identities = []
const temp = res const temp = res
let total = 0
for (let i = 0; i < temp.length; i += 1) { for (let i = 0; i < temp.length; i += 1) {
total += temp[i].tokens
const { identity } = temp[i].description const { identity } = temp[i].description
const url = this.$store.getters['chains/getAvatarById'](identity) const url = this.$store.getters['chains/getAvatarById'](identity)
if (url) { if (url) {
@ -153,6 +152,7 @@ export default {
identities.push(identity) identities.push(identity)
} }
} }
this.stakingPool = total
this.validators = temp this.validators = temp
// fetch avatar from keybase // fetch avatar from keybase
@ -179,7 +179,7 @@ export default {
} else { } else {
window.sum += item.tokens window.sum += item.tokens
} }
const rank = window.sum / this.stakingPool.bondedToken const rank = window.sum / this.stakingPool
if (rank < 0.333) { if (rank < 0.333) {
return 'danger' return 'danger'
} }

View File

@ -1,7 +1,11 @@
<template> <template>
<div> <div>
<b-card title="Baisc"> <b-card title="Baisc">
<b-table-simple> <object-field-component
v-if="!tx.std"
:tablefield="tx.raw"
/>
<b-table-simple v-else>
<b-tr> <b-tr>
<b-td style="width:200px"> <b-td style="width:200px">
{{ 'txhash' }} {{ 'txhash' }}