From b26192f933f99a479f1dbb1611688c7c6f7751cb Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 8 Feb 2022 16:32:24 +0100 Subject: [PATCH] Start re-imagining anchors * Anchors are loaded alongside projects, but project listings always come from seeds now * Removing project info loading from `Widget` * Start unifying anchor handling * Rename "Project*" to "Anchor*" when appropriate * Move to new project api with embedded metadata Signed-off-by: Alexis Sellier --- src/Profile.svelte | 2 +- src/base/orgs/Org.ts | 40 +++--- src/base/orgs/View/Projects.svelte | 130 +++++++----------- .../AnchorActions.svelte} | 22 +-- src/base/profiles/AnchorBadge.svelte | 74 ++++++++++ src/base/projects/BranchSelector.svelte | 8 +- src/base/projects/Header.svelte | 57 +------- src/base/projects/View.svelte | 25 ++-- src/base/projects/Widget.svelte | 129 +++++------------ src/base/seeds/Seed.ts | 5 +- src/base/seeds/View.svelte | 31 +++-- src/profile.ts | 49 ++++++- src/project.ts | 41 +++--- 13 files changed, 303 insertions(+), 310 deletions(-) rename src/base/{orgs/View/Anchor.svelte => profiles/AnchorActions.svelte} (89%) create mode 100644 src/base/profiles/AnchorBadge.svelte diff --git a/src/Profile.svelte b/src/Profile.svelte index 32aada937..f73f85d5f 100644 --- a/src/Profile.svelte +++ b/src/Profile.svelte @@ -133,6 +133,7 @@ } .members { margin-top: 2rem; + padding-bottom: 1rem; align-items: center; display: flex; flex-wrap: wrap; @@ -141,7 +142,6 @@ display: flex; align-items: center; margin-right: 2rem; - margin-bottom: 1rem; } .members .member:last-child { margin-right: 0; diff --git a/src/base/orgs/Org.ts b/src/base/orgs/Org.ts index 304056f9e..68b5fdaf9 100644 --- a/src/base/orgs/Org.ts +++ b/src/base/orgs/Org.ts @@ -7,7 +7,7 @@ import { assert } from '@app/error'; import * as utils from '@app/utils'; import type { Safe } from '@app/utils'; import type { Config } from '@app/config'; -import type { PendingProject, Project } from '@app/project'; +import type { PendingAnchor, Anchor } from '@app/project'; const GetProjects = ` query GetProjects($org: ID!) { @@ -184,15 +184,16 @@ export class Org { return members.includes(address.toLowerCase()); } - async getProjects(config: Config): Promise { + async getProjects(config: Config): Promise { const result = await utils.querySubgraph( config.orgs.subgraph, GetProjects, { org: this.address } ); - const projects: Project[] = []; + const projects: Anchor[] = []; for (const p of result.projects) { try { - const proj: Project = { + const proj: Anchor = { + confirmed: true, id: utils.formatRadicleId(ethers.utils.arrayify(p.anchor.objectId)), anchor: { stateHash: utils.formatProjectHash( @@ -208,39 +209,34 @@ export class Org { return projects; } - async getPendingProjects(config: Config): Promise { + async getPendingProjects(config: Config): Promise { if (! config.safe.client) return []; const orgAddr = ethers.utils.getAddress(this.address); const response = await config.safe.client.getPendingTransactions( ethers.utils.getAddress(this.owner) ); - const projects: PendingProject[] = []; + const projects: PendingAnchor[] = []; for (const tx of response.results || []) { if (tx.data && tx.to === orgAddr) { - const project = parseAnchorTx(tx.data, config); + const anchor = parseAnchorTx(tx.data, config); const confirmations = tx.confirmations?.map(t => t.owner) || []; - if (project) { - projects.push({ ...project, confirmations, safeTxHash: tx.safeTxHash }); + if (anchor) { + projects.push({ + id: anchor.id, + anchor: { stateHash: anchor.stateHash }, + confirmations, + safeTxHash: tx.safeTxHash, + confirmed: false, + }); } } } return projects; } - async getAllProjects(config: Config): Promise> { - const result = await Promise.allSettled([ - this.getPendingProjects(config), - this.getProjects(config), - ]); - - return result.flatMap(r => { - return r.status === "fulfilled" ? r.value : []; - }); - } - static async getAnchor(orgAddr: string, urn: string, config: Config): Promise { const org = new ethers.Contract( orgAddr, @@ -377,7 +373,7 @@ export class Org { } } -export function parseAnchorTx(data: string, config: Config): Project | null { +export function parseAnchorTx(data: string, config: Config): { id: string; stateHash: string } | null { const iface = new ethers.utils.Interface(config.abi.org); const parsedTx = iface.parseTransaction({ data }); @@ -390,7 +386,7 @@ export function parseAnchorTx(data: string, config: Config): Project | null { const byteArray = ethers.utils.arrayify(encodedCommitHash); const stateHash = utils.formatProjectHash(byteArray); - return { id, anchor: { stateHash } }; + return { id, stateHash }; } return null; } diff --git a/src/base/orgs/View/Projects.svelte b/src/base/orgs/View/Projects.svelte index 993c8bc97..5e3af90db 100644 --- a/src/base/orgs/View/Projects.svelte +++ b/src/base/orgs/View/Projects.svelte @@ -1,32 +1,44 @@
- {#if profile.org} - {#await getProjects()} - - {:then projects} - {#each projects as project} -
- {#if "safeTxHash" in project} - - - commit {formatCommit(project.anchor.stateHash)} - commit {project.anchor.stateHash} - - - {#if profile.org.safe && account} - updateRecords()} {account} {config} /> - {/if} - - - {:else} - - - commit {formatCommit(project.anchor.stateHash)} - commit {project.anchor.stateHash} - - - {/if} -
- {/each} - {:catch err} - - Error: failed to load anchored projects: {err.message}. - - {/await} - {:else} -
- {#if profile.anchorsAccount} - {#await Org.get(profile.anchorsAccount, config)} - - {:then org} - {#if org} - {#await org.getProjects(config) then projects} - {#each projects as project} -
- - - commit {formatCommit(project.anchor.stateHash)} - commit {project.anchor.stateHash} - - -
- {/each} - {:catch err} - - Error: failed to load projects: {err.message}. - - {/await} - {/if} - {/await} - {/if} -
- {/if} + {#await Seed.getProjects(config)} + + {:then projects} + {#each projects as project} + {@const anchor = anchors[project.urn]} + {@const pendingAnchor = pendingAnchors[project.urn]} +
+ onClick(project)}> + + {#if profile.org?.safe && account && anchor} + {#if pendingAnchor} + loadAnchors()} /> + {/if} + {/if} + + +
+ {/each} + {:catch err} + + Error: failed to load projects: {err.message}. + + {/await}
diff --git a/src/base/orgs/View/Anchor.svelte b/src/base/profiles/AnchorActions.svelte similarity index 89% rename from src/base/orgs/View/Anchor.svelte rename to src/base/profiles/AnchorActions.svelte index 8c6b3de6b..261fb8e69 100644 --- a/src/base/orgs/View/Anchor.svelte +++ b/src/base/profiles/AnchorActions.svelte @@ -1,7 +1,7 @@ @@ -108,7 +108,7 @@
- {#each project.confirmations as signee} + {#each anchor.confirmations as signee} {/each}
@@ -158,8 +158,8 @@ {#if state == State.Confirm}
-
Project
{project.id} -
Hash
{project.anchor.stateHash} +
Project
{anchor.id} +
Hash
{anchor.anchor.stateHash}
{:else if state == State.Failed}
{error}
@@ -168,7 +168,7 @@ {#if state == State.Confirm} -