From 909267f4cf48916b2602c0b73ab6c43cb85f0bc7 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Wed, 19 Jul 2023 02:36:19 -0400 Subject: [PATCH] remove duplicate rounds in round list --- vue-app/src/api/round.ts | 2 +- vue-app/src/api/rounds.ts | 48 ++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/vue-app/src/api/round.ts b/vue-app/src/api/round.ts index ba6fc3e5c..48c7eb6b8 100644 --- a/vue-app/src/api/round.ts +++ b/vue-app/src/api/round.ts @@ -62,7 +62,7 @@ export async function getCurrentRound(): Promise { const rounds = await getRounds() const roundIndex = rounds.findIndex(round => isSameAddress(round.address, fundingRoundAddress)) - if (roundIndex >= Number(import.meta.env.VITE_FIRST_ROUND || 0)) { + if (roundIndex >= 0) { return fundingRoundAddress } return null diff --git a/vue-app/src/api/rounds.ts b/vue-app/src/api/rounds.ts index e68ebd2de..45e48998e 100644 --- a/vue-app/src/api/rounds.ts +++ b/vue-app/src/api/rounds.ts @@ -1,11 +1,17 @@ import sdk from '@/graphql/sdk' import extraRounds from '@/rounds/rounds.json' +import { chain } from './core' export interface Round { index: number address: string network?: string hasLeaderboard: boolean + startTime: number +} + +function toRoundId({ network, address }: { network: string; address: string }): string { + return `${network}-${address}`.toLowerCase() } //TODO: update to take factory address as a parameter @@ -14,16 +20,42 @@ export async function getRounds(): Promise { //NOTE: why not instantiate the sdk here? const data = await sdk.GetRounds() - const rounds: Round[] = extraRounds.map(({ address, network }, index): Round => { - return { index, address, network, hasLeaderboard: true } + const rounds: Round[] = extraRounds.map(({ address, network, startTime }, index): Round => { + return { index, address, network, hasLeaderboard: true, startTime } }) - for (const fundingRound of data.fundingRounds) { - rounds.push({ - index: rounds.length, - address: fundingRound.id, - hasLeaderboard: false, - }) + const leaderboardRounds = new Set(rounds.map(r => toRoundId({ network: r.network || '', address: r.address }))) + + const firstRound = Number(import.meta.env.VITE_FIRST_ROUND || 0) + + for (let roundIndex = 0; roundIndex < data.fundingRounds.length; roundIndex++) { + if (roundIndex < firstRound) { + // filter out cancelled or test rounds + continue + } + + const fundingRound = data.fundingRounds[roundIndex] + const address = fundingRound.id + const isLeaderboardRound = leaderboardRounds.has(toRoundId({ network: chain.label, address })) + if (!isLeaderboardRound) { + rounds.push({ + index: rounds.length, + address, + hasLeaderboard: false, + startTime: Number(fundingRound.startTime), + }) + } } + return rounds + .sort((a, b) => a.startTime - b.startTime) + .map((r, index) => { + return { + index, + address: r.address, + hasLeaderboard: r.hasLeaderboard, + startTime: r.startTime, + network: r.network, + } + }) }