Skip to content

Commit

Permalink
Merge pull request #677 from clrfund/fix/recipient-list
Browse files Browse the repository at this point in the history
Projects not showing if a round does not exist
  • Loading branch information
yuetloo authored Jun 9, 2023
2 parents 4762945 + 0e7f61a commit 149b301
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
2 changes: 2 additions & 0 deletions vue-app/src/api/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ export async function getFactoryInfo() {
const nativeTokenDecimals = await nativeToken.decimals()

const userRegistryAddress = await factory.userRegistry()
const recipientRegistryAddress = await factory.recipientRegistry()

return {
fundingRoundAddress: factory.address,
nativeTokenAddress,
nativeTokenSymbol,
nativeTokenDecimals,
userRegistryAddress,
recipientRegistryAddress,
}
}
56 changes: 42 additions & 14 deletions vue-app/src/views/ProjectList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div class="project-container">
<loader v-if="isLoading"></loader>
<div v-else class="project-container">
<div class="projects">
<div
:class="{
Expand Down Expand Up @@ -60,6 +61,7 @@ import { ref, computed, onMounted } from 'vue'
import { getCurrentRound, getRoundInfo } from '@/api/round'
import { type Project, getProjects } from '@/api/projects'
import { getFactoryInfo } from '@/api/factory'
import CallToActionCard from '@/components/CallToActionCard.vue'
import ProjectListItem from '@/components/ProjectListItem.vue'
Expand All @@ -68,6 +70,13 @@ import Links from '@/components/Links.vue'
import { useRoute } from 'vue-router'
import { useAppStore, useUserStore } from '@/stores'
import { storeToRefs } from 'pinia'
import { DateTime } from 'luxon'
type ProjectRoundInfo = {
recipientRegistryAddress: string
startTime: number
votingDeadline: number
}
const SHUFFLE_RANDOM_SEED = Math.random()
Expand Down Expand Up @@ -108,25 +117,44 @@ const projectsByCategoriesSelected = computed<Project[]>(() => {
})
onMounted(async () => {
//TODO: update to take factory address as a parameter, default to env. variable
roundAddress.value = (route.params.address as string) || currentRoundAddress.value! || (await getCurrentRound()) || ''
if (roundAddress.value) {
await loadProjects(roundAddress.value)
try {
roundAddress.value =
(route.params.address as string) || currentRoundAddress.value || (await getCurrentRound()) || ''
const round = await loadProjectRoundInfo(roundAddress.value)
await loadProjects(round)
} catch (err) {
/* eslint-disable-next-line no-console */
console.error('Error loading projects', err)
}
isLoading.value = false
})
async function loadProjects(roundAddress: string) {
const round = await getRoundInfo(roundAddress, currentRound.value)
if (!round) {
return
async function loadProjectRoundInfo(roundAddress: string): Promise<ProjectRoundInfo> {
// defaults when a round has not been created yet
let recipientRegistryAddress = ''
let startTime = 0
let votingDeadline = DateTime.local().toSeconds()
if (roundAddress) {
const round = await getRoundInfo(roundAddress, currentRound.value)
if (round) {
recipientRegistryAddress = round.recipientRegistryAddress
startTime = round.startTime.toSeconds()
votingDeadline = round.votingDeadline.toSeconds()
}
}
const _projects = await getProjects(
round.recipientRegistryAddress,
round.startTime.toSeconds(),
round.votingDeadline.toSeconds(),
)
if (!recipientRegistryAddress) {
// get recipient registry address from the factory if a round does not exist
const factory = await getFactoryInfo()
recipientRegistryAddress = factory.recipientRegistryAddress
}
return { recipientRegistryAddress, startTime, votingDeadline }
}
async function loadProjects(round: ProjectRoundInfo) {
const _projects = await getProjects(round.recipientRegistryAddress, round.startTime, round.votingDeadline)
const visibleProjects = _projects.filter(project => {
return !project.isHidden && !project.isLocked
})
Expand Down

0 comments on commit 149b301

Please sign in to comment.