From ae4d557a9be3ee6a9db6e67962042cdfd2d594b0 Mon Sep 17 00:00:00 2001 From: csrapr <26280794+csrapr@users.noreply.github.com> Date: Wed, 3 Mar 2021 20:06:32 +0000 Subject: [PATCH] Fix: show correct percentage icon and use BigNumber methods for maths --- .../SystemPerformance/SystemPerformance.js | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js b/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js index ed3c5143..817364ed 100644 --- a/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js +++ b/new-lamassu-admin/src/pages/Dashboard/SystemPerformance/SystemPerformance.js @@ -124,18 +124,17 @@ const SystemPerformance = () => { } const getPercentChange = () => { - const thisTimePeriodProfit = getProfit(transactionsToShow).toNumber() - const previousTimePeriodProfit = getProfit( - transactionsLastTimePeriod - ).toNumber() + const thisTimePeriodProfit = getProfit(transactionsToShow) + const previousTimePeriodProfit = getProfit(transactionsLastTimePeriod) - if (thisTimePeriodProfit === previousTimePeriodProfit) return 0 - if (previousTimePeriodProfit === 0) return 100 + if (thisTimePeriodProfit.eq(previousTimePeriodProfit)) return 0 + if (previousTimePeriodProfit.eq(0)) return 100 - return new BigNumber( - ((thisTimePeriodProfit - previousTimePeriodProfit) * 100) / - previousTimePeriodProfit - ).toFormat(2) + return thisTimePeriodProfit + .minus(previousTimePeriodProfit) + .times(100) + .div(previousTimePeriodProfit) + .toNumber() } const getDirectionPercent = () => { @@ -211,7 +210,7 @@ const SystemPerformance = () => {
{getPercentageIcon()} - {`${percentChange}%`} + {`${new BigNumber(percentChange).toFormat(2)}%`}