clean code

This commit is contained in:
liangping 2021-08-05 20:53:01 +08:00
parent 2293446c93
commit 79b4bc671b
9 changed files with 6 additions and 19 deletions

View File

@ -39,7 +39,6 @@ const chainAPI = class ChainFetch {
chain.sdk_version = refetchVersion(chain) chain.sdk_version = refetchVersion(chain)
} }
this.config = chain this.config = chain
console.log(this.config)
return this.config return this.config
} }
@ -52,9 +51,7 @@ const chainAPI = class ChainFetch {
} }
async getTxs(hash) { async getTxs(hash) {
const FIELD = 'sdk_version'
const ver = this.getSelectedConfig() ? this.config.sdk_version : '0.41' const ver = this.getSelectedConfig() ? this.config.sdk_version : '0.41'
console.log(ver, this.config[FIELD])
// /cosmos/tx/v1beta1/txs/{hash} // /cosmos/tx/v1beta1/txs/{hash}
if (ver && compareVersions(ver, '0.40') < 1) { if (ver && compareVersions(ver, '0.40') < 1) {
return this.get(`/txs/${hash}`).then(data => WrapStdTx.create(data, ver)) return this.get(`/txs/${hash}`).then(data => WrapStdTx.create(data, ver))
@ -167,7 +164,7 @@ const chainAPI = class ChainFetch {
async get(url) { async get(url) {
this.getSelectedConfig() this.getSelectedConfig()
const ret = await fetch(this.config.api + url).then(response => response.json()).catch(e => console.log(e)) const ret = await fetch(this.config.api + url).then(response => response.json()).catch(e => console.error(e))
return ret return ret
} }
} }

View File

@ -24,9 +24,8 @@ Object.keys(chains).forEach(key => {
// eslint-disable-next-line prefer-destructuring // eslint-disable-next-line prefer-destructuring
chain.sdk_version = version[0] chain.sdk_version = version[0]
localStorage.setItem('chains', JSON.stringify(chains)) localStorage.setItem('chains', JSON.stringify(chains))
console.log(`${chain.api}/node_info`, localStorage.getItem('chains'))
}) })
.catch(e => console.log(`Failed get api vesion of ${key}`, e)) .catch(e => console.error(`Failed get api vesion of ${key}`, e))
}) })
export default { export default {

View File

@ -78,13 +78,11 @@ export default {
const tx = Tx.create(origin) const tx = Tx.create(origin)
tx.setHash(txs[i]) tx.setHash(txs[i])
array.push(tx) array.push(tx)
console.log('tx', origin, tx)
} catch (e) { } catch (e) {
console.log(e) console.error(e)
} }
} }
if (array.length > 0) this.txs = array if (array.length > 0) this.txs = array
console.log(this.txs)
}) })
}, },
} }

View File

@ -92,7 +92,7 @@ export default {
for (let i = 1; i < 20; i += 1) { for (let i = 1; i < 20; i += 1) {
list.push(height - i) list.push(height - i)
} }
console.log(height, list)
let promise = Promise.resolve() let promise = Promise.resolve()
list.forEach(item => { list.forEach(item => {
promise = promise.then(() => new Promise(resolve => { promise = promise.then(() => new Promise(resolve => {

View File

@ -139,7 +139,7 @@ export default {
Object.keys(this.chains).forEach(k => { Object.keys(this.chains).forEach(k => {
const chain = this.chains[k] const chain = this.chains[k]
fetch(`${chain.api}/blocks/latest`).then(res => res.json()).then(b => { fetch(`${chain.api}/blocks/latest`).then(res => res.json()).then(b => {
console.log(b.block.header) // console.log(b.block.header)
const { header } = b.block const { header } = b.block
this.$set(chain, 'height', header.height) this.$set(chain, 'height', header.height)
this.$set(chain, 'time', toDay(header.time)) this.$set(chain, 'time', toDay(header.time))

View File

@ -265,7 +265,7 @@ export default {
this.$http.getGovernance(pid).then(p => { this.$http.getGovernance(pid).then(p => {
if (p.status === 2) { if (p.status === 2) {
this.$http.getGovernanceTally(pid, 0).then(t => p.updateTally(t)).catch(e => console.log('failed on update voting tally:', e)) this.$http.getGovernanceTally(pid, 0).then(t => p.updateTally(t)).catch(e => console.error('failed on update voting tally:', e))
} }
this.proposal = p this.proposal = p
}) })

View File

@ -161,7 +161,6 @@ export default {
this.validators = temp this.validators = temp
// fetch avatar from keybase // fetch avatar from keybase
console.log(identities)
let promise = Promise.resolve() let promise = Promise.resolve()
identities.forEach(item => { identities.forEach(item => {
promise = promise.then(() => new Promise(resolve => { promise = promise.then(() => new Promise(resolve => {
@ -171,7 +170,6 @@ export default {
}) })
}, },
beforeDestroy() { beforeDestroy() {
console.log('destroying')
this.islive = false this.islive = false
}, },
methods: { methods: {
@ -202,10 +200,8 @@ export default {
if (this.islive) { if (this.islive) {
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 const pic = d.them[0].pictures
console.log('fetch new avatar:', pic)
if (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', pic.primary.url) this.$set(validator, 'avatar', pic.primary.url)

View File

@ -329,7 +329,6 @@ export default {
this.initBlocks() this.initBlocks()
}, },
beforeDestroy() { beforeDestroy() {
console.log('destroying')
clearInterval(this.timer) clearInterval(this.timer)
}, },
methods: { methods: {
@ -343,7 +342,6 @@ export default {
this.accountAddress = operatorAddressToAccount(operAddress) this.accountAddress = operatorAddressToAccount(operAddress)
this.hexAddress = consensusPubkeyToHexAddress(consensusPubkey) this.hexAddress = consensusPubkeyToHexAddress(consensusPubkey)
this.$http.getStakingDelegatorDelegation(this.accountAddress, operAddress).then(d => { this.$http.getStakingDelegatorDelegation(this.accountAddress, operAddress).then(d => {
console.log(d)
this.selfDelegation = d this.selfDelegation = d
}) })
}, },

View File

@ -106,7 +106,6 @@ export default {
created() { created() {
const { hash } = this.$route.params const { hash } = this.$route.params
this.$http.getTxs(hash).then(res => { this.$http.getTxs(hash).then(res => {
console.log(res)
this.tx = res this.tx = res
}) })
}, },