Skip to content

Commit

Permalink
Updated fundamentals abbrevations to use hard coded values
Browse files Browse the repository at this point in the history
  • Loading branch information
mokelgit committed Sep 19, 2023
1 parent a08394a commit eb05ed2
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions components/layout/MetricsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,45 @@ const MetricsTable = ({
},
);

function formatNumber(number: number): string {
if (number === 0) {
return "0";
} else if (Math.abs(number) >= 1e9) {
if (Math.abs(number) >= 1e12) {
return (number / 1e12).toFixed(2) + "T";
} else if (Math.abs(number) >= 1e9) {
return (number / 1e9).toFixed(2) + "B";
}
} else if (Math.abs(number) >= 1e6) {
return (number / 1e6).toFixed(2) + "M";
} else if (Math.abs(number) >= 1e3) {
const rounded = (number / 1e3).toFixed(2);
return `${rounded}${Math.abs(number) >= 10000 ? "K" : "K"}`;
} else if (Math.abs(number) >= 100) {
return number.toFixed(2);
} else if (Math.abs(number) >= 10) {
return number.toFixed(2);
} else {
return number.toFixed(2);
}

// Default return if none of the conditions are met
return "";
}

const getDisplayValue = useCallback(
(item: any) => {
let prefix = "";
let suffix = "";
let value = Intl.NumberFormat(undefined, {
notation: "compact",
maximumFractionDigits: 2,
minimumFractionDigits: 2,
}).format(item.data.daily.data[item.data.daily.data.length - 1][1]);
let value = formatNumber(
item.data.daily.data[item.data.daily.data.length - 1][1],
);

if (item.data.daily.types.includes("eth")) {
if (!showUsd) {
prefix = "Ξ";

value = Intl.NumberFormat(undefined, {
notation: "compact",
maximumFractionDigits: 2,
minimumFractionDigits: 2,
}).format(
value = formatNumber(
item.data.daily.data[item.data.daily.data.length - 1][
item.data.daily.types.indexOf("eth")
],
Expand All @@ -174,23 +194,15 @@ const MetricsTable = ({
if (navItem && navItem.page?.showGwei) {
prefix = "";
suffix = " Gwei";
value = Intl.NumberFormat(undefined, {
notation: "compact",
maximumFractionDigits: 2,
minimumFractionDigits: 2,
}).format(
value = formatNumber(
item.data.daily.data[item.data.daily.data.length - 1][
item.data.daily.types.indexOf("eth")
] * 1000000000,
);
}
} else {
prefix = "$";
value = Intl.NumberFormat(undefined, {
notation: "compact",
maximumFractionDigits: 2,
minimumFractionDigits: 2,
}).format(
value = formatNumber(
item.data.daily.data[item.data.daily.data.length - 1][
item.data.daily.types.indexOf("usd")
],
Expand Down

1 comment on commit eb05ed2

@vercel
Copy link

@vercel vercel bot commented on eb05ed2 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.