Skip to content

Commit

Permalink
correctly set prize for current season
Browse files Browse the repository at this point in the history
  • Loading branch information
merklejerk committed Jun 5, 2024
1 parent 13f17eb commit 735680a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/lib/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,25 @@ export async function fetchSeasons(
client: PublicClient,
startBlock?: number,
): Promise<SeasonInfo[]> {
const logs = await getContestLogs(
client, [
'SeasonStarted',
'SeasonClosed',
'SeasonRevealed',
'WinnerDeclared',
'PrizeClaimed',
],
startBlock,
);
const [logs, [currentPrize, currentSeasonIdx]] = await Promise.all([
getContestLogs(
client, [
'SeasonStarted',
'SeasonClosed',
'SeasonRevealed',
'WinnerDeclared',
'PrizeClaimed',
],
startBlock,
),
multiReadContestContract<bigint>({
client,
calls: [
{ fn: 'currentSeasonPrize' },
{ fn: 'currentSeasonIdx' },
],
}),
]);
const seasonsByIdx = {} as { [idx: number]: SeasonInfo };
for (const log of logs) {
const { args } = log;
Expand Down Expand Up @@ -215,6 +224,9 @@ export async function fetchSeasons(
szn.unclaimedPrize = 0n;
}
}
if (seasonsByIdx[currentSeasonIdx]) {
seasonsByIdx[currentSeasonIdx].prize = currentPrize;
}
// Get block times.
const uniqueBlocks = Object.values(Object.assign({},
...Object.values(seasonsByIdx)
Expand Down

0 comments on commit 735680a

Please sign in to comment.