Skip to content

Commit

Permalink
Merge pull request #531 from clrfund/fix/ethStaker-rounds
Browse files Browse the repository at this point in the history
Round information retrieval overwrite issue
  • Loading branch information
auryn-macmillan authored Jul 14, 2022
2 parents 7eef2fb + 66f84cf commit 2f21d5a
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 237 deletions.
21 changes: 16 additions & 5 deletions vue-app/src/api/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isSameAddress } from '@/utils/accounts'
export interface RoundInfo {
fundingRoundAddress: string
userRegistryAddress: string
recipientRegistryAddress: string
maciAddress: string
recipientTreeDepth: number
maxContributors: number
Expand Down Expand Up @@ -54,10 +55,8 @@ export async function getCurrentRound(): Promise<string | null> {
return null
}
const rounds = await getRounds()
// round.address is empty if the round is configured in VUE_APP_EXTRA_ROUNDS
const roundIndex = rounds.findIndex(
(round) =>
!!round.address && isSameAddress(round.address, fundingRoundAddress)
const roundIndex = rounds.findIndex((round) =>
isSameAddress(round.address, fundingRoundAddress)
)

if (roundIndex >= Number(process.env.VUE_APP_FIRST_ROUND || 0)) {
Expand All @@ -68,19 +67,30 @@ export async function getCurrentRound(): Promise<string | null> {

//TODO: update to take factory address as a parameter, default to env. variable
export async function getRoundInfo(
fundingRoundAddress: string
fundingRoundAddress: string,
cachedRound?: RoundInfo
): Promise<RoundInfo> {
if (
cachedRound &&
isSameAddress(fundingRoundAddress, cachedRound.fundingRoundAddress)
) {
// the requested round matches the cached round, quick return
return cachedRound
}

const fundingRound = new Contract(fundingRoundAddress, FundingRound, provider)
const [
maciAddress,
nativeTokenAddress,
recipientRegistryAddress,
userRegistryAddress,
voiceCreditFactor,
isFinalized,
isCancelled,
] = await Promise.all([
fundingRound.maci(),
fundingRound.nativeToken(),
fundingRound.recipientRegistry(),
fundingRound.userRegistry(),
fundingRound.voiceCreditFactor(),
fundingRound.isFinalized(),
Expand Down Expand Up @@ -159,6 +169,7 @@ export async function getRoundInfo(

return {
fundingRoundAddress,
recipientRegistryAddress,
userRegistryAddress,
maciAddress,
recipientTreeDepth: maciTreeDepths.voteOptionTreeDepth,
Expand Down
29 changes: 24 additions & 5 deletions vue-app/src/components/ProjectListItem.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<template>
<div class="project-item">
<div>
<links :to="{ name: 'project', params: { id: project.id } }">
<links :to="projectRoute">
<div class="project-image">
<img :src="projectImageUrl" :alt="project.name" />
<div class="tag">{{ project.category }}</div>
</div>
</links>
<div class="project-info">
<div class="project-name">
<links :to="{ name: 'project', params: { id: project.id } }">
<links :to="projectRoute">
{{ project.name }}
</links>
</div>
<links :to="{ name: 'project', params: { id: project.id } }">
<links :to="projectRoute">
<div class="project-description">{{ project.tagline }}</div>
</links>
</div>
</div>
<div class="buttons">
<add-to-cart-button v-if="shouldShowCartInput" :project="project" />
<links :to="{ name: 'project', params: { id: project.id } }">
<links :to="projectRoute">
<button class="more-btn">More</button>
</links>
</div>
Expand All @@ -36,6 +36,7 @@ import Links from '@/components/Links.vue'
import { CartItem } from '@/api/contributions'
import { Project } from '@/api/projects'
import { markdown } from '@/utils/markdown'
import { Route } from 'vue-router'
@Component({
components: {
Expand All @@ -46,6 +47,7 @@ import { markdown } from '@/utils/markdown'
export default class ProjectListItem extends Vue {
@Prop()
project!: Project
@Prop({ default: '' }) roundAddress!: string
get descriptionHtml(): string {
return markdown.renderInline(this.project.description)
Expand All @@ -69,9 +71,26 @@ export default class ProjectListItem extends Vue {
return index !== -1
}
get isCurrentRound(): boolean {
const { currentRoundAddress } = this.$store.state
const roundAddress = this.roundAddress || currentRoundAddress
return this.$store.getters.isCurrentRound(roundAddress)
}
get shouldShowCartInput(): boolean {
const { isRoundContributionPhase, canUserReallocate } = this.$store.getters
return isRoundContributionPhase || canUserReallocate
return (
this.isCurrentRound && (isRoundContributionPhase || canUserReallocate)
)
}
get projectRoute(): Partial<Route> {
return this.$route.name === 'round'
? {
name: 'round-project',
params: { address: this.roundAddress, id: this.project.id },
}
: { name: 'project', params: { id: this.project.id } }
}
}
</script>
Expand Down
11 changes: 10 additions & 1 deletion vue-app/src/components/ProjectProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export default class ProjectProfile extends Vue {
hasContributeBtn(): boolean {
return (
this.isCurrentRound &&
this.$store.state.currentRound &&
this.project !== null &&
this.project.index !== 0
Expand Down Expand Up @@ -200,9 +201,17 @@ export default class ProjectProfile extends Vue {
return this.ens || this.project.address
}
get isCurrentRound(): boolean {
const roundAddress =
this.$route.params.address || this.$store.state.currentRoundAddress
return this.$store.getters.isCurrentRound(roundAddress)
}
get shouldShowCartInput(): boolean {
const { isRoundContributionPhase, canUserReallocate } = this.$store.getters
return isRoundContributionPhase || canUserReallocate
return (
this.isCurrentRound && (isRoundContributionPhase || canUserReallocate)
)
}
}
</script>
Expand Down
Loading

0 comments on commit 2f21d5a

Please sign in to comment.