fix: NaN on stat card (#179)

* fix: NaN % change

* ref: format

Co-authored-by: Jonathan <axis@axis.moe>

Co-authored-by: Jonathan <axis@axis.moe>
Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
This commit is contained in:
Derock 2022-10-15 15:22:57 -04:00 committed by GitHub
parent a095768eae
commit 4cb92a7257
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View file

@ -62,7 +62,7 @@ export default function StatCard({ stat }: StatsGridProps) {
weight={500}
className={classes.diff}
>
<span>{stat.diff}%</span>
<span>{stat.diff === Infinity ? '∞' : stat.diff}%</span>
{
stat.diff >= 0 ? (
<ArrowUpRight size={16} />

View file

@ -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;
}