Skip to content

Commit e9e0773

Browse files
committed
fix(web): round decimals in stats
1 parent 53bc949 commit e9e0773

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

web/src/pages/Courts/CourtDetails/Stats.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import StatDisplay, { IStatDisplay } from "components/StatDisplay";
88
import BalanceIcon from "svgs/icons/law-balance.svg";
99
import MinStake from "svgs/icons/min-stake.svg";
1010
import { commify } from "utils/commify";
11+
import { roundDecimals } from "utils/roundDecimals";
1112
import VoteStake from "svgs/icons/vote-stake.svg";
1213
import PNKIcon from "svgs/icons/pnk.svg";
1314
import PNKRedistributedIcon from "svgs/icons/redistributed-pnk.svg";
@@ -61,7 +62,7 @@ const stats: IStat[] = [
6162
{
6263
title: "PNK Staked",
6364
coinId: 0,
64-
getText: (data) => commify(formatUnits(data?.stake, 18)),
65+
getText: (data) => commify(roundDecimals(formatUnits(data?.stake, 18), 0)),
6566
getSubtext: (data, coinPrice) =>
6667
(parseInt(formatUnits(data?.stake, 18)) * (coinPrice ?? 0)).toFixed(2).toString() + "$",
6768
color: "purple",
@@ -84,7 +85,7 @@ const stats: IStat[] = [
8485
{
8586
title: "ETH paid to Jurors",
8687
coinId: 1,
87-
getText: (data) => commify(formatEther(BigInt(data?.paidETH))),
88+
getText: (data) => commify(roundDecimals(formatEther(BigInt(data?.paidETH)), 4)),
8889
getSubtext: (data, coinPrice) =>
8990
(Number(formatUnits(data?.paidETH, 18)) * (coinPrice ?? 0)).toFixed(2).toString() + "$",
9091
color: "blue",
@@ -93,7 +94,7 @@ const stats: IStat[] = [
9394
{
9495
title: "PNK redistributed",
9596
coinId: 0,
96-
getText: (data) => commify(formatUnits(data?.paidPNK, 18)),
97+
getText: (data) => commify(roundDecimals(formatUnits(data?.paidPNK, 18), 0)),
9798
getSubtext: (data, coinPrice) =>
9899
(parseInt(formatUnits(data?.paidPNK, 18)) * (coinPrice ?? 0)).toFixed(2).toString() + "$",
99100
color: "purple",

web/src/pages/Home/CourtOverview/Stats.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import BalanceIcon from "svgs/icons/law-balance.svg";
1111
import { KLEROS_CONTRACT_ADDRESS, WETH_CONTRACT_ADDRESS } from "src/consts/index";
1212
import { commify } from "utils/commify";
1313
import { isUndefined } from "utils/index";
14+
import { roundDecimals } from "utils/roundDecimals";
1415
import { useHomePageContext, HomePageQuery, HomePageQueryDataPoints } from "hooks/useHomePageContext";
1516
import { useCoinPrice } from "hooks/useCoinPrice";
1617

@@ -39,7 +40,7 @@ const stats: IStat[] = [
3940
{
4041
title: "PNK staked",
4142
coinId: 0,
42-
getText: (counters) => commify(formatUnits(getLastOrZero(counters, "stakedPNK"), 18)),
43+
getText: (counters) => commify(roundDecimals(formatUnits(getLastOrZero(counters, "stakedPNK"), 18), 0)),
4344
getSubtext: (counters, coinPrice) =>
4445
(parseInt(formatUnits(getLastOrZero(counters, "stakedPNK"), 18)) * (coinPrice ?? 0)).toFixed(2).toString() + "$",
4546
color: "purple",
@@ -48,7 +49,7 @@ const stats: IStat[] = [
4849
{
4950
title: "ETH Paid to jurors",
5051
coinId: 1,
51-
getText: (counters) => commify(formatEther(getLastOrZero(counters, "paidETH"))),
52+
getText: (counters) => commify(roundDecimals(formatEther(getLastOrZero(counters, "paidETH")), 4)),
5253
getSubtext: (counters, coinPrice) =>
5354
(Number(formatUnits(getLastOrZero(counters, "paidETH"), 18)) * (coinPrice ?? 0)).toFixed(2).toString() + "$",
5455
color: "blue",
@@ -57,7 +58,7 @@ const stats: IStat[] = [
5758
{
5859
title: "PNK redistributed",
5960
coinId: 0,
60-
getText: (counters) => commify(formatUnits(getLastOrZero(counters, "redistributedPNK"), 18)),
61+
getText: (counters) => commify(roundDecimals(formatUnits(getLastOrZero(counters, "redistributedPNK"), 18), 0)),
6162
getSubtext: (counters, coinPrice) =>
6263
(parseInt(formatUnits(getLastOrZero(counters, "redistributedPNK"), 18)) * (coinPrice ?? 0))
6364
.toFixed(2)

web/src/utils/roundDecimals.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const roundDecimals = (value: string, decimals: number): string => {
2+
const numberValue = parseFloat(value);
3+
const roundedValue = Math.round(numberValue * Math.pow(10, decimals)) / Math.pow(10, decimals);
4+
return roundedValue.toString();
5+
};

0 commit comments

Comments
 (0)