Improve Ui/Ux

This commit is contained in:
liangping 2021-09-13 11:40:13 +08:00
parent 87aed10821
commit 393d69b60f
10 changed files with 110 additions and 34 deletions

View File

@ -24,7 +24,7 @@
</noscript> </noscript>
<div id="loading-bg"> <div id="loading-bg">
<div class="loading-logo"> <div class="loading-logo">
<img src="<%= BASE_URL %>logo.svg" alt="Logo" /> <img src="<%= BASE_URL %>logo.svg" alt="Logo" width="80"/>
</div> </div>
<div class="loading"> <div class="loading">
<div class="effect-1 effects"></div> <div class="effect-1 effects"></div>

View File

@ -44,7 +44,7 @@
size="42" size="42"
:src="selected_chain.logo" :src="selected_chain.logo"
class="badge-minimal" class="badge-minimal"
:badge-variant="chainVariant" :badge-variant="variant"
/></b-link> /></b-link>
</b-media-aside> </b-media-aside>
<b-media-body class="my-auto"> <b-media-body class="my-auto">
@ -166,22 +166,31 @@ export default {
}, },
data() { data() {
return { return {
chainVariant: 'success', variant: 'success',
tips: 'Synced', tips: 'Synced',
} }
}, },
computed: { computed: {
selected_chain() { selected_chain() {
this.block()
return store.state.chains.selected return store.state.chains.selected
}, },
chainVariant() {
return this.variant
},
}, },
created() { methods: {
this.$http.getLatestBlock().then(block => { block() {
if (timeIn(block.block.header.time, 1, 'm')) { store.commit('setHeight', 0)
this.chainVariant = 'danger' this.$http.getLatestBlock().then(block => {
this.tips = `Halted ${toDay(block.block.header.time, 'from')} ` store.commit('setHeight', Number(block.block.header.height))
} this.tips = `Synced height:${block.block.header.height}`
}) if (timeIn(block.block.header.time, 1, 'm')) {
this.variant = 'danger'
this.tips = `Halted ${toDay(block.block.header.time, 'from')}, Height: ${store.state.chains.height} `
}
})
},
}, },
} }
</script> </script>

View File

@ -112,6 +112,10 @@ const chainAPI = class ChainFetch {
}) })
} }
async getValidatorListByHeight(height) {
return this.get(`/validatorsets/${height}`).then(data => commonProcess(data))
}
async getStakingValidator(address) { async getStakingValidator(address) {
return this.get(`/staking/validators/${address}`).then(data => new Validator().init(commonProcess(data))) return this.get(`/staking/validators/${address}`).then(data => new Validator().init(commonProcess(data)))
} }

View File

@ -46,6 +46,7 @@ export default {
config: chains, config: chains,
selected, selected,
avatars: {}, avatars: {},
height: 0,
}, },
getters: { getters: {
getchains: state => state.chains, getchains: state => state.chains,
@ -61,7 +62,9 @@ export default {
cacheAvatar(state, args) { cacheAvatar(state, args) {
state.chains.avatars[args.identity] = args.url state.chains.avatars[args.identity] = args.url
}, },
setHeight(state, height) {
state.chains.height = height
},
}, },
actions: {}, actions: {},
} }

View File

@ -4,7 +4,7 @@
:items="tablefield" :items="tablefield"
:sticky-header="true" :sticky-header="true"
:no-border-collapse="true" :no-border-collapse="true"
responsive responsive="sm"
class="ml-0 mr-0" class="ml-0 mr-0"
> >
<template #cell()="data"> <template #cell()="data">
@ -24,13 +24,10 @@
<script> <script>
import { BTable } from 'bootstrap-vue' import { BTable } from 'bootstrap-vue'
// import fetch from 'node-fetch'
import { import {
getStakingValidatorByHex, isHexAddress, isToken, toDay, tokenFormatter, getStakingValidatorByHex, isHexAddress, isToken, toDay, tokenFormatter,
} from '@/libs/data/data' } from '@/libs/data/data'
// import { Proposal, Proposer } from '@/libs/data'
// import { formatToken } from '@/libs/data/data'
export default { export default {
name: 'ArrayFieldComponent', name: 'ArrayFieldComponent',
@ -62,6 +59,9 @@ export default {
if (reg.test(value)) { if (reg.test(value)) {
return toDay(value) return toDay(value)
} }
if (value.length > 30) {
return value.substring(0, 30).concat('...')
}
return value return value
}, },
formatTokens(value) { formatTokens(value) {

View File

@ -33,7 +33,10 @@
</b-card> </b-card>
<b-card title="Last Commit"> <b-card title="Last Commit">
<object-field-component :tablefield="block.block.last_commit" /> <object-field-component
:tablefield="block.block.last_commit"
:small="true"
/>
</b-card> </b-card>
</div> </div>
</template> </template>
@ -101,7 +104,3 @@ export default {
}, },
} }
</script> </script>
<style>
</style>

View File

@ -372,5 +372,7 @@ export default {
.addzone :hover { .addzone :hover {
border: 2px dashed #7367F0; border: 2px dashed #7367F0;
} }
@media (min-width: 768px) {
td:first-child { width: 20% ;}
}
</style> </style>

View File

@ -131,7 +131,7 @@ export default {
} }
</script> </script>
<style lang='css'> <style lang='css' scoped>
@media (min-width: 768px) { @media (min-width: 768px) {
td:first-child { width: 20% ;} td:first-child { width: 20% ;}
} }

View File

