Fixed issues

This commit is contained in:
liangping 2021-10-13 20:24:49 +08:00
parent 793ddf1a18
commit 367523db78
5 changed files with 51 additions and 17 deletions

View File

@ -6,9 +6,9 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1" />
<!-- Splash Screen/Loader Styles --> <!-- Splash Screen/Loader Styles -->
<link rel="stylesheet" type="text/css" href="loader.css" /> <link rel="stylesheet" type="text/css" href="/loader.css" />
<link rel="icon" href="favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<link <link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap" href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap"
rel="stylesheet" rel="stylesheet"
@ -24,7 +24,7 @@
</noscript> </noscript>
<div id="loading-bg"> <div id="loading-bg">
<div class="loading-logo"> <div class="loading-logo">
<img src="logo.svg" alt="Logo" width="80"/> <img src="/logo.svg" alt="Logo" width="80"/>
</div> </div>
<div class="loading"> <div class="loading">
<div class="effect-1 effects"></div> <div class="effect-1 effects"></div>

View File

@ -261,6 +261,8 @@ export function formatTokenDenom(tokenDenom) {
denom = 'CRO' denom = 'CRO'
} else if (denom.startsWith('IBC')) { } else if (denom.startsWith('IBC')) {
denom = 'IBC...' denom = 'IBC...'
} else if (denom.startsWith('NANOLIKE')) {
denom = 'LIKE'
} }
return denom return denom
@ -298,9 +300,9 @@ export function formatTokenAmount(tokenAmount, fraction = 2, denom = 'uatom') {
return parseFloat(amount) return parseFloat(amount)
} }
export function formatToken(token, IBCDenom = {}) { export function formatToken(token, IBCDenom = {}, decimals = 0) {
if (token) { if (token) {
return `${formatTokenAmount(token.amount, 0, token.denom)} ${formatTokenDenom(IBCDenom[token.denom] || token.denom)}` return `${formatTokenAmount(token.amount, decimals, token.denom)} ${formatTokenDenom(IBCDenom[token.denom] || token.denom)}`
} }
return token return token
} }

View File

