Skip to content

Commit

Permalink
upd: learboard table -> points col
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTeaLeaf committed Nov 7, 2024
1 parent 69c79a2 commit c5488c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/constants/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ const USERS_TABLE: TTableColumn[] = [
sortType: "none",
dataType: "number",
},
{
name: "Points",
keyName: "points",
sortType: "none",
dataType: "number",
},
];

const CONTESTS_TABLE: TTableColumn[] = [
Expand Down
43 changes: 33 additions & 10 deletions src/modules/Users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,40 @@ const Users = (): JSX.Element => {
...data,
rank: index + 1,
}));

setTableStates(USERS_TABLE);
setTableData(contestData);
}
};

const allContests = useMemo(
() => ({
PAST: $apiData?.leaderboards?.[previousPeriod as keyof YieldContest],
ACTIVE: $apiData?.leaderboards?.[currentPeriod as keyof YieldContest],
ABSOLUTE: $apiData?.leaderboards.absolute,
}),
[$apiData?.leaderboards]
);
const allContests = useMemo(() => {
const absoluteLeaderboard = $apiData?.leaderboards.absolute.map((user) =>
user?.points ? user : { ...user, points: 0 }
);

const absoluteLeaderboardMap = absoluteLeaderboard
? Object.fromEntries(
absoluteLeaderboard?.map((user) => [user.address, user.points])
)
: {};

const fillPoints = (leaderboard?: { address: string; points?: number }[]) =>
leaderboard?.map((user) => ({
...user,
points: absoluteLeaderboardMap[user?.address] ?? 0,
}));

const pastLeaderboard = fillPoints(
$apiData?.leaderboards?.[previousPeriod as keyof YieldContest]
);
const activeLeaderboard = fillPoints(
$apiData?.leaderboards?.[currentPeriod as keyof YieldContest]
);

return {
PAST: pastLeaderboard,
ACTIVE: activeLeaderboard,
ABSOLUTE: absoluteLeaderboard,
};
}, [$apiData?.leaderboards]);

useEffect(() => {
initTableData();
Expand Down Expand Up @@ -173,6 +193,9 @@ const Users = (): JSX.Element => {
? (Math.round(user.deposit * 100) / 100).toFixed(2)
: ""}
</td>
<td className="text-center px-4 py-3">
{user.points ? user.points : ""}
</td>
</tr>
))}
</tbody>
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ type TLeaderboard = {
address: TAddress;
deposit: number;
earned: number;
points?: number;
};

type TTAbleFiltersVariant = {
Expand Down

0 comments on commit c5488c6

Please sign in to comment.