diff options
| author | Adam Soltys <[email protected]> | 2024-11-26 20:54:49 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-26 20:54:49 -0800 |
| commit | 872aa0b3b0b9a847b8afcdee7f1ad53c524ce4f0 (patch) | |
| tree | 4d505c5b7c3f137b56c84cfaca12ed486aa4972c /src/routes | |
| parent | f9300236a3c0227e0eec58326fa322e58613bc2d (diff) | |
| download | coinos-ui-872aa0b3b0b9a847b8afcdee7f1ad53c524ce4f0.tar.gz coinos-ui-872aa0b3b0b9a847b8afcdee7f1ad53c524ce4f0.zip | |
warnings
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.svelte | 19 | ||||
| -rw-r--r-- | src/routes/(app)/sent/[id]/+page.svelte | 6 | ||||
| -rw-r--r-- | src/routes/(app)/settings/security/+page.svelte | 32 | ||||
| -rw-r--r-- | src/routes/(static)/register/+page.server.ts | 13 | ||||
| -rw-r--r-- | src/routes/(static)/register/+page.svelte | 86 | ||||
| -rw-r--r-- | src/routes/+layout.svelte | 2 |
6 files changed, 67 insertions, 91 deletions
diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index d2b3727c..f0811f2e 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -13,32 +13,23 @@ import Numpad from "$comp/Numpad.svelte"; import Spinner from "$comp/Spinner.svelte"; import { page } from "$app/stores"; - import { - btc, - sat, - post, - back, - f, - toFiat, - s, - sats, - focus, - } from "$lib/utils"; + import { btc, sat, post, back, f, toFiat, s, sats, focus } from "$lib/utils"; let { data, form } = $props(); let { invoice, rates, user } = $state(data); let { address, hash, payreq, user: recipient, tip } = $state(invoice); let { currency } = $state(user); + let { amount } = $state(form || invoice); - let amount = $state(form?.amount || invoice.amount); let rate = $derived( invoice.rate * (rates[user.currency] / rates[invoice.currency]), ); + let a = $state(), af = $state(), - fiat = $state(!amount); + fiat = $state(untrack(() => !amount)); - let amountFiat = $state(amount * (rate / sats)); + let amountFiat = $state((untrack(() => amount) * untrack(() => rate)) / sats); let setAmount = () => { amount = a; amountFiat = af; diff --git a/src/routes/(app)/sent/[id]/+page.svelte b/src/routes/(app)/sent/[id]/+page.svelte index 2eb1f18b..d973d35d 100644 --- a/src/routes/(app)/sent/[id]/+page.svelte +++ b/src/routes/(app)/sent/[id]/+page.svelte @@ -4,13 +4,13 @@ import Success from "$comp/Success.svelte"; let { data } = $props(); - let { amount, rate, tip, user } = $state(data); + let { rate, tip, user } = $state(data); let { currency, username } = user; - amount = Math.abs(amount); + let amount = $state(Math.abs(data.amount)); </script> <Success {amount} {rate} {tip} {currency} title={`${$t("payments.sent")}!`} /> -<a href={`/${username}`} use:focus> +<a href={`/${username}`} use:focus aria-label="Continue"> <div class="opacity-0 w-screen h-screen fixed top-0 left-0 z-50"></div> </a> diff --git a/src/routes/(app)/settings/security/+page.svelte b/src/routes/(app)/settings/security/+page.svelte index cc988d6c..d40439ac 100644 --- a/src/routes/(app)/settings/security/+page.svelte +++ b/src/routes/(app)/settings/security/+page.svelte @@ -1,12 +1,11 @@ <script> import { getContext } from "svelte"; - import { getMnemonic, getNsec } from "$lib/nostr"; import { tick } from "svelte"; import { t } from "$lib/translations"; import Pin from "$comp/Pin.svelte"; - import Icon from "$comp/Icon.svelte"; import Qr from "$comp/Qr.svelte"; + import PasswordInput from "$comp/PasswordInput.svelte"; import { copy, post, success, fail } from "$lib/utils"; import { save, pin as current } from "$lib/store"; import { invalidate } from "$app/navigation"; @@ -48,7 +47,6 @@ } }; - let togglePassword = () => (revealPassword = !revealPassword); let toggleSeed = async () => { try { mnemonic = await getMnemonic(user); @@ -168,26 +166,8 @@ <label for="password" class="block font-bold block mb-1" >{$t("user.settings.newPassword")}</label > - <label - for="password" - class="input flex items-center justify-center gap-2 w-full" - > - {#if revealPassword} - <input name="password" type="text" bind:value={password} class="clean" /> - {:else} - <input - name="password" - type="password" - bind:value={password} - class="clean" - /> - {/if} - <iconify-icon - onclick={togglePassword} - icon={revealPassword ? "ph:eye-bold" : "ph:eye-slash-bold"} - width="32" - ></iconify-icon> - </label> + + <PasswordInput bind:value={password} /> </div> <div> @@ -299,7 +279,11 @@ {/if} {#if revealNsec} - <button type="button" class="btn break-all !h-auto font-normal leading-normal flex-nowrap" onclick={() => copy(nsec)}> + <button + type="button" + class="btn break-all !h-auto font-normal leading-normal flex-nowrap" + onclick={() => copy(nsec)} + > <div>{nsec}</div> <iconify-icon icon="ph:copy-bold" width="32"></iconify-icon> diff --git a/src/routes/(static)/register/+page.server.ts b/src/routes/(static)/register/+page.server.ts index 2dffef01..1781602f 100644 --- a/src/routes/(static)/register/+page.server.ts +++ b/src/routes/(static)/register/+page.server.ts @@ -1,5 +1,5 @@ +import { fd, login, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -import { fd, post, login } from "$lib/utils"; export const load = async ({ parent }) => { const { user } = await parent(); @@ -24,18 +24,19 @@ export const actions = { try { await post("/register", { user }, { "cf-connecting-ip": ip }); - } catch (e: any) { - error = e.message; + } catch (e) { + ({ message: error } = e as Error); } try { await login(user, cookies, ip); error = null; - } catch (e: any) { - error ||= e.message; + } catch (e) { + const { message } = e as Error; + error ||= message; } if (error) return fail(400, { error }); - redirect(307, loginRedirect || `/${user.username}`); + redirect(303, loginRedirect || `/${user.username}`); }, }; diff --git a/src/routes/(static)/register/+page.svelte b/src/routes/(static)/register/+page.svelte index c179552c..8a2a5015 100644 --- a/src/routes/(static)/register/+page.svelte +++ b/src/routes/(static)/register/+page.svelte @@ -1,6 +1,4 @@ <script> - import { run, preventDefault } from 'svelte/legacy'; - import punks from "$lib/punks"; import { upload } from "$lib/upload"; import { afterNavigate, invalidateAll } from "$app/navigation"; @@ -40,7 +38,8 @@ } }; - let refresh = async () => { + let refresh = async (e) => { + e.preventDefault(); username = uniqueNamesGenerator({ dictionaries: [animals, NumberDictionary.generate({ min: 10, max: 99 })], length: 2, @@ -64,27 +63,27 @@ } }); - let token = $state(), formElement; + let token = $state(), + formElement; let code = []; let redirect; let cancel = () => (need2fa = false); - let email, btn = $state(); - - let update = (form) => form && ({ username, password: $password } = form); - + let email, + btn = $state(); let revealPassword = $state(); let loading = $state(); async function handleSubmit(e) { + e.preventDefault(); + loading = true; let data = new FormData(this); let user = Object.fromEntries(data); - console.log("USER", JSON.stringify(user)); await generate(user); for (let k in user) { @@ -144,26 +143,17 @@ reader.readAsDataURL(file); }; - run(() => { - data && ($avatar = undefined); - }); - let need2fa; - run(() => { - need2fa = form?.message === "2fa"; - }); - run(() => { - if (form?.message === "2fa" && form.token === token) token = ""; - }); - run(() => { - update(form); + + let need2fa = $derived(form?.message === "2fa"); + let src = $derived(`/api/public/${punks[index]}.webp`); + + $effect(() => { + if (need2fa && form.token === token) token = ""; }); - run(() => { + + $effect(() => { token && token?.length === 6 && tick().then(() => btn.click()); }); - let src; - run(() => { - src = `/api/public/${punks[index]}.webp`; - }); </script> {#if need2fa} @@ -185,11 +175,12 @@ <button class="absolute w-8 h-12 left-12 bg-base-100 rounded top-12" onclick={decr} + aria-label="Previous" > <iconify-icon icon="ph:caret-left-bold" width="32"></iconify-icon> </button> - <div class="block relative w-32 mx-auto" onclick={selectAvatar}> - <button + <button class="block relative w-32 mx-auto" onclick={selectAvatar}> + <div class="w-32 h-32 rounded-full border-4 border-white overflow-hidden flex mx-auto relative" > <img @@ -197,16 +188,17 @@ class="w-full h-full object-cover object-center overflow-hidden" alt={username} /> - </button> - <button + </div> + <div class="absolute bg-base-100 rounded-full p-2 mx-auto right-0 bottom-0 z-10 w-12" > <iconify-icon icon="ph:upload-simple-bold" width="24"></iconify-icon> - </button> - </div> + </div> + </button> <button class="absolute w-8 h-12 right-12 bg-base-100 rounded top-12" onclick={incr} + aria-label="Next" > <iconify-icon icon="ph:caret-right-bold" width="32"></iconify-icon> </button> @@ -218,7 +210,7 @@ </div> {/if} - <form class="space-y-5" onsubmit={preventDefault(handleSubmit)} method="POST"> + <form class="space-y-5" onsubmit={handleSubmit} method="POST"> <input type="hidden" name="loginRedirect" @@ -241,13 +233,16 @@ autocapitalize="none" placeholder={$t("login.username")} /> - <iconify-icon - class="cursor-pointer" + <button + type="button" tabindex="-1" onclick={refresh} - icon="ph:dice-three-bold" - width="32" -></iconify-icon> + aria-label="Randomize" + class="contents" + > + <iconify-icon icon="ph:dice-three-bold" width="32" + ></iconify-icon></button + > </label> <label @@ -276,13 +271,18 @@ placeholder={$t("login.password")} /> {/if} - <iconify-icon + <button + type="button" tabindex="-1" - class="cursor-pointer" onclick={() => (revealPassword = !revealPassword)} - icon={revealPassword ? "ph:eye-bold" : "ph:eye-slash-bold"} - width="32" -></iconify-icon> + class="contents" + aria-label="Toggle" + > + <iconify-icon + icon={revealPassword ? "ph:eye-bold" : "ph:eye-slash-bold"} + width="32" + ></iconify-icon></button + > </label> <button type="submit" class="btn" disabled={loading} bind:this={btn}> diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index e7baa137..7cb90195 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -10,7 +10,7 @@ let { data, children } = $props(); let { pathname, theme } = $state(data); - $themeStore = theme; + $themeStore = data.theme; $effect(() => (theme = $themeStore)); let host = PUBLIC_DOMAIN.includes("localhost") |