@ -259,7 +259,10 @@ const chainAPI = class ChainFetch {
return this.get('/bank/balances/'.concat(address)).then(data => commonProcess(data)) return this.get('/bank/balances/'.concat(address)).then(data => commonProcess(data))
} }
async getStakingReward(address) { async getStakingReward(address, config = null) {
if (compareVersions(config || this.config.sdk_version, '0.40') < 0) {
return this.get(`/distribution/delegators/${address}/rewards`, config).then(data => commonProcess(data))
}
return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/rewards`).then(data => commonProcess(data)) return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/rewards`).then(data => commonProcess(data))
} }
@ -268,15 +271,33 @@ const chainAPI = class ChainFetch {
} }
async getStakingDelegations(address, config = null) { async getStakingDelegations(address, config = null) {
if (compareVersions(config || this.config.sdk_version, '0.40') < 0) {
return this.get(`/staking/delegators/${address}/delegations`, config).then(data => commonProcess(data).map(x => {
const xh = x
if (!xh.delegation) {
xh.delegation = {
validator_address: x.validator_address,
delegator_address: x.delegator_address,
}
}
return xh
}))
}
return this.get(`/cosmos/staking/v1beta1/delegations/${address}`, config).then(data => commonProcess(data)) return this.get(`/cosmos/staking/v1beta1/delegations/${address}`, config).then(data => commonProcess(data))
} }
async getStakingRedelegations(address, config = null) { async getStakingRedelegations(address, config = null) {
if (compareVersions(config || this.config.sdk_version, '0.40') < 0) {
return this.get(`/staking/redelegations?delegator=${address}`, config).then(data => commonProcess(data))
}
return this.get(`/cosmos/staking/v1beta1/delegators/${address}/redelegations`, config).then(data => commonProcess(data)) return this.get(`/cosmos/staking/v1beta1/delegators/${address}/redelegations`, config).then(data => commonProcess(data))
} }
async getStakingUnbonding(address) { async getStakingUnbonding(address, config = null) {
return this.get(`/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`).then(data => commonProcess(data)) if (compareVersions(config || this.config.sdk_version, '0.40') < 0) {
return this.get(`/staking/delegators/${address}/unbonding_delegations`, config).then(data => commonProcess(data))
}
return this.get(`/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`, config).then(data => commonProcess(data))
} }
async getBankBalances(address, config = null) { async getBankBalances(address, config = null) {

View File

@ -17,7 +17,6 @@
<script> <script>
import { BTable, BCardTitle, BCard } from 'bootstrap-vue' import { BTable, BCardTitle, BCard } from 'bootstrap-vue'
import { formatNumber, formatTokenAmount, formatTokenDenom } from '@/libs/data' import { formatNumber, formatTokenAmount, formatTokenDenom } from '@/libs/data'
import chainAPI from '@/libs/fetch'
export default { export default {
components: { components: {
@ -27,6 +26,7 @@ export default {
}, },
data() { data() {
return { return {
islive: true,
assets: [], assets: [],
denoms: [], denoms: [],
cfield: [ cfield: [
@ -43,21 +43,32 @@ export default {
} }
}, },
created() { created() {
const denoms = []
this.$http.getBankTotals().then(res => { this.$http.getBankTotals().then(res => {
const toshow = res.sort() const toshow = res.sort()
this.assets = toshow.reverse().map(x => { this.assets = toshow.reverse().map(x => {
if (x.denom.startsWith('ibc/')) { if (x.denom.startsWith('ibc/')) {
chainAPI.getIBCDenomTraceText(this.$http.config.api, x.denom).then(denom => { denoms.push(x.denom)
this.$set(this.denoms, x.denom, denom)
})
} }
const xh = x const xh = x
const amount = Number(x.amount) / 1000000 const amount = Number(x.amount) / 1000000
xh.abbr = amount > 1 ? formatNumber(formatTokenAmount(x.amount, 0, x.denom), true, 2) : amount xh.abbr = amount > 1 ? formatNumber(formatTokenAmount(x.amount, 0, x.denom), true, 2) : amount
return xh return xh
}) })
// let promise = Promise.resolve()
// denoms.forEach(x => {
// promise = promise.then(() => new Promise(resolve => {
// chainAPI.getIBCDenomTraceText(this.$http.config.api, x).then(denom => {
// if (this.islive) resolve()
// this.$set(this.denoms, x, denom)
// })
// }))
// })
}) })
}, },
beforeDestroy() {
this.islive = false
},
methods: { methods: {
formatDenom(v) { formatDenom(v) {
return formatTokenDenom(this.denoms[v] ? this.denoms[v] : v) return formatTokenDenom(this.denoms[v] ? this.denoms[v] : v)

View File

@ -565,7 +565,7 @@ export default {
const reward = this.reward.rewards.find(r => r.validator_address === e.delegation.validator_address) const reward = this.reward.rewards.find(r => r.validator_address === e.delegation.validator_address)
re.push({ re.push({
validator: getStakingValidatorOperator(this.$http.config.chain_name, e.delegation.validator_address, 8), validator: getStakingValidatorOperator(this.$http.config.chain_name, e.delegation.validator_address, 8),
token: formatToken(e.balance), token: formatToken(e.balance, {}, 2),
reward: tokenFormatter(reward.reward), reward: tokenFormatter(reward.reward),
action: e.delegation.validator_address, action: e.delegation.validator_address,
}) })
@ -612,13 +612,13 @@ export default {
this.reward = res this.reward = res
}) })
this.$http.getStakingDelegations(this.address).then(res => { this.$http.getStakingDelegations(this.address).then(res => {
this.delegations = res.delegation_responses this.delegations = res.delegation_responses || res
}) })
this.$http.getStakingRedelegations(this.address).then(res => { this.$http.getStakingRedelegations(this.address).then(res => {
this.redelegations = res.redelegation_responses this.redelegations = res.redelegation_responses || res
}) })
this.$http.getStakingUnbonding(this.address).then(res => { this.$http.getStakingUnbonding(this.address).then(res => {
this.unbonding = res.unbonding_responses this.unbonding = res.unbonding_responses || res
}) })
this.$http.getTxsBySender(this.address).then(res => { this.$http.getTxsBySender(this.address).then(res => {
this.transactions = res this.transactions = res
@ -641,7 +641,7 @@ export default {
formatDenom(v) { formatDenom(v) {
return formatTokenDenom(this.denoms[v] ? this.denoms[v] : v) return formatTokenDenom(this.denoms[v] ? this.denoms[v] : v)
}, },
formatAmount(v, dec, denom) { formatAmount(v, dec = 2, denom = 'uatom') {
return formatTokenAmount(v, dec, denom) return formatTokenAmount(v, dec, denom)
}, },
formatToken(v) { formatToken(v) {