Skip to content

Commit

Permalink
feat(BlobBurn): round USD to two decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
alextes committed Mar 27, 2024
1 parent 84fc047 commit 1bafea3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 15 additions & 5 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ const usdZeroDecimals = new Intl.NumberFormat("en-US", {
export const formatUsdZeroDecimals = (num: number): string =>
usdZeroDecimals.format(num);

const usdTwoDecimals = new Intl.NumberFormat("en-US", {
currency: "USD",
style: "currency",
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});

export const formatUsdTwoDecimals = (num: number): string =>
usdTwoDecimals.format(num);

const percentOneDecimalSigned = new Intl.NumberFormat("en-US", {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
Expand Down Expand Up @@ -178,11 +188,11 @@ export function convertToInternationalCurrencySystem(labelValue: number) {
? Number(Math.abs(Number(labelValue)) / 1.0e9).toFixed(2) + "B"
: // Six Zeroes for Millions
Math.abs(Number(labelValue)) >= 1.0e6
? Number(Math.abs(Number(labelValue)) / 1.0e6).toFixed(2) + "M"
: // Three Zeroes for Thousands
Math.abs(Number(labelValue)) >= 1.0e3
? Number(Math.abs(Number(labelValue)) / 1.0e3).toFixed(2) + "K"
: Math.abs(Number(labelValue)).toFixed(2);
? Number(Math.abs(Number(labelValue)) / 1.0e6).toFixed(2) + "M"
: // Three Zeroes for Thousands
Math.abs(Number(labelValue)) >= 1.0e3
? Number(Math.abs(Number(labelValue)) / 1.0e3).toFixed(2) + "K"
: Math.abs(Number(labelValue)).toFixed(2);
}

export const capitalize = (str: unknown) =>
Expand Down
10 changes: 2 additions & 8 deletions src/mainsite/components/BlobBurnWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
import type { TimeFrame } from "../../mainsite/time-frames";
import TimeFrameIndicator from "./TimeFrameIndicator";
import type { OnClick } from "../../components/TimeFrameControl";
import { formatUsdTwoDecimals, formatUsdZeroDecimals } from "../../format";

const GWEI_FORMATTING_THRESHOLD = 1e15; // Threshold in wei below which to convert format as Gwei instead of ETH
const ETH_BURN_DECIMALS = 3;
const USD_BURN_DECIMALS = 9;

function addCommas(inputNumber: number) {
// Convert number to string without scientific notation
Expand Down Expand Up @@ -74,13 +74,7 @@ const BlobBurnWidget: FC<Props> = ({ onClickTimeFrame, timeFrame }) => {
const blobFeeBurnUSD =
feesBurned === undefined
? undefined
: addCommas(
parseFloat(
feesBurned[timeframeFeesBurnedMap[timeFrame]["usd"]].toFixed(
USD_BURN_DECIMALS,
),
),
);
: formatUsdTwoDecimals(feesBurned[timeframeFeesBurnedMap[timeFrame]["usd"]]);

const formatBurnAsGwei =
blobFeeBurn !== undefined && blobFeeBurn < GWEI_FORMATTING_THRESHOLD;
Expand Down

0 comments on commit 1bafea3

Please sign in to comment.