Skip to content

Commit

Permalink
Formatting added
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitarangelkov authored and masiedu4 committed Aug 12, 2024
1 parent fd631d5 commit 714117e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/theme/AnnouncementBar/Content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ export default function AnnouncementBarContent(props) {
const [dynamicContent, setDynamicContent] = useState(content);
const [balanceLoaded, setBalanceLoaded] = useState(false);

function formatNumber(num) {
const absNum = Math.abs(num);

if (absNum >= 1000000000000) {
return (num / 1000000000000).toFixed(1) + "T";
} else if (absNum >= 1000000000) {
return (num / 1000000000).toFixed(1) + "B";
} else if (absNum >= 1000000) {
return (num / 1000000).toFixed(1) + "M";
} else if (absNum >= 1000) {
return (num / 1000).toFixed(1) + "K";
} else {
return num.toString();
}
}

// Fetch data for variables in the content
const getBalance = async () => {
if (typeof window === "undefined") {
Expand All @@ -37,7 +53,8 @@ export default function AnnouncementBarContent(props) {
args: ["0x0974CC873dF893B302f6be7ecf4F9D4b1A15C366"],
});
setBalanceLoaded(true);
return new Intl.NumberFormat().format(parseInt(formatEther(contractRead)));
const balanceInEther = parseFloat(formatEther(contractRead));
return formatNumber(balanceInEther);
};

// Add all variables and fetchers here
Expand Down

0 comments on commit 714117e

Please sign in to comment.