From 2fc2639b49c0d86f5814325cfa3e8856955d1f1d Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 9 Feb 2022 09:58:31 +0100 Subject: [PATCH] Fix anchor lookup in project view Signed-off-by: Alexis Sellier --- src/anchors.ts | 8 +++----- src/base/projects/View.svelte | 4 ++-- src/profile.ts | 10 ++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/anchors.ts b/src/anchors.ts index f7e30e3d9..574d460db 100644 --- a/src/anchors.ts +++ b/src/anchors.ts @@ -16,13 +16,11 @@ interface AnchorObject { multihash: string; } -export async function getAllAnchors(config: Config, urn: string, anchors?: string | null): Promise { - if (! anchors) { - return []; - } +export async function getProjectAnchors(urn: string, anchorsStorage: string, config: Config): Promise { const unpadded = decodeRadicleId(urn); const id = ethers.utils.hexZeroPad(unpadded, 32); - const allAnchors = await querySubgraph(config.orgs.subgraph, GetAllAnchors, { project: id, org: anchors }); + const allAnchors = await querySubgraph(config.orgs.subgraph, GetAllAnchors, { project: id, org: anchorsStorage }); + return allAnchors.anchors .map((anchor: AnchorObject) => formatProjectHash(ethers.utils.arrayify(anchor.multihash))); } diff --git a/src/base/projects/View.svelte b/src/base/projects/View.svelte index bccfe2a50..e709ac7c2 100644 --- a/src/base/projects/View.svelte +++ b/src/base/projects/View.svelte @@ -9,7 +9,6 @@ import { formatOrg, formatSeedId, isRadicleId } from '@app/utils'; import { getOid } from '@app/project'; import { Seed } from '@app/base/seeds/Seed'; - import { getAllAnchors } from '@app/anchors'; import Header from '@app/base/projects/Header.svelte'; import ProjectContentRoutes from '@app/base/projects/ProjectContentRoutes.svelte'; @@ -41,7 +40,8 @@ const cfg = seedInstance && seedInstance.valid ? config.withSeed(seedInstance) : config; const info = await proj.getInfo(id, cfg); const urn = isRadicleId(id) ? id : info.urn; - const anchors = await getAllAnchors(config, urn, profile?.anchorsAccount ?? addressOrName); + const anchors = profile ? await profile.confirmedProjectAnchors(urn, config) : []; + let branches = Array([info.defaultBranch, info.head]) as [string, string][]; let peers: proj.Peer[] = []; diff --git a/src/profile.ts b/src/profile.ts index f7d071b34..12460c8e1 100644 --- a/src/profile.ts +++ b/src/profile.ts @@ -8,6 +8,7 @@ import type { Config } from "@app/config"; import type { Seed, InvalidSeed } from "@app/base/seeds/Seed"; import { Org } from "@app/base/orgs/Org"; import { NotFoundError } from "@app/error"; +import { getProjectAnchors } from "@app/anchors"; import type { Anchor, PendingAnchor } from "@app/project"; export interface IProfile { @@ -164,6 +165,15 @@ export class Profile { } } + async confirmedProjectAnchors(urn: string, config: Config): Promise { + const storage = this.anchorsAccount || this.org?.address; + + if (storage) { + return await getProjectAnchors(urn, storage, config); + } + return []; + } + // Get the anchors account as an org, or the org, if available. private async getAnchorsOrg(config: Config): Promise { if (this.anchorsAccount) {