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" />
<!-- 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
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap"
rel="stylesheet"
@ -24,7 +24,7 @@
</noscript>
<div id="loading-bg">
<div class="loading-logo">
<img src="logo.svg" alt="Logo" width="80"/>
<img src="/logo.svg" alt="Logo" width="80"/>
</div>
<div class="loading">
<div class="effect-1 effects"></div>

View File

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

View File

@ -259,7 +259,10 @@ const chainAPI = class ChainFetch {
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))
}
@ -268,15 +271,33 @@ const chainAPI = class ChainFetch {
}
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))
}
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))
}
async getStakingUnbonding(address) {
return this.get(`/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`).then(data => commonProcess(data))
async getStakingUnbonding(address, config = null) {
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) {

View File

@ -17,7 +17,6 @@
<script>
import { BTable, BCardTitle, BCard } from 'bootstrap-vue'
import { formatNumber, formatTokenAmount, formatTokenDenom } from '@/libs/data'
import chainAPI from '@/libs/fetch'
export default {
components: {
@ -27,6 +26,7 @@ export default {
},
data() {
return {
islive: true,
assets: [],
denoms: [],
cfield: [
@ -43,21 +43,32 @@ export default {
}
},
created() {
const denoms = []
this.$http.getBankTotals().then(res => {
const toshow = res.sort()
this.assets = toshow.reverse().map(x => {
if (x.denom.startsWith('ibc/')) {
chainAPI.getIBCDenomTraceText(this.$http.config.api, x.denom).then(denom => {
this.$set(this.denoms, x.denom, denom)
})
denoms.push(x.denom)
}
const xh = x
const amount = Number(x.amount) / 1000000
xh.abbr = amount > 1 ? formatNumber(formatTokenAmount(x.amount, 0, x.denom), true, 2) : amount
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: {
formatDenom(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)
re.push({
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),
action: e.delegation.validator_address,
})
@ -612,13 +612,13 @@ export default {
this.reward = 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.redelegations = res.redelegation_responses
this.redelegations = res.redelegation_responses || 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.transactions = res
@ -641,7 +641,7 @@ export default {
formatDenom(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)
},
formatToken(v) {