Skip to content

Commit 9ddd81a

Browse files
committed
fix: remove one unnecessary loop and move the variables to the return directly
1 parent c2d85fa commit 9ddd81a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

web/src/hooks/queries/useHomePageBlockQuery.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ export const useHomePageBlockQuery = (blockNumber: number | null, allTime: boole
6262
numberVotes: presentCourt.numberVotes,
6363
treeNumberVotes: presentCourt.numberVotes,
6464
effectiveStake: presentCourt.effectiveStake,
65+
votesPerPnk: Number(presentCourt.numberVotes) / (Number(presentCourt.effectiveStake) / 1e18),
66+
treeVotesPerPnk: Number(presentCourt.numberVotes) / (Number(presentCourt.effectiveStake) / 1e18),
6567
}))
6668
: usedQuery.data.presentCourts.map((presentCourt) => {
6769
const pastCourt = usedQuery.data.pastCourts.find((pastCourt) => pastCourt.id === presentCourt.id);
70+
6871
return {
6972
...presentCourt,
7073
numberDisputes: pastCourt
@@ -78,6 +81,22 @@ export const useHomePageBlockQuery = (blockNumber: number | null, allTime: boole
7881
effectiveStake: pastCourt
7982
? (BigInt(presentCourt.effectiveStake) + BigInt(pastCourt.effectiveStake)) / 2n
8083
: presentCourt.effectiveStake,
84+
votesPerPnk:
85+
Number(pastCourt ? presentCourt.numberVotes - pastCourt.numberVotes : presentCourt.numberVotes) /
86+
(Number(
87+
pastCourt
88+
? (BigInt(presentCourt.effectiveStake) + BigInt(pastCourt.effectiveStake)) / 2n
89+
: presentCourt.effectiveStake
90+
) /
91+
1e18),
92+
treeVotesPerPnk:
93+
Number(pastCourt ? presentCourt.numberVotes - pastCourt.numberVotes : presentCourt.numberVotes) /
94+
(Number(
95+
pastCourt
96+
? (BigInt(presentCourt.effectiveStake) + BigInt(pastCourt.effectiveStake)) / 2n
97+
: presentCourt.effectiveStake
98+
) /
99+
1e18),
81100
};
82101
});
83102

@@ -93,10 +112,7 @@ export const useHomePageBlockQuery = (blockNumber: number | null, allTime: boole
93112
}
94113
}
95114
}
96-
for (const c of diffCourts) {
97-
c.votesPerPnk = Number(c.numberVotes) / (Number(c.effectiveStake) / 1e18);
98-
c.treeVotesPerPnk = c.votesPerPnk;
99-
}
115+
100116
for (const parent of diffCourts) {
101117
for (const child of diffCourts) {
102118
if (parent.id === child.parent?.id) {

0 commit comments

Comments
 (0)