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 => {
promise = promise.then(() => new Promise(resolve => { if (this.islive) {
this.avatar(item.description.identity, index, resolve) promise = promise.then(() => new Promise(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) keybase(identity).then(d => {
if (url !== undefined) {
resolve() resolve()
console.log(identity)
const validator = this.validators.find(u => u.description.identity === identity) if (Array.isArray(d.them) && d.them.length > 0) {
this.$set(validator, 'avatar', url) const pic = d.them[0].pictures
} else if (identity) { console.log('fetch new avatar:', pic)
keybase(identity).then(d => { if (pic) {
resolve()
if (Array.isArray(d.them) && d.them.length > 0) {
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()
}
}, },
}, },
} }