Skip to content

Commit

Permalink
remove duplicate rounds in round list
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jul 19, 2023
1 parent 56d8035 commit 909267f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion vue-app/src/api/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function getCurrentRound(): Promise<string | null> {
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
Expand Down
48 changes: 40 additions & 8 deletions vue-app/src/api/rounds.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,16 +20,42 @@ export async function getRounds(): Promise<Round[]> {
//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,
}
})
}

0 comments on commit 909267f

Please sign in to comment.