From 24f39e3bce24834e53a004752825ce4d347e3ac7 Mon Sep 17 00:00:00 2001
From: liangping <18786721@qq.com>
Date: Wed, 16 Feb 2022 11:07:32 +0800
Subject: [PATCH] imporove disploy of token amount
---
src/chains/mainnet/provenance.json | 2 +-
src/libs/utils.js | 12 +++++++++---
src/views/StakingRewardComponent.vue | 15 +++++++++------
src/views/SummaryAssetsComponent.vue | 16 ++++++++++------
4 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/src/chains/mainnet/provenance.json b/src/chains/mainnet/provenance.json
index 7b4445ab..c8965a54 100644
--- a/src/chains/mainnet/provenance.json
+++ b/src/chains/mainnet/provenance.json
@@ -4,7 +4,7 @@
"api": "https://api.provenance.io",
"sdk_version": "0.44.3",
"coin_type": "505",
- "min_tx_fee": "3000",
+ "min_tx_fee": "400000000",
"addr_prefix": "pb",
"logo": "https://raw.githubusercontent.com/provenance-io/provenance/main/docs/pio.svg",
"assets": [{
diff --git a/src/libs/utils.js b/src/libs/utils.js
index cb863779..e36bc012 100644
--- a/src/libs/utils.js
+++ b/src/libs/utils.js
@@ -357,6 +357,12 @@ export function getUnitAmount(amount, tokenDenom) {
return String(BigInt(Number(amount) * (10 ** exp)))
}
+export function numberWithCommas(x) {
+ const parts = x.toString().split('.')
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
+ return parts.join('.')
+}
+
export function formatTokenAmount(tokenAmount, fraction = 2, tokenDenom = 'uatom') {
const denom = tokenDenom.denom_trace ? tokenDenom.denom_trace.base_denom : tokenDenom
let amount = 0
@@ -372,9 +378,9 @@ export function formatTokenAmount(tokenAmount, fraction = 2, tokenDenom = 'uatom
})
amount = Number(Number(tokenAmount)) / (10 ** exp)
if (amount > 10) {
- return parseFloat(amount.toFixed(fraction))
+ return numberWithCommas(parseFloat(amount.toFixed(fraction)))
}
- return parseFloat(amount)
+ return parseFloat(amount.toFixed(fraction))
}
export function isTestnet() {
@@ -405,7 +411,7 @@ export function formatNumber(count, withAbbr = false, decimals = 2) {
export function tokenFormatter(tokens, denoms = {}) {
if (Array.isArray(tokens)) {
- return tokens.map(t => formatToken(t, denoms, 2)).join()
+ return tokens.map(t => formatToken(t, denoms, 2)).join(', ')
}
return formatToken(tokens, denoms, 2)
}
diff --git a/src/views/StakingRewardComponent.vue b/src/views/StakingRewardComponent.vue
index 8024015a..17645d6f 100644
--- a/src/views/StakingRewardComponent.vue
+++ b/src/views/StakingRewardComponent.vue
@@ -32,9 +32,9 @@
- {{ formatNumber(d.amount) }}
+ {{ formatDenom(d) }}
- {{ formatDenom(d.denom) }}
+ {{ formatNumber(d.amount) }}
- {{ formatNumber(d.amount) }}
+ {{ formatDenom(d) }}
- {{ formatDenom(d.denom) }}
+ {{ formatNumber(d.amount) }}
{
x.denom_traces.forEach(trace => {
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`)))
- this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom)
+ this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace)
})
})
this.$http.getBankTotals().then(res => {
const toshow = res.sort()
this.assets = toshow.reverse().map(x => {
const xh = x
- xh.abbr = x.amount > 1 ? formatNumber(formatTokenAmount(x.amount, 0, x.denom), true, 2) : x.amount
+ xh.abbr = formatTokenAmount(x.amount, 0, x.denom)
return xh
})
})
@@ -65,7 +65,11 @@ export default {
},
methods: {
formatDenom(v) {
- return formatTokenDenom(this.denoms[v] ? this.denoms[v] : v)
+ if (this.denoms[v]) {
+ const trace = this.denoms[v]
+ return `* ${formatTokenDenom(trace.base_denom)} (${trace.path})`
+ }
+ return v
},
},
}