Skip to content

Commit 79aa34a

Browse files
committed
feat: show no activity in this period, fix nan bug in court stats hook
1 parent 3ec316b commit 79aa34a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

web/src/hooks/queries/useHomePageBlockQuery.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ const processData = (data: HomePageBlockQuery, allTime: boolean) => {
128128
};
129129

130130
const addTreeValues = (court: Court): CourtWithTree => {
131-
const votesPerPnk = Number(court.numberVotes) / (Number(court.effectiveStake) / 1e18);
132-
const disputesPerPnk = Number(court.numberDisputes) / (Number(court.effectiveStake) / 1e18);
131+
const votesPerPnk = Number(court.numberVotes) / (Number(court.effectiveStake) / 1e18) || 0;
132+
const disputesPerPnk = Number(court.numberDisputes) / (Number(court.effectiveStake) / 1e18) || 0;
133133
const expectedRewardPerPnk = votesPerPnk * (Number(court.feeForJuror) / 1e18);
134134
return {
135135
...court,
@@ -154,8 +154,8 @@ const addTreeValuesWithDiff = (presentCourt: Court, pastCourt: Court): CourtWith
154154
const diffNumberVotes = presentCourtWithTree.numberVotes - pastCourtWithTree.numberVotes;
155155
const diffNumberDisputes = presentCourtWithTree.numberDisputes - pastCourtWithTree.numberDisputes;
156156
const avgEffectiveStake = (presentCourtWithTree.effectiveStake + pastCourtWithTree.effectiveStake) / 2n;
157-
const votesPerPnk = diffNumberVotes / (Number(avgEffectiveStake) / 1e18);
158-
const disputesPerPnk = diffNumberDisputes / (Number(avgEffectiveStake) / 1e18);
157+
const votesPerPnk = diffNumberVotes / (Number(avgEffectiveStake) / 1e18) || 0;
158+
const disputesPerPnk = diffNumberDisputes / (Number(avgEffectiveStake) / 1e18) || 0;
159159
const expectedRewardPerPnk = votesPerPnk * (Number(presentCourt.feeForJuror) / 1e18);
160160
return {
161161
...presentCourt,

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ const StyledCard = styled.div`
1717
justify-content: center;
1818
`;
1919

20+
const StyledLabel = styled.label`
21+
margin-top: 24px;
22+
font-size: 14px;
23+
font-weight: 600;
24+
`;
25+
2026
interface IStat {
2127
title: string;
2228
getText: (data) => string;
@@ -77,9 +83,13 @@ const ExtraStats = () => {
7783
}
7884
icon={LawBalance}
7985
/>
80-
{stats.map(({ title, getText, icon }) => (
81-
<ExtraStatsDisplay key={title} {...{ title, icon }} text={getText(data)} />
82-
))}
86+
{data.data?.mostDisputedCourt?.numberDisputes === 0 ? (
87+
<StyledLabel>No activity in this period</StyledLabel>
88+
) : (
89+
stats.map(({ title, getText, icon }) => (
90+
<ExtraStatsDisplay key={title} {...{ title, icon }} text={getText(data)} />
91+
))
92+
)}
8393
</StyledCard>
8494
);
8595
};

0 commit comments

Comments
 (0)