From 4cb92a72571273e2fbe07dd03d070d443d10d30f Mon Sep 17 00:00:00 2001 From: Derock Date: Sat, 15 Oct 2022 15:22:57 -0400 Subject: [PATCH] fix: NaN on stat card (#179) * fix: NaN % change * ref: format Co-authored-by: Jonathan Co-authored-by: Jonathan Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com> --- src/components/StatCard.tsx | 2 +- src/lib/utils/client.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/StatCard.tsx b/src/components/StatCard.tsx index b380e98..f6837c2 100644 --- a/src/components/StatCard.tsx +++ b/src/components/StatCard.tsx @@ -62,7 +62,7 @@ export default function StatCard({ stat }: StatsGridProps) { weight={500} className={classes.diff} > - {stat.diff}% + {stat.diff === Infinity ? '∞' : stat.diff}% { stat.diff >= 0 ? ( diff --git a/src/lib/utils/client.ts b/src/lib/utils/client.ts index 70dca73..7961c4b 100644 --- a/src/lib/utils/client.ts +++ b/src/lib/utils/client.ts @@ -85,5 +85,8 @@ export function parseExpiry(header: string): Date | null { } export function percentChange(initial: number, final: number) { + if (initial === 0 && final === 0) return 0; + if (initial === 0) return Infinity; + return ((final - initial) / initial) * 100; } \ No newline at end of file