Run svelte-check

This commit is contained in:
Alexis Sellier
2021-05-04 12:13:40 +02:00
parent 8c623ceaed
commit fb1d496ed0
13 changed files with 61 additions and 59 deletions
+4 -6
View File
@@ -1,8 +1,6 @@
<script lang="typescript">
// TODO: Navigating directly to /vesting doesn't work.
import { ethers } from 'ethers';
import { get } from 'svelte/store';
import { Router, Link, Route } from "svelte-routing";
import { Router, Route } from "svelte-routing";
import { getConfig } from '@app/config';
import { session } from '@app/session';
@@ -16,7 +14,7 @@
const query = new URLSearchParams(window.location.search);
export let url = path === "/" ? defaultPath : path;
function handleKeydown(event) {
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Enter') {
(document.querySelector('button.primary') as HTMLElement).click();
}
@@ -45,10 +43,10 @@
<Vesting {config} session={$session} />
</Route>
<Register {config} {query} session={$session} />
<Orgs {config} {query} />
<Orgs {config} />
</Router>
</div>
</div>
{:catch err}
{:catch}
<!-- Show error -->
{/await}
+2 -2
View File
@@ -1,9 +1,9 @@
<script lang="typescript">
import { derived } from "svelte/store";
import { Connection } from "@app/session";
import { state } from '@app/session';
import type { Config } from '@app/config';
export let config;
export let config: Config;
export let caption = "Connect";
export let className = "";
export let style = "";
-2
View File
@@ -3,8 +3,6 @@
// TODO: Link to correct network on etherscan
// TODO: There's a bug where sometimes on first load, the 'Connect' button
// won't display the address even though we're connected.
import { derived } from "svelte/store";
import { ethers } from "ethers";
import { link } from "svelte-routing";
import { formatBalance, formatAddress } from "@app/utils";
import { error, Failure } from '@app/error';
+3 -13
View File
@@ -1,22 +1,12 @@
<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 type { SvelteComponent } from 'svelte';
import { session } from '@app/session';
import CreateOrg from '@app/base/orgs/CreateOrg.svelte';
import type { Config } from '@app/config';
enum State {
Idle,
}
export let config: Config;
export const query = {};
let modal = null;
let state = State.Idle;
let modal: typeof SvelteComponent | null = null;
$: owner = $session && $session.address;
</script>
@@ -30,4 +20,4 @@
</button>
</main>
<svelte:component this="{modal}" {owner} {config} on:close={() => modal = null} />
<svelte:component this={modal} {owner} {config} on:close={() => modal = null} />
-1
View File
@@ -4,7 +4,6 @@
import type { Config } from '@app/config';
export let config: Config;
export let query;
</script>
<Route path="/orgs">
+6 -8
View File
@@ -1,10 +1,8 @@
<script lang="typescript">
import { onMount } from 'svelte';
import { get } from 'svelte/store';
import { navigate } from "svelte-routing";
import { ethers } from 'ethers';
import { error } from '@app/error';
import { registrar } from './registrar';
import type { Config } from '@app/config';
import Modal from '@app/Modal.svelte';
@@ -15,20 +13,20 @@
NameUnavailable,
}
export let config;
export let config: Config;
let state = State.Idle;
let inputValue;
let inputElement;
let inputValue: string;
let inputElement: HTMLElement;
onMount(() => {
inputElement.focus();
});
function checkAvailability(name) {
function checkAvailability(name: string) {
state = State.CheckingAvailability;
registrar(config).available(name).then(isAvailable => {
registrar(config).available(name).then((isAvailable: boolean) => {
if (isAvailable) {
state = State.NameAvailable;
navigate(`/register/${name}`);
+10 -6
View File
@@ -3,10 +3,12 @@
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 type { Config } from '@app/config';
import type { Session } from '@app/session';
export let session;
export let config;
export let query;
export let session: Session | null;
export let config: Config;
export let query: Record<string, any>;
</script>
<Route path="register">
@@ -17,6 +19,8 @@
<Begin {config} subdomain={params.name} {query} />
</Route>
<Route path="register/:name/submit" let:params>
<Submit {config} subdomain={params.name} {query} {session} />
</Route>
{#if session}
<Route path="register/:name/submit" let:params>
<Submit {config} subdomain={params.name} {query} {session} />
</Route>
{/if}
+1 -1
View File
@@ -45,7 +45,7 @@ export async function registerName(name: string, owner: string, config: Config)
await commitAndRegister(name, owner, config);
}
} catch (e) {
throw { type: Failure.TransactionFailed, message: e.message, hash: e.txHash };
throw { type: Failure.TransactionFailed, message: e.message, txHash: e.txHash };
}
}
+4 -4
View File
@@ -1,9 +1,9 @@
<script lang="typescript">
import { navigate } from 'svelte-routing';
import { error } from '@app/error';
import { formatAddress } from '@app/utils';
import { registrar } from '../registrar';
import { session } from '@app/session';
import type { Config } from '@app/config';
import Connect from '@app/Connect.svelte';
@@ -13,9 +13,9 @@
NameUnavailable,
}
export let config;
export let subdomain;
export let query;
export let config: Config;
export let subdomain: string;
export let query: Record<string, any>;
let state = State.Initial;
$: registrationOwner = query.get("owner") || ($session && $session.address);
+7 -6
View File
@@ -3,19 +3,20 @@
import { get } from 'svelte/store';
import { navigate } from 'svelte-routing';
import { ethers } from 'ethers';
import { registrar, registerName, registrationFee } from '../registrar';
import { registerName, registrationFee } from '../registrar';
import { State, state } from '../state';
import type { Session } from '@app/session';
import type { Config } from '@app/config';
export let config;
export let subdomain;
export let query;
export let config: Config;
export let subdomain: string;
export let query: Record<string, any>;
export let session: Session;
let error = null;
let error: Error | null = null;
let registrationOwner = query.get("owner") || session.address;
async function getFee(cfg) {
async function getFee(cfg: Config) {
let fee = await registrationFee(cfg);
return ethers.utils.formatUnits(fee);
}
+7 -8
View File
@@ -1,26 +1,25 @@
<script lang="typescript">
import { onMount } from 'svelte';
import { get, derived, writable } from 'svelte/store';
import type { Writable } from 'svelte/store';
import { ethers } from 'ethers';
import { formatAddress } from '@app/utils';
import { State, state } from './state';
import { getInfo, withdrawVested } from './vesting';
import type { VestingInfo } from './vesting';
import type { Session } from '@app/session';
import type { Config } from '@app/config';
let input;
let input: HTMLElement;
onMount(() => {
input.focus();
});
export let config;
export let session: Session;
export let config: Config;
export let session: Session | null;
let contractAddress = "";
let info = null;
let info: VestingInfo | null = null;
async function loadContract(config) {
async function loadContract(config: Config) {
state.set(State.Loading);
info = await getInfo(contractAddress, config);
state.set(State.Idle);
+10 -1
View File
@@ -21,6 +21,15 @@ const tokenAbi = [
"function symbol() view returns (string)",
];
export interface VestingInfo {
token: string,
symbol: string,
beneficiary: string,
totalVesting: string,
withdrawableBalance: string,
withdrawn: string
}
export async function withdrawVested(address: string, config: Config) {
const contract = new ethers.Contract(address, abi, config.provider);
const signer = config.provider.getSigner();
@@ -35,7 +44,7 @@ export async function withdrawVested(address: string, config: Config) {
state.set(State.Withdrawn);
}
export async function getInfo(address: string, config: Config) {
export async function getInfo(address: string, config: Config): Promise<VestingInfo> {
const contract = new ethers.Contract(address, abi, config.provider);
const signer = config.provider.getSigner();
+7 -1
View File
@@ -1,10 +1,16 @@
import { writable } from "svelte/store";
export interface Err {
type: Failure,
txHash?: string,
message?: string,
}
export enum Failure {
TransactionFailed = 1,
}
export const error = writable(null);
export const error = writable<Err | null>(null);
export class Unreachable extends Error {
constructor(value?: never) {