From 2928e2fe14a0a25c28e8ac7d0fdcd9d4505871f2 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 21 Jul 2021 16:39:58 +0200 Subject: [PATCH] Implement org profile fallback When an org doesn't have its own profile, but its owner does, we fallback on that profile. This allows for "user" orgs, where a user keeps his projects anchored under an org, but all profile information under the user. --- src/Address.svelte | 4 ++- src/Icon.svelte | 2 +- src/base/orgs/Org.ts | 21 ++++++++++++++ src/base/orgs/View.svelte | 50 ++++++++++++++++++++------------- src/base/projects/View.svelte | 10 +++---- src/base/projects/Widget.svelte | 4 +-- src/base/users/View.svelte | 5 ++-- src/profile.ts | 19 +++++++++++++ 8 files changed, 82 insertions(+), 33 deletions(-) diff --git a/src/Address.svelte b/src/Address.svelte index 8fff854da..8efba112d 100644 --- a/src/Address.svelte +++ b/src/Address.svelte @@ -66,7 +66,9 @@ contract {:else if addressType === AddressType.EOA} {addressLabel} - {:else if !noBadge} + {:else if profile?.name} + {addressLabel} + {:else}
{/if} diff --git a/src/Icon.svelte b/src/Icon.svelte index a0affd88d..d381e1fad 100644 --- a/src/Icon.svelte +++ b/src/Icon.svelte @@ -2,7 +2,7 @@ export let name: string; export let width: number | null = null; export let height: number | null = null; - export let inline: boolean = false; + export let inline = false; const icons = [ { diff --git a/src/base/orgs/Org.ts b/src/base/orgs/Org.ts index 488d80ef1..1e276a59f 100644 --- a/src/base/orgs/Org.ts +++ b/src/base/orgs/Org.ts @@ -3,6 +3,7 @@ import type { TransactionResponse } from '@ethersproject/providers'; import type { ContractReceipt } from '@ethersproject/contracts'; import { OperationType } from "@gnosis.pm/safe-core-sdk-types"; +import { Profile } from '@app/profile'; import { assert } from '@app/error'; import * as utils from '@app/utils'; import type { Config } from '@app/config'; @@ -141,6 +142,10 @@ export class Org { return projects; } + async getProfile(config: Config): Promise { + return Org.getProfile(this.address, config); + } + static async getAnchor(orgAddr: string, urn: string, config: Config): Promise { const org = new ethers.Contract( orgAddr, @@ -207,6 +212,22 @@ export class Org { } } + // Return only org profile if there is one, otherwise tries to get the profile + // of its owner. + static async getProfile(address: string, config: Config): Promise { + const profile = await Profile.get(address, config); + + if (profile.ens) { + return profile; + } + const org = await Org.get(address, config); + + if (org) { + return Profile.get(org.owner, config); + } + return profile; + } + // Return only Orgs that have a specific user as owner static async getOrgsByOwner(owner: string, config: Config): Promise { const orgsResult = await utils.querySubgraph(config.orgs.subgraph, GetOrgsByOwner, { owners: [owner] }); diff --git a/src/base/orgs/View.svelte b/src/base/orgs/View.svelte index c10b8f762..e732195f7 100644 --- a/src/base/orgs/View.svelte +++ b/src/base/orgs/View.svelte @@ -85,6 +85,10 @@ width: 64px; height: 64px; } + .title { + display: flex; + align-items: center; + } .links { display: flex; align-items: center; @@ -127,7 +131,7 @@ {:then org} {#if org}
- {#await Profile.get(address, config)} + {#await org.getProfile(config)}
@@ -139,6 +143,9 @@
{parseEnsLabel(profile.name, config) ?? address} + {#if profile.address === org.owner} + org + {/if} -
Name
-
- {#if profile.name} - {profile.name} - {:else} - Not set - {/if} -
-
- {#await isAuthorized(org)} - - {:then authorized} - {#if authorized} - + + {#if profile.address === org.address} +
Name
+
+ {#if profile.name} + {profile.name} + {:else} + Not set {/if} - {/await} -
+
+
+ {#await isAuthorized(org)} + + {:then authorized} + {#if authorized} + + {/if} + {/await} +
+ {/if}
{#await org.getMembers(config)} @@ -224,7 +234,7 @@ {:then projects} {#each projects as project}
- +
{/each} {:catch err} diff --git a/src/base/projects/View.svelte b/src/base/projects/View.svelte index 045f81607..ef1d7a049 100644 --- a/src/base/projects/View.svelte +++ b/src/base/projects/View.svelte @@ -5,7 +5,7 @@ import Loading from '@app/Loading.svelte'; import Modal from '@app/Modal.svelte'; import Avatar from '@app/Avatar.svelte'; - import { Profile } from '@app/profile'; + import { Org } from '@app/base/orgs/Org'; import Browser from './Browser.svelte'; @@ -16,13 +16,11 @@ export let path: string; let projectRoot = proj.path({ urn, org, commit }); - let getProject = new Promise(resolve => { + let getProject = new Promise(resolve => { if (org) { - Profile.get(org, config).then((p: Profile) => { - resolve(p.seed); - }); + Org.getProfile(org, config).then(p => resolve(p?.seed || null)); } else { - resolve(undefined); + resolve(null); } }).then(async (seed) => { const cfg = seed ? config.withSeed(seed) : config; diff --git a/src/base/projects/Widget.svelte b/src/base/projects/Widget.svelte index 2838be778..5d357be29 100644 --- a/src/base/projects/Widget.svelte +++ b/src/base/projects/Widget.svelte @@ -16,15 +16,13 @@ export let project: proj.Project; export let config: Config; export let org: string | undefined; - export let seed: string | undefined; let state: State = { status: Status.Loading }; let info: proj.Info | null = null; onMount(async () => { try { - const cfg = seed ? config.withSeed(seed) : config; - const result = await proj.getInfo(project.id, cfg); + const result = await proj.getInfo(project.id, config); state = { status: Status.Loaded }; info = result; } catch (err) { diff --git a/src/base/users/View.svelte b/src/base/users/View.svelte index 44443f833..551598e43 100644 --- a/src/base/users/View.svelte +++ b/src/base/users/View.svelte @@ -16,6 +16,7 @@