Improve error code

This commit is contained in:
Alexis Sellier
2021-05-04 20:02:58 +02:00
parent 836bd4cbea
commit fbce111e22
8 changed files with 128 additions and 97 deletions
+56 -50
View File
@@ -1,6 +1,8 @@
<script lang="typescript">
import { createEventDispatcher } from 'svelte';
import Modal from '@app/Modal.svelte';
import Error from '@app/Error.svelte';
import type { Err } from '@app/error';
import { Org } from '@app/base/orgs/Org';
import type { Config } from '@app/config';
@@ -15,7 +17,7 @@
}
let state = State.Idle;
let error: Error | null = null;
let error: Err | null = null;
let org: Org | null = null;
const dispatch = createEventDispatcher();
@@ -38,56 +40,60 @@
};
</script>
<Modal floating {error} on:close>
<span slot="title">
{#if !org}
Create an Org
{:else}
🎉
{/if}
</span>
{#if error}
<Error {error} floating on:close />
{:else}
<Modal floating on:close>
<span slot="title">
{#if !org}
Create an Org
{:else}
🎉
{/if}
</span>
<span slot="subtitle">
{#if org}
<strong>Your org was successfully created.</strong>
{/if}
</span>
<span slot="subtitle">
{#if org}
<strong>Your org was successfully created.</strong>
{/if}
</span>
<span slot="body">
{#if org}
<table>
<tr><td class="label">Address</td><td>{org.address}</td></tr>
<tr><td class="label">Safe</td><td>{org.safe}</td></tr>
</table>
{:else}
<table>
<tr><td class="label">Member</td><td>{owner}</td></tr>
</table>
{/if}
</span>
<span slot="body">
{#if org}
<table>
<tr><td class="label">Address</td><td>{org.address}</td></tr>
<tr><td class="label">Safe</td><td>{org.safe}</td></tr>
</table>
{:else}
<table>
<tr><td class="label">Member</td><td>{owner}</td></tr>
</table>
{/if}
</span>
<span slot="actions">
{#if !org}
<button
on:click={createOrg}
class="primary"
data-waiting={[State.Signing, State.Pending].includes(state) || null}
disabled={state !== State.Idle}
>
{#if state === State.Pending}
Creating...
{:else}
Create
{/if}
</button>
<span slot="actions">
{#if !org}
<button
on:click={createOrg}
class="primary"
data-waiting={[State.Signing, State.Pending].includes(state) || null}
disabled={state !== State.Idle}
>
{#if state === State.Pending}
Creating...
{:else}
Create
{/if}
</button>
<button on:click={() => dispatch('close')} class="text">
Cancel
</button>
{:else}
<button on:click={() => dispatch('close')}>
Done
</button>
{/if}
</span>
</Modal>
<button on:click={() => dispatch('close')} class="text">
Cancel
</button>
{:else}
<button on:click={() => dispatch('close')}>
Done
</button>
{/if}
</span>
</Modal>
{/if}
+12 -5
View File
@@ -1,10 +1,12 @@
<script lang="typescript">
import { Route } from "svelte-routing";
import { Route, navigate } from "svelte-routing";
import Register from '@app/base/register/Register.svelte';
import Begin from '@app/base/register/steps/Begin.svelte';
import Submit from '@app/base/register/steps/Submit.svelte';
import Error from '@app/Error.svelte';
import type { Config } from '@app/config';
import type { Session } from '@app/session';
import { Failure } from '@app/error';
export let session: Session | null;
export let config: Config;
@@ -19,8 +21,13 @@
<Begin {config} subdomain={params.name} {query} />
</Route>
{#if session}
<Route path="register/:name/submit" let:params>
<Route path="register/:name/submit" let:params>
{#if session}
<Submit {config} subdomain={params.name} {query} {session} />
</Route>
{/if}
{:else}
<Error
message={"You must connect your wallet to register"}
on:close={() => navigate("/register")}
/>
{/if}
</Route>
+4
View File
@@ -11,3 +11,7 @@ export enum State {
}
export const state = writable(State.Idle);
state.subscribe(s => {
console.log("regiter.state", s);
});
+13 -16
View File
@@ -1,6 +1,5 @@
<script lang="typescript">
import { onMount } from 'svelte';
import { get } from 'svelte/store';
import { navigate } from 'svelte-routing';
import { ethers } from 'ethers';
import { registerName, registrationFee } from '../registrar';
@@ -22,14 +21,12 @@
}
onMount(async () => {
let oldState = get(state);
try {
await registerName(subdomain, registrationOwner, config);
} catch (e) {
console.error("Error", e);
state.set(oldState);
state.set(State.Idle);
error = e;
}
});
@@ -52,7 +49,16 @@
</div>
{/if}
{#if $state === State.Approving}
{#if error}
<div class="modal-body error">
<strong>Error:</strong> {error.message}
</div>
<div class="modal-actions">
<button on:click={() => navigate("/register")} class="error">
Back
</button>
</div>
{:else if $state === State.Approving}
<div class="modal-body">
Approving Registry for {#await getFee(config)}
?
@@ -73,7 +79,7 @@
</div>
{:else if $state === State.WaitingToRegister}
<div class="modal-body">
Waiting for wallet confirmation...
<!-- TODO -->
</div>
<div class="modal-actions">
<button disabled class="primary register">
@@ -88,21 +94,12 @@
</div>
{:else if $state === State.Registered}
<div class="modal-body">
The name <span class="domain">{subdomain}</span> has been successfully registered to {session.address}.
The name <span class="domain">{subdomain}</span> has been successfully registered to {registrationOwner}.
</div>
<div class="modal-actions">
<button on:click={() => state.set(State.Idle)} class="primary register">
Done
</button>
</div>
{:else if error}
<div class="modal-body error">
<strong>Error:</strong> {error.message}
</div>
<div class="modal-actions">
<button on:click={() => navigate("/register")} class="error">
Back
</button>
</div>
{/if}
</div>