Make printableCoin aware of NEXT_PUBLIC_DISPLAY_DENOM/NEXT_PUBLIC_DISPLAY_DENOM_EXPONENT
This commit is contained in:
parent
c7def77752
commit
1751962bf1
@ -24,17 +24,32 @@ const thinSpace = "\u202F";
|
||||
// Takes a Coin (e.g. `{"amount": "1234", "denom": "uatom"}`) and converts it
|
||||
// into a user-readable string.
|
||||
//
|
||||
// The configured NEXT_PUBLIC_DISPLAY_DENOM/NEXT_PUBLIC_DISPLAY_DENOM_EXPONENT
|
||||
// will be used if the denom matches NEXT_PUBLIC_DENOM.
|
||||
//
|
||||
// A leading "u" is interpreted as µ (micro) and uxyz will be converted to XYZ
|
||||
// for displaying.
|
||||
const printableCoin = (coin) => {
|
||||
// null, undefined and this sort of things
|
||||
if (!coin) return "–";
|
||||
|
||||
if (coin.denom?.startsWith("u")) {
|
||||
const ticker = coin.denom.slice(1).toUpperCase();
|
||||
return Decimal.fromAtomics(coin.amount ?? "0", 6).toString() + thinSpace + ticker;
|
||||
} else {
|
||||
return coin.amount + thinSpace + coin.denom;
|
||||
// The display denom from configuration
|
||||
if (coin.denom === process.env.NEXT_PUBLIC_DENOM) {
|
||||
const exponent = Number(process.env.NEXT_PUBLIC_DISPLAY_DENOM_EXPONENT);
|
||||
const value = Decimal.fromAtomics(coin.amount ?? "0", exponent).toString();
|
||||
const ticker = process.env.NEXT_PUBLIC_DISPLAY_DENOM;
|
||||
return value + thinSpace + ticker;
|
||||
}
|
||||
|
||||
// Auto-convert leading "u"s
|
||||
if (coin.denom?.startsWith("u")) {
|
||||
const value = Decimal.fromAtomics(coin.amount ?? "0", 6).toString();
|
||||
const ticker = coin.denom.slice(1).toUpperCase();
|
||||
return value + thinSpace + ticker;
|
||||
}
|
||||
|
||||
// Fallback to plain coin display
|
||||
return coin.amount + thinSpace + coin.denom;
|
||||
}
|
||||
|
||||
const printableCoins = (coins) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user