fix staking changes

This commit is contained in:
donne1226 2022-03-20 15:44:58 +08:00
parent 38c728b7f5
commit fd132b9e14
2 changed files with 31 additions and 25 deletions

View File

@ -157,15 +157,15 @@ export default class ChainFetch {
} }
async getValidatorListByStatus(status) { async getValidatorListByStatus(status) {
return this.get(`/cosmos/staking/v1beta1/validators?status=${status}`).then(data => { return this.get(`/cosmos/staking/v1beta1/validators?status=${status}&pagination.limit=500`).then(data => {
const result = commonProcess(data) const result = commonProcess(data)
const vals = result.validators ? result.validators : result const vals = result.validators ? result.validators : result
return vals.map(i => new Validator().init(i)) return vals.map(i => new Validator().init(i))
}) })
} }
async getValidatorListByHeight(height) { async getValidatorListByHeight(height, offset) {
return this.get(`/cosmos/base/tendermint/v1beta1/validatorsets/${height}?pagination.limit=500`).then(data => commonProcess(data)) return this.get(`/cosmos/base/tendermint/v1beta1/validatorsets/${height}?pagination.limit=100&pagination.offset=${offset}`).then(data => commonProcess(data))
} }
async getStakingValidator(address) { async getStakingValidator(address) {

View File

@ -327,18 +327,29 @@ export default {
}, },
}, },
created() { created() {
this.$http.getValidatorListByHeight('latest').then(data => { this.getValidatorListByHeight()
this.$http.getStakingParameters().then(res => {
this.stakingParameters = res
})
this.getValidatorListByStatus(this.selectedStatus)
},
beforeDestroy() {
this.islive = false
},
methods: {
getValidatorListByHeight(offset = 0) {
this.$http.getValidatorListByHeight('latest', offset).then(data => {
let height = Number(data.block_height) let height = Number(data.block_height)
if (height > 14400) { if (height > 14400) {
height -= 14400 height -= 14400
} else { } else {
height = 1 height = 1
} }
const changes = {} const { changes } = this
data.validators.forEach(x => { data.validators.forEach(x => {
changes[x.pub_key.key] = { latest: Number(x.voting_power), previous: 0 } changes[x.pub_key.key] = { latest: Number(x.voting_power), previous: 0 }
}) })
this.$http.getValidatorListByHeight(height).then(previous => { this.$http.getValidatorListByHeight(height, offset).then(previous => {
previous.validators.forEach(x => { previous.validators.forEach(x => {
if (changes[x.pub_key.key]) { if (changes[x.pub_key.key]) {
changes[x.pub_key.key].previous = Number(x.voting_power) changes[x.pub_key.key].previous = Number(x.voting_power)
@ -349,15 +360,7 @@ export default {
this.$set(this, 'changes', changes) this.$set(this, 'changes', changes)
}) })
}) })
this.$http.getStakingParameters().then(res => {
this.stakingParameters = res
})
this.getValidatorListByStatus(this.selectedStatus)
}, },
beforeDestroy() {
this.islive = false
},
methods: {
getValidatorListByStatus(statusList) { getValidatorListByStatus(statusList) {
this.validators = [] this.validators = []
statusList.forEach(status => { statusList.forEach(status => {
@ -376,6 +379,9 @@ export default {
} }
} }
this.stakingPool = total this.stakingPool = total
if (total > 100) {
this.getValidatorListByHeight(100)
}
this.validators.push(...temp) this.validators.push(...temp)
// fetch avatar from keybase // fetch avatar from keybase