Improve performance of loading

This commit is contained in:
liangping 2021-08-03 09:41:46 +08:00
parent e4fca8f41b
commit ec23ca0ebd

View File

@ -102,6 +102,7 @@ export default {
}, },
data() { data() {
return { return {
islive: true,
mintInflation: 0, mintInflation: 0,
stakingPool: {}, stakingPool: {},
stakingParameters: new StakingParameters(), stakingParameters: new StakingParameters(),
@ -146,15 +147,35 @@ export default {
this.stakingParameters = res this.stakingParameters = res
}) })
this.$http.getValidatorList().then(res => { this.$http.getValidatorList().then(res => {
this.validators = res const identities = []
const temp = res
for (let i = 0; i < temp.length; i += 1) {
const { identity } = temp[i].description
const url = this.$store.getters['chains/getAvatarById'](identity)
if (url) {
temp[i].avatar = url
} else if (identity && identity !== '') {
identities.push(identity)
}
}
this.validators = temp
// fetch avatar from keybase
console.log(identities)
let promise = Promise.resolve() let promise = Promise.resolve()
res.forEach((item, index) => { identities.forEach(item => {
if (this.islive) {
promise = promise.then(() => new Promise(resolve => { promise = promise.then(() => new Promise(resolve => {
this.avatar(item.description.identity, index, resolve) this.avatar(item, resolve)
})) }))
}
}) })
}) })
}, },
beforeDestroy() {
console.log('destroying')
this.islive = false
},
methods: { methods: {
percent, percent,
tokenFormatter(amount, denom) { tokenFormatter(amount, denom) {
@ -179,25 +200,20 @@ export default {
} }
return 'primary' return 'primary'
}, },
avatar(identity, index, resolve) { avatar(identity, resolve) {
const url = this.$store.getters['chains/getAvatarById'](identity)
if (url !== undefined) {
resolve()
const validator = this.validators.find(u => u.description.identity === identity)
this.$set(validator, 'avatar', url)
} else if (identity) {
keybase(identity).then(d => { keybase(identity).then(d => {
resolve() resolve()
console.log(identity)
if (Array.isArray(d.them) && d.them.length > 0) { if (Array.isArray(d.them) && d.them.length > 0) {
const pic = d.them[0].pictures
console.log('fetch new avatar:', pic)
if (pic) {
const validator = this.validators.find(u => u.description.identity === identity) const validator = this.validators.find(u => u.description.identity === identity)
this.$set(validator, 'avatar', d.them[0].pictures.primary.url) this.$set(validator, 'avatar', pic.primary.url)
this.$store.commit('cacheAvatar', { identity, url: d.them[0].pictures.primary.url }) this.$store.commit('cacheAvatar', { identity, url: pic.primary.url })
}
} }
}) })
} else {
resolve()
}
}, },
}, },
} }