Fix router bug

This commit is contained in:
liangping
2021-08-07 23:22:41 +08:00
parent aaee720df8
commit d92ba1538c
7 changed files with 172 additions and 33 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ async function refetchVersion(chain) {
const re = /(\d+(\.\d+)*)/i
const version = sdk.match(re)
return version[0]
})
}).catch(() => null)
}
const chainAPI = class ChainFetch {
+6 -15
View File
@@ -1,6 +1,5 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import fetch from 'node-fetch'
import store from '../store'
Vue.use(VueRouter)
@@ -190,20 +189,12 @@ const router = new VueRouter({
router.beforeEach((to, from, next) => {
const c = to.params.chain
const has = Object.keys(store.state.chains.config).findIndex(i => i === c)
if (has > -1) {
const chain = store.state.chains.config[c]
store.commit('select', { chain_name: c })
if (chain.sdk_version) {
fetch(`${chain.api}/node_info`)
.then(res => res.json())
.then(json => {
const sdk = json.application_version.build_deps.find(e => e.startsWith('github.com/cosmos/cosmos-sdk'))
const re = /(\d+(\.\d+)*)/i
const version = sdk.match(re)
store.commit('setup_sdk_version', { chain_name: c, version: version[0] })
})
}
store.commit('select', { chain_name: c })
const config = JSON.parse(localStorage.getItem('chains'))
console.log(config, c)
// const has = Object.keys(config).findIndex(i => i === c)
if (!config || Object.keys(config).findIndex(i => i === c) > -1) {
next()
} else if (c) {
next({ name: 'chain-404' })
+7 -5
View File
@@ -1,10 +1,5 @@
let chains = {}
const localChains = localStorage.getItem('chains')
if (localChains) {
chains = JSON.parse(localChains)
}
const configs = require.context('.', false, /\.json$/)
const update = {}
@@ -13,6 +8,13 @@ configs.keys().forEach(k => {
update[c.chain_name] = c
})
const localChains = localStorage.getItem('chains')
if (localChains) {
chains = JSON.parse(localChains)
} else {
chains = update
}
Object.keys(update).forEach(key => {
const chain = update[key]
fetch(`${chain.api}/node_info`)
-12
View File
@@ -130,12 +130,6 @@ export default {
tdClass: 'text-right',
thClass: 'text-right',
},
{
key: 'apr',
formatter: (value, i, data) => this.apr(value, i, data),
tdClass: 'text-right',
thClass: 'text-right',
},
{ key: 'operation' },
],
}
@@ -144,9 +138,6 @@ export default {
this.$http.getStakingPool().then(res => {
this.stakingPool = res
})
this.$http.getMintingInflation().then(res => {
this.mintInflation = res
})
this.$http.getStakingParameters().then(res => {
this.stakingParameters = res
})
@@ -181,9 +172,6 @@ export default {
tokenFormatter(amount, denom) {
return formatToken({ amount, denom })
},
apr(value, i, data) {
return `${percent((1 - data.commission.rate) * this.mintInflation)} %`
},
rankBadge(data) {
const { index, item } = data
if (index === 0) {