forked from LaconicNetwork/cosmos-explorer
add Okchain
This commit is contained in:
+11
-3
@@ -26,6 +26,14 @@ export function abbrMessage(msg) {
|
||||
return msg.typeUrl.substring(msg.typeUrl.lastIndexOf('.') + 1).replace('Msg', '')
|
||||
}
|
||||
|
||||
export function isStringArray(value) {
|
||||
let is = false
|
||||
if (Array.isArray(value)) {
|
||||
is = value.findIndex(x => typeof x === 'string') > -1
|
||||
}
|
||||
return is
|
||||
}
|
||||
|
||||
export function isToken(value) {
|
||||
let is = false
|
||||
if (Array.isArray(value)) {
|
||||
@@ -41,11 +49,11 @@ export function formatToken(token) {
|
||||
denom = denom.substring(1)
|
||||
const amount = token.amount / 1000000
|
||||
if (amount > 10) {
|
||||
return `${amount.toFixed()} ${denom}`
|
||||
return `${parseFloat(amount.toFixed())} ${denom}`
|
||||
}
|
||||
return `${amount} ${denom}`
|
||||
return `${parseFloat(amount)} ${denom}`
|
||||
}
|
||||
return `${token.amount} ${denom}`
|
||||
return `${parseFloat(token.amount)} ${denom}`
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
@@ -7,14 +7,22 @@ export default class StakingParameters {
|
||||
this.bond_denom = ''
|
||||
}
|
||||
|
||||
init(element) {
|
||||
static create(element, chain = '') {
|
||||
const self = new StakingParameters()
|
||||
if (element != null) {
|
||||
this.max_entries = Number(element.max_entries)
|
||||
this.historical_entries = Number(element.historical_entries)
|
||||
this.unbonding_time = element.unbonding_time
|
||||
this.max_validators = Number(element.max_validators)
|
||||
this.bond_denom = element.bond_denom
|
||||
if (chain === 'okexchain') {
|
||||
// self = element
|
||||
self.unbonding_time = element.unbonding_time
|
||||
self.max_validators = Number(element.max_bonded_validators)
|
||||
self.bond_denom = 'OKT'
|
||||
} else {
|
||||
self.max_entries = Number(element.max_entries)
|
||||
self.historical_entries = Number(element.historical_entries)
|
||||
self.unbonding_time = element.unbonding_time
|
||||
self.max_validators = Number(element.max_validators)
|
||||
self.bond_denom = element.bond_denom
|
||||
}
|
||||
}
|
||||
return this
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export default class Validator {
|
||||
this.jailed = element.jailed
|
||||
this.status = element.status
|
||||
this.tokens = Number(element.tokens)
|
||||
this.delegator_shares = element.delegator_shares
|
||||
this.delegator_shares = Number(element.delegator_shares)
|
||||
this.description = new ValidatorDescription().init(element.description)
|
||||
this.bond_height = Number(element.bond_height)
|
||||
this.bond_intra_tx_counter = element.bond_intra_tx_counter
|
||||
|
||||
+27
-5
@@ -7,7 +7,10 @@ import {
|
||||
} from './data'
|
||||
|
||||
function commonProcess(res) {
|
||||
return res.result
|
||||
if (res && Object.keys(res).includes('result')) {
|
||||
return res.result
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// 头像
|
||||
@@ -41,6 +44,13 @@ const chainAPI = class ChainFetch {
|
||||
return this.config
|
||||
}
|
||||
|
||||
isModuleLoaded(name) {
|
||||
if (this.config.unload_module) {
|
||||
return !this.config.unload_module.includes(name)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async getLatestBlock() {
|
||||
return this.get('/blocks/latest').then(data => Block.create(data))
|
||||
}
|
||||
@@ -82,11 +92,17 @@ const chainAPI = class ChainFetch {
|
||||
}
|
||||
|
||||
async getMintingInflation() {
|
||||
return this.get('/minting/inflation').then(data => Number(commonProcess(data)))
|
||||
if (this.isModuleLoaded('minting')) {
|
||||
return this.get('/minting/inflation').then(data => Number(commonProcess(data)))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async getStakingParameters() {
|
||||
return this.get('/staking/parameters').then(data => new StakingParameters().init(commonProcess(data)))
|
||||
return this.get('/staking/parameters').then(data => {
|
||||
this.getSelectedConfig()
|
||||
return StakingParameters.create(commonProcess(data), this.config.chain_name)
|
||||
})
|
||||
}
|
||||
|
||||
async getValidatorList() {
|
||||
@@ -98,11 +114,17 @@ const chainAPI = class ChainFetch {
|
||||
}
|
||||
|
||||
async getSlashingParameters() {
|
||||
return this.get('/slashing/parameters').then(data => commonProcess(data))
|
||||
if (this.isModuleLoaded('slashing')) {
|
||||
return this.get('/slashing/parameters').then(data => commonProcess(data))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async getMintParameters() {
|
||||
return this.get('/minting/parameters').then(data => commonProcess(data))
|
||||
if (this.isModuleLoaded('minting')) {
|
||||
return this.get('/minting/parameters').then(data => commonProcess(data))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async getDistributionParameters() {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import Vue from 'vue'
|
||||
import AsyncComputed from 'vue-async-computed'
|
||||
import { ToastPlugin, ModalPlugin } from 'bootstrap-vue'
|
||||
import VueCompositionAPI from '@vue/composition-api'
|
||||
import messages from '@/lang'
|
||||
@@ -19,7 +18,6 @@ import './global-components'
|
||||
import '@/libs/portal-vue'
|
||||
import '@/libs/toastification'
|
||||
|
||||
Vue.use(AsyncComputed)
|
||||
Vue.use(VueI18n)
|
||||
|
||||
const i18n = new VueI18n({
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"chain_name": "okexchain",
|
||||
"api": "https://exchainrpc.okex.org/okexchain/v1",
|
||||
"logo": "https://dl.airtable.com/.attachments/4620a173477efece7f459a3d6fc770c0/9f6618ad/OKexchain.svg",
|
||||
"unload_module": ["minting", "slashing"]
|
||||
}
|
||||
@@ -18,6 +18,9 @@
|
||||
<b-td v-if="isTokenField(value)">
|
||||
{{ formatTokens( value ) }}
|
||||
</b-td>
|
||||
<b-td v-else-if="isArrayText(value)">
|
||||
{{ value.join(', ') }}
|
||||
</b-td>
|
||||
<b-td v-else-if="Array.isArray(value)">
|
||||
<array-field-component :tablefield="value" />
|
||||
</b-td>
|
||||
@@ -56,7 +59,9 @@
|
||||
import {
|
||||
BTableSimple, BTr, BTd, BTabs, BTab,
|
||||
} from 'bootstrap-vue'
|
||||
import { abbr, isToken, tokenFormatter } from '@/libs/data'
|
||||
import {
|
||||
abbr, isStringArray, isToken, tokenFormatter,
|
||||
} from '@/libs/data'
|
||||
import ArrayFieldComponent from './ArrayFieldComponent.vue'
|
||||
|
||||
export default {
|
||||
@@ -95,6 +100,9 @@ export default {
|
||||
isTokenField(value) {
|
||||
return isToken(value)
|
||||
},
|
||||
isArrayText(value) {
|
||||
return isStringArray(value)
|
||||
},
|
||||
formatTokens(value) {
|
||||
return tokenFormatter(value)
|
||||
},
|
||||
|
||||
@@ -67,10 +67,14 @@
|
||||
</template>
|
||||
<!-- Token -->
|
||||
<template #cell(tokens)="data">
|
||||
<div class="d-flex flex-column">
|
||||
<div
|
||||
v-if="data.item.tokens > 0"
|
||||
class="d-flex flex-column"
|
||||
>
|
||||
<span class="font-weight-bold mb-0">{{ tokenFormatter(data.item.tokens, stakingParameters.bond_denom) }}</span>
|
||||
<span class="font-small-2 text-muted text-nowrap">{{ percent(data.item.tokens/stakingPool.bondedToken) }}%</span>
|
||||
</div>
|
||||
<span v-else>{{ data.item.delegator_shares }}</span>
|
||||
</template>
|
||||
</b-table>
|
||||
</b-card>
|
||||
@@ -187,6 +191,7 @@ export default {
|
||||
} else {
|
||||
window.sum += item.tokens
|
||||
}
|
||||
console.log(this.stakingPool.bondedToken)
|
||||
const rank = window.sum / this.stakingPool.bondedToken
|
||||
if (rank < 0.333) {
|
||||
return 'danger'
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
<span class="font-weight-bold">Identity</span>
|
||||
</th>
|
||||
<td class="pb-50">
|
||||
{{ validator.description.identity }}
|
||||
{{ validator.description.identity || '-' }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -138,7 +138,7 @@
|
||||
<span class="font-weight-bold">Unbond Height</span>
|
||||
</th>
|
||||
<td class="pb-50 text-capitalize">
|
||||
{{ validator.unbonding_height }}
|
||||
{{ validator.unbonding_height || '-' }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -162,7 +162,7 @@
|
||||
<span class="font-weight-bold">Min Self Delegation</span>
|
||||
</th>
|
||||
<td class="pb-50">
|
||||
{{ validator.min_self_delegation }}
|
||||
{{ parseFloat(validator.min_self_delegation) }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -174,7 +174,7 @@
|
||||
<span class="font-weight-bold">Jailed</span>
|
||||
</th>
|
||||
<td class="pb-50">
|
||||
{{ validator.jailed }}
|
||||
{{ validator.jailed || '-' }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -186,7 +186,7 @@
|
||||
<span class="font-weight-bold">Contact</span>
|
||||
</th>
|
||||
<td>
|
||||
{{ validator.security_contact }}
|
||||
{{ validator.security_contact || '-' }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -77,7 +77,7 @@ export default {
|
||||
},
|
||||
slasing: {
|
||||
title: 'Slasing Parameters',
|
||||
items: [],
|
||||
items: null,
|
||||
},
|
||||
mint: {
|
||||
title: 'Mint Parameters',
|
||||
@@ -145,6 +145,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
normalize(data, title) {
|
||||
if (!data) return null
|
||||
const items = this.makeItems(data)
|
||||
return {
|
||||
title,
|
||||
|
||||
Reference in New Issue
Block a user