From aa5ab97f1b314bd4e7a2358e49572eb1a02baf7b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 10 Oct 2024 00:07:06 -0700 Subject: followers --- src/lib/utils.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/lib/utils.ts') diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b32095cb..2ecd332b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -60,7 +60,6 @@ export let post = async ( .then(async (r) => { if (r.ok) return r.text(); let text = await r.text(); - console.log("TEXT", text) let message; try { @@ -217,20 +216,16 @@ export let f = (s: number, currency: string): string => { export let s = (s: number): string => new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(s); -export let sat = (s: number): string => { - s = Math.abs(s); - let p = Math.floor(Math.log(s) / Math.LN10 + 0.000000001); - let d = Math.floor((p + 1) / 3); - - return ( - "⚡️" + - (parseInt(s.toString()) > 0 - ? new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format( - s / Math.pow(1000, d) - ) + ["", "K", "M", "G", "T", "P", "E", "Z"][d] - : 0 - ).toString() - ); +export let sat = (s: number): string => "⚡️" + si(Math.abs(s)).toString(); + +export let si = (s: number) => { + if (s < 1000) return s.toString(); // Return the original number if it's less than 1000 + + const units = ["", "K", "M", "G", "T", "P", "E", "Z"]; + const d = Math.floor(Math.log10(s) / 3); // Calculate the unit index + const scaled = s / Math.pow(1000, d); // Scale the number to the correct unit + + return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(scaled) + units[d]; }; export let sats = 100000000; @@ -363,4 +358,3 @@ export let versions = { public: 0x043587cf, }, }[PUBLIC_COINOS_NETWORK]; - -- cgit v1.2.3