Reviewed #544, made the logic in useFormatter instead

This commit is contained in:
ZENODE 2024-02-20 20:14:44 +01:00
parent dc1c4a5ca1
commit 4835781d29
2 changed files with 24 additions and 12 deletions

View File

@ -291,7 +291,6 @@ export const useDashboard = defineStore('dashboard', {
if(this.chains[k]) this.chains[k].assets.forEach(a => { if(this.chains[k]) this.chains[k].assets.forEach(a => {
if(a.coingecko_id !== undefined && a.coingecko_id.length > 0) { if(a.coingecko_id !== undefined && a.coingecko_id.length > 0) {
coinIds.push(a.coingecko_id) coinIds.push(a.coingecko_id)
}
a.denom_units.forEach(u => { a.denom_units.forEach(u => {
this.coingecko[u.denom] = { this.coingecko[u.denom] = {
coinId: a.coingecko_id || '', coinId: a.coingecko_id || '',
@ -299,6 +298,7 @@ export const useDashboard = defineStore('dashboard', {
symbol: a.symbol symbol: a.symbol
} }
}) })
}
}) })
}) })

View File

@ -121,16 +121,15 @@ export const useFormatter = defineStore('formatter', {
case denom.startsWith("a"): return 18 case denom.startsWith("a"): return 18
case denom==='inj': return 18 case denom==='inj': return 18
} }
return 0 return this.exponentForDenom(denom)
}, },
tokenAmountNumber(token?: Coin) { tokenAmountNumber(token?: Coin) {
if(!token || !token.denom) return 0 if(!token || !token.denom) return 0
// find the symbol // find the symbol
const symbol = this.dashboard.coingecko[token.denom]?.symbol || token.denom const symbol = this.dashboard.coingecko[token.denom]?.symbol || token.denom
// convert denomination to to symbol // convert denomination to symbol
const exponent = const exponent = this.dashboard.coingecko[symbol?.toLowerCase()]?.exponent || this.specialDenom(token.denom);
this.dashboard.coingecko[symbol?.toLowerCase()]?.exponent || this.specialDenom(token.denom);
// caculate amount of symbol // caculate amount of symbol
const amount = Number(token.amount) / (10 ** exponent) const amount = Number(token.amount) / (10 ** exponent)
return amount return amount
@ -160,7 +159,20 @@ export const useFormatter = defineStore('formatter', {
} }
return undefined return undefined
}, },
exponentForDenom(denom: string) {
const asset: Asset | undefined = this.findGlobalAssetConfig(denom)
let exponent = 0;
if (asset) {
// find the max exponent for display
asset.denom_units.forEach((x) => {
if (x.exponent >= exponent) {
exponent = x.exponent;
}
});
}
return exponent;
},
tokenDisplayDenom(denom?: string) { tokenDisplayDenom(denom?: string) {
if (denom) { if (denom) {
let asset: Asset | undefined; let asset: Asset | undefined;