Fix endpoint issues
This commit is contained in:
parent
85ca2e3989
commit
1a348f6d3e
@ -54,7 +54,6 @@
|
||||
<small id="data-provider">
|
||||
{{ currentApi }} ({{ selected_chain.sdk_version || '-' }})
|
||||
<b-dropdown
|
||||
v-if="apiOptions.length > 1"
|
||||
class="ml-0"
|
||||
variant="flat-primary"
|
||||
no-caret
|
||||
@ -163,7 +162,6 @@ import DarkToggler from '@core/layouts/components/app-navbar/components/DarkTogg
|
||||
import Locale from '@core/layouts/components/app-navbar/components/Locale.vue'
|
||||
import SearchBar from '@core/layouts/components/app-navbar/components/SearchBar.vue'
|
||||
// import CartDropdown from '@core/layouts/components/app-navbar/components/CartDropdown.vue'
|
||||
import store from '@/store'
|
||||
import { getLocalAccounts, timeIn, toDay } from '@/libs/utils'
|
||||
// import UserDropdown from '@core/layouts/components/app-navbar/components/UserDropdown.vue'
|
||||
|
||||
@ -197,12 +195,10 @@ export default {
|
||||
},
|
||||
},
|
||||
data() {
|
||||
const conf = store.state.chains.selected
|
||||
const s = localStorage.getItem(`${conf.chain_name}-api-index`)
|
||||
return {
|
||||
variant: 'success',
|
||||
tips: 'Synced',
|
||||
index: s || 0,
|
||||
index: 0,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -212,16 +208,16 @@ export default {
|
||||
},
|
||||
selected_chain() {
|
||||
this.block()
|
||||
return store.state.chains.selected
|
||||
return this.$store.state.chains.selected
|
||||
},
|
||||
chainVariant() {
|
||||
return this.variant
|
||||
},
|
||||
currentApi() {
|
||||
return this.apiOptions[Number(this.index)]
|
||||
return this.index + 1 > this.apiOptions.length ? this.apiOptions[0] : this.apiOptions[this.index]
|
||||
},
|
||||
apiOptions() {
|
||||
const conf = store.state.chains.selected
|
||||
const conf = this.$store.state.chains.selected
|
||||
if (Array.isArray(conf.api)) {
|
||||
return conf.api
|
||||
}
|
||||
@ -237,16 +233,19 @@ export default {
|
||||
methods: {
|
||||
change(v) {
|
||||
this.index = v
|
||||
const conf = store.state.chains.selected
|
||||
const conf = this.$store.state.chains.selected
|
||||
localStorage.setItem(`${conf.chain_name}-api-index`, v)
|
||||
},
|
||||
block() {
|
||||
store.commit('setHeight', 0)
|
||||
const conf = this.$store.state.chains.selected
|
||||
const s = localStorage.getItem(`${conf.chain_name}-api-index`) || 0
|
||||
this.index = Number(s)
|
||||
this.$store.commit('setHeight', 0)
|
||||
this.$http.getLatestBlock().then(block => {
|
||||
store.commit('setHeight', Number(block.block.header.height))
|
||||
this.$store.commit('setHeight', Number(block.block.header.height))
|
||||
if (timeIn(block.block.header.time, 1, 'm')) {
|
||||
this.variant = 'danger'
|
||||
this.tips = `Halted ${toDay(block.block.header.time, 'from')}, Height: ${store.state.chains.height} `
|
||||
this.tips = `Halted ${toDay(block.block.header.time, 'from')}, Height: ${this.$store.state.chains.height} `
|
||||
} else {
|
||||
this.variant = 'success'
|
||||
this.tips = 'Synced'
|
||||
|
@ -251,33 +251,6 @@ export default class ChainFetch {
|
||||
})
|
||||
}
|
||||
|
||||
async get(url, config = null) {
|
||||
let host = ''
|
||||
if (!config) {
|
||||
this.getSelectedConfig()
|
||||
}
|
||||
host = (config ? config.api : this.config.api)
|
||||
const finalurl = (Array.isArray(host) ? host[this.getApiIndex(config)] : host) + url
|
||||
// finalurl = finalurl.replaceAll('v1beta1', this.getEndpointVersion())
|
||||
const ret = await fetch(finalurl).then(response => response.json())
|
||||
return ret
|
||||
}
|
||||
|
||||
getApiIndex(config = null) {
|
||||
const conf = config || this.config
|
||||
return localStorage.getItem(`${conf.chain_name}-api-index`) || 0
|
||||
}
|
||||
|
||||
async getUrl(url) {
|
||||
this.getSelectedConfig()
|
||||
return fetch(url).then(res => res.json())
|
||||
}
|
||||
|
||||
static fetch(host, url) {
|
||||
const ret = fetch((Array.isArray(host) ? host[0] : host) + url).then(response => response.json())
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAuthAccount(address, config = null) {
|
||||
return this.get('/auth/accounts/'.concat(address), config).then(data => {
|
||||
const result = commonProcess(data)
|
||||
@ -420,9 +393,9 @@ export default class ChainFetch {
|
||||
this.getSelectedConfig()
|
||||
}
|
||||
const conf = config || this.config
|
||||
const index = localStorage.getItem(`${conf.chain_name}-api-index`) || 0
|
||||
const index = this.getApiIndex(config)
|
||||
// Default options are marked with *
|
||||
const response = await fetch((Array.isArray(conf.api) ? conf.api[Number(index)] : conf.api) + url, {
|
||||
const response = await fetch((Array.isArray(conf.api) ? conf.api[index] : conf.api) + url, {
|
||||
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
||||
// mode: 'cors', // no-cors, *cors, same-origin
|
||||
// credentials: 'same-origin', // redirect: 'follow', // manual, *follow, error
|
||||
@ -437,6 +410,33 @@ export default class ChainFetch {
|
||||
// const response = axios.post((config ? config.api : this.config.api) + url, data)
|
||||
return response.json() // parses JSON response into native JavaScript objects
|
||||
}
|
||||
|
||||
async get(url, config = null) {
|
||||
if (!config) {
|
||||
this.getSelectedConfig()
|
||||
}
|
||||
const conf = config || this.config
|
||||
const finalurl = (Array.isArray(conf.api) ? conf.api[this.getApiIndex(config)] : conf.api) + url
|
||||
// finalurl = finalurl.replaceAll('v1beta1', this.getEndpointVersion())
|
||||
const ret = await fetch(finalurl).then(response => response.json())
|
||||
return ret
|
||||
}
|
||||
|
||||
getApiIndex(config = null) {
|
||||
const conf = config || this.config
|
||||
const index = Number(localStorage.getItem(`${conf.chain_name}-api-index`) || 0)
|
||||
return index < conf.api.length ? index : 0
|
||||
}
|
||||
|
||||
async getUrl(url) {
|
||||
this.getSelectedConfig()
|
||||
return fetch(url).then(res => res.json())
|
||||
}
|
||||
|
||||
static fetch(host, url) {
|
||||
const ret = fetch((Array.isArray(host) ? host[0] : host) + url).then(response => response.json())
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
// export default chainAPI
|
||||
|
Loading…
Reference in New Issue
Block a user