diff --git a/src/App.svelte b/src/App.svelte index 531b2bd3a..e28ce543e 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -16,7 +16,7 @@ import Projects from "@app/base/projects/View.svelte"; import Registrations from "@app/base/registrations/Routes.svelte"; import Seeds from "@app/base/seeds/Routes.svelte"; - import Vesting from "@app/base/vesting/Index.svelte"; + import Vesting from "@app/base/vesting/Routes.svelte"; initialize(); @@ -105,7 +105,7 @@ session={$session} activeRoute={$activeRouteStore} /> {:else if $activeRouteStore.resource === "vesting"} - + {:else if $activeRouteStore.resource === "projects"} {:else if $activeRouteStore.resource === "profile"} diff --git a/src/base/vesting/Form.svelte b/src/base/vesting/Form.svelte new file mode 100644 index 000000000..063e240cd --- /dev/null +++ b/src/base/vesting/Form.svelte @@ -0,0 +1,91 @@ + + + + + + Radicle – Vesting + + +
+
+ Your Radicle vesting contract +
+ +
+ + + +
+
diff --git a/src/base/vesting/Routes.svelte b/src/base/vesting/Routes.svelte new file mode 100644 index 000000000..68b9edb4b --- /dev/null +++ b/src/base/vesting/Routes.svelte @@ -0,0 +1,22 @@ + + +{#if activeRoute.params.view.resource === "form"} +
+{:else if activeRoute.params.view.resource === "view"} + +{/if} diff --git a/src/base/vesting/Index.svelte b/src/base/vesting/View.svelte similarity index 53% rename from src/base/vesting/Index.svelte rename to src/base/vesting/View.svelte index 95d6962b6..da0e3cd9c 100644 --- a/src/base/vesting/Index.svelte +++ b/src/base/vesting/View.svelte @@ -3,77 +3,44 @@ import type { Wallet } from "@app/wallet"; import type { VestingInfo } from "./vesting"; + import * as router from "@app/router"; import * as utils from "@app/utils"; import Address from "@app/Address.svelte"; import Button from "@app/Button.svelte"; import Modal from "@app/Modal.svelte"; - import TextInput from "@app/TextInput.svelte"; import { state, getInfo, withdrawVested } from "./vesting"; + import { onMount } from "svelte"; + import ErrorModal from "@app/ErrorModal.svelte"; + import Loading from "@app/Loading.svelte"; - export let wallet: Wallet; + export let contractAddress: string; + export let info: VestingInfo | null = null; export let session: Session | null; + export let wallet: Wallet; - let contractAddress = ""; - let info: VestingInfo | null = null; - let validationMessage: string | undefined = undefined; - let valid: boolean = false; + let error: Error | undefined = undefined; - async function loadContract(wallet: Wallet) { - if (!valid) { - return; - } - - state.set("loading"); - try { - info = await getInfo(contractAddress, wallet); - } catch (error) { - validationMessage = - "Couldn't load contract, check dev console for details."; - console.error(error); + onMount(async () => { + if (!info) { + state.set("loading"); + try { + info = await getInfo(contractAddress, wallet); + } catch (e) { + error = e as Error; + } } state.set("idle"); - } + }); - $: isBeneficiary = - info && session && utils.isAddressEqual(info.beneficiary, session.address); - - function validate(address: string) { - if (address === "") { - return { valid: false }; - } - - if (!utils.isAddress(address)) { - return { - valid: false, - validationMessage: "Please enter a valid Ethereum address.", - }; - } - - return { valid: true }; - } - - $: ({ valid, validationMessage } = validate(contractAddress)); + const parseVestingPeriods = (input: string[]): string => { + const total = input + .map(s => parseInt(s)) + .reduce((prev, curr) => prev + curr, 0); + return new Date(total * 1000).toDateString(); + };