diff --git a/vue-app/src/api/projects.ts b/vue-app/src/api/projects.ts index 773a6c24..323ed0f6 100644 --- a/vue-app/src/api/projects.ts +++ b/vue-app/src/api/projects.ts @@ -58,11 +58,27 @@ export async function getRecipientRegistryAddress(roundAddress: string | null): } } -export async function getProjects(registryAddress: string, startTime?: number, endTime?: number): Promise { +/** + * Get all the projects added between the start and end time + * @returns List of projects + */ +export async function getProjects({ + registryAddress, + fundingRoundAddress, + network, + startTime, + endTime, +}: { + registryAddress: string + fundingRoundAddress?: string + network?: string + startTime?: number + endTime?: number +}): Promise { if (recipientRegistryType === 'simple') { return await SimpleRegistry.getProjects(registryAddress, startTime, endTime) } else if (recipientRegistryType === 'optimistic') { - return await OptimisticRegistry.getProjects(registryAddress, startTime, endTime) + return await OptimisticRegistry.getProjects({ registryAddress, fundingRoundAddress, network, startTime, endTime }) } else if (recipientRegistryType === 'kleros') { return await KlerosRegistry.getProjects(registryAddress, startTime, endTime) } else { @@ -80,11 +96,21 @@ export async function getProjects(registryAddress: string, startTime?: number, e * @param filter filter result by locked or verified status * @returns project information */ -export async function getProject(registryAddress: string, recipientId: string, filter = true): Promise { +export async function getProject({ + registryAddress, + fundingRoundAddress, + recipientId, + filter = true, +}: { + registryAddress: string + fundingRoundAddress?: string + recipientId: string + filter: boolean +}): Promise { if (recipientRegistryType === 'simple') { return await SimpleRegistry.getProject(registryAddress, recipientId) } else if (recipientRegistryType === 'optimistic') { - return await OptimisticRegistry.getProject(recipientId, filter) + return await OptimisticRegistry.getProject({ fundingRoundAddress, recipientId, filter }) } else if (recipientRegistryType === 'kleros') { return await KlerosRegistry.getProject(registryAddress, recipientId) } else { diff --git a/vue-app/src/api/recipient-registry-optimistic.ts b/vue-app/src/api/recipient-registry-optimistic.ts index 84e888f5..8a2f5b05 100644 --- a/vue-app/src/api/recipient-registry-optimistic.ts +++ b/vue-app/src/api/recipient-registry-optimistic.ts @@ -12,7 +12,7 @@ import { hasDateElapsed } from '@/utils/dates' import type { RegistryInfo, RecipientApplicationData } from './types' import { formToRecipientData } from './recipient' import { isSameAddress } from '@/utils/accounts' -import { findStaticRound } from './round' +import { findStaticRound, getStaticRoundInfo } from './round' async function getRegistryInfo(registryAddress: string): Promise { const registry = new Contract(registryAddress, OptimisticRecipientRegistry, provider) @@ -310,14 +310,36 @@ function decodeProject(recipient: Partial): Project { } } -export async function getProjects(registryAddress: string, startTime?: number, endTime?: number): Promise { +/** + * Get a list of projects created between the start time and end time + * @param registryAddress The recipient registry address + * @param fundingRoundAddress The funding round address to search in the static rounds + * @returns List of projects + */ +export async function getProjects({ + registryAddress, + fundingRoundAddress, + network, + startTime, + endTime, +}: { + registryAddress: string + fundingRoundAddress?: string + network?: string + startTime?: number + endTime?: number +}): Promise { let data: GetRecipientsQuery try { data = await sdk.GetRecipients({ registryAddress: registryAddress.toLowerCase(), }) } catch { - return [] + if (!fundingRoundAddress) { + return [] + } + const _round = await getStaticRoundInfo(fundingRoundAddress, network) + return _round?.projects || [] } if (!data.recipients.length) { @@ -383,14 +405,22 @@ export async function getProjects(registryAddress: string, startTime?: number, e /** * Find the project from the static round file * @param projectId The project id + * @param fundingRoundAddress The funding round address * @param filter Filter the project if it's deleted */ -async function findStaticProject(projectId: string, filter: boolean): Promise { +async function findStaticProject({ + projectId, + fundingRoundAddress, + filter, +}: { + fundingRoundAddress?: string + projectId: string + filter: boolean +}): Promise { let project: Project | null = null try { - const fundingRoundAddress = await clrFundContract.getCurrentRound() - const network = chain.label.toLowerCase() - const round = await findStaticRound(fundingRoundAddress, network) + const roundAddress = fundingRoundAddress ?? (await clrFundContract.getCurrentRound()) + const round = await findStaticRound(roundAddress) if (round?.projects) { const staticProject = round.projects.find(project => project.id === projectId) if (staticProject) { @@ -412,10 +442,19 @@ async function findStaticProject(projectId: string, filter: boolean): Promise { +export async function getProject({ + recipientId, + fundingRoundAddress, + filter = true, +}: { + recipientId: string + fundingRoundAddress?: string + filter: boolean +}): Promise { if (!isHexString(recipientId, 32)) { return null } @@ -426,7 +465,7 @@ export async function getProject(recipientId: string, filter = true): Promise { if (!recipientRegistryAddress.value) return - const currentRoundAddress = currentRound.value?.fundingRoundAddress - if (currentRoundAddress) { - const round = await getRoundInfo(currentRoundAddress, currentRound.value) - if (round?.projects) { - _projects = round.projects - } - } - - if (!_projects) { - _projects = await getProjects( - recipientRegistryAddress.value, - currentRound.value?.startTime.toSeconds(), - currentRound.value?.votingDeadline.toSeconds(), - ) - } + _projects = await getProjects({ + registryAddress: recipientRegistryAddress.value, + fundingRoundAddress: currentRound.value?.fundingRoundAddress, + network: currentRound.value?.network, + startTime: currentRound.value?.startTime.toSeconds(), + endTime: currentRound.value?.votingDeadline.toSeconds(), + }) const userProjects: Project[] = _projects.filter( ({ address, requester }) => diff --git a/vue-app/src/views/Project.vue b/vue-app/src/views/Project.vue index ab3d64d6..4eda5cf0 100644 --- a/vue-app/src/views/Project.vue +++ b/vue-app/src/views/Project.vue @@ -60,8 +60,14 @@ onMounted(async () => { roundAddress.value = (route.params.address as string) || currentRoundAddress || '' + const recipientId = route.params.id as string const registryAddress = await getRecipientRegistryAddress(roundAddress.value || null) - const _project = await getProject(registryAddress, route.params.id as string) + const _project = await getProject({ + registryAddress, + fundingRoundAddress: roundAddress.value || undefined, + recipientId, + filter: false, + }) if (_project === null || _project.isHidden) { // Project not found router.push({ name: 'projects' }) diff --git a/vue-app/src/views/ProjectList.vue b/vue-app/src/views/ProjectList.vue index 83fa0450..9b2ef9c9 100644 --- a/vue-app/src/views/ProjectList.vue +++ b/vue-app/src/views/ProjectList.vue @@ -137,7 +137,7 @@ async function loadProjectRoundInfo(roundAddress: string) { let startTime = 0 let votingDeadline = DateTime.local().toSeconds() let network = '' - let roundProjects: Project[] | undefined = undefined + let fundingRoundAddress = '' if (roundAddress) { const round = await getRoundInfo(roundAddress, currentRound.value) @@ -146,9 +146,7 @@ async function loadProjectRoundInfo(roundAddress: string) { startTime = round.startTime.toSeconds() votingDeadline = round.votingDeadline.toSeconds() network = round.network || '' - if (round.projects) { - roundProjects = round.projects - } + fundingRoundAddress = round.fundingRoundAddress } } @@ -157,11 +155,14 @@ async function loadProjectRoundInfo(roundAddress: string) { recipientRegistryAddress = await getRecipientRegistryAddress(null) } - if (!roundProjects) { - roundProjects = await getProjects(recipientRegistryAddress, startTime, votingDeadline) - } - - const visibleProjects = roundProjects.filter(project => { + const _projects = await getProjects({ + registryAddress: recipientRegistryAddress, + fundingRoundAddress, + network, + startTime, + endTime: votingDeadline, + }) + const visibleProjects = _projects.filter(project => { return !project.isHidden && !project.isLocked }) shuffleArray(visibleProjects) diff --git a/vue-app/src/views/RecipientProfile.vue b/vue-app/src/views/RecipientProfile.vue index b9f3890b..9e3bfecf 100644 --- a/vue-app/src/views/RecipientProfile.vue +++ b/vue-app/src/views/RecipientProfile.vue @@ -91,8 +91,12 @@ onMounted(async () => { const recipientRegistryAddress = await getRecipientRegistryAddress(currentRoundAddress) // retrieve the project information without filtering by the locked or verified status - const filter = false - recipient.value = await getProject(recipientRegistryAddress, recipientId, filter) + recipient.value = await getProject({ + registryAddress: recipientRegistryAddress, + fundingRoundAddress: currentRoundAddress || undefined, + recipientId, + filter: false, + }) if (recipient.value?.address) { ens.value = await ensLookup(recipient.value.address) }