Skip to content

Commit 22e54d7

Browse files
committed
chore: move coherence percent function to utils, change name for clarity
1 parent 94c7637 commit 22e54d7

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

web/src/pages/Home/TopJurors/JurorCard/Coherence.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { Tooltip } from "@kleros/ui-components-library";
21
import React from "react";
2+
33
import styled from "styled-components";
4+
import { Tooltip } from "@kleros/ui-components-library";
5+
6+
import { getCoherencePercent } from "utils/getCoherencePercent";
47

58
const Container = styled.div`
69
display: flex;
@@ -11,11 +14,6 @@ const Container = styled.div`
1114
justify-content: center;
1215
`;
1316

14-
export const getPercent = (num: number, den: number): string => {
15-
if (den === 0) return "0%";
16-
return `${Math.floor((num * 100) / den)}%`;
17-
};
18-
1917
interface ICoherence {
2018
totalCoherentVotes: string;
2119
totalResolvedVotes: string;
@@ -26,7 +24,9 @@ const Coherence: React.FC<ICoherence> = ({ totalCoherentVotes, totalResolvedVote
2624

2725
return (
2826
<Container>
29-
<Tooltip text={coherenceRatio}>{getPercent(Number(totalCoherentVotes), Number(totalResolvedVotes))}</Tooltip>
27+
<Tooltip text={coherenceRatio}>
28+
{getCoherencePercent(Number(totalCoherentVotes), Number(totalResolvedVotes))}
29+
</Tooltip>
3030
</Container>
3131
);
3232
};

web/src/pages/Home/TopJurors/JurorCard/JurorLevel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from "react";
22
import styled, { css } from "styled-components";
33

4-
import { getUserLevelData } from "utils/userLevelCalculation";
5-
64
import { landscapeStyle } from "styles/landscapeStyle";
75

6+
import { getUserLevelData } from "utils/userLevelCalculation";
7+
import { getCoherencePercent } from "utils/getCoherencePercent";
8+
89
import PixelArt from "pages/Profile/JurorInfo/PixelArt";
9-
import { getPercent } from "./Coherence";
1010

1111
const Container = styled.div`
1212
display: flex;
@@ -46,7 +46,7 @@ interface IJurorLevel {
4646
}
4747

4848
const JurorLevel: React.FC<IJurorLevel> = ({ totalCoherentVotes, totalResolvedVotes, totalResolvedDisputes }) => {
49-
const coherencePercentage = getPercent(Number(totalCoherentVotes), Number(totalResolvedVotes));
49+
const coherencePercentage = getCoherencePercent(Number(totalCoherentVotes), Number(totalResolvedVotes));
5050
const userLevelData = getUserLevelData(coherencePercentage, Number(totalResolvedDisputes));
5151
const level = userLevelData.level;
5252

web/src/pages/Profile/JurorInfo/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled, { css } from "styled-components";
44
import { Card as _Card } from "@kleros/ui-components-library";
55

66
import { getUserLevelData } from "utils/userLevelCalculation";
7+
import { getCoherencePercent } from "utils/getCoherencePercent";
78

89
import { useUserQuery } from "queries/useUser";
910

@@ -14,7 +15,6 @@ import Coherence from "./Coherence";
1415
import Header from "./Header";
1516
import JurorRewards from "./JurorRewards";
1617
import PixelArt from "./PixelArt";
17-
import { getPercent } from "pages/Home/TopJurors/JurorCard/Coherence";
1818

1919
const Container = styled.div``;
2020

@@ -47,7 +47,7 @@ const JurorInfo: React.FC<IJurorInfo> = ({ addressToQuery }) => {
4747
const totalCoherentVotes = data?.user ? parseInt(data?.user?.totalCoherentVotes) : 0;
4848
const totalResolvedVotes = data?.user ? parseInt(data?.user?.totalResolvedVotes) : 0;
4949
const totalResolvedDisputes = data?.user ? parseInt(data?.user?.totalResolvedDisputes) : 0;
50-
const coherencePercentage = getPercent(Number(totalCoherentVotes), Number(totalResolvedVotes));
50+
const coherencePercentage = getCoherencePercent(Number(totalCoherentVotes), Number(totalResolvedVotes));
5151
const userLevelData = getUserLevelData(coherencePercentage, totalResolvedDisputes);
5252

5353
return (
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const getCoherencePercent = (num: number, den: number): string => {
2+
if (den === 0) return "0%";
3+
return `${Math.floor((num * 100) / den)}%`;
4+
};

0 commit comments

Comments
 (0)