mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
Scaffolding for orgs
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<script lang="typescript">
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { session } from '@app/session';
|
||||
import Modal from '@app/Modal.svelte';
|
||||
import { Org } from '@app/base/orgs/Org';
|
||||
|
||||
export let config;
|
||||
export let owner;
|
||||
|
||||
enum State {
|
||||
Idle,
|
||||
Waiting,
|
||||
Success,
|
||||
}
|
||||
|
||||
let state = State.Idle;
|
||||
let error = null;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const createOrg = async () => {
|
||||
state = State.Waiting;
|
||||
|
||||
console.log("creating org");
|
||||
try {
|
||||
let tx = await Org.create(owner, config);
|
||||
let receipt = await tx.wait();
|
||||
console.log(receipt);
|
||||
let org = Org.fromReceipt(receipt);
|
||||
console.log(org);
|
||||
state = State.Success;
|
||||
} catch (e) {
|
||||
state = State.Idle;
|
||||
console.error(e);
|
||||
error = e;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Modal floating {error} on:close>
|
||||
<span slot="title">
|
||||
Create an Org
|
||||
</span>
|
||||
<span slot="body">
|
||||
<table>
|
||||
<tr><td class="label">Owner</td><td>{owner}</td></tr>
|
||||
</table>
|
||||
</span>
|
||||
<span slot="actions">
|
||||
<button
|
||||
on:click={createOrg}
|
||||
class="primary"
|
||||
data-waiting={state === State.Waiting || null}
|
||||
disabled={state !== State.Idle}
|
||||
>Create</button>
|
||||
|
||||
<button on:click={() => dispatch('close')} class="text">
|
||||
Cancel
|
||||
</button>
|
||||
</span>
|
||||
</Modal>
|
||||
@@ -0,0 +1,42 @@
|
||||
import * as ethers from 'ethers';
|
||||
import type { TransactionReceipt, TransactionResponse } from '@ethersproject/providers';
|
||||
import type { ContractReceipt } from '@ethersproject/contracts';
|
||||
|
||||
import type { Config } from '@app/config';
|
||||
|
||||
const orgFactoryAbi = [
|
||||
"function createOrg(address[], uint256) returns (address)",
|
||||
"event OrgCreated(address, address)",
|
||||
];
|
||||
|
||||
const orgAbi = ["function owner() view returns (address)"];
|
||||
|
||||
export class Org {
|
||||
address: string
|
||||
safe: string
|
||||
|
||||
constructor(address: string, safe: string) {
|
||||
this.address = address;
|
||||
this.safe = safe;
|
||||
}
|
||||
|
||||
static fromReceipt(receipt: ContractReceipt): Org {
|
||||
let event = receipt.events.find(e => e.event === 'OrgCreated');
|
||||
let address = event.args[0];
|
||||
let safe = event.args[1];
|
||||
|
||||
return new Org(address, safe);
|
||||
}
|
||||
|
||||
static async create(
|
||||
owner: string,
|
||||
config: Config,
|
||||
): Promise<TransactionResponse> {
|
||||
const orgFactory = new ethers.Contract(
|
||||
config.orgFactory.address,
|
||||
orgFactoryAbi,
|
||||
config.signer
|
||||
);
|
||||
return await orgFactory.createOrg([owner], 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="typescript">
|
||||
import { onMount } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
import { Router, Link, Route, navigate } from "svelte-routing";
|
||||
import { ethers } from 'ethers';
|
||||
import { error } from '@app/error';
|
||||
import { session } from '@app/session';
|
||||
import CreateOrg from '@app/base/orgs/CreateOrg.svelte';
|
||||
|
||||
enum State {
|
||||
Idle,
|
||||
}
|
||||
|
||||
export let config;
|
||||
export let query;
|
||||
|
||||
let modal = null;
|
||||
let state = State.Idle;
|
||||
|
||||
$: owner = $session.address;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
|
||||
<main>
|
||||
<button on:click={() => modal = CreateOrg} disabled={!owner} data-disabled-tooltip="No!" class="secondary">
|
||||
Create an Org
|
||||
</button>
|
||||
</main>
|
||||
|
||||
<svelte:component this="{modal}" {owner} {config} on:close={() => modal = null} />
|
||||
@@ -0,0 +1,11 @@
|
||||
<script lang="typescript">
|
||||
import { Route } from "svelte-routing";
|
||||
import Orgs from '@app/base/orgs/Orgs.svelte';
|
||||
|
||||
export let config;
|
||||
export let query;
|
||||
</script>
|
||||
|
||||
<Route path="/orgs">
|
||||
<Orgs {config} />
|
||||
</Route>
|
||||
@@ -35,16 +35,12 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.available {
|
||||
line-height: 1.75em;
|
||||
padding: 2rem;
|
||||
}
|
||||
.domain {
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="modal {error ? 'error' : ''}">
|
||||
<div class="modal" class:error={error}>
|
||||
{#if error}
|
||||
<div class="modal-title error">
|
||||
Transaction failed
|
||||
|
||||
Reference in New Issue
Block a user