diff --git a/src/Blockies.svelte b/src/Blockies.svelte index c086b763a..b60084f81 100644 --- a/src/Blockies.svelte +++ b/src/Blockies.svelte @@ -21,6 +21,8 @@ .icon { width: 100%; height: 100%; + min-width: 1rem; + min-height: 1rem; background-size: cover; background-repeat: no-repeat; border-radius: 50%; diff --git a/src/base/orgs/Create.svelte b/src/base/orgs/Create.svelte index 89680185f..5013fcbd7 100644 --- a/src/base/orgs/Create.svelte +++ b/src/base/orgs/Create.svelte @@ -67,7 +67,7 @@ {#if error} {:else if org} - + 🎉 @@ -90,7 +90,7 @@ {:else} - +
🎪
Create an Org @@ -128,7 +128,7 @@ {/if}
diff --git a/src/base/orgs/Index.svelte b/src/base/orgs/Index.svelte index ebd2360a6..d1f1d3341 100644 --- a/src/base/orgs/Index.svelte +++ b/src/base/orgs/Index.svelte @@ -2,19 +2,63 @@ import type { SvelteComponent } from 'svelte'; import { session } from '@app/session'; import Create from '@app/base/orgs/Create.svelte'; + import { Org } from '@app/base/orgs/Org'; import type { Config } from '@app/config'; import Error from '@app/Error.svelte'; + import Blockies from '@app/Blockies.svelte'; + import Loading from '@app/Loading.svelte'; export let config: Config; - let modal: typeof SvelteComponent = Create; - let owner: string | null = $session && $session.address; + const onCreate = () => modal = Create; + + let modal: typeof SvelteComponent | null = null; + + $: account = $session && $session.address; -{#if owner} - window.history.back()} /> -{:else} - window.history.back()}> - Not connected. - -{/if} + + +
+ {#await Org.getAll(config)} + + {:then orgs} +
+ Orgs on the Radicle network. + +
+ {#each orgs as org} +
+ {/each} + {/await} +
+ + modal = null} /> diff --git a/src/base/orgs/Org.ts b/src/base/orgs/Org.ts index 0946cd5af..bfa04b2ec 100644 --- a/src/base/orgs/Org.ts +++ b/src/base/orgs/Org.ts @@ -16,6 +16,16 @@ const GetProjects = ` } `; +// TODO: Add timestamps to org creation. +const GetOrgs = ` + query GetOrgs { + orgs { + id + owner + } + } +`; + const orgFactoryAbi = [ "function createOrg(address) returns (address)", "function createOrg(address[], uint256) returns (address)", @@ -85,6 +95,21 @@ export class Org { return projects; } + static async getAll(config: Config): Promise> { + const result = await utils.querySubgraph(GetOrgs, {}, config); + console.log(result); + let orgs: Org[] = []; + + for (let o of result.orgs) { + try { + orgs.push(new Org(o.id, o.owner)); + } catch (e) { + console.error(e); + } + } + return orgs; + } + static fromReceipt(receipt: ContractReceipt): Org | null { let event = receipt.events?.find(e => e.event === 'OrgCreated'); diff --git a/src/utils.ts b/src/utils.ts index f2d7ca91b..d9f9fcfbc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -73,7 +73,7 @@ export async function querySubgraph( query: string, variables: Record, config: Config -): Promise { +): Promise { const response = await fetch(config.orgs.subgraph, { method: 'POST', headers: { @@ -84,7 +84,14 @@ export async function querySubgraph( variables, }) }); - const json = await response.json() + const json = await response.json(); + + if (json.errors) { + for (let e of json.errors) { + console.error("querySubgraph:", e.message); + } + return null; + } return json.data; }