From c2b8fb84c165963cd0d32e5247fbbc57e6659b0c Mon Sep 17 00:00:00 2001 From: Kristof Csillag Date: Wed, 5 Jun 2024 10:04:23 +0200 Subject: [PATCH] Avoid showing "NaN%" in the charts when there is no prev data --- .changelog/1443.trivial.md | 1 + src/app/components/PercentageGain/index.tsx | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 .changelog/1443.trivial.md diff --git a/.changelog/1443.trivial.md b/.changelog/1443.trivial.md new file mode 100644 index 000000000..e52717bac --- /dev/null +++ b/.changelog/1443.trivial.md @@ -0,0 +1 @@ +Avoid showing "NaN%" in the charts when there is no prev data diff --git a/src/app/components/PercentageGain/index.tsx b/src/app/components/PercentageGain/index.tsx index f7b28e8f3..027b29b37 100644 --- a/src/app/components/PercentageGain/index.tsx +++ b/src/app/components/PercentageGain/index.tsx @@ -13,6 +13,9 @@ interface PercentageGainProps { * Negative percentage shows red box with down arrow. */ export const PercentageGain: FC = ({ earliestValue, latestValue }) => { + // If the previous data was zero, we can't divide with it, it would just get us infinity or Nan... + if (earliestValue === 0) return + const ratio = (latestValue - earliestValue) / earliestValue return (