add ibc denom mapping

This commit is contained in:
liangping 2021-08-14 21:27:19 +08:00
parent 3e16fa9de8
commit 69d84b7a34
2 changed files with 23 additions and 2 deletions

View File

@ -227,6 +227,9 @@ export default {
if (isToken(data[k])) { if (isToken(data[k])) {
return { title: tokenFormatter(data[k]), subtitle: k } return { title: tokenFormatter(data[k]), subtitle: k }
} }
if (typeof data[k] === 'boolean') {
return { title: data[k], subtitle: k }
}
const d = Number(data[k]) const d = Number(data[k])
if (d < 1.01) { if (d < 1.01) {
return { title: `${percent(d)}%`, subtitle: k } return { title: `${percent(d)}%`, subtitle: k }

View File

@ -5,6 +5,7 @@
</b-card-title> </b-card-title>
<b-table <b-table
:items="assets" :items="assets"
:fields="cfield"
hover hover
striped striped
sticky-header="true" sticky-header="true"
@ -15,7 +16,8 @@
<script> <script>
import { BTable, BCardTitle, BCard } from 'bootstrap-vue' import { BTable, BCardTitle, BCard } from 'bootstrap-vue'
import { formatNumber } from '@/libs/data' import { formatNumber, formatTokenDenom } from '@/libs/data'
import chainAPI from '@/libs/fetch'
export default { export default {
components: { components: {
@ -26,11 +28,17 @@ export default {
data() { data() {
return { return {
assets: [], assets: [],
field: [ denoms: [],
cfield: [
{ {
key: 'denom', key: 'denom',
formatter: this.formatDenom,
tdClass: 'text-nowrap text-truncate overflow-hidden', tdClass: 'text-nowrap text-truncate overflow-hidden',
}, },
'abbr',
{
key: 'amount',
},
], ],
} }
}, },
@ -38,6 +46,11 @@ export default {
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/')) {
chainAPI.getIBCDenomTraceText(this.$http.config.api, x.denom).then(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(amount, true) : amount xh.abbr = amount > 1 ? formatNumber(amount, true) : amount
@ -45,6 +58,11 @@ export default {
}) })
}) })
}, },
methods: {
formatDenom(v) {
return formatTokenDenom(this.denoms[v] ? this.denoms[v] : v)
},
},
} }
</script> </script>