@ -20,7 +20,7 @@
</b-card-header> </b-card-header>
<b-card-body class="pl-0 pr-0"> <b-card-body class="pl-0 pr-0">
<b-table <b-table
:items="validators" :items="list"
:fields="validator_fields" :fields="validator_fields"
:sort-desc="true" :sort-desc="true"
sort-by="tokens" sort-by="tokens"
@ -30,15 +30,17 @@
> >
<!-- A virtual column --> <!-- A virtual column -->
<template #cell(index)="data"> <template #cell(index)="data">
<b-badge <b-badge :variant="rankBadge(data)">
:variant="rankBadge(data)"
>
{{ data.index + 1 }} {{ data.index + 1 }}
</b-badge> </b-badge>
</template> </template>
<!-- Column: Validator --> <!-- Column: Validator -->
<template #cell(description)="data"> <template #cell(description)="data">
<b-media vertical-align="center d-none d-md-block"> <b-media
vertical-align="center"
class="text-truncate"
style="max-width:320px;"
>
<template #aside> <template #aside>
<b-avatar <b-avatar
v-if="data.item.avatar" v-if="data.item.avatar"
@ -63,7 +65,9 @@
{{ data.item.description.moniker }} {{ data.item.description.moniker }}
</router-link> </router-link>
</span> </span>
<small class="text-muted">{{ data.item.description.website || data.item.description.identity }}</small> <small
class="text-muted"
>{{ data.item.description.website || data.item.description.identity }}</small>
</b-media> </b-media>
</template> </template>
<!-- Token --> <!-- Token -->
@ -77,6 +81,18 @@
</div> </div>
<span v-else>{{ data.item.delegator_shares }}</span> <span v-else>{{ data.item.delegator_shares }}</span>
</template> </template>
<!-- Token -->
<template #cell(changes)="data">
<small
v-if="data.item.changes>0"
class="text-success"
>+{{ data.item.changes }}</small>
<small v-else-if="data.item.changes===0">-</small>
<small
v-else
class="text-danger"
>{{ data.item.changes }}</small>
</template>
</b-table> </b-table>
</b-card-body> </b-card-body>
</b-card> </b-card>
@ -91,6 +107,7 @@ import {
Validator, percent, StakingParameters, formatToken, Validator, percent, StakingParameters, formatToken,
} from '@/libs/data' } from '@/libs/data'
import { keybase } from '@/libs/fetch' import { keybase } from '@/libs/fetch'
// import { toHex } from '@cosmjs/encoding'
// import fetch from 'node-fetch' // import fetch from 'node-fetch'
export default { export default {
@ -115,6 +132,7 @@ export default {
stakingParameters: new StakingParameters(), stakingParameters: new StakingParameters(),
validators: [new Validator()], validators: [new Validator()],
delegations: [new Validator()], delegations: [new Validator()],
changes: {},
validator_fields: [ validator_fields: [
{ {
key: 'index', key: 'index',
@ -131,20 +149,54 @@ export default {
thClass: 'text-right', thClass: 'text-right',
sortByFormatted: true, sortByFormatted: true,
}, },
{
key: 'changes',
label: '24H Changes',
},
{ {
key: 'commission', key: 'commission',
formatter: value => `${percent(value.rate)}%`, formatter: value => `${percent(value.rate)}%`,
tdClass: 'text-right d-none d-md-block', tdClass: 'text-right d-none d-md-block',
thClass: 'text-right d-none d-md-block', thClass: 'text-right d-none d-md-block',
}, },
{
key: 'operation',
label: '',
},
], ],
} }
}, },
computed: {
list() {
return this.validators.map(x => {
const xh = x
const change = this.changes[x.consensus_pubkey.value]
if (change) {
xh.changes = change.latest - change.previous
}
return xh
})
},
},
created() { created() {
this.$http.getValidatorListByHeight('latest').then(data => {
let height = Number(data.block_height)
if (height > 14400) {
height -= 14400
} else {
height = 1
}
const changes = []
data.validators.forEach(x => {
changes[x.pub_key.value] = { latest: Number(x.voting_power), previous: 0 }
})
this.$http.getValidatorListByHeight(height).then(previous => {
previous.validators.forEach(x => {
if (changes[x.pub_key.value]) {
changes[x.pub_key.value].previous = Number(x.voting_power)
} else {
changes[x.pub_key.value] = { latest: 0, previous: Number(x.voting_power) }
}
})
this.$set(this, 'changes', changes)
})
})
this.$http.getStakingParameters().then(res => { this.$http.getStakingParameters().then(res => {
this.stakingParameters = res this.stakingParameters = res
}) })

View File

@ -140,7 +140,13 @@
<span class="font-weight-bold">Status</span> <span class="font-weight-bold">Status</span>
</th> </th>
<td class="pb-50 text-capitalize"> <td class="pb-50 text-capitalize">
{{ validator.status }} <b-badge
v-if="validator.status===3"
variant="light-success"
>
Active
</b-badge>
<span v-else>{{ validator.status }}</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -281,7 +287,7 @@
<script> <script>
import { import {
BCard, BButton, BAvatar, BRow, BCol, BCardBody, BCardFooter, VBTooltip, VBModal, BCard, BButton, BAvatar, BRow, BCol, BCardBody, BCardFooter, VBTooltip, VBModal, BBadge,
} from 'bootstrap-vue' } from 'bootstrap-vue'
import { import {
@ -304,6 +310,7 @@ export default {
BAvatar, BAvatar,
BCardBody, BCardBody,
BCardFooter, BCardFooter,
BBadge,
StakingAddressComponent, StakingAddressComponent,
StakingCommissionComponent, StakingCommissionComponent,
StakingRewardComponent, StakingRewardComponent,