From 18e0d933b02549c7ba56353345eb826186235507 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 1 Aug 2021 07:13:47 +0800 Subject: [PATCH] finished staking list --- src/libs/data/index.js | 1 + src/libs/data/staking-parameters.js | 24 ++++ src/libs/data/valdiator-description.js | 4 +- src/libs/data/validator.js | 6 +- src/libs/fetch.js | 10 +- src/store/chains/index.js | 5 + src/views/Staking.vue | 168 +++++++++++++++++++------ 7 files changed, 175 insertions(+), 43 deletions(-) create mode 100644 src/libs/data/staking-parameters.js diff --git a/src/libs/data/index.js b/src/libs/data/index.js index f4fd12b2..f1c15db8 100644 --- a/src/libs/data/index.js +++ b/src/libs/data/index.js @@ -5,6 +5,7 @@ export { default as Proposer } from './proposer' export { default as Votes } from './votes' export { default as Deposit } from './deposit' export { default as Validator } from './validator' +export { default as StakingParameters } from './staking-parameters' export * from './data' export default class Test {} diff --git a/src/libs/data/staking-parameters.js b/src/libs/data/staking-parameters.js new file mode 100644 index 00000000..4b778765 --- /dev/null +++ b/src/libs/data/staking-parameters.js @@ -0,0 +1,24 @@ +export default class StakingParameters { + constructor() { + this.max_entries = 0 + this.historical_entries = 0 + this.unbonding_time = '' + this.max_validators = 0 + this.bond_denom = '' + } + + init(element) { + if (element != null) { + this.max_entries = Number(element.max_entries) + this.historical_entries = Number(element.historical_entries) + this.unbonding_time = element.unbonding_time + this.max_validators = Number(element.max_validators) + this.bond_denom = element.bond_denom + } + return this + } + + debug() { + return console.log(this) + } +} diff --git a/src/libs/data/valdiator-description.js b/src/libs/data/valdiator-description.js index 7e75fb01..856f2c8e 100644 --- a/src/libs/data/valdiator-description.js +++ b/src/libs/data/valdiator-description.js @@ -1,8 +1,8 @@ export default class ValidatorDescription { constructor() { - this.moniker = 'string' + this.moniker = 'Ping' this.identity = 'string' - this.website = 'string' + this.website = 'https://ping.pub' this.security_contact = 'string' this.details = 'string' } diff --git a/src/libs/data/validator.js b/src/libs/data/validator.js index 9e2ff694..afd826a6 100644 --- a/src/libs/data/validator.js +++ b/src/libs/data/validator.js @@ -7,7 +7,7 @@ export default class Validator { this.consensus_pubkey = 'cosmosvalconspub1zcjduepq0vu2zgkgk49efa0nqwzndanq5m4c7pa3u4apz4g2r9gspqg6g9cs3k9cuf' this.jailed = true this.status = 0 - this.tokens = '-' + this.tokens = 0 this.delegator_shares = 0 this.description = new ValidatorDescription() this.bond_height = 0 @@ -22,10 +22,10 @@ export default class Validator { this.consensus_pubkey = element.consensus_pubkey this.jailed = element.jailed this.status = element.status - this.tokens = element.tokens + this.tokens = Number(element.tokens) this.delegator_shares = element.delegator_shares this.description = new ValidatorDescription().init(element.description) - this.bond_height = element.bond_height + this.bond_height = Number(element.bond_height) this.bond_intra_tx_counter = element.bond_intra_tx_counter this.unbonding_height = element.unbonding_height this.unbonding_time = element.unbonding_time diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 8446fbfc..4ea55be8 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -2,7 +2,7 @@ import fetch from 'node-fetch' import store from '@/store' import { Proposal, ProposalTally, Proposer, StakingPool, Votes, Deposit, - Validator, + Validator, StakingParameters, } from './data' function commonProcess(res) { @@ -25,6 +25,14 @@ const chainAPI = class ChainFetch { return this.get('/staking/pool').then(data => new StakingPool().init(commonProcess(data))) } + async getMintingInflation() { + return this.get('/minting/inflation').then(data => Number(commonProcess(data))) + } + + async getStakingParameters() { + return this.get('/staking/parameters').then(data => new StakingParameters().init(commonProcess(data))) + } + async getValidatorList() { return this.get('/staking/validators').then(data => commonProcess(data).map(i => new Validator().init(i))) } diff --git a/src/store/chains/index.js b/src/store/chains/index.js index 481775f0..27800d07 100644 --- a/src/store/chains/index.js +++ b/src/store/chains/index.js @@ -11,9 +11,11 @@ export default { state: { config: chains, selected: {}, + avatars: {}, }, getters: { getchains: state => state.chains, + getAvatarById: state => id => state.avatars[id], }, mutations: { setup_sdk_version(state, info) { @@ -22,6 +24,9 @@ export default { select(state, args) { state.chains.selected = state.chains.config[args.chain_name] }, + cacheAvatar(state, args) { + state.chains.avatars[args.identity] = args.url + }, }, actions: {}, diff --git a/src/views/Staking.vue b/src/views/Staking.vue index 9fd929ca..bdd45ee0 100644 --- a/src/views/Staking.vue +++ b/src/views/Staking.vue @@ -1,76 +1,115 @@ - + + + Validators (Max:{{ stakingParameters.max_validators }}) + + + + + Top 33% + + + + Top 67% of Voting Power + + + - - - - + + + + {{ data.index + 1 }} + + + + + - + {{ data.item.description.moniker }} {{ data.item.description.website || data.item.description.identity }} + + + + {{ tokenFormatter(data.item.tokens, stakingParameters.bond_denom) }} + {{ percent(data.item.tokens/stakingPool.bondedToken) }}% + + - +