Skip to content

Commit

Permalink
Merge pull request #704 from clrfund/fix/slow-load
Browse files Browse the repository at this point in the history
Fix slow loading landing page
  • Loading branch information
yuetloo authored Jul 28, 2023
2 parents e639856 + 9380596 commit 9f3829d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
8 changes: 3 additions & 5 deletions vue-app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ VITE_RECIPIENT_REGISTRY_TYPE=optimistic

VITE_RECIPIENT_REGISTRY_POLICY=QmeygKjvrpidJeFHv6ywjUrj718nwtFQgCCPPR4r5nL87R

# Comma-separated list of IPFS hashes
VITE_EXTRA_ROUNDS=

# Operator of clr.fund instance
VITE_OPERATOR=

# Index of first round to consider
VITE_FIRST_ROUND=
# Comma-separated list of cancelled round address that should not display on the app
# VITE_VOIDED_ROUNDS=0x123,0x456
VITE_VOIDED_ROUNDS=

# Default Language
VITE_I18N_LOCALE=
Expand Down
5 changes: 5 additions & 0 deletions vue-app/src/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ export const recipientJoinDeadlineConfig = deadline?.isValid ? deadline : null

// make sure walletconnect qrcode modal is not blocked by the Wallet Modal
export const walletConnectZIndex = import.meta.env.VITE_WALLET_CONNECT_Z_INDEX || '1500'

// use this to filter out rounds that should not be displayed on the app
export const voidedRounds = new Set(
(import.meta.env.VITE_VOIDED_ROUNDS || '').split(',').map(round => round.toLowerCase()),
)
9 changes: 2 additions & 7 deletions vue-app/src/api/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PubKey } from '@clrfund/maci-utils'
import { FundingRound, MACI } from './abi'
import { provider, factory } from './core'
import { getTotalContributed } from './contributions'
import { getRounds } from './rounds'
import { isVoidedRound } from './rounds'
import sdk from '@/graphql/sdk'

import { isSameAddress } from '@/utils/accounts'
Expand Down Expand Up @@ -59,13 +59,8 @@ export async function getCurrentRound(): Promise<string | null> {
if (fundingRoundAddress === '0x0000000000000000000000000000000000000000') {
return null
}
const rounds = await getRounds()
const roundIndex = rounds.findIndex(round => isSameAddress(round.address, fundingRoundAddress))

if (roundIndex >= 0) {
return fundingRoundAddress
}
return null
return isVoidedRound(fundingRoundAddress) ? null : fundingRoundAddress
}

function toRoundInfo(data: any, network: string): RoundInfo {
Expand Down
23 changes: 15 additions & 8 deletions vue-app/src/api/rounds.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sdk from '@/graphql/sdk'
import extraRounds from '@/rounds/rounds.json'
import { chain } from './core'
import { chain, voidedRounds } from './core'

export interface Round {
index: number
Expand All @@ -10,32 +10,39 @@ export interface Round {
startTime: number
}

export function isVoidedRound(address: string): boolean {
return voidedRounds.has(address.toLowerCase())
}

function toRoundId({ network, address }: { network: string; address: string }): string {
return `${network}-${address}`.toLowerCase()
}

//TODO: update to take factory address as a parameter
export async function getRounds(): Promise<Round[]> {
//TODO: updateto pass factory address as a parameter, default to env. variable
//NOTE: why not instantiate the sdk here?
const data = await sdk.GetRounds()

let data
try {
data = await sdk.GetRounds()
} catch {
return []
}

const rounds: Round[] = extraRounds.map(({ address, network, startTime }, index): Round => {
return { index, address, network, hasLeaderboard: true, startTime }
})

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 (const fundingRound of data.fundingRounds) {
const address = fundingRound.id

for (let roundIndex = 0; roundIndex < data.fundingRounds.length; roundIndex++) {
if (roundIndex < firstRound) {
if (isVoidedRound(address)) {
// 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({
Expand Down
3 changes: 2 additions & 1 deletion vue-app/src/views/Landing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ import ImageResponsive from '@/components/ImageResponsive.vue'
import { useAppStore } from '@/stores'
import { storeToRefs } from 'pinia'
import { getAssetsUrl } from '@/utils/url'
import { isSameAddress } from '@/utils/accounts'
const appStore = useAppStore()
const {
Expand All @@ -200,7 +201,7 @@ const leaderboardRoute = computed(() => {
}
const roundAddress = currentRoundAddress.value || ''
const leaderboard = leaderboardRounds.find(round => round.address === roundAddress)
const leaderboard = leaderboardRounds.find(round => isSameAddress(round.address, roundAddress))
return leaderboard ? { name: 'leaderboard', params: { network: leaderboard.network, address: roundAddress } } : null
})
Expand Down

0 comments on commit 9f3829d

Please sign in to comment.