Skip to content

Commit

Permalink
fix leaderboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
totop716 committed Jun 28, 2023
1 parent 6bd7cb9 commit f511ff7
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/pages/ContestPage/ContestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,41 @@ const ContestPage: React.FC = () => {

const data = await res.json();

const lensRes = await fetch(
`${
process.env.REACT_APP_LEADERBOARD_APP_URL
}/utils/lens-profiles?addresses=${data.leaderboardData
.map((e: any) => e.origin)
.join('_')}`,
);
if (!lensRes.ok) {
const errorText = await lensRes.text();
throw new Error(
errorText || lensRes.statusText || `Failed to get leaderboard`,
let lensArray: any[] = [];
for (const ind of Array.from(
{ length: Math.ceil(data.leaderboardData.length / 150) },
(_, i) => i,
)) {
const lensRes = await fetch(
`${
process.env.REACT_APP_LEADERBOARD_APP_URL
}/utils/lens-profiles?addresses=${data.leaderboardData
.slice(ind * 150, (ind + 1) * 150)
.map((e: any) => e.origin)
.join('_')}`,
);
if (!lensRes.ok) {
const errorText = await lensRes.text();
throw new Error(
errorText || lensRes.statusText || `Failed to get leaderboard`,
);
}
const lensData = await lensRes.json();
lensArray = lensArray.concat(lensData.data);
}
const lensData = await lensRes.json();

console.log('ccc', lensData);

// Fetch lens handles of all the addresses
let result = data.leaderboardData;
if (lensData && lensData.data) {
result = result.map((d: ContestLeaderBoard, i: number) => {
const result = data.leaderboardData.map(
(d: ContestLeaderBoard, i: number) => {
return {
...d,
lensHandle:
lensData.data[i] && lensData.data[i].length > 0
? lensData.data[i][0].handle
lensArray[i] && lensArray[i].length > 0
? lensArray[i][0].handle
: undefined,
};
});
}
},
);

setContestLeaderBoard(result);
setLoading(false);
Expand Down

0 comments on commit f511ff7

Please sign in to comment.