Files
tom goriunovandGitHub 57cf51cdc7 Gas tracker improvements (#1941)
* Alter gas tracker behaviour in case of null gas prices from backend

* display small amounts of gwei

* remove links to stats if feature is not enabled

* fix test
2024-05-23 12:35:49 +02:00

33 lines
842 B
TypeScript

import type { GasPriceInfo } from 'types/api/stats';
import type { GasUnit } from 'types/client/gasTracker';
import { currencyUnits } from 'lib/units';
export default function formatGasValue(data: GasPriceInfo, unit: GasUnit) {
switch (unit) {
case 'gwei': {
if (!data.price) {
return `N/A ${ currencyUnits.gwei }`;
}
if (Number(data.price) < 0.1) {
return `< 0.1 ${ currencyUnits.gwei }`;
}
return `${ Number(data.price).toLocaleString(undefined, { maximumFractionDigits: 1 }) } ${ currencyUnits.gwei }`;
}
case 'usd': {
if (!data.fiat_price) {
return `$N/A`;
}
if (Number(data.fiat_price) < 0.01) {
return `< $0.01`;
}
return `$${ Number(data.fiat_price).toLocaleString(undefined, { maximumFractionDigits: 2 }) }`;
}
}
}