Skip to content

Commit

Permalink
fix error displaying project profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Apr 23, 2024
1 parent 51ddc99 commit 2454097
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
16 changes: 16 additions & 0 deletions vue-app/src/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,19 @@ export function staticDataToProjectInterface(project: any): Project {
isLocked: false,
}
}

/**
* Get the list of projects for a static round
* @param roundAddress The funding round contract address
* @param network The network
* @returns Array of projects
*/
export async function getProjectsForStaticRound(roundAddress: string, network: string): Promise<Project[]> {
const data = await getLeaderboardData(roundAddress, network)
if (!data) {
return []
}

const projects = data.projects.map(staticDataToProjectInterface)
return projects
}
3 changes: 2 additions & 1 deletion vue-app/src/api/rounds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sdk from '@/graphql/sdk'
import extraRounds from '@/rounds/rounds.json'
import { getNumber } from 'ethers'
import { chain, voidedRounds, isActiveApp, clrfundContractAddress } from './core'

export interface Round {
Expand Down Expand Up @@ -36,7 +37,7 @@ export async function getRounds(): Promise<Round[]> {
}

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

const leaderboardRounds = new Set(rounds.map(r => toRoundId({ network: r.network || '', address: r.address })))
Expand Down
24 changes: 17 additions & 7 deletions vue-app/src/components/ProjectListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ import { markdown } from '@/utils/markdown'
import { useRoute, type RouteLocationRaw } from 'vue-router'
import { useAppStore } from '@/stores'
import { storeToRefs } from 'pinia'
import { isActiveApp } from '@/api/core'
const route = useRoute()
const appStore = useAppStore()
const { isRoundContributionPhase, canUserReallocate, currentRoundAddress, categoryLocaleKey } = storeToRefs(appStore)
const { isRoundContributionPhase, canUserReallocate, currentRoundAddress, categoryLocaleKey, currentRound } =
storeToRefs(appStore)
interface Props {
project: Project
roundAddress: string
Expand Down Expand Up @@ -81,12 +83,20 @@ const shouldShowCartInput = computed<boolean>(() => {
})
const projectRoute = computed<RouteLocationRaw>(() => {
return route.name === 'round'
? {
name: 'round-project',
params: { address: props.roundAddress, id: props.project.id },
}
: { name: 'project', params: { id: props.project.id } }
if (isActiveApp) {
return route.name === 'round'
? {
name: 'round-project',
params: { address: props.roundAddress, id: props.project.id },
}
: { name: 'project', params: { id: props.project.id } }
} else {
const network = currentRound.value?.network || ''
return {
name: 'leaderboard-project',
params: { address: props.roundAddress, network, id: props.project.id },
}
}
})
</script>

Expand Down
7 changes: 2 additions & 5 deletions vue-app/src/views/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import Loader from '@/components/Loader.vue'
import FundsNeededWarning from '@/components/FundsNeededWarning.vue'
import { userRegistryType, UserRegistryType, chain, isActiveApp } from '@/api/core'
import { type Project, getProjects, staticDataToProjectInterface } from '@/api/projects'
import { type Project, getProjects, getProjectsForStaticRound } from '@/api/projects'
import { isSameAddress } from '@/utils/accounts'
import { getTokenLogo } from '@/utils/tokens'
import { useAppStore, useUserStore, useRecipientStore, useWalletStore } from '@/stores'
Expand Down Expand Up @@ -191,10 +191,7 @@ async function loadProjects(): Promise<void> {
} else {
const currentRoundAddress = currentRound.value?.fundingRoundAddress || ''
const network = currentRound.value?.network || ''
const data = await getLeaderboardData(currentRoundAddress, network)
if (data) {
_projects = data.projects.map(p => staticDataToProjectInterface(p))
}
_projects = await getProjectsForStaticRound(currentRoundAddress, network)
}
const userProjects: Project[] = _projects.filter(
Expand Down
15 changes: 12 additions & 3 deletions vue-app/src/views/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import { ref, computed, onMounted } from 'vue'
import { getCurrentRound, getRoundInfo } from '@/api/round'
import { type Project, getProjects, getRecipientRegistryAddress } from '@/api/projects'
import { type Project, getProjects, getRecipientRegistryAddress, getProjectsForStaticRound } from '@/api/projects'
import CallToActionCard from '@/components/CallToActionCard.vue'
import ProjectListItem from '@/components/ProjectListItem.vue'
Expand All @@ -70,6 +70,7 @@ import { useRoute } from 'vue-router'
import { useAppStore, useUserStore } from '@/stores'
import { storeToRefs } from 'pinia'
import { DateTime } from 'luxon'
import { isActiveApp } from '@/api/core'
type ProjectRoundInfo = {
recipientRegistryAddress: string
Expand Down Expand Up @@ -119,8 +120,16 @@ onMounted(async () => {
try {
roundAddress.value =
(route.params.address as string) || currentRoundAddress.value || (await getCurrentRound()) || ''
const round = await loadProjectRoundInfo(roundAddress.value)
await loadProjects(round)
if (isActiveApp) {
const round = await loadProjectRoundInfo(roundAddress.value)
await loadProjects(round)
} else {
await appStore.loadStaticClrFundInfo()
const network = currentRound.value?.network || ''
const visibleProjects = await getProjectsForStaticRound(roundAddress.value, network)
shuffleArray(visibleProjects)
projects.value = visibleProjects
}
} catch (err) {
/* eslint-disable-next-line no-console */
console.error('Error loading projects', err)
Expand Down
3 changes: 1 addition & 2 deletions vue-app/src/views/RoundList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ import { onMounted, ref } from 'vue'
import { type Round, getRounds } from '@/api/rounds'
import Links from '@/components/Links.vue'
import { DateTime } from 'luxon'
import { clrfundContractAddress } from '@/api/core'
const rounds = ref<Round[]>([])
onMounted(async () => {
rounds.value = await getRounds(clrfundContractAddress)
rounds.value = await getRounds()
})
</script>

Expand Down

0 comments on commit 2454097

Please sign in to comment.