Skip to content

Commit 61bffc7

Browse files
committed
fix: juror levels calculations according to the figma
1 parent 8613090 commit 61bffc7

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ const JurorInfo: React.FC = () => {
4646
const coherenceScore = data?.user ? parseInt(data?.user?.coherenceScore) : 0;
4747
const totalCoherentVotes = data?.user ? parseInt(data?.user?.totalCoherentVotes) : 0;
4848
const totalResolvedVotes = data?.user ? parseInt(data?.user?.totalResolvedVotes) : 0;
49+
const totalResolvedDisputes = data?.user ? parseInt(data?.user?.totalResolvedDisputes) : 0;
4950

50-
const userLevelData = getUserLevelData(coherenceScore);
51+
const userLevelData = getUserLevelData(coherenceScore, totalResolvedDisputes);
5152

5253
return (
5354
<Container>

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface IDesktopCard {
3535
address: string;
3636
totalCoherentVotes: number;
3737
totalResolvedVotes: number;
38+
totalResolvedDisputes: number;
3839
coherenceScore: number;
3940
}
4041

@@ -43,6 +44,7 @@ const DesktopCard: React.FC<IDesktopCard> = ({
4344
address,
4445
totalCoherentVotes,
4546
totalResolvedVotes,
47+
totalResolvedDisputes,
4648
coherenceScore,
4749
}) => {
4850
return (
@@ -51,7 +53,7 @@ const DesktopCard: React.FC<IDesktopCard> = ({
5153
<JurorTitle address={address} />
5254
<Rewards address={address} />
5355
<Coherency {...{ totalCoherentVotes, totalResolvedVotes }} />
54-
<JurorLevel coherenceScore={coherenceScore} />
56+
<JurorLevel {...{ coherenceScore, totalResolvedDisputes }} />
5557
</Container>
5658
);
5759
};

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ const StyledLabel = styled.label`
4040

4141
interface IJurorLevel {
4242
coherenceScore: number;
43+
totalResolvedDisputes: number;
4344
}
4445

45-
const JurorLevel: React.FC<IJurorLevel> = ({ coherenceScore }) => {
46-
const userLevelData = getUserLevelData(coherenceScore);
46+
const JurorLevel: React.FC<IJurorLevel> = ({ coherenceScore, totalResolvedDisputes }) => {
47+
const userLevelData = getUserLevelData(coherenceScore, totalResolvedDisputes);
4748
const level = userLevelData.level;
4849

4950
return (

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ interface IMobileCard {
7777
coherenceScore: number;
7878
totalCoherentVotes: number;
7979
totalResolvedVotes: number;
80+
totalResolvedDisputes: number;
8081
}
8182

8283
const MobileCard: React.FC<IMobileCard> = ({
@@ -85,6 +86,7 @@ const MobileCard: React.FC<IMobileCard> = ({
8586
coherenceScore,
8687
totalCoherentVotes,
8788
totalResolvedVotes,
89+
totalResolvedDisputes,
8890
}) => {
8991
return (
9092
<Container>
@@ -93,7 +95,7 @@ const MobileCard: React.FC<IMobileCard> = ({
9395
<Rank rank={rank} />
9496
<JurorTitle address={address} />
9597
</RankAndTitle>
96-
<JurorLevel coherenceScore={coherenceScore} />
98+
<JurorLevel {...{ coherenceScore, totalResolvedDisputes }} />
9799
</TopSide>
98100
<BottomSide>
99101
<HeaderRewardsAndRewards>

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ interface IJurorCard {
99
coherenceScore: number;
1010
totalCoherentVotes: number;
1111
totalResolvedVotes: number;
12+
totalResolvedDisputes: number;
1213
}
1314

14-
const JurorCard: React.FC<IJurorCard> = ({ rank, address, coherenceScore, totalCoherentVotes, totalResolvedVotes }) => {
15-
const allProps = { rank, address, coherenceScore, totalCoherentVotes, totalResolvedVotes };
15+
const JurorCard: React.FC<IJurorCard> = ({
16+
rank,
17+
address,
18+
coherenceScore,
19+
totalCoherentVotes,
20+
totalResolvedVotes,
21+
totalResolvedDisputes,
22+
}) => {
23+
const allProps = { rank, address, coherenceScore, totalCoherentVotes, totalResolvedVotes, totalResolvedDisputes };
1624

1725
return (
1826
<>

web/src/utils/userLevelCalculation.ts

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
export const levelTitles = [
2-
{ scoreRange: [0, 20], level: 0, title: "Diogenes" },
3-
{ scoreRange: [20, 40], level: 1, title: "Pythagoras" },
4-
{ scoreRange: [40, 60], level: 2, title: "Socrates" },
5-
{ scoreRange: [60, 80], level: 3, title: "Plato" },
6-
{ scoreRange: [80, 100], level: 4, title: "Aristotle" },
2+
{ level: 0, title: "Diogenes" },
3+
{ level: 1, title: "Pythagoras" },
4+
{ level: 2, title: "Socrates" },
5+
{ level: 3, title: "Plato" },
6+
{ level: 4, title: "Aristotle" },
77
];
88

9-
export const getUserLevelData = (coherencyScore: number) => {
10-
return (
11-
levelTitles.find(({ scoreRange }) => {
12-
return coherencyScore >= scoreRange[0] && coherencyScore < scoreRange[1];
13-
}) ?? levelTitles[0]
14-
);
9+
export const getUserLevelData = (coherencyScore: number, totalResolvedDisputes: number) => {
10+
if (totalResolvedDisputes >= 3 && coherencyScore < 50) {
11+
return levelTitles.find(({ level }) => level === 0);
12+
}
13+
14+
if (totalResolvedDisputes === 0 || (totalResolvedDisputes >= 1 && coherencyScore >= 0 && coherencyScore <= 70)) {
15+
return levelTitles.find(({ level }) => level === 1);
16+
}
17+
18+
if (totalResolvedDisputes >= 3 && coherencyScore > 70 && coherencyScore <= 80) {
19+
return levelTitles.find(({ level }) => level === 2);
20+
}
21+
22+
if (totalResolvedDisputes >= 7 && coherencyScore > 80 && coherencyScore <= 90) {
23+
return levelTitles.find(({ level }) => level === 3);
24+
}
25+
26+
if (totalResolvedDisputes >= 10 && coherencyScore > 90) {
27+
return levelTitles.find(({ level }) => level === 4);
28+
}
29+
30+
return levelTitles.find(({ level }) => level === 1);
1531
};

0 commit comments

Comments
 (0)