Skip to content

Commit

Permalink
Merge pull request #224 from xuhcc/fix-project-list
Browse files Browse the repository at this point in the history
Frontend: Fix bug that caused project list to not load on xDai
  • Loading branch information
xuhcc authored Dec 13, 2020
2 parents 9521a5f + f840905 commit 77d6aec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions vue-app/src/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import KlerosRegistry from './recipient-registry-kleros'

export interface Project {
id: string; // Address or another ID depending on registry implementation
address: string;
name: string;
description: string;
imageUrl: string;
Expand Down
19 changes: 18 additions & 1 deletion vue-app/src/api/recipient-registry-kleros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { provider, ipfsGatewayUrl } from './core'
import { Project } from './projects'

const KLEROS_CURATE_URL = 'https://curate.kleros.io/tcr/0x2E3B10aBf091cdc53cC892A50daBDb432e220398'
// TODO: only for xDai Round 02; we should remove them later
const INVALID_PROJECTS = [
'0xd4b514b8a245c6d6aaa5fc9b97336cfa6607f92184f1ae36e0fb26b7c90faf62',
'0xa13b920b4e1d910ac5af4a95d61af4a1272fedb39c86cdc747bbb734e990c6b6',
'0xc9cc75acbd333a72719da5446fc1752406ae0922a3c8818f769d6156af04adeb',
]

export enum TcrItemStatus {
Absent = 0,
Expand All @@ -32,6 +38,7 @@ async function getTcrColumns(tcr: Contract): Promise<TcrColumn[]> {
}

function decodeTcrItemData(columns: TcrColumn[], data: any[]): {
address: string;
name: string;
description: string;
imageUrl: string;
Expand All @@ -44,6 +51,7 @@ function decodeTcrItemData(columns: TcrColumn[], data: any[]): {
console.error = consoleError
/* eslint-enable no-console */
return {
address: decodedMetadata[1] as string,
name: decodedMetadata[0] as string,
description: decodedMetadata[3] as string,
imageUrl: `${ipfsGatewayUrl}${decodedMetadata[2]}`,
Expand All @@ -70,18 +78,27 @@ export async function getProjects(
const tcr = new Contract(tcrAddress, KlerosGTCR, provider)
const tcrColumns = await getTcrColumns(tcr)
const recipientAddedFilter = registry.filters.RecipientAdded()
const recipientAddedEvents = await registry.queryFilter(recipientAddedFilter, 0, endBlock)
const recipientAddedEvents = await registry.queryFilter(recipientAddedFilter, 0)
const recipientRemovedFilter = registry.filters.RecipientRemoved()
const recipientRemovedEvents = await registry.queryFilter(recipientRemovedFilter, 0)
const projects: Project[] = []
for (const event of recipientAddedEvents) {
if (endBlock && event.blockNumber >= endBlock) {
// Skip recipients added after the end of round.
// We can not do this with filter because on xDai node returns
// "One of the blocks specified in filter ... cannot be found"
continue
}
let project
try {
project = decodeRecipientAdded(event, tcrColumns)
} catch {
// Invalid metadata
continue
}
if (INVALID_PROJECTS.includes(project.id)) {
continue
}
const removed = recipientRemovedEvents.find((event) => {
return (event.args as any)._recipient === project.id
})
Expand Down
1 change: 1 addition & 0 deletions vue-app/src/api/recipient-registry-simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function decodeRecipientAdded(event: Event): Project {
const metadata = JSON.parse(args._metadata)
return {
id: args._recipient,
address: args._recipient,
name: metadata.name,
description: metadata.description,
imageUrl: `${ipfsGatewayUrl}/ipfs/${metadata.imageHash}`,
Expand Down
2 changes: 1 addition & 1 deletion vue-app/src/views/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</a>
<div v-if="project" class="project-page">
<img class="project-image" :src="project.imageUrl" :alt="project.name">
<h2 class="project-name">
<h2 class="project-name" :title="project.address">
<a
v-if="klerosCurateUrl"
:href="klerosCurateUrl"
Expand Down

0 comments on commit 77d6aec

Please sign in to comment.