diff options
| author | Adam Soltys <[email protected]> | 2026-02-11 17:51:24 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-11 17:51:24 -0800 |
| commit | 13466248004327e9a026cb89f94926f9b060d1c1 (patch) | |
| tree | 47b4972c33809ccdf866b043c92cd3e0ecf5dcd0 /src/routes/(app) | |
| parent | 3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff) | |
| download | coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip | |
linting
Diffstat (limited to 'src/routes/(app)')
136 files changed, 2142 insertions, 1854 deletions
diff --git a/src/routes/(app)/+layout.server.ts b/src/routes/(app)/+layout.server.ts index 8b694241..3b29df70 100644 --- a/src/routes/(app)/+layout.server.ts +++ b/src/routes/(app)/+layout.server.ts @@ -2,63 +2,63 @@ import { auth, get, isInvalidTokenError, sleep } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; export async function load({ cookies, request, url, params }) { - const { pathname } = url; - const { id, username } = params; - const token = cookies.get("token"); + const { pathname } = url; + const { id, username } = params; + const token = cookies.get("token"); - let user; - if (token) { - try { - user = await get("/me", auth(cookies)); - } catch (e) { - const { message } = e as Error; - if (message.startsWith("Rate")) { - await sleep(3000); - try { - user = await get("/me", auth(cookies)); - } catch (retryError) { - if (isInvalidTokenError(retryError) && pathname !== "/logout") { - redirect(307, "/logout"); - } - throw retryError; - } - } else if (isInvalidTokenError(e) && pathname !== "/logout") { - redirect(307, "/logout"); - } else { - throw e; - } - } - } + let user; + if (token) { + try { + user = await get("/me", auth(cookies)); + } catch (e) { + const { message } = e as Error; + if (message.startsWith("Rate")) { + await sleep(3000); + try { + user = await get("/me", auth(cookies)); + } catch (retryError) { + if (isInvalidTokenError(retryError) && pathname !== "/logout") { + redirect(307, "/logout"); + } + throw retryError; + } + } else if (isInvalidTokenError(e) && pathname !== "/logout") { + redirect(307, "/logout"); + } else { + throw e; + } + } + } - let subject; + let subject; - if (url.pathname.includes("/invoice") && id) { - try { - ({ user: subject } = await get(`/invoice/${id}`)); - } catch (e) { - console.log("unable to fetch invoice", id, e); - } - } else if (username) { - try { - subject = await get(`/users/${username}`); - } catch (e) { - error(500, "Unable to retrieve user account data"); - } - } + if (url.pathname.includes("/invoice") && id) { + try { + ({ user: subject } = await get(`/invoice/${id}`)); + } catch (e) { + console.log("unable to fetch invoice", id, e); + } + } else if (username) { + try { + subject = await get(`/users/${username}`); + } catch { + error(500, "Unable to retrieve user account data"); + } + } - if (user?.needsMigration) { - redirect(307, "/migrate"); - } + if (user?.needsMigration) { + redirect(307, "/migrate"); + } - if ( - user && - ["/login", "/register"].includes(pathname) && - request.method === "GET" - ) { - redirect(307, `/${user.username}`); - } + if ( + user && + ["/login", "/register"].includes(pathname) && + request.method === "GET" + ) { + redirect(307, `/${user.username}`); + } - const theme = cookies.get("theme") || "light"; + const theme = cookies.get("theme") || "light"; - return { user, token, subject, theme }; + return { user, token, subject, theme }; } diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 6ac9bed5..346cc93e 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -24,7 +24,12 @@ import Password from "$comp/Password.svelte"; import { s, f, toFiat, success, getCookie, warning } from "$lib/utils"; import { t, locale, loading } from "$lib/translations"; - import { goto, invalidate, afterNavigate, preloadData } from "$app/navigation"; + import { + goto, + invalidate, + afterNavigate, + preloadData, + } from "$app/navigation"; let { data, children } = $props(); @@ -58,7 +63,9 @@ if (result?.received > 0) { if ($fiat && $rateStore && user?.currency) { - success(`Received ${f(toFiat(result.received, $rateStore), user.currency)}!`); + success( + `Received ${f(toFiat(result.received, $rateStore), user.currency)}!`, + ); } else { success(`Received ⚡️${s(result.received)}!`); } diff --git a/src/routes/(app)/[username]/(profile)/+layout.server.ts b/src/routes/(app)/[username]/(profile)/+layout.server.ts index 251388e5..9c916d7a 100644 --- a/src/routes/(app)/[username]/(profile)/+layout.server.ts +++ b/src/routes/(app)/[username]/(profile)/+layout.server.ts @@ -1,10 +1,10 @@ import getRates from "$lib/rates"; export async function load({ depends, parent }) { - depends("app:user"); + depends("app:user"); - const rates = await getRates(); - const { subject, user } = await parent(); + const rates = await getRates(); + const { subject } = await parent(); - return { rate: rates[subject.currency] }; + return { rate: rates[subject.currency] }; } diff --git a/src/routes/(app)/[username]/(profile)/+layout.svelte b/src/routes/(app)/[username]/(profile)/+layout.svelte index 8331c98e..1bb9447f 100644 --- a/src/routes/(app)/[username]/(profile)/+layout.svelte +++ b/src/routes/(app)/[username]/(profile)/+layout.svelte @@ -291,7 +291,7 @@ </div> <div class="text-secondary flex ml-auto items-center gap-1"> {#if satsPerCurrency >= 1} - <div>{f(1, currency, locale)} = </div> + <div>{f(1, currency, locale)} =</div> <div class="flex items-center"> <iconify-icon noobserver diff --git a/src/routes/(app)/[username]/(profile)/+page.server.ts b/src/routes/(app)/[username]/(profile)/+page.server.ts index 5f0e7579..9c97c947 100644 --- a/src/routes/(app)/[username]/(profile)/+page.server.ts +++ b/src/routes/(app)/[username]/(profile)/+page.server.ts @@ -2,14 +2,14 @@ import getRates from "$lib/rates"; import { auth, get } from "$lib/utils"; export async function load({ cookies, depends, parent }) { - depends("app:payments"); - depends("app:items"); + depends("app:payments"); + depends("app:items"); - const { subject } = await parent(); + const { subject } = await parent(); - let accounts = []; - if (cookies.get("token")) accounts = await get("/accounts", auth(cookies)); + let accounts = []; + if (cookies.get("token")) accounts = await get("/accounts", auth(cookies)); - const rates = await getRates(); - return { accounts, rate: rates[subject.currency] }; + const rates = await getRates(); + return { accounts, rate: rates[subject.currency] }; } diff --git a/src/routes/(app)/[username]/(profile)/+page.ts b/src/routes/(app)/[username]/(profile)/+page.ts index 7fe2192a..0a6c78b2 100644 --- a/src/routes/(app)/[username]/(profile)/+page.ts +++ b/src/routes/(app)/[username]/(profile)/+page.ts @@ -4,7 +4,7 @@ import { get } from "svelte/store"; export const ssr = false; export async function load() { - const sk = cookies.get("sk"); - if (sk && !get(signer)) - signer.set({ method: "nsec", params: { sk }, ready: true }); + const sk = cookies.get("sk"); + if (sk && !get(signer)) + signer.set({ method: "nsec", params: { sk }, ready: true }); } diff --git a/src/routes/(app)/[username]/(profile)/notes/+page.server.ts b/src/routes/(app)/[username]/(profile)/notes/+page.server.ts index b7186bc0..4a898798 100644 --- a/src/routes/(app)/[username]/(profile)/notes/+page.server.ts +++ b/src/routes/(app)/[username]/(profile)/notes/+page.server.ts @@ -2,12 +2,12 @@ import { get } from "$lib/utils"; import { error } from "@sveltejs/kit"; export async function load({ parent }) { - try { - const { subject } = await parent(); - const events = await get(`/${subject.pubkey}/events`); - return { events }; - } catch (e) { - console.log(e); - error(500, { message: "Failed to get events" }); - } + try { + const { subject } = await parent(); + const events = await get(`/${subject.pubkey}/events`); + return { events }; + } catch (e) { + console.log(e); + error(500, { message: "Failed to get events" }); + } } diff --git a/src/routes/(app)/[username]/+layout.server.ts b/src/routes/(app)/[username]/+layout.server.ts index bff8848c..ab755410 100644 --- a/src/routes/(app)/[username]/+layout.server.ts +++ b/src/routes/(app)/[username]/+layout.server.ts @@ -2,23 +2,23 @@ import { get } from "$lib/utils"; import { error } from "@sveltejs/kit"; export const load = async ({ - cookies, - depends, - params: { username }, - parent, + cookies, + depends, + params: { username }, + parent, }) => { - depends("app:user"); + depends("app:user"); - try { - const subject = await get(`/users/${username}`); - const { user } = await parent(); + try { + const subject = await get(`/users/${username}`); + const { user } = await parent(); - const expires = new Date(); - expires.setSeconds(expires.getSeconds() + 380 * 24 * 60 * 60); - cookies.set("username", username, { path: "/", expires, httpOnly: false }); + const expires = new Date(); + expires.setSeconds(expires.getSeconds() + 380 * 24 * 60 * 60); + cookies.set("username", username, { path: "/", expires, httpOnly: false }); - return { subject, user }; - } catch (e) { - error(500, "Unable to retrieve user account data"); - } + return { subject, user }; + } catch { + error(500, "Unable to retrieve user account data"); + } }; diff --git a/src/routes/(app)/[username]/accepted/[text]/+page.server.ts b/src/routes/(app)/[username]/accepted/[text]/+page.server.ts index aa25ce7f..4da700e0 100644 --- a/src/routes/(app)/[username]/accepted/[text]/+page.server.ts +++ b/src/routes/(app)/[username]/accepted/[text]/+page.server.ts @@ -1,6 +1,6 @@ export async function load({ params, url }) { - const { text } = params; - const query = new URLSearchParams(url.search); - const nfc = !!query.get("nfc"); - return { nfc, text }; + const { text } = params; + const query = new URLSearchParams(url.search); + const nfc = !!query.get("nfc"); + return { nfc, text }; } diff --git a/src/routes/(app)/[username]/accepted/[text]/+page.svelte b/src/routes/(app)/[username]/accepted/[text]/+page.svelte index fd2c7991..339f6c9c 100644 --- a/src/routes/(app)/[username]/accepted/[text]/+page.svelte +++ b/src/routes/(app)/[username]/accepted/[text]/+page.svelte @@ -1,4 +1,5 @@ -<script> import Qr from "$comp/Qr.svelte"; +<script> + import Qr from "$comp/Qr.svelte"; import { back, copy } from "$lib/utils"; import { bech32 } from "@scure/base"; import { page } from "$app/stores"; diff --git a/src/routes/(app)/[username]/accepted/[text]/raw/+server.ts b/src/routes/(app)/[username]/accepted/[text]/raw/+server.ts index a24d3a3c..ad7fc6b1 100644 --- a/src/routes/(app)/[username]/accepted/[text]/raw/+server.ts +++ b/src/routes/(app)/[username]/accepted/[text]/raw/+server.ts @@ -1,16 +1,16 @@ import Qr from "qrcode-base64"; export async function GET({ params }) { - const { text } = params; + const { text } = params; - const dataUri = Qr.drawImg(text, { size: 600 }); - const base64Data = dataUri.split(",")[1]; - const binaryData = Buffer.from(base64Data, "base64"); + const dataUri = Qr.drawImg(text, { size: 600 }); + const base64Data = dataUri.split(",")[1]; + const binaryData = Buffer.from(base64Data, "base64"); - return new Response(binaryData, { - headers: { - "Content-Type": "image/gif", - "Cache-Control": "public, max-age=31536000, immutable", - }, - }); + return new Response(binaryData, { + headers: { + "Content-Type": "image/gif", + "Cache-Control": "public, max-age=31536000, immutable", + }, + }); } diff --git a/src/routes/(app)/[username]/accepted/create/+page.svelte b/src/routes/(app)/[username]/accepted/create/+page.svelte index 339aae16..189a734d 100644 --- a/src/routes/(app)/[username]/accepted/create/+page.svelte +++ b/src/routes/(app)/[username]/accepted/create/+page.svelte @@ -1,10 +1,12 @@ <script lang="ts"> - import { run, preventDefault } from 'svelte/legacy'; + import { run, preventDefault } from "svelte/legacy"; import { goto } from "$app/navigation"; import { browser } from "$app/environment"; import { t } from "$lib/translations"; - let el = $state(), text = $state(), pasted = $state(); + let el = $state(), + text = $state(), + pasted = $state(); let keypress = (e) => e.key === "Enter" ? e.preventDefault() || el.click() : (pasted = false); @@ -37,7 +39,7 @@ bind:value={text} onpaste={() => (pasted = true)} autocapitalize="none" -></textarea> + ></textarea> </div> <div class="flex gap-2"> diff --git a/src/routes/(app)/[username]/receive/+page.server.js b/src/routes/(app)/[username]/receive/+page.server.js index 777c1dd7..2aa875dd 100644 --- a/src/routes/(app)/[username]/receive/+page.server.js +++ b/src/routes/(app)/[username]/receive/+page.server.js @@ -2,15 +2,15 @@ import getRates from "$lib/rates"; import { redirect } from "@sveltejs/kit"; export const load = async ({ cookies, params: { username }, parent, url }) => { - const token = cookies.get("token"); - const rates = await getRates(); - if (!token) redirect(307, `/pay/${username}`); - const { subject, user } = await parent(); - const aid = cookies.get("aid"); + const token = cookies.get("token"); + const rates = await getRates(); + if (!token) redirect(307, `/pay/${username}`); + const { subject, user } = await parent(); + const aid = cookies.get("aid"); - if (aid && user?.id !== aid) redirect(307, "/invoice"); - return { - rate: rates[subject.currency], - text: `${username}@${url.host}`, - }; + if (aid && user?.id !== aid) redirect(307, "/invoice"); + return { + rate: rates[subject.currency], + text: `${username}@${url.host}`, + }; }; diff --git a/src/routes/(app)/account/+server.ts b/src/routes/(app)/account/+server.ts index e6dc7e0c..fbe1214b 100644 --- a/src/routes/(app)/account/+server.ts +++ b/src/routes/(app)/account/+server.ts @@ -2,11 +2,11 @@ import { auth, post } from "$lib/utils"; import { error, json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - try { - const body = await request.json(); - return json(await post("/accounts", body, auth(cookies))); - } catch (e: any) { - console.log(e); - error(500, e.message); - } + try { + const body = await request.json(); + return json(await post("/accounts", body, auth(cookies))); + } catch (e: any) { + console.log(e); + error(500, e.message); + } } diff --git a/src/routes/(app)/account/[id]/+page.server.ts b/src/routes/(app)/account/[id]/+page.server.ts index b91a0788..0fcfbdd9 100644 --- a/src/routes/(app)/account/[id]/+page.server.ts +++ b/src/routes/(app)/account/[id]/+page.server.ts @@ -2,23 +2,23 @@ import { error, redirect } from "@sveltejs/kit"; import { auth, get, post, fd } from "$lib/utils"; export const load = async ({ cookies, params }) => { - const account = await get(`/account/${params.id}`, auth(cookies)); - return { account }; + const account = await get(`/account/${params.id}`, auth(cookies)); + return { account }; }; export const actions = { - default: async ({ cookies, params, request }) => { - const { id } = params; - const body = await fd(request); - const username = cookies.get("username"); + default: async ({ cookies, params, request }) => { + const { id } = params; + const body = await fd(request); + const username = cookies.get("username"); - try { - await post(`/account/${id}`, body, auth(cookies)); - } catch (e: any) { - console.log(e); - error(400, { message: e.message }); - } + try { + await post(`/account/${id}`, body, auth(cookies)); + } catch (e: any) { + console.log(e); + error(400, { message: e.message }); + } - redirect(303, `/${username}`); - }, + redirect(303, `/${username}`); + }, }; diff --git a/src/routes/(app)/account/[id]/+page.svelte b/src/routes/(app)/account/[id]/+page.svelte index 4a23a211..6b48bac2 100644 --- a/src/routes/(app)/account/[id]/+page.svelte +++ b/src/routes/(app)/account/[id]/+page.svelte @@ -71,7 +71,6 @@ fail(e.message); } }; - </script> <div class="space-y-5"> diff --git a/src/routes/(app)/account/ark/+page.svelte b/src/routes/(app)/account/ark/+page.svelte index 0c4d8783..42329ef8 100644 --- a/src/routes/(app)/account/ark/+page.svelte +++ b/src/routes/(app)/account/ark/+page.svelte @@ -9,10 +9,7 @@ import { goto } from "$app/navigation"; import { arkServerUrl } from "$lib/ark"; import { HDKey } from "@scure/bip32"; - import { - entropyToMnemonic, - mnemonicToSeed, - } from "@scure/bip39"; + import { entropyToMnemonic, mnemonicToSeed } from "@scure/bip39"; import { wordlist } from "@scure/bip39/wordlists/english.js"; import { rememberForOptions, @@ -168,7 +165,8 @@ {#if hasMasterSeed} <form onsubmit={preventDefault(submit)} class="space-y-5"> <p class="text-secondary"> - Your Ark wallet will be derived from your master seed. Enter your wallet password to continue. + Your Ark wallet will be derived from your master seed. Enter your + wallet password to continue. </p> <label @@ -220,7 +218,8 @@ id="rememberFor" class="w-full" value={rememberForMs} - onchange={(e) => (rememberForMs = Number((e.target as HTMLSelectElement).value))} + onchange={(e) => + (rememberForMs = Number((e.target as HTMLSelectElement).value))} > {#each rememberForOptions as option} <option value={option.ms}>{option.label}</option> @@ -230,9 +229,7 @@ <div class="flex gap-2"> <a href={`/${user.username}`} class="contents"> - <button type="button" class="btn !w-auto grow"> - Back - </button> + <button type="button" class="btn !w-auto grow"> Back </button> </a> <button disabled={submitting} @@ -250,7 +247,8 @@ {:else if !confirmed} <div class="space-y-4"> <p class="text-secondary"> - Your Ark wallet is secured by a private key. Please copy it down somewhere safe. + Your Ark wallet is secured by a private key. Please copy it down + somewhere safe. </p> {#if showNsec} @@ -266,14 +264,24 @@ </div> <div class="flex gap-2"> - <button type="button" class="btn btn-accent flex-grow" onclick={confirmBackup}> - <iconify-icon noobserver icon="ph:check-bold" width="24"></iconify-icon> + <button + type="button" + class="btn btn-accent flex-grow" + onclick={confirmBackup} + > + <iconify-icon noobserver icon="ph:check-bold" width="24" + ></iconify-icon> I've backed it up </button> </div> {:else} - <button type="button" class="btn btn-warning w-full" onclick={revealNsec}> - <iconify-icon noobserver icon="ph:eye-bold" width="24"></iconify-icon> + <button + type="button" + class="btn btn-warning w-full" + onclick={revealNsec} + > + <iconify-icon noobserver icon="ph:eye-bold" width="24" + ></iconify-icon> Reveal backup key </button> {/if} @@ -281,7 +289,8 @@ {:else} <form onsubmit={preventDefault(submit)} class="space-y-5"> <p class="text-secondary"> - Set a password to encrypt your key. You'll need this password to send funds. + Set a password to encrypt your key. You'll need this password to send + funds. </p> <label @@ -371,7 +380,8 @@ id="rememberFor" class="w-full" value={rememberForMs} - onchange={(e) => (rememberForMs = Number((e.target as HTMLSelectElement).value))} + onchange={(e) => + (rememberForMs = Number((e.target as HTMLSelectElement).value))} > {#each rememberForOptions as option} <option value={option.ms}>{option.label}</option> diff --git a/src/routes/(app)/account/bitcoin/+page.svelte b/src/routes/(app)/account/bitcoin/+page.svelte index ca90c758..87dc32e2 100644 --- a/src/routes/(app)/account/bitcoin/+page.svelte +++ b/src/routes/(app)/account/bitcoin/+page.svelte @@ -11,7 +11,8 @@ <a href="/account/seed" class="block"> <div class="card card-side shadow shadow-base-300 p-8 hover:bg-base-200"> <figure class="w-20 flex items-center justify-center"> - <iconify-icon noobserver icon="ph:file-plus-bold" width="64"></iconify-icon> + <iconify-icon noobserver icon="ph:file-plus-bold" width="64" + ></iconify-icon> </figure> <div> <div class="text-xl">{$t("accounts.create")}</div> @@ -22,7 +23,8 @@ <a href="/account/import" class="block"> <div class="card card-side shadow shadow-base-300 p-8 hover:bg-base-200"> <figure class="w-20 flex items-center justify-center"> - <iconify-icon noobserver icon="ph:folder-open-bold" width="64"></iconify-icon> + <iconify-icon noobserver icon="ph:folder-open-bold" width="64" + ></iconify-icon> </figure> <div> <div class="text-xl">{$t("accounts.import")}</div> diff --git a/src/routes/(app)/account/cash/+page.svelte b/src/routes/(app)/account/cash/+page.svelte index 378d36ee..188eaf66 100644 --- a/src/routes/(app)/account/cash/+page.svelte +++ b/src/routes/(app)/account/cash/+page.svelte @@ -1,5 +1,6 @@ <script lang="ts"> - import { t } from "$lib/translations";</script> + import { t } from "$lib/translations"; +</script> <div class="space-y-5"> <h1 class="text-center text-3xl font-semibold">Choose your custodian</h1> diff --git a/src/routes/(app)/account/new/+page.svelte b/src/routes/(app)/account/new/+page.svelte index a514237a..4100e001 100644 --- a/src/routes/(app)/account/new/+page.svelte +++ b/src/routes/(app)/account/new/+page.svelte @@ -7,7 +7,9 @@ <div class="container w-full mx-auto text-lg px-4 max-w-xl space-y-5"> <a href="/account/bitcoin" class="block"> - <div class="card card-side shadow shadow-base-300 p-8 hover:bg-base-200 gap-4 items-center"> + <div + class="card card-side shadow shadow-base-300 p-8 hover:bg-base-200 gap-4 items-center" + > <iconify-icon noobserver icon="logos:bitcoin" width={48}></iconify-icon> <div> <div class="text-xl">Bitcoin (On-chain)</div> @@ -18,7 +20,9 @@ </div> </a> <a href="/account/ark" class="block"> - <div class="card card-side shadow shadow-base-300 p-8 hover:bg-base-200 gap-4 items-center"> + <div + class="card card-side shadow shadow-base-300 p-8 hover:bg-base-200 gap-4 items-center" + > <img src="/images/ark.png" class="w-12 h-12 rounded-full object-cover" diff --git a/src/routes/(app)/account/pass/+page.svelte b/src/routes/(app)/account/pass/+page.svelte index 4e9573d4..2f62c38c 100644 --- a/src/routes/(app)/account/pass/+page.svelte +++ b/src/routes/(app)/account/pass/+page.svelte @@ -98,7 +98,9 @@ onsubmit={preventDefault(submit)} class="container w-full mx-auto text-lg px-4 max-w-xl space-y-5" > - <p class="text-secondary p-4 bg-warning/80 rounded-2xl border-warning border-2"> + <p + class="text-secondary p-4 bg-warning/80 rounded-2xl border-warning border-2" + > {$t("accounts.passwordWarning")} </p> @@ -188,7 +190,8 @@ id="rememberFor" class="w-full" value={rememberForMs} - onchange={(e) => (rememberForMs = Number((e.target as HTMLSelectElement).value))} + onchange={(e) => + (rememberForMs = Number((e.target as HTMLSelectElement).value))} > {#each rememberForOptions as option} <option value={option.ms}>{option.label}</option> diff --git a/src/routes/(app)/account/seed/+page.svelte b/src/routes/(app)/account/seed/+page.svelte index 537121af..cbfe1024 100644 --- a/src/routes/(app)/account/seed/+page.svelte +++ b/src/routes/(app)/account/seed/+page.svelte @@ -32,8 +32,7 @@ {/if} <button type="button" class="btn" onclick={() => copy($mnemonic)}> - <iconify-icon noobserver icon="ph:copy-bold" width="32" - ></iconify-icon> + <iconify-icon noobserver icon="ph:copy-bold" width="32"></iconify-icon> <div class="my-auto"> {$t("payments.copy")} </div> diff --git a/src/routes/(app)/account/setup/+page.svelte b/src/routes/(app)/account/setup/+page.svelte index 09703d92..9d747578 100644 --- a/src/routes/(app)/account/setup/+page.svelte +++ b/src/routes/(app)/account/setup/+page.svelte @@ -19,7 +19,11 @@ </a> <a href="/account/new" class="block"> <div class="shadow p-8 rounded-xl flex gap-4 hover:bg-primary"> - <img src="/images/keys.png" class="w-20 my-auto" alt="Savings account" /> + <img + src="/images/keys.png" + class="w-20 my-auto" + alt="Savings account" + /> <div> <div class="text-xl">Savings</div> <div class="text-secondary"> diff --git a/src/routes/(app)/admin/+layout.server.ts b/src/routes/(app)/admin/+layout.server.ts index a2da1a90..01f328a0 100644 --- a/src/routes/(app)/admin/+layout.server.ts +++ b/src/routes/(app)/admin/+layout.server.ts @@ -2,16 +2,16 @@ import { auth, get, isInvalidTokenError } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies }) { - const token = cookies.get("token"); - if (!token) redirect(307, "/login"); - let user; - try { - user = await get("/me", auth(cookies)); - } catch (e) { - if (isInvalidTokenError(e)) redirect(307, "/logout"); - throw e; - } - if (!user) redirect(307, "/login"); + const token = cookies.get("token"); + if (!token) redirect(307, "/login"); + let user; + try { + user = await get("/me", auth(cookies)); + } catch (e) { + if (isInvalidTokenError(e)) redirect(307, "/logout"); + throw e; + } + if (!user) redirect(307, "/login"); - return { user }; + return { user }; } diff --git a/src/routes/(app)/admin/+page.server.ts b/src/routes/(app)/admin/+page.server.ts index 8c250026..7bb7d1f3 100644 --- a/src/routes/(app)/admin/+page.server.ts +++ b/src/routes/(app)/admin/+page.server.ts @@ -2,11 +2,11 @@ import { auth, get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies, parent }) { - const { user } = await parent(); - if (!user) redirect(307, "/login"); + const { user } = await parent(); + if (!user) redirect(307, "/login"); - const users = (await get("/users", auth(cookies))).sort( - (a, b) => b.balance - a.balance, - ); - return { users }; + const users = (await get("/users", auth(cookies))).sort( + (a, b) => b.balance - a.balance, + ); + return { users }; } diff --git a/src/routes/(app)/apps/[pubkey]/+page.server.ts b/src/routes/(app)/apps/[pubkey]/+page.server.ts index a2cc50e7..ff10668f 100644 --- a/src/routes/(app)/apps/[pubkey]/+page.server.ts +++ b/src/routes/(app)/apps/[pubkey]/+page.server.ts @@ -3,24 +3,24 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export const load = async ({ cookies, params, parent }) => { - const { pubkey } = params; - const { user } = await parent(); - const rates = await getRates(); - const rate = rates[user.currency]; - const app = await get(`/app/${pubkey}`, auth(cookies)); - return { app, rate }; + const { pubkey } = params; + const { user } = await parent(); + const rates = await getRates(); + const rate = rates[user.currency]; + const app = await get(`/app/${pubkey}`, auth(cookies)); + return { app, rate }; }; export const actions = { - default: async ({ cookies, request }) => { - try { - const body = await fd(request); - await post("/app", body, auth(cookies)); - } catch (e) { - const { message: error } = e as Error; - return fail(400, { error }); - } + default: async ({ cookies, request }) => { + try { + const body = await fd(request); + await post("/app", body, auth(cookies)); + } catch (e) { + const { message: error } = e as Error; + return fail(400, { error }); + } - redirect(307, "/settings/nostr"); - }, + redirect(307, "/settings/nostr"); + }, }; diff --git a/src/routes/(app)/apps/[pubkey]/payments/+page.server.ts b/src/routes/(app)/apps/[pubkey]/payments/+page.server.ts index 546dacdf..0df40562 100644 --- a/src/routes/(app)/apps/[pubkey]/payments/+page.server.ts +++ b/src/routes/(app)/apps/[pubkey]/payments/+page.server.ts @@ -1,6 +1,6 @@ import { auth, get } from "$lib/utils"; export const load = async ({ cookies, params }) => { - const app = await get(`/app/${params.pubkey}`, auth(cookies)); - return { app }; + const app = await get(`/app/${params.pubkey}`, auth(cookies)); + return { app }; }; diff --git a/src/routes/(app)/apps/new/+page.server.ts b/src/routes/(app)/apps/new/+page.server.ts index eaecfd68..a78b9093 100644 --- a/src/routes/(app)/apps/new/+page.server.ts +++ b/src/routes/(app)/apps/new/+page.server.ts @@ -3,39 +3,39 @@ import { auth, fd, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export const load = async ({ parent, url }) => { - const { user } = await parent(); + const { user } = await parent(); - if (!user) - redirect( - 307, - `/login?redirect=${encodeURIComponent(url.pathname + url.search)}`, - ); + if (!user) + redirect( + 307, + `/login?redirect=${encodeURIComponent(url.pathname + url.search)}`, + ); - let max_amount = url.searchParams.get("max_amount"); - max_amount = max_amount ? Math.round(Number(max_amount) / 1000) : undefined; + let max_amount = url.searchParams.get("max_amount"); + max_amount = max_amount ? Math.round(Number(max_amount) / 1000) : undefined; - const app = { - name: url.searchParams.get("name"), - pubkey: url.searchParams.get("pubkey"), - max_amount, - budget_renewal: url.searchParams.get("budget_renewal"), - }; + const app = { + name: url.searchParams.get("name"), + pubkey: url.searchParams.get("pubkey"), + max_amount, + budget_renewal: url.searchParams.get("budget_renewal"), + }; - const rates = await getRates(); - const rate = rates[user.currency]; - return { app, rate }; + const rates = await getRates(); + const rate = rates[user.currency]; + return { app, rate }; }; export const actions = { - default: async ({ cookies, request }) => { - try { - const body = await fd(request); - await post("/app", body, auth(cookies)); - } catch (e) { - const { message: error } = e as Error; - return fail(400, { error }); - } + default: async ({ cookies, request }) => { + try { + const body = await fd(request); + await post("/app", body, auth(cookies)); + } catch (e) { + const { message: error } = e as Error; + return fail(400, { error }); + } - redirect(307, "/settings/nostr"); - }, + redirect(307, "/settings/nostr"); + }, }; diff --git a/src/routes/(app)/contacts/+server.ts b/src/routes/(app)/contacts/+server.ts index e448bda2..2bc5d28e 100644 --- a/src/routes/(app)/contacts/+server.ts +++ b/src/routes/(app)/contacts/+server.ts @@ -2,11 +2,11 @@ import { auth, get } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function GET({ cookies }) { - try { - const contacts = await get("/contacts", auth(cookies)); - return json(contacts); - } catch (e) { - console.log(e); - return json({}); - } + try { + const contacts = await get("/contacts", auth(cookies)); + return json(contacts); + } catch (e) { + console.log(e); + return json({}); + } } diff --git a/src/routes/(app)/disable2fa/+server.ts b/src/routes/(app)/disable2fa/+server.ts index 81ee2ff2..0d1c4573 100644 --- a/src/routes/(app)/disable2fa/+server.ts +++ b/src/routes/(app)/disable2fa/+server.ts @@ -2,12 +2,12 @@ import { error, json } from "@sveltejs/kit"; import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - try { - const body = await request.json(); - const res = await post("/disable2fa", body, auth(cookies)); + try { + const body = await request.json(); + const res = await post("/disable2fa", body, auth(cookies)); - return json(res); - } catch (e) { - error(500, "Problem disabling 2fa"); - } + return json(res); + } catch { + error(500, "Problem disabling 2fa"); + } } diff --git a/src/routes/(app)/dm/+page.svelte b/src/routes/(app)/dm/+page.svelte index 95cb208e..173871c1 100644 --- a/src/routes/(app)/dm/+page.svelte +++ b/src/routes/(app)/dm/+page.svelte @@ -1,512 +1,664 @@ <script lang="ts"> - import { tick, onMount } from "svelte"; + import { tick, onMount } from "svelte"; + import { isValid, queryProfile } from "nostr-tools/nip05"; + import * as toolsnip17 from "nostr-tools/nip17"; - import { isValid, queryProfile } from "nostr-tools/nip05"; - import * as toolsnip17 from 'nostr-tools/nip17'; + import { getNostrUserInfo } from "$lib/nip01"; + import { relaysSupporting } from "$lib/nip11"; + import { getMessageRumours } from "$lib/nip17"; + import * as libnip17 from "$lib/nip17"; + import { npubEncode, decode } from "nostr-tools/nip19"; + import { mute, unmute, mutedAccounts } from "$lib/nip51"; + import { sign, getPrivateKey, pTagKeys } from "$lib/nostr"; + import { t } from "$lib/translations"; + import { theme } from "$lib/store"; - import { getNostrUserInfo } from '$lib/nip01'; - import { relaysSupporting } from '$lib/nip11'; - import { getMessageRumours } from '$lib/nip17'; - import * as libnip17 from '$lib/nip17'; - import { npubEncode, decode } from 'nostr-tools/nip19'; - import { mute, unmute, mutedAccounts } from '$lib/nip51'; - import { sign, getPrivateKey, pTagKeys } from '$lib/nostr'; - import { t } from "$lib/translations"; - import { theme } from "$lib/store"; + let { data } = $props(); + const { user } = data; - let { data } = $props(); - const { user } = data; + if (!user) { + window.location.replace("/login"); + } - if (!user) { - window.location.replace("/login"); - } + /// chat selection + const usernameFromPubkey = async (pubkey: string): Promise<string | null> => { + const response = await fetch(`/api/users/${pubkey}`); + if (response.ok) { + const userInfo = await response.json(); + return userInfo.anon ? null : userInfo.username; + } else { + return null; + } + }; - /// chat selection - const usernameFromPubkey = async (pubkey: string): Promise<string | null> => { - const response = await fetch(`/api/users/${pubkey}`); - if (response.ok) { - const userInfo = await response.json(); - return userInfo.anon ? null : userInfo.username; - } else { - return null; - } - } + const userInfo = async (pubkey: string) => { + if (pubkey.slice(0, 4) === "npub") { + return userInfo(decode(pubkey).data as string); + } - const userInfo = async (pubkey: string) => { - if (pubkey.slice(0, 4) === "npub") { - return userInfo(decode(pubkey).data as string); - } + const nostrUserInfo = (await getNostrUserInfo(pubkey)) || {}; + const valid = + "nip05" in nostrUserInfo && (await isValid(pubkey, nostrUserInfo.nip05)); + const username = await usernameFromPubkey(pubkey); + return { + coinosUsername: username, + nostrName: nostrUserInfo?.name, + nip05: nostrUserInfo?.nip05, + nip05Valid: valid, + pubkey, + }; + }; - const nostrUserInfo = await getNostrUserInfo(pubkey) || {}; - const valid = 'nip05' in nostrUserInfo && await isValid(pubkey, nostrUserInfo.nip05); - const username = await usernameFromPubkey(pubkey); - return { - coinosUsername: username, - nostrName: nostrUserInfo?.name, - nip05: nostrUserInfo?.nip05, - nip05Valid: valid, pubkey }; - } + const name = (userInfo: any): string => { + return userInfo.coinosUsername || userInfo.nostrName || $t("dm.anonymous"); + }; - const name = (userInfo: any): string => { - return userInfo.coinosUsername || userInfo.nostrName || $t("dm.anonymous"); - } + const id = (userInfo: any): string => { + if (userInfo.nip05 && userInfo.nip05.slice(0, 2) == "_@") { + return userInfo.nip05.slice(2); + } - const id = (userInfo: any): string => { - if (userInfo.nip05 && userInfo.nip05.slice(0, 2) == "_@") { - return userInfo.nip05.slice(2); - } + return userInfo.nip05 || npubEncode(userInfo.pubkey).slice(0, 16) + "..."; + }; - return userInfo.nip05 || (npubEncode(userInfo.pubkey).slice(0, 16) + "..."); - } + const idValid = (userInfo: any): boolean => { + return !userInfo.nip05 || userInfo.nip05Valid; + }; - const idValid = (userInfo: any): boolean => { - return !userInfo.nip05 || userInfo.nip05Valid; - } + const rumourInvolves = (rumour: any, pubkey: string) => { + if (rumour.pubkey === pubkey) { + return true; + } else { + for (const tagPK of pTagKeys(rumour)) { + if (tagPK === pubkey) { + return true; + } + } + return false; + } + }; - const rumourInvolves = (rumour: any, pubkey: string) => { - if (rumour.pubkey === pubkey) { - return true; - } else { - for (const tagPK of pTagKeys(rumour)) { - if (tagPK === pubkey) { - return true; - } - } - return false; - } - } + const mostRecentCommunication = (rumours: any[], pubkey: string) => { + let mostRecentTime = null; + for (const rumour of rumours.filter((r) => rumourInvolves(r, pubkey))) { + if (!mostRecentTime || rumour.created_at > mostRecentTime) { + mostRecentTime = rumour.created_at; + } + } + return mostRecentTime; + }; - const mostRecentCommunication = (rumours: any[], pubkey: string) => { - let mostRecentTime = null; - for (const rumour of rumours.filter((r) => rumourInvolves(r, pubkey))) { - if (!mostRecentTime || rumour.created_at > mostRecentTime) { - mostRecentTime = rumour.created_at; - } - } - return mostRecentTime; - } + const updateSendersRecipients = async (rumours: any[]) => { + const senders = new Set<any>(); + const recipients = new Set<any>(); + for (const rumour of rumours) { + if (rumour.pubkey !== user.pubkey) { + senders.add(await userInfo(rumour.pubkey)); + } else { + for (const pubkey of pTagKeys(rumour)) { + recipients.add(await userInfo(pubkey)); + } + } + } + messageSenders = Array.from(senders); + messageRecipients = Array.from(recipients); - const updateSendersRecipients = async (rumours: any[]) => { - const senders = new Set<any>(); - const recipients = new Set<any>(); - for (const rumour of rumours) { - if (rumour.pubkey !== user.pubkey) { - senders.add(await userInfo(rumour.pubkey)); - } else { - for (const pubkey of pTagKeys(rumour)) { - recipients.add(await userInfo(pubkey)); - } - } - } - messageSenders = Array.from(senders); - messageRecipients = Array.from(recipients); + const chatMap = new Map<string, any>(); + for (const sender of senders) { + chatMap.set(sender.pubkey, sender); + } + for (const recipient of recipients) { + chatMap.set(recipient.pubkey, recipient); + } + chats = Array.from(chatMap.values()); + chats.sort( + (a, b) => + (mostRecentCommunication(rumours, b.pubkey) ?? 0) - + (mostRecentCommunication(rumours, a.pubkey) ?? 0), + ); + }; - const chatMap = new Map<string, any>(); - for (const sender of senders) { - chatMap.set(sender.pubkey, sender); - } - for (const recipient of recipients) { - chatMap.set(recipient.pubkey, recipient); - } - chats = Array.from(chatMap.values()); - chats.sort((a, b) => (mostRecentCommunication(rumours, b.pubkey) ?? 0) - (mostRecentCommunication(rumours, a.pubkey) ?? 0)); - }; + let messageSenders: any[] = $state([]); + let messageRecipients: any[] = $state([]); + let chats: any[] = $state([]); + getMessageRumours(user).then(updateSendersRecipients); - let messageSenders: any[] = $state([]); - let messageRecipients: any[] = $state([]); - let chats: any[] = $state([]); - getMessageRumours(user).then(updateSendersRecipients); + let selectedChat: any = $state(null); + let creatingNewChat = $state(false); + let searchQuery = $state(""); - let selectedChat: any = $state(null); - let creatingNewChat = $state(false); - let searchQuery = $state(""); + /// individual chat + let text = $state(""); + let allRumours: any[] = $state([]); + let messageRumours: any = $state([]); + let dates: any[] = $state([]); + let relayWarningShown = $state(false); + let expiryEnabled = $state(false); + let expiryDays = $state(7); + let canSend = $state(false); + let canSendExpiring = $state(false); + let nostrUserInfo: any = $state({}); - /// individual chat - let text = $state(""); - let allRumours: any[] = $state([]); - let messageRumours: any = $state([]); - let dates: any[] = $state([]); - let relayWarningShown = $state(false); - let expiryEnabled = $state(false); - let expiryDays = $state(7); - let canSend = $state(false); - let canSendExpiring = $state(false); - let nostrUserInfo: any = $state({}); + const includesPubkey = (chats: any[], pubkey: string) => { + for (const c of chats) { + if (c.pubkey === pubkey) { + return true; + } + } + return false; + }; - const includesPubkey = (chats: any[], pubkey: string) => { - for (const c of chats) { - if (c.pubkey === pubkey) { - return true; - } - } - return false; - } + const selectChat = (c: any) => { + selectedChat = c; + if (!includesPubkey(chats, c.pubkey)) { + chats.unshift(c); + } + userInfo(selectedChat.pubkey).then((info) => (nostrUserInfo = info)); + libnip17.getPreferredRelays(selectedChat.pubkey).then((relays) => { + canSend = relays && relays.length > 0; + relaysSupporting(relays, [40]).then( + (supporting) => (canSendExpiring = supporting.length > 0), + ); + }); + updateEvents(); + }; - const selectChat = (c: any) => { - selectedChat = c; - if (!includesPubkey(chats, c.pubkey)) { - chats.unshift(c); - } - userInfo(selectedChat.pubkey).then(info => nostrUserInfo = info); - libnip17.getPreferredRelays(selectedChat.pubkey).then((relays) => { - canSend = relays && relays.length > 0; - relaysSupporting(relays, [40]) - .then((supporting) => canSendExpiring = supporting.length > 0); - }); - updateEvents(); - } + const selectChatUsername = async (username: string) => { + const response = await fetch(`/api/users/${username}`); + if (!response.ok) { + alert("Invalid username"); + return; + } + const coinosUserInfo = await response.json(); + selectChatPubkey(coinosUserInfo.pubkey); + }; - const selectChatUsername = async (username: string) => { - const response = await fetch(`/api/users/${username}`); - if (!response.ok) { - alert("Invalid username"); - return; - } - const coinosUserInfo = await response.json(); - selectChatPubkey(coinosUserInfo.pubkey); - } + const selectChatNip05 = async (nip05: string) => { + const response = await queryProfile(nip05); + if (response == null) { + alert("Invalid nip-05"); + return; + } + selectChatPubkey(response.pubkey); + }; - const selectChatNip05 = async (nip05: string) => { - const response = await queryProfile(nip05); - if (response == null) { - alert("Invalid nip-05"); - return; - } - selectChatPubkey(response.pubkey); - } + const selectChatPubkey = async (pubkey: string) => { + selectChat(await userInfo(pubkey)); + creatingNewChat = false; + }; - const selectChatPubkey = async (pubkey: string) => { - selectChat(await userInfo(pubkey)); - creatingNewChat = false; - } + onMount(() => { + const urlParams = new URLSearchParams(window.location.search); + if (urlParams.get("username")) { + selectChatUsername(urlParams.get("username")!); + } else if (urlParams.get("nip05")) { + selectChatNip05(urlParams.get("nip05")!); + } else if (urlParams.get("pubkey")) { + selectChatPubkey(urlParams.get("pubkey")!); + } + }); - onMount(() => { - const urlParams = new URLSearchParams(window.location.search); - if (urlParams.get('username')) { - selectChatUsername(urlParams.get('username')!); - } else if (urlParams.get('nip05')) { - selectChatNip05(urlParams.get('nip05')!); - } else if (urlParams.get('pubkey')) { - selectChatPubkey(urlParams.get('pubkey')!); - } - }); + const appendMultimap = (map: Map<any, any>, key: any, value: any) => { + if (map.has(key)) { + map.get(key)!.push(value); + } else { + map.set(key, [value]); + } + }; - const appendMultimap = (map: Map<any, any>, key: any, value: any) => { - if (map.has(key)) { - map.get(key)!.push(value); - } else { - map.set(key, [value]); - } - } + const dateMap = (events: any[]): Map<any, any> => { + let eventsMap = new Map(); + for (const event of events) { + const created = Math.floor(event.created_at / 86400); + appendMultimap(eventsMap, created, event); + } + for (const [date, dateEvents] of eventsMap) { + dateEvents.sort((ev1, ev2) => ev1.created_at - ev2.created_at); + } + return eventsMap; + }; - const dateMap = (events: any[]): Map<any, any> => { - let eventsMap = new Map(); - for (const event of events) { - const created = Math.floor(event.created_at / 86400); - appendMultimap(eventsMap, created, event); - } - for (const [date, dateEvents] of eventsMap) { - dateEvents.sort((ev1, ev2) => ev1.created_at - ev2.created_at); - } - return eventsMap; - } + const updateEvents = async () => { + allRumours = await libnip17.getMessageRumours(user); + const rumours = allRumours.filter( + (r) => + (r.pubkey === user.pubkey && + pTagKeys(r).includes(selectedChat.pubkey)) || + (r.pubkey === selectedChat.pubkey && pTagKeys(r).includes(user.pubkey)), + ); + messageRumours = dateMap(rumours); - const updateEvents = async () => { - allRumours = await libnip17.getMessageRumours(user); - const rumours = allRumours.filter((r) => - (r.pubkey === user.pubkey && pTagKeys(r).includes(selectedChat.pubkey)) || - (r.pubkey === selectedChat.pubkey && pTagKeys(r).includes(user.pubkey))); - messageRumours = dateMap(rumours); + dates = Array.from(messageRumours.keys()); + dates.sort((d1, d2) => d1 - d2); - dates = Array.from(messageRumours.keys()); - dates.sort((d1, d2) => d1 - d2); + await tick(); + const messages = document.getElementById("messages"); + if (messages) { + messages.scrollTop = messages.scrollHeight; + } + }; - await tick(); - const messages = document.getElementById("messages"); - if (messages) { - messages.scrollTop = messages.scrollHeight; - } - } + const TIME = new Intl.DateTimeFormat(undefined, { + hour: "numeric", + hour12: false, + minute: "numeric", + }); + const NEAR_DATE = new Intl.DateTimeFormat(undefined, { + month: "short", + day: "numeric", + weekday: "short", + }); + const FAR_DATE = new Intl.DateTimeFormat(undefined, { + year: "numeric", + month: "short", + day: "numeric", + weekday: "short", + }); + const NEAR_DISTANCE = 182 * 24 * 60 * 60 * 1000; // around 6 months + const formatDate = (date: Date): string => { + if (date.getTime() >= Date.now() - NEAR_DISTANCE) { + return NEAR_DATE.format(date); + } else { + return FAR_DATE.format(date); + } + }; - const TIME = new Intl.DateTimeFormat( - undefined, { hour: "numeric", hour12: false, minute: "numeric" }); - const NEAR_DATE = new Intl.DateTimeFormat( - undefined, { month: "short", day: "numeric", weekday: "short" }); - const FAR_DATE = new Intl.DateTimeFormat( - undefined, { year: "numeric", month: "short", day: "numeric", weekday: "short" }); - const NEAR_DISTANCE = 182 * 24 * 60 * 60 * 1000; // around 6 months - const formatDate = (date: Date): string => { - if (date.getTime() >= Date.now() - NEAR_DISTANCE) { - return NEAR_DATE.format(date); - } else { - return FAR_DATE.format(date); - } - } + const expirationClose = (expiration: number) => { + return expiration <= Date.now() / 1000 + 2 * 86400; + }; - const expirationClose = (expiration: number) => { - return expiration <= (Date.now() / 1000 + 2 * 86400); - } + const sendMessage = async (message: string) => { + const expiry = expiryEnabled ? expiryDays : undefined; + await libnip17.send(message, user, selectedChat, expiry); + updateEvents(); + }; - const sendMessage = async (message: string) => { - const expiry = expiryEnabled ? expiryDays : undefined; - await libnip17.send(message, user, selectedChat, expiry); - updateEvents(); - } + libnip17.getPreferredRelays(user.pubkey).then((relays) => { + if (!relays || relays.length == 0) { + relayWarningShown = true; + return; + } + relayWarningShown = false; + }); - libnip17.getPreferredRelays(user.pubkey).then((relays) => { - if (!relays || relays.length == 0) { - relayWarningShown = true; - return; - } - relayWarningShown = false; - }); + let muted = $state(new Set<string>()); + mutedAccounts(user).then((m) => (muted = m)); - let muted = $state(new Set<string>()); - mutedAccounts(user).then((m) => muted = m); - - const toggleMute = async (pubkey: string) => { - if (muted && muted.has(pubkey)) { - await unmute(user, pubkey); - } else { - await mute(user, pubkey, true); - } - muted = await mutedAccounts(user); - } + const toggleMute = async (pubkey: string) => { + if (muted && muted.has(pubkey)) { + await unmute(user, pubkey); + } else { + await mute(user, pubkey, true); + } + muted = await mutedAccounts(user); + }; </script> -<style> - .warning { - color: #ff7f00; - } +<div class="super-container"> + <div + class={"sidebar " + ($theme === "light" ? "light-sidebar" : "dark-sidebar")} + > + <h2 class="text-xl chat-header"> + {creatingNewChat ? $t("dm.newChatHeader") : $t("dm.chatHeader")} + <button + class={"chat-btn push-right " + + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn") + + (creatingNewChat + ? $theme === "light" + ? " light-selected" + : " dark-selected" + : "")} + on:click={() => { + creatingNewChat = !creatingNewChat; + selectedChat = null; + }}>+</button + > + </h2> + {#if creatingNewChat} + <input + type="text" + class="short" + bind:value={searchQuery} + placeholder={$t("dm.searchPrompt")} + /> + {/if} + {#if !creatingNewChat} + {#each chats as c} + {#if (selectedChat && selectedChat.pubkey === c.pubkey) || !(muted && muted.has(c.pubkey))} + <button + class={"chat-btn tall-btn " + + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn") + + (selectedChat && selectedChat.pubkey == c.pubkey + ? $theme === "light" + ? " light-selected" + : " dark-selected" + : "")} + on:click={() => selectChat(c)} + > + <span + class={"text-xl" + + (muted && muted.has(c.pubkey) ? " secondary" : "")} + >{name(c)}</span + > + <span class={(idValid(c) ? "" : "invalid ") + "secondary text-xs"} + >{id(c)}</span + > + </button> + {/if} + {/each} + {:else if searchQuery !== ""} + <button + class={"chat-btn tall-btn " + + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} + on:click={() => selectChatUsername(searchQuery)} + > + <span class="text-xl">{$t("dm.findByUsername")}</span> + </button> + {#if searchQuery.includes(".")} + <button + class={"chat-btn tall-btn " + + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} + on:click={() => selectChatNip05(searchQuery)} + > + <span class="text-xl">{$t("dm.findByNIP05")}</span> + </button> + {/if} + {#if searchQuery.length === 64 || searchQuery.slice(0, 4) === "npub"} + <button + class={"chat-btn tall-btn " + + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} + on:click={() => selectChatPubkey(searchQuery)} + > + <span class="text-xl">{$t("dm.findByPubkey")}</span> + </button> + {/if} + {/if} + </div> + <div + class="main container space-y-2 mx-auto space-y-5 lg:max-w-xl xl:max-w-2xl lg:pl-10 mt-5 lg:mt-0" + > + <h1 + class="text-5xl font-medium text-left w-full mx-auto lg:mx-0 md:w-[500px]" + > + {$t("dm.header")} + </h1> - .secondary { - color: #7f7f7f; - } + {#if selectedChat} + <h1> + {#if selectedChat.coinosUsername} + <a class="text-3xl" href="/{selectedChat.coinosUsername}" + >{name(selectedChat)}</a + > + {:else} + <span class="text-3xl">{name(selectedChat)}</span> + {/if} + <span + class={"secondary timestamp text-small" + + (idValid(selectedChat) ? "" : " invalid")} + title={npubEncode(selectedChat.pubkey)}>{id(selectedChat)}</span + > + <button + class={"small-btn push-right " + + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} + on:click={() => toggleMute(selectedChat.pubkey)} + >{$t( + muted && muted.has(selectedChat.pubkey) ? "dm.unmute" : "dm.mute", + )}</button + > + </h1> - .link { - text-decoration-line: underline; - } + {#if !(muted && muted.has(selectedChat.pubkey))} + <div id="messages" style="overflow-y: scroll; max-height: 600px;"> + {#each dates as day} + <p class="date-header secondary"> + {formatDate(new Date(day * 86400 * 1000))} + </p> + <ul> + {#each messageRumours.get(day) as rumour} + {#if rumour.pubkey === user.pubkey && pTagKeys(rumour).includes(selectedChat.pubkey)} + <li + class={(rumour.expiration && + expirationClose(rumour.expiration) + ? "secondary " + : "") + + ($theme === "light" + ? "light-message " + : "dark-message ") + + "message by-user"} + > + {rumour.content} + <span class="timestamp secondary text-xs" + >{TIME.format(new Date(rumour.created_at * 1000))}</span + > + </li> + {:else if rumour.pubkey === selectedChat.pubkey && pTagKeys(rumour).includes(user.pubkey)} + <li + class={(rumour.expiration && + expirationClose(rumour.expiration) + ? "secondary " + : "") + + ($theme === "light" + ? "light-message " + : "dark-message ") + + "message by-other"} + > + {rumour.content} + <span class="timestamp secondary text-xs" + >{TIME.format(new Date(rumour.created_at * 1000))}</span + > + </li> + {/if} + {/each} + </ul> + {/each} + </div> - .inline { - white-space: nowrap; - } + <textarea id="message-contents" bind:value={text}></textarea> + <input + id="send-message" + type="button" + class="btn btn-accent" + disabled={!canSend} + value={canSend + ? $t("dm.sendMessage") + : $t("dm.relaysNotFound").replace("[R]", name(selectedChat))} + on:click={async () => sendMessage(text)} + /> + {/if} - .short { - height: 1.5em; - margin-bottom: 10px; - } + {#if !(muted && muted.has(selectedChat.pubkey))} + <input + type="checkbox" + id="expiryCheckbox" + class="tiny" + bind:checked={expiryEnabled} + disabled={!canSendExpiring} + /> + <label for="expiryCheckbox">{$t("dm.expiry")}</label>: + <input + type="number" + class="short small-width vcenter" + bind:value={expiryDays} + disabled={!expiryEnabled} + min="1" + step="1" + max="99999" + /> <label for="expiryCheckbox">{$t("dm.days")}</label>. + <p class="secondary">{$t("dm.fadedWarning")}</p> + {#if canSend && !canSendExpiring} + <p class="warning"> + <em + >{$t("dm.cantSendExpiring").replace( + "[R]", + name(selectedChat), + )}</em + > + </p> + {/if} + {/if} + {:else if chats.length == 0} + <p>{$t("dm.noChats")}</p> + {:else} + <p>{$t("dm.selectChat")}</p> + {/if} + {#if relayWarningShown} + <p class="warning"> + <em + >{$t("dm.noRelaysSet")} + <a class="link" href="/settings/nostr#dm-relays" + >{$t("dm.nostrSettingsLink")}</a + ></em + > + </p> + {/if} + </div> +</div> - .small-width { - width: 6em; - } +<style> + .warning { + color: #ff7f00; + } - .tiny { - width: 2em; - } + .secondary { + color: #7f7f7f; + } - .invalid { - text-decoration: line-through; - } + .link { + text-decoration-line: underline; + } - .super-container { - display: flex; - } + .inline { + white-space: nowrap; + } - .sidebar { - max-width: 300px; - padding: 0px 10px 5px; - margin: 0px 5px; - height: 100%; - border-radius: 10px; - } + .short { + height: 1.5em; + margin-bottom: 10px; + } - .light-sidebar { - background-color: #eeeeee; - } + .small-width { + width: 6em; + } - .dark-sidebar { - background-color: #222222; - } + .tiny { + width: 2em; + } - .chat-btn { - margin: 2px 0px; - padding: 0 25px; - border-radius: 10px; - min-width: 30px; - text-align: left; - } + .invalid { + text-decoration: line-through; + } - .tall-btn { - min-height: 3em; - width: 100%; - } + .super-container { + display: flex; + } - .small-btn { - padding: 0 15px; - border-radius: 5px; - text-align: left; - } + .sidebar { + max-width: 300px; + padding: 0px 10px 5px; + margin: 0px 5px; + height: 100%; + border-radius: 10px; + } - .push-right { - margin-left: auto; - } + .light-sidebar { + background-color: #eeeeee; + } - .chat-header { - margin: 1em 15px 0.5em; - } + .dark-sidebar { + background-color: #222222; + } - .light-chat-btn { - background-color: #eeeeee; - } + .chat-btn { + margin: 2px 0px; + padding: 0 25px; + border-radius: 10px; + min-width: 30px; + text-align: left; + } - .dark-chat-btn { - background-color: #222222; - } + .tall-btn { + min-height: 3em; + width: 100%; + } - .light-chat-btn:hover { - background-color: #dddddd; - } + .small-btn { + padding: 0 15px; + border-radius: 5px; + text-align: left; + } - .dark-chat-btn:hover { - background-color: #333333; - } + .push-right { + margin-left: auto; + } - .light-selected { - background-color: #dddddd; - } + .chat-header { + margin: 1em 15px 0.5em; + } - .dark-selected { - background-color: #333333; - } + .light-chat-btn { + background-color: #eeeeee; + } - .main { - padding-left: 0px; - margin-left: 30px; - } + .dark-chat-btn { + background-color: #222222; + } - .date-header { - text-align: center; - margin: 1.5em 0em; - } + .light-chat-btn:hover { + background-color: #dddddd; + } - .timestamp { - margin-left: 0.5em; - text-align: right; - } + .dark-chat-btn:hover { + background-color: #333333; + } - .message { - padding: 0.25em 0.75em; - width: fit-content; - max-width: 75%; - border-radius: 10px; - } + .light-selected { + background-color: #dddddd; + } - .light-message { - background-color: #DDD; - } + .dark-selected { + background-color: #333333; + } - .dark-message { - background-color: #222; - } + .main { + padding-left: 0px; + margin-left: 30px; + } - .by-user { - margin: 3px 0px 3px auto; - } + .date-header { + text-align: center; + margin: 1.5em 0em; + } - .by-other { - margin: 3px auto 3px 0px; - } + .timestamp { + margin-left: 0.5em; + text-align: right; + } - .vcenter { - margin: auto 0px; - } -</style> + .message { + padding: 0.25em 0.75em; + width: fit-content; + max-width: 75%; + border-radius: 10px; + } -<div class="super-container"> - <div class={"sidebar " + ($theme === "light" ? "light-sidebar" : "dark-sidebar")}> - <h2 class="text-xl chat-header"> - {creatingNewChat ? $t("dm.newChatHeader") : $t("dm.chatHeader")} - <button class={"chat-btn push-right " + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn") + (creatingNewChat ? ($theme === "light" ? " light-selected" : " dark-selected") : "")} on:click={() => {creatingNewChat = !creatingNewChat; selectedChat = null}}>+</button> - </h2> - {#if creatingNewChat} - <input type="text" class="short" bind:value={searchQuery} placeholder="{$t("dm.searchPrompt")}"> - {/if} - {#if !creatingNewChat} - {#each chats as c} - {#if (selectedChat && selectedChat.pubkey === c.pubkey) || !(muted && muted.has(c.pubkey))} - <button class={"chat-btn tall-btn " + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn") + (selectedChat && selectedChat.pubkey == c.pubkey ? ($theme === "light" ? " light-selected" : " dark-selected") : "")} on:click={() => selectChat(c)}> - <span class="{"text-xl" + (muted && muted.has(c.pubkey) ? " secondary" : "")}">{name(c)}</span> <span class={(idValid(c) ? "" : "invalid ") + "secondary text-xs"}>{id(c)}</span> - </button> - {/if} - {/each} - {:else if searchQuery !== ""} - <button class={"chat-btn tall-btn " + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} on:click={() => selectChatUsername(searchQuery)}> - <span class="text-xl">{$t("dm.findByUsername")}</span> - </button> - {#if searchQuery.includes(".")} - <button class={"chat-btn tall-btn " + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} on:click={() => selectChatNip05(searchQuery)}> - <span class="text-xl">{$t("dm.findByNIP05")}</span> - </button> - {/if} - {#if searchQuery.length === 64 || searchQuery.slice(0, 4) === "npub"} - <button class={"chat-btn tall-btn " + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} on:click={() => selectChatPubkey(searchQuery)}> - <span class="text-xl">{$t("dm.findByPubkey")}</span> - </button> - {/if} - {/if} - </div> - <div class="main container space-y-2 mx-auto space-y-5 lg:max-w-xl xl:max-w-2xl lg:pl-10 mt-5 lg:mt-0"> - <h1 - class="text-5xl font-medium text-left w-full mx-auto lg:mx-0 md:w-[500px]" - >{$t("dm.header")}</h1> + .light-message { + background-color: #ddd; + } - {#if selectedChat} - <h1> - {#if selectedChat.coinosUsername} - <a class="text-3xl" href="/{selectedChat.coinosUsername}">{name(selectedChat)}</a> - {:else} - <span class="text-3xl">{name(selectedChat)}</span> - {/if} - <span class={"secondary timestamp text-small" + (idValid(selectedChat) ? "" : " invalid")} title="{npubEncode(selectedChat.pubkey)}">{id(selectedChat)}</span> - <button class={"small-btn push-right " + ($theme === "light" ? "light-chat-btn" : "dark-chat-btn")} on:click={() => toggleMute(selectedChat.pubkey)}>{$t(muted && muted.has(selectedChat.pubkey) ? "dm.unmute" : "dm.mute")}</button> - </h1> + .dark-message { + background-color: #222; + } - {#if !(muted && muted.has(selectedChat.pubkey))} - <div id="messages" style="overflow-y: scroll; max-height: 600px;"> - {#each dates as day} - <p class="date-header secondary">{formatDate(new Date(day * 86400 * 1000))}</p> - <ul> - {#each messageRumours.get(day) as rumour} - {#if rumour.pubkey === user.pubkey && pTagKeys(rumour).includes(selectedChat.pubkey)} - <li class={(rumour.expiration && expirationClose(rumour.expiration) ? "secondary " : "") + ($theme === "light" ? "light-message " : "dark-message ") + "message by-user"}>{rumour.content} <span class="timestamp secondary text-xs">{TIME.format(new Date(rumour.created_at * 1000))}</span></li> - {:else if rumour.pubkey === selectedChat.pubkey && pTagKeys(rumour).includes(user.pubkey)} - <li class={(rumour.expiration && expirationClose(rumour.expiration) ? "secondary " : "") + ($theme === "light" ? "light-message " : "dark-message ") + "message by-other"}>{rumour.content} <span class="timestamp secondary text-xs">{TIME.format(new Date(rumour.created_at * 1000))}</span></li> - {/if} - {/each} - </ul> - {/each} - </div> + .by-user { + margin: 3px 0px 3px auto; + } - <textarea id="message-contents" bind:value={text}></textarea> - <input id="send-message" type="button" class="btn btn-accent" disabled={!canSend} value={canSend ? $t("dm.sendMessage") : $t("dm.relaysNotFound").replace("[R]", name(selectedChat))} on:click={async () => sendMessage(text)}> - {/if} + .by-other { + margin: 3px auto 3px 0px; + } - {#if !(muted && muted.has(selectedChat.pubkey))} - <input type="checkbox" id="expiryCheckbox" class="tiny" bind:checked={expiryEnabled} disabled={!canSendExpiring}> - <label for="expiryCheckbox">{$t("dm.expiry")}</label>: <input type="number" class="short small-width vcenter" bind:value={expiryDays} disabled={!expiryEnabled} min="1" step="1" max="99999"> <label for="expiryCheckbox">{$t("dm.days")}</label>. - <p class="secondary">{$t("dm.fadedWarning")}</p> - {#if canSend && !canSendExpiring} - <p class="warning"><em>{$t("dm.cantSendExpiring").replace("[R]", name(selectedChat))}</em></p> - {/if} - {/if} - {:else if chats.length == 0} - <p>{$t("dm.noChats")}</p> - {:else} - <p>{$t("dm.selectChat")}</p> - {/if} - {#if relayWarningShown} - <p class="warning"><em>{$t("dm.noRelaysSet")} <a class="link" href="/settings/nostr#dm-relays">{$t("dm.nostrSettingsLink")}</a></em></p> - {/if} - </div> -</div> + .vcenter { + margin: auto 0px; + } +</style> diff --git a/src/routes/(app)/e/[id]/+page.server.ts b/src/routes/(app)/e/[id]/+page.server.ts index 2a62dba0..8cb59334 100644 --- a/src/routes/(app)/e/[id]/+page.server.ts +++ b/src/routes/(app)/e/[id]/+page.server.ts @@ -1,12 +1,12 @@ -import { get, post } from "$lib/utils"; +import { get } from "$lib/utils"; import { error } from "@sveltejs/kit"; export async function load({ params }) { - try { - const event = await get(`/event/${params.id}/full`); - return { event }; - } catch (e) { - console.log(e); - error(500, { message: "Failed to get event" }); - } + try { + const event = await get(`/event/${params.id}/full`); + return { event }; + } catch (e) { + console.log(e); + error(500, { message: "Failed to get event" }); + } } diff --git a/src/routes/(app)/ecash/[id]/[...version]/+layout.server.ts b/src/routes/(app)/ecash/[id]/[...version]/+layout.server.ts index 50be6986..2093e8ec 100644 --- a/src/routes/(app)/ecash/[id]/[...version]/+layout.server.ts +++ b/src/routes/(app)/ecash/[id]/[...version]/+layout.server.ts @@ -2,22 +2,22 @@ import getRates from "$lib/rates"; import { get } from "$lib/utils"; export async function load({ params, parent }) { - const { user } = await parent(); - const rates = await getRates(); - let { id, version } = params; - version ||= 4; - version = parseInt(version); + const { user } = await parent(); + const rates = await getRates(); + let { id, version } = params; + version ||= 4; + version = parseInt(version); - const { token, status } = await get(`/cash/${id}/${version}`); - const { spent, total, mint, external } = status; - return { - id, - token, - spent, - total, - mint, - external, - version, - rate: rates[user?.currency || "USD"], - }; + const { token, status } = await get(`/cash/${id}/${version}`); + const { spent, total, mint, external } = status; + return { + id, + token, + spent, + total, + mint, + external, + version, + rate: rates[user?.currency || "USD"], + }; } diff --git a/src/routes/(app)/ecash/[id]/[...version]/+page.server.ts b/src/routes/(app)/ecash/[id]/[...version]/+page.server.ts index 26ccb307..08efb998 100644 --- a/src/routes/(app)/ecash/[id]/[...version]/+page.server.ts +++ b/src/routes/(app)/ecash/[id]/[...version]/+page.server.ts @@ -3,26 +3,26 @@ import { auth, fd, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ parent }) { - const { user } = await parent(); - const rates = await getRates(); - return { rate: rates[user?.currency || "USD"] }; + const { user } = await parent(); + const rates = await getRates(); + return { rate: rates[user?.currency || "USD"] }; } export const actions = { - default: async ({ cookies, request, url }) => { - if (!cookies.get("username")) - redirect(307, `/register?redirect=${url.pathname}`); + default: async ({ cookies, request, url }) => { + if (!cookies.get("username")) + redirect(307, `/register?redirect=${url.pathname}`); - const { token } = await fd(request); - let claimed; - try { - claimed = await post("/claim", { token }, auth(cookies)); - claimed = { ok: true }; - } catch (e: any) { - return fail(400, { error: e.message }); - } - if (claimed?.ok) { - redirect(307, "/payments"); - } - }, + const { token } = await fd(request); + let claimed; + try { + claimed = await post("/claim", { token }, auth(cookies)); + claimed = { ok: true }; + } catch (e: any) { + return fail(400, { error: e.message }); + } + if (claimed?.ok) { + redirect(307, "/payments"); + } + }, }; diff --git a/src/routes/(app)/ecash/[id]/[...version]/swap/+page.server.ts b/src/routes/(app)/ecash/[id]/[...version]/swap/+page.server.ts index f82bdbb1..14e4767d 100644 --- a/src/routes/(app)/ecash/[id]/[...version]/swap/+page.server.ts +++ b/src/routes/(app)/ecash/[id]/[...version]/swap/+page.server.ts @@ -1,3 +1,3 @@ export async function load() { - return { test: 123 }; + return { test: 123 }; } diff --git a/src/routes/(app)/ecash/mint/+server.ts b/src/routes/(app)/ecash/mint/+server.ts index 02170650..e933208e 100644 --- a/src/routes/(app)/ecash/mint/+server.ts +++ b/src/routes/(app)/ecash/mint/+server.ts @@ -2,6 +2,6 @@ import { auth, post } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const result = await post("/mint", await request.json(), auth(cookies)); - return json(result); + const result = await post("/mint", await request.json(), auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/ecash/post/+server.ts b/src/routes/(app)/ecash/post/+server.ts index bc6cb099..371582bc 100644 --- a/src/routes/(app)/ecash/post/+server.ts +++ b/src/routes/(app)/ecash/post/+server.ts @@ -1,11 +1,11 @@ import { json } from "@sveltejs/kit"; export async function POST({ fetch, request }) { - const { target, payload } = await request.json(); - const res = await fetch(target, { - method: "POST", - body: JSON.stringify(payload), - headers: { "Content-Type": "application/json" }, - }); - return json(res); + const { target, payload } = await request.json(); + const res = await fetch(target, { + method: "POST", + body: JSON.stringify(payload), + headers: { "Content-Type": "application/json" }, + }); + return json(res); } diff --git a/src/routes/(app)/email/+server.ts b/src/routes/(app)/email/+server.ts index eb98a401..437c0ef0 100644 --- a/src/routes/(app)/email/+server.ts +++ b/src/routes/(app)/email/+server.ts @@ -2,6 +2,6 @@ import { auth, post } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const result = await post("/request", await request.json(), auth(cookies)); - return json(result); + const result = await post("/request", await request.json(), auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/enable2fa/+server.ts b/src/routes/(app)/enable2fa/+server.ts index 988dd0ed..76737968 100644 --- a/src/routes/(app)/enable2fa/+server.ts +++ b/src/routes/(app)/enable2fa/+server.ts @@ -1,8 +1,8 @@ import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - const body = await request.json(); - const res = await post("/2fa", body, auth(cookies)); + const body = await request.json(); + const res = await post("/2fa", body, auth(cookies)); - return new Response(JSON.stringify(res)); + return new Response(JSON.stringify(res)); } diff --git a/src/routes/(app)/events/+server.ts b/src/routes/(app)/events/+server.ts index f3010834..e2553753 100644 --- a/src/routes/(app)/events/+server.ts +++ b/src/routes/(app)/events/+server.ts @@ -2,11 +2,11 @@ import { auth, post } from "$lib/utils"; import { error, json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const body = await request.json(); - try { - const result = await post("/event", body, auth(cookies)); - return json(result); - } catch (e: any) { - error(500, e.message); - } + const body = await request.json(); + try { + const result = await post("/event", body, auth(cookies)); + return json(result); + } catch (e: any) { + error(500, e.message); + } } diff --git a/src/routes/(app)/fund/[id]/+layout.server.ts b/src/routes/(app)/fund/[id]/+layout.server.ts index 3669eb7d..bf132e7b 100644 --- a/src/routes/(app)/fund/[id]/+layout.server.ts +++ b/src/routes/(app)/fund/[id]/+layout.server.ts @@ -2,11 +2,11 @@ import getRates from "$lib/rates"; import { get } from "$lib/utils"; export const load = async ({ depends, params: { id }, parent }) => { - depends("app:payments"); - const data = await get(`/fund/${id}`); - data.managers = await get(`/fund/${id}/managers`); - const rates = await getRates(); - const { user } = await parent(); - data.rate = rates[user?.currency || "USD"]; - return data; + depends("app:payments"); + const data = await get(`/fund/${id}`); + data.managers = await get(`/fund/${id}/managers`); + const rates = await getRates(); + const { user } = await parent(); + data.rate = rates[user?.currency || "USD"]; + return data; }; diff --git a/src/routes/(app)/fund/[id]/+page.server.ts b/src/routes/(app)/fund/[id]/+page.server.ts index cd2bd979..5a30e560 100644 --- a/src/routes/(app)/fund/[id]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/+page.server.ts @@ -2,14 +2,14 @@ import { auth, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export const actions = { - default: async ({ cookies, locals, params }) => { - const { user } = locals; + default: async ({ cookies, locals, params }) => { + const { user } = locals; - if (user) { - await post("/redeem", params, auth(cookies)); - redirect(307, "/payments"); - } + if (user) { + await post("/redeem", params, auth(cookies)); + redirect(307, "/payments"); + } - redirect(307, "/register"); - }, + redirect(307, "/register"); + }, }; diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index c3fa7ce1..34e0d503 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -21,7 +21,9 @@ let currency = user ? user.currency : "CAD"; let amountFiat = $derived(parseFloat(((amount * rate) / sats).toFixed(2))); - $effect(() => { $loginRedirect = $page.url.pathname; }); + $effect(() => { + $loginRedirect = $page.url.pathname; + }); let show = $state(); let toggle = () => (show = !show); diff --git a/src/routes/(app)/fund/[id]/access/+page.server.ts b/src/routes/(app)/fund/[id]/access/+page.server.ts index 36191643..6e995f1c 100644 --- a/src/routes/(app)/fund/[id]/access/+page.server.ts +++ b/src/routes/(app)/fund/[id]/access/+page.server.ts @@ -2,21 +2,21 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail } from "@sveltejs/kit"; export const load = async ({ params: { id } }) => { - const managers = await get(`/fund/${id}/managers`); - return { managers, id }; + const managers = await get(`/fund/${id}/managers`); + return { managers, id }; }; export const actions = { - default: async ({ cookies, request }) => { - const form = await fd(request); + default: async ({ cookies, request }) => { + const form = await fd(request); - try { - const managers = await post("/fund/managers", form, auth(cookies)); + try { + const managers = await post("/fund/managers", form, auth(cookies)); - return { managers }; - } catch (e) { - const { message } = e as Error; - return fail(400, { message }); - } - }, + return { managers }; + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } + }, }; diff --git a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts index e5683ae6..94d9ff62 100644 --- a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts @@ -3,34 +3,34 @@ import { auth, get, post, sats } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { user } = await parent(); - const { id } = params; - let [amount, currency] = params.amount.split("/"); - let fiat; + const { user } = await parent(); + const { id } = params; + let [amount, currency] = params.amount.split("/"); + let fiat; - if (!currency) currency = user?.currency; + if (!currency) currency = user?.currency; if (currency) currency = currency.toUpperCase(); - const rates = await getRates(); - const rate = rates[currency || "USD"]; - if (currency && !rate) error(500, "Invalid currency symbol"); + const rates = await getRates(); + const rate = rates[currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); - if (!amount) { - const balance = await get(`/fund/${id}`); - amount = balance.amount; - } else if (currency) { - fiat = amount; - amount = Math.round((fiat * sats) / rate); - } + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.amount; + } else if (currency) { + fiat = amount; + amount = Math.round((fiat * sats) / rate); + } - if (!amount) redirect(307, `/fund/${id}`); + if (!amount) redirect(307, `/fund/${id}`); - try { - await post("/authorize", { amount, currency, fiat, id }, auth(cookies)); - } catch (e) { - console.log("caught", e); - redirect(307, `/fund/${id}`); - } + try { + await post("/authorize", { amount, currency, fiat, id }, auth(cookies)); + } catch (e) { + console.log("caught", e); + redirect(307, `/fund/${id}`); + } - return { amount, currency, id, rate, rates }; + return { amount, currency, id, rate, rates }; } diff --git a/src/routes/(app)/fund/[id]/gift/+page.server.ts b/src/routes/(app)/fund/[id]/gift/+page.server.ts index bd39d82b..549fc9d0 100644 --- a/src/routes/(app)/fund/[id]/gift/+page.server.ts +++ b/src/routes/(app)/fund/[id]/gift/+page.server.ts @@ -1,6 +1,6 @@ export const load = async ({ params, parent }) => { - const p = await parent(); - const { amount, rate } = p; - const { id } = params; - return { amount, id, rate }; + const p = await parent(); + const { amount, rate } = p; + const { id } = params; + return { amount, id, rate }; }; diff --git a/src/routes/(app)/fund/[id]/gift/+page.svelte b/src/routes/(app)/fund/[id]/gift/+page.svelte index 4e1efad3..9bef9c64 100644 --- a/src/routes/(app)/fund/[id]/gift/+page.svelte +++ b/src/routes/(app)/fund/[id]/gift/+page.svelte @@ -1,7 +1,8 @@ <script lang="ts"> import Amount from "$comp/Amount.svelte"; import { t } from "$lib/translations"; - import { page } from "$app/stores"; import Qr from "$comp/Qr.svelte"; + import { page } from "$app/stores"; + import Qr from "$comp/Qr.svelte"; import { loc, copy } from "$lib/utils"; let { data } = $props(); diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index 8cc463c2..82854fb2 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -5,52 +5,51 @@ import { error, redirect } from "@sveltejs/kit"; import { env } from "$env/dynamic/private"; export async function load({ cookies, request, params, parent }) { - let { user } = await parent(); - const { id } = params; - let [amount, currency] = params.amount.split("/"); + let { user } = await parent(); + const { id } = params; + let [amount, currency] = params.amount.split("/"); - if (!currency) currency = user?.currency; - if (currency) currency = currency.toUpperCase(); - const rates = await getRates(); - const rate = rates[currency || "USD"]; - if (currency && !rate) error(500, "Invalid currency symbol"); + if (!currency) currency = user?.currency; + if (currency) currency = currency.toUpperCase(); + const rates = await getRates(); + const rate = rates[currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); - if (!amount) { - const balance = await get(`/fund/${id}`); - amount = balance.authorization || balance.amount; - } else if (currency) { - amount = Math.round((amount * sats) / rate); - } + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.authorization || balance.amount; + } else if (currency) { + amount = Math.round((amount * sats) / rate); + } - const username = randomName() + Math.floor(Math.random() * 99) + 1; - const password = randomPassword(); + const username = randomName() + Math.floor(Math.random() * 99) + 1; + const password = randomPassword(); - if (!amount) redirect(307, `/fund/${id}`); - if (!user) { - const ip = request.headers.get("cf-connecting-ip"); + if (!amount) redirect(307, `/fund/${id}`); + if (!user) { + const ip = request.headers.get("cf-connecting-ip"); - user = { - username, - password, - fresh: true, - }; + user = { + username, + password, + fresh: true, + }; - let redirectUrl = `/fund/${id}/sweep`; - if (params.amount && !params.currency) redirectUrl += `/${params.amount}`; - if (params.currency) redirectUrl += `/${params.amount}/params.currency}`; + let redirectUrl = `/fund/${id}/sweep`; + if (params.amount && !params.currency) redirectUrl += `/${params.amount}`; + if (params.currency) redirectUrl += `/${params.amount}/params.currency}`; - const extraHeaders: Record<string, string> = {}; - if (env.INTERNAL_API_KEY) - extraHeaders["x-api-key"] = env.INTERNAL_API_KEY; + const extraHeaders: Record<string, string> = {}; + if (env.INTERNAL_API_KEY) extraHeaders["x-api-key"] = env.INTERNAL_API_KEY; - await register(user, ip, cookies, redirectUrl, undefined, extraHeaders); - } + await register(user, ip, cookies, redirectUrl, undefined, extraHeaders); + } - try { - ({ amount } = await post("/take", { amount, id }, auth(cookies))); - } catch (e) { - redirect(307, `/fund/${id}`); - } + try { + ({ amount } = await post("/take", { amount, id }, auth(cookies))); + } catch { + redirect(307, `/fund/${id}`); + } - return { amount, currency, id, rate, rates, password }; + return { amount, currency, id, rate, rates, password }; } diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts index 696c52ff..d302b4c1 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts +++ b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts @@ -3,25 +3,25 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ params, parent }) { - const { user } = await parent(); - if (!user) redirect(307, "/register"); - const rates = await getRates(); - const rate = rates[user.currency]; - const fund = await get(`/fund/${params.id}`); - const { amount: balance } = fund; - return { ...params, balance, rate }; + const { user } = await parent(); + if (!user) redirect(307, "/register"); + const rates = await getRates(); + const rate = rates[user.currency]; + const fund = await get(`/fund/${params.id}`); + const { amount: balance } = fund; + return { ...params, balance, rate }; } export const actions = { - default: async ({ cookies, request }) => { - const body = await fd(request); - try { - await post("/take", body, auth(cookies)); - } catch (e) { - const { message } = e as Error; - return fail(400, { message }); - } + default: async ({ cookies, request }) => { + const body = await fd(request); + try { + await post("/take", body, auth(cookies)); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } - redirect(307, `/fund/${body.id}`); - }, + redirect(307, `/fund/${body.id}`); + }, }; diff --git a/src/routes/(app)/fund/[id]/withdraw/+server.ts b/src/routes/(app)/fund/[id]/withdraw/+server.ts index dabef6f8..96d66413 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+server.ts +++ b/src/routes/(app)/fund/[id]/withdraw/+server.ts @@ -2,5 +2,5 @@ import { json } from "@sveltejs/kit"; import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - return json(await post("/take", await request.json(), auth(cookies))); + return json(await post("/take", await request.json(), auth(cookies))); } diff --git a/src/routes/(app)/funder/+page.svelte b/src/routes/(app)/funder/+page.svelte index e6549360..408b1236 100644 --- a/src/routes/(app)/funder/+page.svelte +++ b/src/routes/(app)/funder/+page.svelte @@ -1,6 +1,6 @@ <script lang="ts"> - import { onMount } from 'svelte'; -let here = false; + import { onMount } from "svelte"; + let here = false; let ready = false; let success = false; let controller: AbortController | null = null; @@ -26,21 +26,21 @@ let here = false; { records: [ { - recordType: 'url', - data: 'https://coinos.io', + recordType: "url", + data: "https://coinos.io", }, ], }, - { signal: controller.signal } + { signal: controller.signal }, ); success = true; } catch (err) { - if (err.name === 'AbortError') { - console.warn('Previous write aborted'); + if (err.name === "AbortError") { + console.warn("Previous write aborted"); } else { - console.error('Write failed', err); - alert('❌ Write failed: ' + err.message); + console.error("Write failed", err); + alert("❌ Write failed: " + err.message); } } finally { await NfcWriter.disableExclusiveNfcMode(); diff --git a/src/routes/(app)/invoice/+page.server.ts b/src/routes/(app)/invoice/+page.server.ts index 64c49ebc..dc024229 100644 --- a/src/routes/(app)/invoice/+page.server.ts +++ b/src/routes/(app)/invoice/+page.server.ts @@ -4,29 +4,29 @@ import { auth, post } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; export const load = async ({ cookies, parent }) => { - const aid = cookies.get("aid"); - let { subject, user } = await parent(); + const aid = cookies.get("aid"); + let { subject, user } = await parent(); - const rates = await getRates(); - if (aid === user.id) redirect(307, `/${user.username}/receive`); + const rates = await getRates(); + if (aid === user.id) redirect(307, `/${user.username}/receive`); - let invoice: Invoice = { - aid, - rate: rates[user?.currency || subject?.currency], - }; + let invoice: Invoice = { + aid, + rate: rates[user?.currency || subject?.currency], + }; - if (!user) user = subject; + if (!user) user = subject; - try { - invoice = await post("/invoice", { invoice, aid, user }, auth(cookies)); - } catch (e) { - console.log(e); - error(500, "Failed to generate invoice"); - } + try { + invoice = await post("/invoice", { invoice, aid, user }, auth(cookies)); + } catch (e) { + console.log(e); + error(500, "Failed to generate invoice"); + } - const { id } = invoice; + const { id } = invoice; - if (invoice.memoPrompt && !invoice.memo) { - redirect(307, `/invoice/${id}/memo`); - } else redirect(307, `/invoice/${id}`); + if (invoice.memoPrompt && !invoice.memo) { + redirect(307, `/invoice/${id}/memo`); + } else redirect(307, `/invoice/${id}`); }; diff --git a/src/routes/(app)/invoice/+server.ts b/src/routes/(app)/invoice/+server.ts index f494c153..b18eae15 100644 --- a/src/routes/(app)/invoice/+server.ts +++ b/src/routes/(app)/invoice/+server.ts @@ -2,11 +2,11 @@ import { auth, post } from "$lib/utils"; import { error, json } from "@sveltejs/kit"; export const POST = async ({ cookies, request }) => { - try { - const body = await request.json(); - return json(await post("/invoice", body, auth(cookies))); - } catch (e) { - const { message } = e as Error; - error(500, message); - } + try { + const body = await request.json(); + return json(await post("/invoice", body, auth(cookies))); + } catch (e) { + const { message } = e as Error; + error(500, message); + } }; diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index ce76d150..d6ee4246 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -2,43 +2,43 @@ import { get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies, depends, params, url, parent }) { - depends("app:invoice"); + depends("app:invoice"); - const token = cookies.get("token"); - let { subject, user } = await parent(); - const { id } = params; - let invoice; + const token = cookies.get("token"); + let { subject, user } = await parent(); + const { id } = params; + let invoice; - if (id) { - invoice = await get(`/invoice/${id}`); - const options = !!url.searchParams.get("options"); - let { amount, pending, received } = invoice; - amount = parseInt(amount); + if (id) { + invoice = await get(`/invoice/${id}`); + const options = !!url.searchParams.get("options"); + let { amount, pending, received } = invoice; + amount = parseInt(amount); - const paid = - (!amount && (pending || received)) || - (amount > 0 && (pending >= amount || received >= amount)); - if (paid && !url.pathname.endsWith("paid")) { - redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); - } + const paid = + (!amount && (pending || received)) || + (amount > 0 && (pending >= amount || received >= amount)); + if (paid && !url.pathname.endsWith("paid")) { + redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); + } - subject = invoice.user; + subject = invoice.user; - const aid = cookies.get("aid") || user?.id; - if ( - user && - (invoice.uid !== user?.id || aid !== invoice.aid) && - !(url.pathname.includes("tip") || url.pathname.includes("memo")) && - !options - ) { - if (invoice.prompt && invoice.tip === null) - redirect(307, `/invoice/${id}/tip`); - else { - redirect(307, `/send/invoice/${id}`); - } - } - } + const aid = cookies.get("aid") || user?.id; + if ( + user && + (invoice.uid !== user?.id || aid !== invoice.aid) && + !(url.pathname.includes("tip") || url.pathname.includes("memo")) && + !options + ) { + if (invoice.prompt && invoice.tip === null) + redirect(307, `/invoice/${id}/tip`); + else { + redirect(307, `/send/invoice/${id}`); + } + } + } - const theme = cookies.get("theme") || "light"; - return { id, invoice, subject, user, token, theme }; + const theme = cookies.get("theme") || "light"; + return { id, invoice, subject, user, token, theme }; } diff --git a/src/routes/(app)/invoice/[id]/+page.server.ts b/src/routes/(app)/invoice/[id]/+page.server.ts index d54ff30d..a57efa64 100644 --- a/src/routes/(app)/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/+page.server.ts @@ -1,5 +1,5 @@ import invoice from "$lib/invoice"; export const actions = { - default: invoice, + default: invoice, }; diff --git a/src/routes/(app)/invoice/[id]/memo/+page.server.ts b/src/routes/(app)/invoice/[id]/memo/+page.server.ts index d54ff30d..a57efa64 100644 --- a/src/routes/(app)/invoice/[id]/memo/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/memo/+page.server.ts @@ -1,5 +1,5 @@ import invoice from "$lib/invoice"; export const actions = { - default: invoice, + default: invoice, }; diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 851d3f1b..16cc22fa 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -3,53 +3,53 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { id } = params; - const rates = await getRates(); - let { invoice, subject, user } = await parent(); - if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); - const pin = cookies.get("pin"); + const { id } = params; + const rates = await getRates(); + let { invoice, subject, user } = await parent(); + if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); + const pin = cookies.get("pin"); - if (user) { - const trust = await get("/trust", auth(cookies)); - const trusted = trust.includes(invoice.uid); - if (trusted && (pin || !user.haspin)) { - let p; - try { - if (invoice.tip === null && invoice.user.prompt) { - if (user.tip > 0) { - invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); - p = await post("/payments", { ...invoice, pin }, auth(cookies)); - } - } else { - p = await post("/payments", { ...invoice, pin }, auth(cookies)); - } - } catch (e) { - const { message } = e as Error; - fail(400, { message }); - } - if (p) redirect(307, `/sent/${p.id}`); - } - } + if (user) { + const trust = await get("/trust", auth(cookies)); + const trusted = trust.includes(invoice.uid); + if (trusted && (pin || !user.haspin)) { + let p; + try { + if (invoice.tip === null && invoice.user.prompt) { + if (user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); + p = await post("/payments", { ...invoice, pin }, auth(cookies)); + } + } else { + p = await post("/payments", { ...invoice, pin }, auth(cookies)); + } + } catch (e) { + const { message } = e as Error; + fail(400, { message }); + } + if (p) redirect(307, `/sent/${p.id}`); + } + } - const rate = rates[subject?.currency]; - const invoiceRate = rates[invoice.currency]; - return { rate, invoiceRate }; + const rate = rates[subject?.currency]; + const invoiceRate = rates[invoice.currency]; + return { rate, invoiceRate }; } export const actions = { - default: async ({ cookies, request }) => { - const form = await fd(request); - const invoice = { - tip: form.tip ?? null, - }; + default: async ({ cookies, request }) => { + const form = await fd(request); + const invoice = { + tip: form.tip ?? null, + }; - const { id } = await post( - `/invoice/${form.id}`, - { invoice }, - auth(cookies), - ); + const { id } = await post( + `/invoice/${form.id}`, + { invoice }, + auth(cookies), + ); - redirect(307, `/invoice/${id}`); - }, + redirect(307, `/invoice/${id}`); + }, }; diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index 4d3af188..1183093e 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -173,11 +173,7 @@ </div> {/if} - <button - type="submit" - bind:this={submit} - aria-label="Submit tip" - ></button> + <button type="submit" bind:this={submit} aria-label="Submit tip"></button> </form> {#if showCustomAmount} diff --git a/src/routes/(app)/invoice/sent/+page.svelte b/src/routes/(app)/invoice/sent/+page.svelte index f8a05801..457ff108 100644 --- a/src/routes/(app)/invoice/sent/+page.svelte +++ b/src/routes/(app)/invoice/sent/+page.svelte @@ -1,5 +1,6 @@ <script lang="ts"> - import Avatar from "$comp/Avatar.svelte"; import { request } from "$lib/store"; + import Avatar from "$comp/Avatar.svelte"; + import { request } from "$lib/store"; </script> Invoice sent to diff --git a/src/routes/(app)/invoices/+page.server.ts b/src/routes/(app)/invoices/+page.server.ts index eb822802..9c599836 100644 --- a/src/routes/(app)/invoices/+page.server.ts +++ b/src/routes/(app)/invoices/+page.server.ts @@ -1,6 +1,6 @@ import { auth, get } from "$lib/utils"; export async function load({ cookies }) { - const invoices = await get("/invoices", auth(cookies)); - return { invoices }; + const invoices = await get("/invoices", auth(cookies)); + return { invoices }; } diff --git a/src/routes/(app)/items/[id]/+page.server.ts b/src/routes/(app)/items/[id]/+page.server.ts index 32924d03..d160c051 100644 --- a/src/routes/(app)/items/[id]/+page.server.ts +++ b/src/routes/(app)/items/[id]/+page.server.ts @@ -2,20 +2,20 @@ import { fd, auth, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export const load = async ({ params: { id } }) => { - const item = await get(`/items/${id}`); - return { item }; + const item = await get(`/items/${id}`); + return { item }; }; export const actions = { - default: async ({ cookies, request, url }) => { - const form = await fd(request); - try { - await post("/items", form, auth(cookies)); - } catch (e: any) { - return fail(400, { message: e.message }); - } + default: async ({ cookies, request, url }) => { + const form = await fd(request); + try { + await post("/items", form, auth(cookies)); + } catch (e: any) { + return fail(400, { message: e.message }); + } - const success = `/${url.pathname.split("/")[1]}`; - redirect(307, success); - }, + const success = `/${url.pathname.split("/")[1]}`; + redirect(307, success); + }, }; diff --git a/src/routes/(app)/items/[id]/+page.svelte b/src/routes/(app)/items/[id]/+page.svelte index 3128f34d..af5ce095 100644 --- a/src/routes/(app)/items/[id]/+page.svelte +++ b/src/routes/(app)/items/[id]/+page.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { run } from 'svelte/legacy'; + import { run } from "svelte/legacy"; import { t } from "$lib/translations"; import ItemForm from "$comp/ItemForm.svelte"; diff --git a/src/routes/(app)/items/create/+page.server.ts b/src/routes/(app)/items/create/+page.server.ts index e125e047..1e6dacb4 100644 --- a/src/routes/(app)/items/create/+page.server.ts +++ b/src/routes/(app)/items/create/+page.server.ts @@ -2,15 +2,15 @@ import { fail, redirect } from "@sveltejs/kit"; import { fd, auth, post } from "$lib/utils"; export const actions = { - default: async ({ cookies, request, url }) => { - const form = await fd(request); - try { - await post("/items", form, auth(cookies)); - } catch (e: any) { - return fail(400, { message: e.message }); - } + default: async ({ cookies, request, url }) => { + const form = await fd(request); + try { + await post("/items", form, auth(cookies)); + } catch (e: any) { + return fail(400, { message: e.message }); + } - const success = `/${url.pathname.split("/")[1]}`; - redirect(307, success); - }, + const success = `/${url.pathname.split("/")[1]}`; + redirect(307, success); + }, }; diff --git a/src/routes/(app)/items/create/+page.svelte b/src/routes/(app)/items/create/+page.svelte index de400927..5bcb010f 100644 --- a/src/routes/(app)/items/create/+page.svelte +++ b/src/routes/(app)/items/create/+page.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { run } from 'svelte/legacy'; + import { run } from "svelte/legacy"; import { t } from "$lib/translations"; import ItemForm from "$comp/ItemForm.svelte"; diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts index 7348f96c..ae784401 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.ts +++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts @@ -6,120 +6,120 @@ import { error, fail, redirect } from "@sveltejs/kit"; const { decode, fromWords } = bech32; export async function load({ params, parent }) { - const { user } = await parent(); - const rates = await getRates(); + const { user } = await parent(); + const rates = await getRates(); - let data; - const { lnurl } = params; + let data; + const { lnurl } = params; - const url = Buffer.from(fromWords(decode(lnurl, 20000).words)).toString(); + const url = Buffer.from(fromWords(decode(lnurl, 20000).words)).toString(); - try { - data = await get(`/decode?text=${lnurl}`); - } catch (e) { - const { message } = e as Error; - error(500, message); - } + try { + data = await get(`/decode?text=${lnurl}`); + } catch (e) { + const { message } = e as Error; + error(500, message); + } - let { callback, minSendable, maxSendable, comment, tag } = data; - if (tag === "payRequest" && minSendable === maxSendable) { - minSendable = Math.round(minSendable / 1000); - maxSendable = Math.round(maxSendable / 1000); - const amount = minSendable; + let { callback, minSendable, maxSendable, comment, tag } = data; + if (tag === "payRequest" && minSendable === maxSendable) { + minSendable = Math.round(minSendable / 1000); + maxSendable = Math.round(maxSendable / 1000); + const amount = minSendable; - const urlObj = new URL(callback); - urlObj.searchParams.set("amount", (amount * 1000).toString()); - if (comment) { - urlObj.searchParams.set("comment", comment); - } - const url = urlObj.toString(); + const urlObj = new URL(callback); + urlObj.searchParams.set("amount", (amount * 1000).toString()); + if (comment) { + urlObj.searchParams.set("comment", comment); + } + const url = urlObj.toString(); - const { pr } = await fetch(url).then((r) => (r as Response).json()); + const { pr } = await fetch(url).then((r) => (r as Response).json()); - let invoice; - try { - invoice = await get(`/invoice/${pr}`); - } catch (e) {} + let invoice; + try { + invoice = await get(`/invoice/${pr}`); + } catch {} - if (invoice) redirect(307, `/invoice/${invoice.id}`); + if (invoice) redirect(307, `/invoice/${invoice.id}`); - let path = `/send/lightning/${pr}`; - if (comment) path += `/${encodeURIComponent(comment)}`; - redirect(307, path); - } else if (callback.includes(PUBLIC_DOMAIN)) { - const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1]; - redirect(307, `/pay/${username}`); - } + let path = `/send/lightning/${pr}`; + if (comment) path += `/${encodeURIComponent(comment)}`; + redirect(307, path); + } else if (callback.includes(PUBLIC_DOMAIN)) { + const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1]; + redirect(307, `/pay/${username}`); + } - if (!["payRequest", "withdrawRequest"].includes(data.tag)) - error(500, "We only support LNURLp and LNURLw at this time"); + if (!["payRequest", "withdrawRequest"].includes(data.tag)) + error(500, "We only support LNURLp and LNURLw at this time"); - data.rate = rates[user?.currency || "USD"]; - return data; + data.rate = rates[user?.currency || "USD"]; + return data; } export const actions = { - pay: async ({ fetch, request }) => { - let error; + pay: async ({ fetch, request }) => { + let error; - let { callback, amount, minSendable, maxSendable, comment } = - await fd(request); - minSendable = Math.round(minSendable / 1000); - maxSendable = Math.round(maxSendable / 1000); + let { callback, amount, minSendable, maxSendable, comment } = + await fd(request); + minSendable = Math.round(minSendable / 1000); + maxSendable = Math.round(maxSendable / 1000); - if (amount < minSendable) - error = `Amount must be at least ${minSendable} sats`; - if (amount > maxSendable) - error = `Amount must be at most ${maxSendable} sats`; - if (error) return fail(400, { error }); + if (amount < minSendable) + error = `Amount must be at least ${minSendable} sats`; + if (amount > maxSendable) + error = `Amount must be at most ${maxSendable} sats`; + if (error) return fail(400, { error }); - let url = `${callback}?amount=${amount * 1000}`; - if (comment) url += `&comment=${comment}`; + let url = `${callback}?amount=${amount * 1000}`; + if (comment) url += `&comment=${comment}`; - const { pr } = await fetch(url).then((r) => r.json()); + const { pr } = await fetch(url).then((r) => r.json()); - let path = `/send/lightning/${pr}`; - if (comment) path += `/${encodeURIComponent(comment)}`; - redirect(307, path); - }, + let path = `/send/lightning/${pr}`; + if (comment) path += `/${encodeURIComponent(comment)}`; + redirect(307, path); + }, - withdraw: async ({ cookies, fetch, request }) => { - let error; + withdraw: async ({ cookies, fetch, request }) => { + let error; - let { - callback, - amount, - username, - currency, - minWithdrawable, - maxWithdrawable, - k1, - } = await fd(request); + let { + callback, + amount, + username, + currency, + minWithdrawable, + maxWithdrawable, + k1, + } = await fd(request); - minWithdrawable = Math.round(minWithdrawable / 1000); - maxWithdrawable = Math.round(maxWithdrawable / 1000); + minWithdrawable = Math.round(minWithdrawable / 1000); + maxWithdrawable = Math.round(maxWithdrawable / 1000); - if (amount < minWithdrawable) - error = `Amount must be at least ${minWithdrawable} sats`; - if (amount > maxWithdrawable) - error = `Amount must be at most ${maxWithdrawable} sats`; - if (error) return fail(400, { error }); + if (amount < minWithdrawable) + error = `Amount must be at least ${minWithdrawable} sats`; + if (amount > maxWithdrawable) + error = `Amount must be at most ${maxWithdrawable} sats`; + if (error) return fail(400, { error }); - const invoice = { amount, type: "lightning" }; - const user = { username, currency }; + const invoice = { amount, type: "lightning" }; + const user = { username, currency }; - const { text: pr } = await post( - "/invoice", - { invoice, user }, - auth(cookies), - ); + const { text: pr } = await post( + "/invoice", + { invoice, user }, + auth(cookies), + ); - const url = new URL(callback); - url.searchParams.append("k1", k1); - url.searchParams.append("pr", pr); + const url = new URL(callback); + url.searchParams.append("k1", k1); + url.searchParams.append("pr", pr); - await fetch(url.toString()); + await fetch(url.toString()); - redirect(307, "/payments"); - }, + redirect(307, "/payments"); + }, }; diff --git a/src/routes/(app)/locations/+server.ts b/src/routes/(app)/locations/+server.ts index 3184ebdf..9980c5fc 100644 --- a/src/routes/(app)/locations/+server.ts +++ b/src/routes/(app)/locations/+server.ts @@ -2,14 +2,14 @@ import { get } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function GET({ setHeaders }) { - let locations = []; + let locations = []; - try { - ({ locations } = await get("/locations")); - setHeaders({ "cache-control": "public, max-age=600" }); - } catch (e) { - console.log("failed to fetch locations"); - } + try { + ({ locations } = await get("/locations")); + setHeaders({ "cache-control": "public, max-age=600" }); + } catch { + console.log("failed to fetch locations"); + } - return json({ locations }); + return json({ locations }); } diff --git a/src/routes/(app)/logout/+page.server.ts b/src/routes/(app)/logout/+page.server.ts index 1ecc7f87..0a8b5d3a 100644 --- a/src/routes/(app)/logout/+page.server.ts +++ b/src/routes/(app)/logout/+page.server.ts @@ -1,19 +1,19 @@ import { redirect } from "@sveltejs/kit"; const opts = { - expires: new Date(0), - path: "/", + expires: new Date(0), + path: "/", }; export async function load({ cookies }) { - const lang = cookies.get("lang"); - cookies.set("aid", "", opts); - cookies.set("lang", "", opts); - cookies.set("username", "", opts); - cookies.set("token", "", opts); - cookies.set("pin", "", opts); - cookies.set("sk", "", opts); - cookies.set("theme", "", opts); - cookies.set("sid", "", opts); - redirect(307, `/login?lang=${lang}`); + const lang = cookies.get("lang"); + cookies.set("aid", "", opts); + cookies.set("lang", "", opts); + cookies.set("username", "", opts); + cookies.set("token", "", opts); + cookies.set("pin", "", opts); + cookies.set("sk", "", opts); + cookies.set("theme", "", opts); + cookies.set("sid", "", opts); + redirect(307, `/login?lang=${lang}`); } diff --git a/src/routes/(app)/messages/+page.server.ts b/src/routes/(app)/messages/+page.server.ts index b64dfb42..ec83bede 100644 --- a/src/routes/(app)/messages/+page.server.ts +++ b/src/routes/(app)/messages/+page.server.ts @@ -2,43 +2,43 @@ import { get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; interface Message { - created_at: number; + created_at: number; } interface Note { - created_at: number; - seen: number; + created_at: number; + seen: number; } export async function load({ params, parent }) { - const { user } = await parent(); - if (user.username !== params.username) redirect(307, `/${params.username}`); - const { since = 0 } = params; + const { user } = await parent(); + if (user.username !== params.username) redirect(307, `/${params.username}`); + const { since = 0 } = params; - let messages = []; - let notes = []; + let messages = []; + let notes = []; - if (user?.pubkey) { - const { pubkey } = user; - try { - messages = await get(`/${pubkey}/${since}/messages`); - messages = messages.sort( - (a: Message, b: Message) => b.created_at - a.created_at, - ); - } catch (e) { - console.log("failed to fetch nostr messages", e); - } + if (user?.pubkey) { + const { pubkey } = user; + try { + messages = await get(`/${pubkey}/${since}/messages`); + messages = messages.sort( + (a: Message, b: Message) => b.created_at - a.created_at, + ); + } catch (e) { + console.log("failed to fetch nostr messages", e); + } - try { - notes = await get(`/${pubkey}/notes`); - } catch (e) { - console.log(`failed to fetch nostr notes for ${pubkey}`, e); - } + try { + notes = await get(`/${pubkey}/notes`); + } catch (e) { + console.log(`failed to fetch nostr notes for ${pubkey}`, e); + } - notes.map((e: Note) => { - e.seen = e.created_at; - }); - } + notes.map((e: Note) => { + e.seen = e.created_at; + }); + } - return { messages, notes }; + return { messages, notes }; } diff --git a/src/routes/(app)/messages/+page.svelte b/src/routes/(app)/messages/+page.svelte index 2de56e0b..3e97398f 100644 --- a/src/routes/(app)/messages/+page.svelte +++ b/src/routes/(app)/messages/+page.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { run } from 'svelte/legacy'; + import { run } from "svelte/legacy"; import { t } from "$lib/translations"; import Avatar from "$comp/Avatar.svelte"; diff --git a/src/routes/(app)/messages/[recipient]/+page.server.ts b/src/routes/(app)/messages/[recipient]/+page.server.ts index 6e61e1b4..85deabbb 100644 --- a/src/routes/(app)/messages/[recipient]/+page.server.ts +++ b/src/routes/(app)/messages/[recipient]/+page.server.ts @@ -2,24 +2,24 @@ import { get } from "$lib/utils"; import type { Message } from "$lib/types"; export async function load({ params, parent }) { - const { user } = await parent(); - const { since = 0 } = params; + const { user } = await parent(); + const { since = 0 } = params; - let messages: Message[] = []; - const recipient = await get(`/users/${params.recipient}`); + let messages: Message[] = []; + const recipient = await get(`/users/${params.recipient}`); - try { - messages = await get(`/${user.pubkey}/${since}/messages`); + try { + messages = await get(`/${user.pubkey}/${since}/messages`); - messages = messages - .filter( - (m: Message) => - m.recipient?.id === recipient.id || m.author?.id === recipient.id, - ) - .sort((a, b) => a.created_at - b.created_at); - } catch (e) { - console.log("failed to fetch nostr messages", e); - } + messages = messages + .filter( + (m: Message) => + m.recipient?.id === recipient.id || m.author?.id === recipient.id, + ) + .sort((a, b) => a.created_at - b.created_at); + } catch (e) { + console.log("failed to fetch nostr messages", e); + } - return { messages, recipient, user }; + return { messages, recipient, user }; } diff --git a/src/routes/(app)/messages/[recipient]/+page.svelte b/src/routes/(app)/messages/[recipient]/+page.svelte index f399ab25..654ddcca 100644 --- a/src/routes/(app)/messages/[recipient]/+page.svelte +++ b/src/routes/(app)/messages/[recipient]/+page.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { run, preventDefault } from 'svelte/legacy'; + import { run, preventDefault } from "svelte/legacy"; import { cubicInOut } from "svelte/easing"; import { browser } from "$app/environment"; @@ -36,7 +36,8 @@ } let { messages, recipient, user }: any = $state(data); - let input: any, pane: any = $state(); + let input: any, + pane: any = $state(); let initialize = async (p: any) => { await Promise.all( @@ -59,7 +60,9 @@ } }); - let sent: any, submitting: any, message: any = $state(); + let sent: any, + submitting: any, + message: any = $state(); let submit = async () => { submitting = true; @@ -120,7 +123,8 @@ data-sveltekit-preload-data="false" onclick={back} > - <iconify-icon noobserver icon="ph:arrow-left-bold" width="40"></iconify-icon> + <iconify-icon noobserver icon="ph:arrow-left-bold" width="40" + ></iconify-icon> </button> <div diff --git a/src/routes/(app)/otpsecret/+server.ts b/src/routes/(app)/otpsecret/+server.ts index c260b7da..510148fa 100644 --- a/src/routes/(app)/otpsecret/+server.ts +++ b/src/routes/(app)/otpsecret/+server.ts @@ -2,13 +2,13 @@ import { auth, post } from "$lib/utils"; import { error } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - try { - const body = await request.json(); - const { username, secret } = await post("/otpsecret", body, auth(cookies)); - const uri = `otpauth://totp/coinos:${username}?secret=${secret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`; - return new Response(JSON.stringify({ secret, uri })); - } catch (e: any) { - if (e.message.includes("pin")) throw e; - error(500, "Problem saving secret"); - } + try { + const body = await request.json(); + const { username, secret } = await post("/otpsecret", body, auth(cookies)); + const uri = `otpauth://totp/coinos:${username}?secret=${secret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`; + return new Response(JSON.stringify({ secret, uri })); + } catch (e: any) { + if (e.message.includes("pin")) throw e; + error(500, "Problem saving secret"); + } } diff --git a/src/routes/(app)/password/+server.ts b/src/routes/(app)/password/+server.ts index 8e41b9c9..250dcfed 100644 --- a/src/routes/(app)/password/+server.ts +++ b/src/routes/(app)/password/+server.ts @@ -2,6 +2,6 @@ import { json } from "@sveltejs/kit"; import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - const result = await post("/password", await request.json(), auth(cookies)); - return json(result); + const result = await post("/password", await request.json(), auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts index 9c2b1e3b..23918cb3 100644 --- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts +++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts @@ -3,69 +3,69 @@ import { auth, fd, get, post, sats, types } from "$lib/utils"; import { error, fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { username } = params; - const { user } = await parent(); - const rates = await getRates(); + const { username } = params; + const { user } = await parent(); + const rates = await getRates(); - if (user?.username === username) redirect(307, `/${username}/receive`); - const subject = await get(`/users/${username}`); + if (user?.username === username) redirect(307, `/${username}/receive`); + const subject = await get(`/users/${username}`); - let [amount, currency] = params.amount.split("/"); + let [amount, currency] = params.amount.split("/"); - const rate = rates[currency ? currency.toUpperCase() : subject.currency]; - if (currency && !rate) error(500, "Invalid currency symbol"); + const rate = rates[currency ? currency.toUpperCase() : subject.currency]; + if (currency && !rate) error(500, "Invalid currency symbol"); - if (amount) { - if (currency) amount = (amount * sats) / rate; + if (amount) { + if (currency) amount = (amount * sats) / rate; - const { id } = await post( - "/invoice", - { - invoice: { - amount, - currency: currency === subject.currency ? currency : undefined, - prompt: false, - rate: currency === subject.currency ? rate : undefined, - type: types.lightning, - }, - user: { username }, - }, - auth(cookies), - ); + const { id } = await post( + "/invoice", + { + invoice: { + amount, + currency: currency === subject.currency ? currency : undefined, + prompt: false, + rate: currency === subject.currency ? rate : undefined, + type: types.lightning, + }, + user: { username }, + }, + auth(cookies), + ); - redirect(307, `/invoice/${id}`); - } + redirect(307, `/invoice/${id}`); + } - return { amount, rate, subject }; + return { amount, rate, subject }; } export const actions = { - default: async ({ cookies, request }) => { - let id; - const body = await fd(request); - const { amount, rate, prompt, type, username } = body; + default: async ({ cookies, request }) => { + let id; + const body = await fd(request); + const { amount, rate, prompt, type, username } = body; - try { - ({ id } = await post( - "/invoice", - { - invoice: { - amount, - rate, - prompt, - type, - }, - user: { username }, - }, - auth(cookies), - )); - } catch (e) { - const { message } = e as Error; - return fail(400, { message }); - } + try { + ({ id } = await post( + "/invoice", + { + invoice: { + amount, + rate, + prompt, + type, + }, + user: { username }, + }, + auth(cookies), + )); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } - if (parseInt(amount) > 0 && prompt) redirect(307, `/invoice/${id}/tip`); - else if (parseInt(amount) <= 0) redirect(307, `/${username}/receive`); - redirect(307, `/invoice/${id}`); - }, + if (parseInt(amount) > 0 && prompt) redirect(307, `/invoice/${id}/tip`); + else if (parseInt(amount) <= 0) redirect(307, `/${username}/receive`); + redirect(307, `/invoice/${id}`); + }, }; diff --git a/src/routes/(app)/payment/[id]/+page.server.ts b/src/routes/(app)/payment/[id]/+page.server.ts index fffdb451..74029a56 100644 --- a/src/routes/(app)/payment/[id]/+page.server.ts +++ b/src/routes/(app)/payment/[id]/+page.server.ts @@ -1,7 +1,7 @@ import { auth, get } from "$lib/utils"; export async function load({ cookies, depends, params }) { - depends("app:payments"); - const payment = await get(`/payments/${params.id}`, auth(cookies)); - return { payment }; + depends("app:payments"); + const payment = await get(`/payments/${params.id}`, auth(cookies)); + return { payment }; } diff --git a/src/routes/(app)/payment/[id]/bump/+server.ts b/src/routes/(app)/payment/[id]/bump/+server.ts index ae25999c..b24980a0 100644 --- a/src/routes/(app)/payment/[id]/bump/+server.ts +++ b/src/routes/(app)/payment/[id]/bump/+server.ts @@ -2,11 +2,11 @@ import { auth, post } from "$lib/utils"; import { json, error } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const body = await request.json(); - try { - const res = await post("/replace", body, auth(cookies)); - return json(res); - } catch (e: any) { - error(400, e.message); - } + const body = await request.json(); + try { + const res = await post("/replace", body, auth(cookies)); + return json(res); + } catch (e: any) { + error(400, e.message); + } } diff --git a/src/routes/(app)/payment/[id]/plain/+page.server.ts b/src/routes/(app)/payment/[id]/plain/+page.server.ts index 49d9b98b..18c3e8f6 100644 --- a/src/routes/(app)/payment/[id]/plain/+page.server.ts +++ b/src/routes/(app)/payment/[id]/plain/+page.server.ts @@ -1,6 +1,6 @@ import { auth, get } from "$lib/utils"; export async function load({ cookies, params }) { - const payment = await get(`/payments/${params.id}`, auth(cookies)); - return { payment }; + const payment = await get(`/payments/${params.id}`, auth(cookies)); + return { payment }; } diff --git a/src/routes/(app)/payment/[id]/plain/+page.svelte b/src/routes/(app)/payment/[id]/plain/+page.svelte index 30b774a8..46197260 100644 --- a/src/routes/(app)/payment/[id]/plain/+page.svelte +++ b/src/routes/(app)/payment/[id]/plain/+page.svelte @@ -15,7 +15,8 @@ types, } from "$lib/utils"; import { fiat } from "$lib/store"; - import Avatar from "$comp/Avatar.svelte"; import { format } from "date-fns"; + import Avatar from "$comp/Avatar.svelte"; + import { format } from "date-fns"; import { PUBLIC_EXPLORER as expl } from "$env/static/public"; let { data } = $props(); diff --git a/src/routes/(app)/payment/[id]/print/+server.ts b/src/routes/(app)/payment/[id]/print/+server.ts index aab6d3f4..19f8941e 100644 --- a/src/routes/(app)/payment/[id]/print/+server.ts +++ b/src/routes/(app)/payment/[id]/print/+server.ts @@ -2,6 +2,6 @@ import { auth, post } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const body = await request.json(); - return json(post("/print", body, auth(cookies))); + const body = await request.json(); + return json(post("/print", body, auth(cookies))); } diff --git a/src/routes/(app)/payments/[...page]/+page.server.ts b/src/routes/(app)/payments/[...page]/+page.server.ts index 153615b1..bf280937 100644 --- a/src/routes/(app)/payments/[...page]/+page.server.ts +++ b/src/routes/(app)/payments/[...page]/+page.server.ts @@ -3,34 +3,34 @@ import { auth, get, str } from "$lib/utils"; const limit = 10; export async function load({ cookies, depends, params }) { - depends("app:payments"); + depends("app:payments"); - const aid = cookies.get("aid"); - const parts = params.page.split("/"); + const aid = cookies.get("aid"); + const parts = params.page.split("/"); - let start; - let end; - let page; - if (parts.length === 1) [page] = parts; - if (parts.length === 2) [start, page] = parts; - if (parts.length === 3) [start, end, page] = parts; - if (!parseInt(page)) page = 1; + let start; + let end; + let page; + if (parts.length === 1) [page] = parts; + if (parts.length === 2) [start, page] = parts; + if (parts.length === 3) [start, end, page] = parts; + if (!parseInt(page)) page = 1; - const offset = (page - 1) * limit; + const offset = (page - 1) * limit; - const q = new URLSearchParams(); - q.set("limit", str(limit)); - q.set("offset", str(offset)); - if (aid) q.set("aid", aid); - if (start) q.set("start", str(start * 1000)); - if (end) q.set("end", str(end * 1000)); + const q = new URLSearchParams(); + q.set("limit", str(limit)); + q.set("offset", str(offset)); + if (aid) q.set("aid", aid); + if (start) q.set("start", str(start * 1000)); + if (end) q.set("end", str(end * 1000)); - const { count, payments, incoming, outgoing } = await get( - `/payments?${str(q)}`, - auth(cookies), - ); + const { count, payments, incoming, outgoing } = await get( + `/payments?${str(q)}`, + auth(cookies), + ); - const pages = new Array(Math.ceil(count / limit)); + const pages = Array.from({ length: Math.ceil(count / limit) }); - return { payments, page, pages, start, end, incoming, outgoing }; + return { payments, page, pages, start, end, incoming, outgoing }; } diff --git a/src/routes/(app)/payments/[...page]/+server.ts b/src/routes/(app)/payments/[...page]/+server.ts index 20315da4..0d010222 100644 --- a/src/routes/(app)/payments/[...page]/+server.ts +++ b/src/routes/(app)/payments/[...page]/+server.ts @@ -2,18 +2,18 @@ import { get, auth } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function GET({ cookies, params }) { - const parts = params.page.split("/"); + const parts = params.page.split("/"); - let start; - let end; - if (parts.length === 1) [start] = parts; - if (parts.length === 2) [start, end] = parts; + let start; + let end; + if (parts.length === 1) [start] = parts; + if (parts.length === 2) [start, end] = parts; - if (!start) start = Date.now() / 1000 - 24 * 60 * 60; + if (!start) start = Date.now() / 1000 - 24 * 60 * 60; - let url = `/payments?start=${start * 1000}`; - if (end) url += `&end=${end * 1000}`; + let url = `/payments?start=${start * 1000}`; + if (end) url += `&end=${end * 1000}`; - const { payments } = await get(url, auth(cookies)); - return json({ payments }); + const { payments } = await get(url, auth(cookies)); + return json({ payments }); } diff --git a/src/routes/(app)/pin/+server.ts b/src/routes/(app)/pin/+server.ts index d819ee5f..b24770d5 100644 --- a/src/routes/(app)/pin/+server.ts +++ b/src/routes/(app)/pin/+server.ts @@ -2,6 +2,6 @@ import { json } from "@sveltejs/kit"; import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - const result = await post("/pin", await request.json(), auth(cookies)); - return json(result); + const result = await post("/pin", await request.json(), auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/pos/+page.server.ts b/src/routes/(app)/pos/+page.server.ts index 1df1bb33..b8f8410c 100644 --- a/src/routes/(app)/pos/+page.server.ts +++ b/src/routes/(app)/pos/+page.server.ts @@ -3,28 +3,28 @@ import { auth, fd, get } from "$lib/utils"; import { hex } from "@scure/base"; export async function load({ cookies }) { - let token; + let token; - try { - token = await get("/ro", auth(cookies)); - } catch (e) {} + try { + token = await get("/ro", auth(cookies)); + } catch {} - return { token }; + return { token }; } export const actions = { - default: async ({ fetch, request }) => { - const body = await fd(request); - const res = await fetch(`${PUBLIC_COINOS_URL}/flash`, { - method: "POST", - body: JSON.stringify(body), - headers: { - "content-type": "application/json", - accept: "application/octet-stream", - }, - }); + default: async ({ fetch, request }) => { + const body = await fd(request); + const res = await fetch(`${PUBLIC_COINOS_URL}/flash`, { + method: "POST", + body: JSON.stringify(body), + headers: { + "content-type": "application/json", + accept: "application/octet-stream", + }, + }); - const buf = new Uint8Array(await res.arrayBuffer()); - return { bytes: hex.encode(buf) }; - }, + const buf = new Uint8Array(await res.arrayBuffer()); + return { bytes: hex.encode(buf) }; + }, }; diff --git a/src/routes/(app)/pos/+page.svelte b/src/routes/(app)/pos/+page.svelte index 6806fec3..056a9254 100644 --- a/src/routes/(app)/pos/+page.svelte +++ b/src/routes/(app)/pos/+page.svelte @@ -18,9 +18,9 @@ // --- Defaults --- const LITTLEFS_ADDRESS_DEFAULT = 0x3d0000; // your existing LittleFS offset - const FW_ADDRESS_DEFAULT = 0x10000; // typical app offset on ESP32-C3 - const CONNECT_BAUD = 115200; // initial - const WORK_BAUD = 921600; // fast flashing + const FW_ADDRESS_DEFAULT = 0x10000; // typical app offset on ESP32-C3 + const CONNECT_BAUD = 115200; // initial + const WORK_BAUD = 921600; // fast flashing // --- Shared state --- let esploader: any = $state(); @@ -38,7 +38,7 @@ // --- New firmware flashing path --- let fwFile: any = $state(null); - let fwBytes: Uint8Array | undefined = $state(); // Uint8Array + let fwBytes: Uint8Array | undefined = $state(); // Uint8Array let fwAddress = $state(FW_ADDRESS_DEFAULT); let fwEraseAll = $state(false); let fwProgress = $state(0); @@ -63,7 +63,9 @@ chip = await esploader.main(); connected = true; - portInfo = (await device.getInfo?.()) ? JSON.stringify(await device.getInfo()) : "Connected"; + portInfo = (await device.getInfo?.()) + ? JSON.stringify(await device.getInfo()) + : "Connected"; } catch (e) { console.log(e); connected = false; @@ -151,17 +153,25 @@ </h1> {#if !connected} - <div class="text-center"> - <button class="btn" onclick={connect}>Connect</button> - <div class="text-sm mt-2 opacity-70">{portInfo}</div> - </div> -{/if} + <div class="text-center"> + <button class="btn" onclick={connect}>Connect</button> + <div class="text-sm mt-2 opacity-70">{portInfo}</div> + </div> + {/if} {#if connected} <!-- Tabs --> <div class="flex gap-2 justify-center"> - <button class="btn" class:btn-neutral={tab === "config"} onclick={() => (tab = "config")}>Flash config</button> - <button class="btn" class:btn-neutral={tab === "firmware"} onclick={() => (tab = "firmware")}>Flash firmware</button> + <button + class="btn" + class:btn-neutral={tab === "config"} + onclick={() => (tab = "config")}>Flash config</button + > + <button + class="btn" + class:btn-neutral={tab === "firmware"} + onclick={() => (tab = "firmware")}>Flash firmware</button + > </div> {#if tab === "config"} @@ -178,18 +188,26 @@ id="littlefs-address" class="input" bind:value={littlefsAddress} - onchange={(e) => (littlefsAddress = Number((e.target as HTMLInputElement).value))} + onchange={(e) => + (littlefsAddress = Number((e.target as HTMLInputElement).value))} /> <div class="mt-3"> <button class="btn" onclick={flashConfig}>Flash config</button> </div> - {#if configProgress > 0}<div class="mt-2">Progress: {configProgress}%</div>{/if} + {#if configProgress > 0}<div class="mt-2"> + Progress: {configProgress}% + </div>{/if} {/if} {:else} <form method="POST" use:enhance class="space-y-2"> <input name="ssid" placeholder="Wifi SSID" class="input" /> <input name="key" placeholder="Wifi password" class="input" /> - <input name="token" bind:value={token} placeholder="Coinos API token" class="input" /> + <input + name="token" + bind:value={token} + placeholder="Coinos API token" + class="input" + /> <button type="submit" class="btn">Generate Config</button> </form> {/if} @@ -214,7 +232,8 @@ id="firmware-address" class="input" bind:value={fwAddress} - onchange={(e) => (fwAddress = Number((e.target as HTMLInputElement).value))} + onchange={(e) => + (fwAddress = Number((e.target as HTMLInputElement).value))} /> <label class="flex items-center gap-2 mt-2"> @@ -223,8 +242,10 @@ </label> <div class="mt-3"> - <button class="btn" disabled={!fwBytes} onclick={flashFirmware}>Flash firmware</button> - </div> + <button class="btn" disabled={!fwBytes} onclick={flashFirmware} + >Flash firmware</button + > + </div> {#if fwProgress > 0 && !fwDone} <div>Progress: {fwProgress}%</div> @@ -243,8 +264,16 @@ <style> @reference "../../../app.css"; - .btn { @apply px-4 py-2 rounded-2xl shadow; } - .btn-neutral { @apply bg-gray-200; } - .input { @apply w-full px-3 py-2 border rounded-xl; } - .label { @apply text-sm opacity-70; } + .btn { + @apply px-4 py-2 rounded-2xl shadow; + } + .btn-neutral { + @apply bg-gray-200; + } + .input { + @apply w-full px-3 py-2 border rounded-xl; + } + .label { + @apply text-sm opacity-70; + } </style> diff --git a/src/routes/(app)/post/[...path]/+server.ts b/src/routes/(app)/post/[...path]/+server.ts index 84df9a36..244683ee 100644 --- a/src/routes/(app)/post/[...path]/+server.ts +++ b/src/routes/(app)/post/[...path]/+server.ts @@ -2,11 +2,11 @@ import { PUBLIC_COINOS_URL as base } from "$env/static/public"; import { auth } from "$lib/utils"; export async function POST({ cookies, fetch, params, request }) { - const { path } = params; + const { path } = params; - return fetch(`${base}/${path}`, { - method: "POST", - body: JSON.stringify(await request.json()), - headers: { "Content-Type": "application/json", ...auth(cookies) }, - }); + return fetch(`${base}/${path}`, { + method: "POST", + body: JSON.stringify(await request.json()), + headers: { "Content-Type": "application/json", ...auth(cookies) }, + }); } diff --git a/src/routes/(app)/printer/+page.server.ts b/src/routes/(app)/printer/+page.server.ts index 7a004848..e3fd9f81 100644 --- a/src/routes/(app)/printer/+page.server.ts +++ b/src/routes/(app)/printer/+page.server.ts @@ -3,17 +3,17 @@ import { fd } from "$lib/utils"; import { hex } from "@scure/base"; export const actions = { - default: async ({ fetch, request }) => { - const body = await fd(request); - const res = await fetch(`${PUBLIC_COINOS_URL}/printer`, { - method: "POST", - body: JSON.stringify(body), - headers: { - "content-type": "application/json", - accept: "application/octet-stream", - }, - }); + default: async ({ fetch, request }) => { + const body = await fd(request); + const res = await fetch(`${PUBLIC_COINOS_URL}/printer`, { + method: "POST", + body: JSON.stringify(body), + headers: { + "content-type": "application/json", + accept: "application/octet-stream", + }, + }); - return { data: hex.encode(new Uint8Array(await res.arrayBuffer())) }; - }, + return { data: hex.encode(new Uint8Array(await res.arrayBuffer())) }; + }, }; diff --git a/src/routes/(app)/qr/[text]/+page.server.ts b/src/routes/(app)/qr/[text]/+page.server.ts index 210c3c45..e2da11c2 100644 --- a/src/routes/(app)/qr/[text]/+page.server.ts +++ b/src/routes/(app)/qr/[text]/+page.server.ts @@ -1,4 +1,4 @@ export async function load({ params }) { - const { text } = params; - return { text }; + const { text } = params; + return { text }; } diff --git a/src/routes/(app)/qr/[text]/+page.svelte b/src/routes/(app)/qr/[text]/+page.svelte index 2f6ca891..a337238e 100644 --- a/src/routes/(app)/qr/[text]/+page.svelte +++ b/src/routes/(app)/qr/[text]/+page.svelte @@ -1,4 +1,5 @@ -<script> import Qr from "$comp/Qr.svelte"; +<script> + import Qr from "$comp/Qr.svelte"; import { back, copy } from "$lib/utils"; let { data } = $props(); let { text } = $derived(data); diff --git a/src/routes/(app)/qr/[text]/[icon]/+server.ts b/src/routes/(app)/qr/[text]/[icon]/+server.ts index c2825877..4a1bb78e 100644 --- a/src/routes/(app)/qr/[text]/[icon]/+server.ts +++ b/src/routes/(app)/qr/[text]/[icon]/+server.ts @@ -2,32 +2,32 @@ import { createCanvas, loadImage } from "canvas"; import QRCode from "qrcode"; export async function GET({ params }) { - const { icon, text } = params; - const size = 600; + const { icon, text } = params; + const size = 600; - const canvas = createCanvas(size, size); - await QRCode.toCanvas(canvas, text, { - errorCorrectionLevel: "H", - width: size, - }); + const canvas = createCanvas(size, size); + await QRCode.toCanvas(canvas, text, { + errorCorrectionLevel: "H", + width: size, + }); - const ctx = canvas.getContext("2d"); + const ctx = canvas.getContext("2d"); - const logo = await loadImage(`static/images/${icon}`); - const logoSize = size * 0.3; - ctx.drawImage( - logo, - (size - logoSize) / 2, - (size - logoSize) / 2, - logoSize, - logoSize, - ); + const logo = await loadImage(`static/images/${icon}`); + const logoSize = size * 0.3; + ctx.drawImage( + logo, + (size - logoSize) / 2, + (size - logoSize) / 2, + logoSize, + logoSize, + ); - const buffer = canvas.toBuffer("image/png"); - return new Response(buffer, { - headers: { - "Content-Type": "image/png", - "Cache-Control": "public, max-age=31536000, immutable", - }, - }); + const buffer = canvas.toBuffer("image/png"); + return new Response(buffer, { + headers: { + "Content-Type": "image/png", + "Cache-Control": "public, max-age=31536000, immutable", + }, + }); } diff --git a/src/routes/(app)/qr/[text]/raw/+server.ts b/src/routes/(app)/qr/[text]/raw/+server.ts index a2626c4d..ad7fc6b1 100644 --- a/src/routes/(app)/qr/[text]/raw/+server.ts +++ b/src/routes/(app)/qr/[text]/raw/+server.ts @@ -1,17 +1,16 @@ import Qr from "qrcode-base64"; export async function GET({ params }) { - const { text } = params; + const { text } = params; - const dataUri = Qr.drawImg(text, { size: 600 }); - const base64Data = dataUri.split(",")[1]; - const binaryData = Buffer.from(base64Data, "base64"); + const dataUri = Qr.drawImg(text, { size: 600 }); + const base64Data = dataUri.split(",")[1]; + const binaryData = Buffer.from(base64Data, "base64"); - return new Response(binaryData, { - headers: { - "Content-Type": "image/gif", - "Cache-Control": "public, max-age=31536000, immutable", - }, - }); + return new Response(binaryData, { + headers: { + "Content-Type": "image/gif", + "Cache-Control": "public, max-age=31536000, immutable", + }, + }); } - diff --git a/src/routes/(app)/qr/create/+page.svelte b/src/routes/(app)/qr/create/+page.svelte index 339aae16..189a734d 100644 --- a/src/routes/(app)/qr/create/+page.svelte +++ b/src/routes/(app)/qr/create/+page.svelte @@ -1,10 +1,12 @@ <script lang="ts"> - import { run, preventDefault } from 'svelte/legacy'; + import { run, preventDefault } from "svelte/legacy"; import { goto } from "$app/navigation"; import { browser } from "$app/environment"; import { t } from "$lib/translations"; - let el = $state(), text = $state(), pasted = $state(); + let el = $state(), + text = $state(), + pasted = $state(); let keypress = (e) => e.key === "Enter" ? e.preventDefault() || el.click() : (pasted = false); @@ -37,7 +39,7 @@ bind:value={text} onpaste={() => (pasted = true)} autocapitalize="none" -></textarea> + ></textarea> </div> <div class="flex gap-2"> diff --git a/src/routes/(app)/receive/[...token]/+page.server.ts b/src/routes/(app)/receive/[...token]/+page.server.ts index 052d507f..edc47b80 100644 --- a/src/routes/(app)/receive/[...token]/+page.server.ts +++ b/src/routes/(app)/receive/[...token]/+page.server.ts @@ -3,15 +3,15 @@ import { fd } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent, url }) { - const { user } = await parent(); - if (!user) redirect(307, `/register?redirect=${url.pathname}`); - await parse(params.token, url.host, cookies); + const { user } = await parent(); + if (!user) redirect(307, `/register?redirect=${url.pathname}`); + await parse(params.token, url.host, cookies); } export const actions = { - default: async ({ cookies, request, url }) => { - const { text } = await fd(request); - await parse(text, url.host, cookies); - return fail(400, { error: "default" }); - }, + default: async ({ cookies, request, url }) => { + const { text } = await fd(request); + await parse(text, url.host, cookies); + return fail(400, { error: "default" }); + }, }; diff --git a/src/routes/(app)/receive/[...token]/+page.svelte b/src/routes/(app)/receive/[...token]/+page.svelte index 59e13239..1f4c81fc 100644 --- a/src/routes/(app)/receive/[...token]/+page.svelte +++ b/src/routes/(app)/receive/[...token]/+page.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { run } from 'svelte/legacy'; + import { run } from "svelte/legacy"; import { page } from "$app/stores"; import { fly } from "svelte/transition"; @@ -16,7 +16,10 @@ let { token } = data; data.subject = data.user; - let el = $state(), text = $state(), pasted = $state(), w = $state(); + let el = $state(), + text = $state(), + pasted = $state(), + w = $state(); let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click()); @@ -57,19 +60,21 @@ bind:value={text} onpaste={() => (pasted = true)} autocapitalize="none" -></textarea> + ></textarea> </div> <div class="flex gap-2"> <a href="/scan" class="contents"> <button type="button" class="btn !w-auto flex-grow"> - <iconify-icon noobserver icon="ph:camera-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:camera-bold" width="32" + ></iconify-icon> <div class="my-auto">{$t("user.send.scan")}</div> </button> </a> <button type="button" class="btn !w-auto flex-grow" onclick={paste}> - <iconify-icon noobserver icon="ph:clipboard-text-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:clipboard-text-bold" width="32" + ></iconify-icon> <div class="my-auto">{$t("user.send.paste")}</div> </button> </div> diff --git a/src/routes/(app)/reset/+server.ts b/src/routes/(app)/reset/+server.ts index 4e8deeaa..4b6692d5 100644 --- a/src/routes/(app)/reset/+server.ts +++ b/src/routes/(app)/reset/+server.ts @@ -2,6 +2,6 @@ import { json } from "@sveltejs/kit"; import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - const result = await post("/reset", await request.json(), auth(cookies)); - return json(result); + const result = await post("/reset", await request.json(), auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/reset/[code]/+page.server.ts b/src/routes/(app)/reset/[code]/+page.server.ts index 35d49be9..dc5b58f0 100644 --- a/src/routes/(app)/reset/[code]/+page.server.ts +++ b/src/routes/(app)/reset/[code]/+page.server.ts @@ -2,30 +2,30 @@ import { fail, redirect } from "@sveltejs/kit"; import { fd, post, login } from "$lib/utils"; export const actions = { - default: async ({ cookies, params, request }) => { - const ip = request.headers.get("cf-connecting-ip"); - let error; + default: async ({ cookies, params, request }) => { + const ip = request.headers.get("cf-connecting-ip"); + let error; - const { code } = params; - const { password, recaptcha } = await fd(request); + const { code } = params; + const { password, recaptcha } = await fd(request); - try { - const user = await post("/reset", { code, password }); - user.password = password; - user.recaptcha = recaptcha; + try { + const user = await post("/reset", { code, password }); + user.password = password; + user.recaptcha = recaptcha; - try { - await login(user, cookies, ip); - error = null; - } catch (e: any) { - error ||= e.message; - } + try { + await login(user, cookies, ip); + error = null; + } catch (e: any) { + error ||= e.message; + } - if (error) return fail(400, { error }); - redirect(307, `/${user.username}`); - } catch (e: any) { - console.log(e.message); - return fail(400, { error: e.message }); - } - }, + if (error) return fail(400, { error }); + redirect(307, `/${user.username}`); + } catch (e: any) { + console.log(e.message); + return fail(400, { error: e.message }); + } + }, }; diff --git a/src/routes/(app)/reset/[code]/+page.svelte b/src/routes/(app)/reset/[code]/+page.svelte index 57deedcd..93fdf8f9 100644 --- a/src/routes/(app)/reset/[code]/+page.svelte +++ b/src/routes/(app)/reset/[code]/+page.svelte @@ -19,7 +19,8 @@ onMount(() => { if (!isTor && recaptchaSiteKey) { let s = document.createElement("script"); - s.src = "https://www.google.com/recaptcha/api.js?render=" + recaptchaSiteKey; + s.src = + "https://www.google.com/recaptcha/api.js?render=" + recaptchaSiteKey; document.head.appendChild(s); } }); @@ -27,7 +28,8 @@ const getRecaptchaToken = () => new Promise((resolve, reject) => { if (isTor) return resolve(""); - if (!browser || !grecaptcha) return reject(new Error("captcha unavailable")); + if (!browser || !grecaptcha) + return reject(new Error("captcha unavailable")); grecaptcha.ready(() => { grecaptcha .execute(recaptchaSiteKey, { action: "reset" }) diff --git a/src/routes/(app)/scan/[email protected] b/src/routes/(app)/scan/[email protected] index 14b35465..a57fa3b9 100644 --- a/src/routes/(app)/scan/[email protected] +++ b/src/routes/(app)/scan/[email protected] @@ -1,6 +1,6 @@ <script lang="ts"> interface Props { - children?: import('svelte').Snippet; + children?: import("svelte").Snippet; } let { children }: Props = $props(); diff --git a/src/routes/(app)/scan/+page.svelte b/src/routes/(app)/scan/+page.svelte index bb64fbec..90e0e79c 100644 --- a/src/routes/(app)/scan/+page.svelte +++ b/src/routes/(app)/scan/+page.svelte @@ -1,5 +1,6 @@ <script lang="ts"> - import { tick } from "svelte"; import { onMount, onDestroy } from "svelte"; + import { tick } from "svelte"; + import { onMount, onDestroy } from "svelte"; import { back } from "$lib/utils"; import { goto } from "$app/navigation"; diff --git a/src/routes/(app)/send/+layout.server.ts b/src/routes/(app)/send/+layout.server.ts index dbb3efad..38ed57cf 100644 --- a/src/routes/(app)/send/+layout.server.ts +++ b/src/routes/(app)/send/+layout.server.ts @@ -1,6 +1,6 @@ import { redirect } from "@sveltejs/kit"; export async function load({ cookies, url }) { - if (!cookies.get("token")) - redirect(307, `/register?redirect=${url.pathname}`); + if (!cookies.get("token")) + redirect(307, `/register?redirect=${url.pathname}`); } diff --git a/src/routes/(app)/send/[...text]/+page.server.ts b/src/routes/(app)/send/[...text]/+page.server.ts index 59d53dbe..dc76da7f 100644 --- a/src/routes/(app)/send/[...text]/+page.server.ts +++ b/src/routes/(app)/send/[...text]/+page.server.ts @@ -5,20 +5,20 @@ import { fail, redirect } from "@sveltejs/kit"; const limit = 10; export async function load({ cookies, depends, params, parent, url }) { depends("app:contacts"); - const { user } = await parent(); - if (!user) redirect(307, "/login"); - const { text } = params; + const { user } = await parent(); + if (!user) redirect(307, "/login"); + const { text } = params; - await parse(text, url.host, cookies); - const contacts = await get(`/contacts/${limit}`, auth(cookies)); + await parse(text, url.host, cookies); + const contacts = await get(`/contacts/${limit}`, auth(cookies)); - return { contacts }; + return { contacts }; } export const actions = { - default: async ({ cookies, request, url }) => { - const { text } = await fd(request); - await parse(text, url.host, cookies); - return fail(400, { error: "default" }); - }, + default: async ({ cookies, request, url }) => { + const { text } = await fd(request); + await parse(text, url.host, cookies); + return fail(400, { error: "default" }); + }, }; diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index 34acb4b0..58db231a 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -6,7 +6,8 @@ import { tick } from "svelte"; import { browser } from "$app/environment"; import { t } from "$lib/translations"; - import Avatar from "$comp/Avatar.svelte"; import Spinner from "$comp/Spinner.svelte"; + import Avatar from "$comp/Avatar.svelte"; + import Spinner from "$comp/Spinner.svelte"; import { back, get, post, fail, focus } from "$lib/utils"; let { data = $bindable(), form } = $props(); diff --git a/src/routes/(app)/send/ark/[address]/+layout.server.ts b/src/routes/(app)/send/ark/[address]/+layout.server.ts index cf16ea36..bb167d2d 100644 --- a/src/routes/(app)/send/ark/[address]/+layout.server.ts +++ b/src/routes/(app)/send/ark/[address]/+layout.server.ts @@ -2,25 +2,25 @@ import { auth, get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { user } = await parent(); - const aid = cookies.get("aid") || user.id; - const { address, amount } = params; - const { balance } = await get(`/account/${aid}`, auth(cookies)); + const { user } = await parent(); + const aid = cookies.get("aid") || user.id; + const { address, amount } = params; + const { balance } = await get(`/account/${aid}`, auth(cookies)); - let invoice; - try { - invoice = await get(`/invoice/${address}`); - } catch (e) { - // invoice not found - } + let invoice; + try { + invoice = await get(`/invoice/${address}`); + } catch { + // invoice not found + } - if (invoice) { - const recipient = await get(`/users/${invoice.uid}`); - let r = `/pay/${recipient.username}`; - if (amount) r += `/${amount}`; - if (recipient?.id !== user.id && recipient.id === invoice.aid) - redirect(307, r); - } + if (invoice) { + const recipient = await get(`/users/${invoice.uid}`); + let r = `/pay/${recipient.username}`; + if (amount) r += `/${amount}`; + if (recipient?.id !== user.id && recipient.id === invoice.aid) + redirect(307, r); + } - return { balance }; + return { balance }; } diff --git a/src/routes/(app)/send/ark/[address]/+page.server.ts b/src/routes/(app)/send/ark/[address]/+page.server.ts index b7d3c5cf..fdf129a0 100644 --- a/src/routes/(app)/send/ark/[address]/+page.server.ts +++ b/src/routes/(app)/send/ark/[address]/+page.server.ts @@ -2,9 +2,9 @@ import getRates from "$lib/rates"; import { auth, get } from "$lib/utils"; export async function load({ cookies, parent }) { - const { user } = await parent(); - const rates = await getRates(); - const aid = cookies.get("aid") || user.id; - const { balance } = await get(`/account/${aid}`, auth(cookies)); - return { balance, rate: rates[user.currency] }; + const { user } = await parent(); + const rates = await getRates(); + const aid = cookies.get("aid") || user.id; + const { balance } = await get(`/account/${aid}`, auth(cookies)); + return { balance, rate: rates[user.currency] }; } diff --git a/src/routes/(app)/send/ark/[address]/+page.svelte b/src/routes/(app)/send/ark/[address]/+page.svelte index 531047fe..0bf9e0de 100644 --- a/src/routes/(app)/send/ark/[address]/+page.svelte +++ b/src/routes/(app)/send/ark/[address]/+page.svelte @@ -27,7 +27,6 @@ await tick(); submit.click(); }; - </script> <div class="container px-4 max-w-xl mx-auto space-y-5 text-center"> @@ -57,10 +56,7 @@ {/if}</button > - <form - action={`/send/ark/${address}/${amount}`} - class="contents" - > + <form action={`/send/ark/${address}/${amount}`} class="contents"> <button bind:this={submit} type="submit" diff --git a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts index 309d75fa..07972e6c 100644 --- a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts +++ b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts @@ -3,47 +3,58 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ params: { address, amount }, cookies, parent }) { - const rates = await getRates(); - const { user } = await parent(); - const aid = cookies.get("aid") || user.id; + const rates = await getRates(); + const { user } = await parent(); + const aid = cookies.get("aid") || user.id; - const account = await get(`/account/${aid}`, auth(cookies)); + const account = await get(`/account/${aid}`, auth(cookies)); - if (account.type === "bitcoin") { - const inv = await post( - "/invoice", - { invoice: { type: "bitcoin", amount: parseInt(amount), forward: address }, user }, - auth(cookies), - ); - redirect(307, `/send/bitcoin/${inv.hash}/${amount}`); - } + if (account.type === "bitcoin") { + const inv = await post( + "/invoice", + { + invoice: { + type: "bitcoin", + amount: parseInt(amount), + forward: address, + }, + user, + }, + auth(cookies), + ); + redirect(307, `/send/bitcoin/${inv.hash}/${amount}`); + } - const rate = rates[user.currency]; + const rate = rates[user.currency]; - return { - account, - amount, - address, - rate, - }; + return { + account, + amount, + address, + rate, + }; } export const actions = { - default: async ({ - cookies, - params: { address, amount, feeRate }, - request, - }) => { - let p; - try { - const body = await fd(request); - p = await post("/ark/send", { ...body, address, amount: parseInt(amount) }, auth(cookies)); - } catch (e) { - console.log("problem sending bitcoin", e); - const { message } = e as Error; - return fail(400, { address, amount, feeRate, message }); - } + default: async ({ + cookies, + params: { address, amount, feeRate }, + request, + }) => { + let p; + try { + const body = await fd(request); + p = await post( + "/ark/send", + { ...body, address, amount: parseInt(amount) }, + auth(cookies), + ); + } catch (e) { + console.log("problem sending bitcoin", e); + const { message } = e as Error; + return fail(400, { address, amount, feeRate, message }); + } - redirect(307, `/sent/${p.id}`); - }, + redirect(307, `/sent/${p.id}`); + }, }; diff --git a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts index e7a216d6..d8df1986 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts +++ b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts @@ -2,24 +2,24 @@ import { auth, get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { user } = await parent(); - const aid = cookies.get("aid") || user.id; - const { address, amount } = params; - const { balance } = await get(`/account/${aid}`, auth(cookies)); + const { user } = await parent(); + const aid = cookies.get("aid") || user.id; + const { address, amount } = params; + const { balance } = await get(`/account/${aid}`, auth(cookies)); - let invoice; - try { - invoice = await get(`/invoice/${address}`); - } catch (e) { - // invoice not found - } + let invoice; + try { + invoice = await get(`/invoice/${address}`); + } catch { + // invoice not found + } - if (invoice) { - const recipient = await get(`/users/${invoice.uid}`); - let r = `/pay/${recipient.username}`; - if (amount) r += `/${amount}`; - if (recipient?.id !== user.id) redirect(307, r); - } + if (invoice) { + const recipient = await get(`/users/${invoice.uid}`); + let r = `/pay/${recipient.username}`; + if (amount) r += `/${amount}`; + if (recipient?.id !== user.id) redirect(307, r); + } - return { balance }; + return { balance }; } diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/+page.server.ts index b7d3c5cf..fdf129a0 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+page.server.ts +++ b/src/routes/(app)/send/bitcoin/[address]/+page.server.ts @@ -2,9 +2,9 @@ import getRates from "$lib/rates"; import { auth, get } from "$lib/utils"; export async function load({ cookies, parent }) { - const { user } = await parent(); - const rates = await getRates(); - const aid = cookies.get("aid") || user.id; - const { balance } = await get(`/account/${aid}`, auth(cookies)); - return { balance, rate: rates[user.currency] }; + const { user } = await parent(); + const rates = await getRates(); + const aid = cookies.get("aid") || user.id; + const { balance } = await get(`/account/${aid}`, auth(cookies)); + return { balance, rate: rates[user.currency] }; } diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/+page.svelte index 96b3fbd9..6c49ad6c 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/+page.svelte @@ -34,7 +34,14 @@ <div class="text-xl text-secondary break-all">{address}</div> - <Numpad bind:amount={a} bind:fiat {currency} {submit} bind:rate={$rate} {locale} /> + <Numpad + bind:amount={a} + bind:fiat + {currency} + {submit} + bind:rate={$rate} + {locale} + /> <div class="flex justify-center gap-2"> <button diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts index 9695247b..7cdd86f5 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts +++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts @@ -3,68 +3,68 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ - params: { address, amount, feeRate }, - cookies, - parent, + params: { address, amount, feeRate }, + cookies, + parent, }) { - const rates = await getRates(); - const { user } = await parent(); - const aid = cookies.get("aid") || user.id; - const account = await get(`/account/${aid}`, auth(cookies)); + const rates = await getRates(); + const { user } = await parent(); + const aid = cookies.get("aid") || user.id; + const account = await get(`/account/${aid}`, auth(cookies)); - if (account.type === "ark") { - const serverArkAddress = await get("/ark/address"); - return { - account, - amount, - address, - rate: rates[user.currency], - serverArkAddress, - }; - } + if (account.type === "ark") { + const serverArkAddress = await get("/ark/address"); + return { + account, + amount, + address, + rate: rates[user.currency], + serverArkAddress, + }; + } - try { - const { fee, fees, inputs, ourfee, hex, subtract } = await post( - "/bitcoin/fee", - { address, amount, feeRate, aid }, - auth(cookies), - ); + try { + const { fee, fees, inputs, ourfee, hex, subtract } = await post( + "/bitcoin/fee", + { address, amount, feeRate, aid }, + auth(cookies), + ); - return { - account, - amount, - address, - fee, - fees, - feeRate, - rate: rates[user.currency], - ourfee, - subtract, - hex, - inputs, - }; - } catch (e) { - const { message } = e as Error; - return { amount, address, feeRate, message }; - } + return { + account, + amount, + address, + fee, + fees, + feeRate, + rate: rates[user.currency], + ourfee, + subtract, + hex, + inputs, + }; + } catch (e) { + const { message } = e as Error; + return { amount, address, feeRate, message }; + } } export const actions = { - default: async ({ - cookies, - params: { address, amount, feeRate }, - request, - }) => { - let p; - try { - const body = await fd(request); - p = await post("/bitcoin/send", body, auth(cookies)); - } catch (e) { - console.log("problem sending bitcoin", e); - const { message } = e as Error; - return fail(400, { address, amount, feeRate, message }); - } + default: async ({ + cookies, + params: { address, amount, feeRate }, + request, + }) => { + let p; + try { + const body = await fd(request); + p = await post("/bitcoin/send", body, auth(cookies)); + } catch (e) { + console.log("problem sending bitcoin", e); + const { message } = e as Error; + return fail(400, { address, amount, feeRate, message }); + } - redirect(307, `/sent/${p.id}`); - }, + redirect(307, `/sent/${p.id}`); + }, }; diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte index ecdb3b08..6581e12f 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte @@ -78,7 +78,8 @@ return; } - if ((account.seed || data.user.seed) && !signed) cancel(), void togglePassword(); + if ((account.seed || data.user.seed) && !signed) + (cancel(), void togglePassword()); return async ({ result }) => { if (result.type === "redirect") { goto(result.location); @@ -102,14 +103,18 @@ import("@scure/bip39"), import("@scure/bip39/wordlists/english.js"), ]); - let entropy = await decrypt(account.seed || data.user.seed, password as string); + let entropy = await decrypt( + account.seed || data.user.seed, + password as string, + ); let mnemonic = entropyToMnemonic(entropy, wordlist); let seed = await mnemonicToSeed(mnemonic, password as string); let master = HDKey.fromMasterSeed(seed, network as any); let child = master.derive(`m/84'/0'/${account.accountIndex ?? 0}'`); let raw = decode(hex); - let isPSBT = raw[0] === 0x70 && raw[1] === 0x73 && raw[2] === 0x62 && raw[3] === 0x74; + let isPSBT = + raw[0] === 0x70 && raw[1] === 0x73 && raw[2] === 0x62 && raw[3] === 0x74; let tx: any = isPSBT ? Transaction.fromPSBT(raw) : Transaction.fromRaw(raw); for (let [i, input] of tx.inputs.entries()) { diff --git a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts index 428d8d78..0c4b4d96 100644 --- a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts +++ b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts @@ -5,24 +5,24 @@ import { fail, redirect } from "@sveltejs/kit"; export async function load({ parent, params }) { let { name, amount } = params; if (!name) name = crypto.randomUUID(); - const { user } = await parent(); - const rates = await getRates(); - const rate = rates[user.currency]; - return { name, amount, rate }; + const { user } = await parent(); + const rates = await getRates(); + const rate = rates[user.currency]; + return { name, amount, rate }; } export const actions = { - default: async ({ cookies, request }) => { - const body = await fd(request); - let p; + default: async ({ cookies, request }) => { + const body = await fd(request); + let p; - try { - p = await post("/payments", body, auth(cookies)); - } catch (e) { - const { message } = e as Error; - return fail(400, { message }); - } + try { + p = await post("/payments", body, auth(cookies)); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } - if (p) redirect(307, `/fund/${body.fund}`); - }, + if (p) redirect(307, `/fund/${body.fund}`); + }, }; diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index c9c7dbd9..2e268b99 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -3,76 +3,76 @@ import { auth, fd, get, post, types } from "$lib/utils"; import { error, fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, depends, params: { id }, parent }) { - depends("app:trust"); - const { subject, user } = await parent(); - const aid = cookies.get("aid") || user.id; - const pin = cookies.get("pin"); + depends("app:trust"); + const { user } = await parent(); + const aid = cookies.get("aid") || user.id; + const pin = cookies.get("pin"); - let invoice = await get(`/invoice/${id}`); + let invoice = await get(`/invoice/${id}`); - const trust = await get("/trust", auth(cookies)); - const trusted = trust.includes(invoice.uid); - if (trusted && (pin || !user.haspin)) { - let p; - try { - if (!invoice.tip && invoice.user.prompt) { - if (user.tip > 0) { - invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); - } else { - throw new Error("tip"); - } - } - p = await post("/payments", { ...invoice, pin }, auth(cookies)); - } catch (e) { - const { message } = e as Error; - if (message === "tip") redirect(307, `/invoice/${id}/tip`); - fail(400, { message }); - } - if (p) redirect(307, `/sent/${p.id}`); - } + const trust = await get("/trust", auth(cookies)); + const trusted = trust.includes(invoice.uid); + if (trusted && (pin || !user.haspin)) { + let p; + try { + if (!invoice.tip && invoice.user.prompt) { + if (user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); + } else { + throw new Error("tip"); + } + } + p = await post("/payments", { ...invoice, pin }, auth(cookies)); + } catch (e) { + const { message } = e as Error; + if (message === "tip") redirect(307, `/invoice/${id}/tip`); + fail(400, { message }); + } + if (p) redirect(307, `/sent/${p.id}`); + } - if (invoice.amount && invoice.prompt && invoice.tip === null) - redirect(307, `/invoice/${id}/tip`); + if (invoice.amount && invoice.prompt && invoice.tip === null) + redirect(307, `/invoice/${id}/tip`); - if (invoice.memoPrompt && invoice.memo === null) - redirect(307, `/invoice/${id}/memo`); + if (invoice.memoPrompt && invoice.memo === null) + redirect(307, `/invoice/${id}/memo`); - if (user && invoice.aid === aid) - error(500, { message: "Cannot send to self" }); - else if (user && ![types.lightning, types.bolt12].includes(invoice.type)) - redirect( - 307, - `/send/${invoice.type === types.ecash ? "ecash" : "bitcoin"}/${ - invoice.hash - }`, - ); + if (user && invoice.aid === aid) + error(500, { message: "Cannot send to self" }); + else if (user && ![types.lightning, types.bolt12].includes(invoice.type)) + redirect( + 307, + `/send/${invoice.type === types.ecash ? "ecash" : "bitcoin"}/${ + invoice.hash + }`, + ); - if (!user) redirect(307, `/invoice/${id}`); + if (!user) redirect(307, `/invoice/${id}`); - const rates = await getRates(); - const rate = rates[user.currency]; - const invoiceRate = rates[invoice.currency]; + const rates = await getRates(); + const rate = rates[user.currency]; + const invoiceRate = rates[invoice.currency]; - const { balance } = await get(`/account/${aid}`, auth(cookies)); - return { balance, invoice, user, rate, invoiceRate, trusted }; + const { balance } = await get(`/account/${aid}`, auth(cookies)); + return { balance, invoice, user, rate, invoiceRate, trusted }; } export const actions = { - default: async ({ cookies, params: { id }, request }) => { - let p; - try { - const body = await fd(request); - body.hash = id; - body.aid = cookies.get("aid"); + default: async ({ cookies, params: { id }, request }) => { + let p; + try { + const body = await fd(request); + body.hash = id; + body.aid = cookies.get("aid"); - p = await post("/payments", body, auth(cookies)); - } catch (e) { - const { message } = e as Error; - console.log("payment failed", id, e); - error(500, { message }); - } + p = await post("/payments", body, auth(cookies)); + } catch (e) { + const { message } = e as Error; + console.log("payment failed", id, e); + error(500, { message }); + } - redirect(307, `/sent/${p.id}`); - }, + redirect(307, `/sent/${p.id}`); + }, }; diff --git a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts index 7a5514e8..de123e2e 100644 --- a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts +++ b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts @@ -3,61 +3,61 @@ import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { user } = await parent(); - let data: any = { ...params }; - const rates = await getRates(); - if (!params.payreq.startsWith("lno")) { - data = { ...data, ...(await post("/parse", params, auth(cookies))) }; - } + const { user } = await parent(); + let data: any = { ...params }; + const rates = await getRates(); + if (!params.payreq.startsWith("lno")) { + data = { ...data, ...(await post("/parse", params, auth(cookies))) }; + } - data.rate = rates[user.currency]; + data.rate = rates[user.currency]; - const aid = cookies.get("aid") || user.id; - if (aid !== user.id) { - const account = await get(`/account/${aid}`, auth(cookies)); - if (account.type === "ark") { - data.account = account; - data.serverArkAddress = await get("/ark/address"); - } else if (account.type === "bitcoin") { - data.account = account; - } - } + const aid = cookies.get("aid") || user.id; + if (aid !== user.id) { + const account = await get(`/account/${aid}`, auth(cookies)); + if (account.type === "ark") { + data.account = account; + data.serverArkAddress = await get("/ark/address"); + } else if (account.type === "bitcoin") { + data.account = account; + } + } - return data; + return data; } export const actions = { - setAmount: async ({ cookies, params, request }) => { - let data = await fd(request); - const { payreq } = params; - const { amount } = data; - if (payreq.startsWith("lno")) { - const { invoice } = await post("/fetchinvoice", { - amount, - offer: payreq, - }); + setAmount: async ({ cookies, params, request }) => { + let data = await fd(request); + const { payreq } = params; + const { amount } = data; + if (payreq.startsWith("lno")) { + const { invoice } = await post("/fetchinvoice", { + amount, + offer: payreq, + }); - data = await post("/parse", { payreq: invoice }, auth(cookies)); - data.payreq = invoice; - } + data = await post("/parse", { payreq: invoice }, auth(cookies)); + data.payreq = invoice; + } - return data; - }, + return data; + }, - send: async ({ cookies, request }) => { - let p; - try { - const body = await fd(request); - body.aid = cookies.get("aid"); + send: async ({ cookies, request }) => { + let p; + try { + const body = await fd(request); + body.aid = cookies.get("aid"); - console.log("BODY", body); + console.log("BODY", body); - p = await post("/payments", body, auth(cookies)); - } catch (e) { - const { message } = e as Error; - return fail(400, { message }); - } + p = await post("/payments", body, auth(cookies)); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } - redirect(307, `/sent/${p.id}`); - }, + redirect(307, `/sent/${p.id}`); + }, }; diff --git a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte index 526038fa..718f3ee2 100644 --- a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte @@ -18,8 +18,12 @@ let { currency, locked } = $derived(user); let locale = $derived(loc(user)); - $effect(() => { $rate ||= data.rate; }); - $effect(() => { if (form) loading = false; }); + $effect(() => { + $rate ||= data.rate; + }); + $effect(() => { + if (form) loading = false; + }); let showMax = $state(); let error = $state(""); @@ -33,7 +37,9 @@ let maxfee = $state( Math.max(5, Math.round(untrack(() => amount) * 0.02 || 0)), ); - $effect(() => { maxfee = Math.max(5, Math.round(amount * 0.02) || 0); }); + $effect(() => { + maxfee = Math.max(5, Math.round(amount * 0.02) || 0); + }); let handler = ({ cancel }) => { loading = true; @@ -67,7 +73,11 @@ (async () => { try { const inv = await post("/post/invoice", { - invoice: { type: "bitcoin", amount: parseInt(amount), forward: payreq }, + invoice: { + type: "bitcoin", + amount: parseInt(amount), + forward: payreq, + }, user, }); @@ -126,12 +136,7 @@ </div> {/if} - <form - method="POST" - use:enhance={handler} - action="?/send" - class="space-y-2" - > + <form method="POST" use:enhance={handler} action="?/send" class="space-y-2"> <input name="payreq" value={payreq} type="hidden" /> <input name="amount" value={amount} type="hidden" /> <input name="pin" value={$pin} type="hidden" /> diff --git a/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts b/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts index 2219c370..a658a5c1 100644 --- a/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts +++ b/src/routes/(app)/send/zap/[id]/[...amount]/+page.server.ts @@ -3,41 +3,41 @@ import { auth, fd, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { - const { user } = await parent(); - const { amount, id } = params; - const rates = await getRates(); + const { user } = await parent(); + const { amount, id } = params; + const rates = await getRates(); - let request; - if (amount) - request = await post("/zapRequest", { amount, id }, auth(cookies)); + let request; + if (amount) + request = await post("/zapRequest", { amount, id }, auth(cookies)); - const rate = rates[user.currency]; - return { amount, id, rates, rate, request }; + const rate = rates[user.currency]; + return { amount, id, rates, rate, request }; } export const actions = { - setAmount: async ({ cookies, params, request }) => { - const data = await fd(request); - const { id } = params; - const { amount } = data; + setAmount: async ({ cookies, params, request }) => { + const data = await fd(request); + const { id } = params; + const { amount } = data; - data.request = await post("/zapRequest", { amount, id }, auth(cookies)); + data.request = await post("/zapRequest", { amount, id }, auth(cookies)); - return data; - }, + return data; + }, - send: async ({ cookies, request }) => { - let p; - try { - const body = await fd(request); + send: async ({ cookies, request }) => { + let p; + try { + const body = await fd(request); - p = await post("/payments", body, auth(cookies)); - console.log("P", p); - } catch (_) { - console.log("WHAT", _); - return fail(400, { message: "payments.failedToRoute" }); - } + p = await post("/payments", body, auth(cookies)); + console.log("P", p); + } catch (_) { + console.log("WHAT", _); + return fail(400, { message: "payments.failedToRoute" }); + } - redirect(307, `/sent/${p.id}`); - }, + redirect(307, `/sent/${p.id}`); + }, }; diff --git a/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte b/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte index 78b4d64f..3d0d144c 100644 --- a/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/zap/[id]/[...amount]/+page.svelte @@ -20,7 +20,9 @@ let locale = $derived(loc(user)); let event = $state(); - $effect(() => { $rate ||= data.rate; }); + $effect(() => { + $rate ||= data.rate; + }); $effect(() => { if (form || request) { (async () => { diff --git a/src/routes/(app)/sent/[id]/+page.server.ts b/src/routes/(app)/sent/[id]/+page.server.ts index 31bf4dd1..b27d2ad8 100644 --- a/src/routes/(app)/sent/[id]/+page.server.ts +++ b/src/routes/(app)/sent/[id]/+page.server.ts @@ -1,7 +1,7 @@ import { auth, get } from "$lib/utils"; export const load = async ({ cookies, params }) => { - const { id } = params; - const p = await get(`/payments/${id}`, auth(cookies)); - return p; + const { id } = params; + const p = await get(`/payments/${id}`, auth(cookies)); + return p; }; diff --git a/src/routes/(app)/sent/[id]/+page.svelte b/src/routes/(app)/sent/[id]/+page.svelte index 3dde854f..ba2b7366 100644 --- a/src/routes/(app)/sent/[id]/+page.svelte +++ b/src/routes/(app)/sent/[id]/+page.svelte @@ -10,7 +10,14 @@ let locale = $derived(loc(user)); </script> -<Success {amount} {rate} {tip} {currency} {locale} title={`${$t("payments.sent")}!`} /> +<Success + {amount} + {rate} + {tip} + {currency} + {locale} + title={`${$t("payments.sent")}!`} +/> <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/+layout.server.ts b/src/routes/(app)/settings/+layout.server.ts index bcb7dbe2..29874012 100644 --- a/src/routes/(app)/settings/+layout.server.ts +++ b/src/routes/(app)/settings/+layout.server.ts @@ -2,11 +2,11 @@ import { auth, get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent, url }) { - const { user } = await parent(); - if (!user) redirect(307, `/register?redirect=${url.pathname}`); - const tab = url.pathname.split("/").filter(Boolean).pop(); - if (tab === "settings") redirect(307, `${url.pathname}/account`); - params.cookies = cookies.getAll(); - const subscriptions = await get("/subscriptions", auth(cookies)); - return { cookies: cookies.getAll(), subscriptions, tab }; + const { user } = await parent(); + if (!user) redirect(307, `/register?redirect=${url.pathname}`); + const tab = url.pathname.split("/").filter(Boolean).pop(); + if (tab === "settings") redirect(307, `${url.pathname}/account`); + params.cookies = cookies.getAll(); + const subscriptions = await get("/subscriptions", auth(cookies)); + return { cookies: cookies.getAll(), subscriptions, tab }; } diff --git a/src/routes/(app)/settings/+layout.svelte b/src/routes/(app)/settings/+layout.svelte index a8792333..b670737f 100644 --- a/src/routes/(app)/settings/+layout.svelte +++ b/src/routes/(app)/settings/+layout.svelte @@ -2,7 +2,8 @@ import { browser } from "$app/environment"; import { onMount, tick } from "svelte"; import { fly } from "svelte/transition"; - import { applyAction, deserialize } from "$app/forms"; import Spinner from "$comp/Spinner.svelte"; + import { applyAction, deserialize } from "$app/forms"; + import Spinner from "$comp/Spinner.svelte"; import Pin from "$comp/Pin.svelte"; import { loading, t } from "$lib/translations"; import { fd, fail, auth, post, sleep, warning, success } from "$lib/utils"; @@ -14,8 +15,8 @@ import { getPublicKey } from "nostr-tools"; import { bytesToHex } from "@noble/hashes/utils.js"; - import { SimplePool } from 'nostr-tools/pool'; - import { finalizeEvent } from 'nostr-tools/pure'; + import { SimplePool } from "nostr-tools/pool"; + import { finalizeEvent } from "nostr-tools/pure"; let { children, data, form }: any = $props(); @@ -45,14 +46,15 @@ let submitting = $state(); const pool = new SimplePool(); - import { PUBLIC_DM_RELAYS } from '$env/static/public'; - const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(','); + import { PUBLIC_DM_RELAYS } from "$env/static/public"; + const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(","); const updateRelaysIfAvailable = async () => { - const relayEntry = document.getElementById('dmRelays') as HTMLTextAreaElement | null; + const relayEntry = document.getElementById( + "dmRelays", + ) as HTMLTextAreaElement | null; if (!relayEntry || relayEntry.value.length === 0) return; - const newRelays = relayEntry.value.split(/[ \r\n\t]+/) - .filter(isValidURL); + const newRelays = relayEntry.value.split(/[ \r\n\t]+/).filter(isValidURL); if (newRelays.length === 0) { warning($t("user.settings.noDMURLsWarning")); return; @@ -61,18 +63,18 @@ const event = { kind: 10050, created_at: Math.floor(Date.now() / 1000), - tags: newRelays.map(r => ["relay", r]), - content: "" + tags: newRelays.map((r) => ["relay", r]), + content: "", }; let signed; - if (await window.nostr!.getPublicKey() === user.pubkey) { + if ((await window.nostr!.getPublicKey()) === user.pubkey) { signed = await window.nostr!.signEvent(event); } else { const sk = await getPrivateKey(user); signed = finalizeEvent(event, sk); } await Promise.any(pool.publish(DM_RELAYS_LIST, signed)); - } + }; const isValidURL = (url: string) => { try { @@ -81,7 +83,7 @@ } catch (err: any) { return false; } - } + }; async function handleSubmit(e: any) { updateRelaysIfAvailable(); @@ -122,7 +124,11 @@ if ($avatar) { try { let { hash } = JSON.parse( - await upload(($avatar as any).file, ($avatar as any).type, ($avatar as any).progress) as string, + (await upload( + ($avatar as any).file, + ($avatar as any).type, + ($avatar as any).progress, + )) as string, ); let url = `${$page.url.origin}/api/public/${hash}.webp`; @@ -137,7 +143,11 @@ if ($banner) { try { let { hash } = JSON.parse( - await upload(($banner as any).file, ($banner as any).type, ($banner as any).progress) as string, + (await upload( + ($banner as any).file, + ($banner as any).type, + ($banner as any).progress, + )) as string, ); let url = `${$page.url.origin}/api/public/${hash}.webp`; diff --git a/src/routes/(app)/settings/account/+page.server.ts b/src/routes/(app)/settings/account/+page.server.ts index ebb90f05..33359425 100644 --- a/src/routes/(app)/settings/account/+page.server.ts +++ b/src/routes/(app)/settings/account/+page.server.ts @@ -3,11 +3,11 @@ import updateUser from "$lib/settings"; import { auth, get } from "$lib/utils"; export async function load({ cookies }) { - const rates = await getRates(); - const connect = await get("/square/connect", auth(cookies)); - return { connect, rates }; + const rates = await getRates(); + const connect = await get("/square/connect", auth(cookies)); + return { connect, rates }; } export const actions = { - default: updateUser, + default: updateUser, }; diff --git a/src/routes/(app)/settings/account/+page.svelte b/src/routes/(app)/settings/account/+page.svelte index a3cc24fd..fb182887 100644 --- a/src/routes/(app)/settings/account/+page.svelte +++ b/src/routes/(app)/settings/account/+page.svelte @@ -20,7 +20,8 @@ let fiats = Object.keys(rates).sort((a, b) => a.localeCompare(b)); let el: any; - let keypress = (e: any) => e.key === "Enter" && (e.preventDefault() || el.click()); + let keypress = (e: any) => + e.key === "Enter" && (e.preventDefault() || el.click()); let editingReserve = $state(), editingThreshold = $state(), diff --git a/src/routes/(app)/settings/nostr/+page.server.ts b/src/routes/(app)/settings/nostr/+page.server.ts index 1767ebaf..b4622384 100644 --- a/src/routes/(app)/settings/nostr/+page.server.ts +++ b/src/routes/(app)/settings/nostr/+page.server.ts @@ -2,11 +2,11 @@ import updateUser from "$lib/settings"; import { auth, get } from "$lib/utils"; export const load = async ({ cookies }) => { - const { challenge } = await get("/challenge"); - const apps = await get("/apps", auth(cookies)); - return { apps, challenge }; + const { challenge } = await get("/challenge"); + const apps = await get("/apps", auth(cookies)); + return { apps, challenge }; }; export const actions = { - default: updateUser, + default: updateUser, }; diff --git a/src/routes/(app)/settings/nostr/+page.svelte b/src/routes/(app)/settings/nostr/+page.svelte index ae074d30..c91150a3 100644 --- a/src/routes/(app)/settings/nostr/+page.svelte +++ b/src/routes/(app)/settings/nostr/+page.svelte @@ -15,7 +15,7 @@ let extensionAvailable = $derived(browser && (window as any).nostr); let { locale } = $derived(user); - import { SimplePool } from 'nostr-tools/pool'; + import { SimplePool } from "nostr-tools/pool"; let newNsec = $state(), nsec: any = $state(), @@ -42,11 +42,13 @@ ($save as any).click(); }; - import { PUBLIC_DM_RELAYS } from '$env/static/public'; - const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(','); + import { PUBLIC_DM_RELAYS } from "$env/static/public"; + const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(","); const pool = new SimplePool(); - getPreferredRelays(user.pubkey).then(relays => { - const relayEntry = document.getElementById('dmRelays') as HTMLTextAreaElement | null; + getPreferredRelays(user.pubkey).then((relays) => { + const relayEntry = document.getElementById( + "dmRelays", + ) as HTMLTextAreaElement | null; if (relayEntry) relayEntry.value = relays.join("\n"); }); </script> @@ -78,8 +80,16 @@ class="text-yellow-300" ></iconify-icon> {#if $fiat && $rate} - {f((app.spent * ($rate as number)) / sats, user.currency, locale)} / - {f((app.max_amount * ($rate as number)) / sats, user.currency, locale)} + {f( + (app.spent * ($rate as number)) / sats, + user.currency, + locale, + )} / + {f( + (app.max_amount * ($rate as number)) / sats, + user.currency, + locale, + )} {:else} {s(app.spent, locale)} / {s(app.max_amount, locale)} @@ -177,24 +187,25 @@ <div class="font-bold">{$t("user.nostrPubkey")}</div> <textarea name="pubkey" bind:value={npub} rows={3}></textarea> <div> - <div class="flex my-auto gap-1"> - <button - type="button" - class="my-auto btn btn-circle !w-auto grow" - onclick={() => copy(npub)} - aria-label="Copy" - ><iconify-icon noobserver icon="ph:copy-bold" width="32" - ></iconify-icon> {$t("accounts.copy")}</button - > + <div class="flex my-auto gap-1"> + <button + type="button" + class="my-auto btn btn-circle !w-auto grow" + onclick={() => copy(npub)} + aria-label="Copy" + ><iconify-icon noobserver icon="ph:copy-bold" width="32"></iconify-icon> + {$t("accounts.copy")}</button + > - <a - href={`/qr/${encodeURIComponent(npub)}`} - class="my-auto btn btn-circle !w-auto grow" - aria-label="QR" - > - <iconify-icon noobserver icon="ph:qr-code-bold" width="32"></iconify-icon> -{$t("accounts.qr")} - </a> + <a + href={`/qr/${encodeURIComponent(npub)}`} + class="my-auto btn btn-circle !w-auto grow" + aria-label="QR" + > + <iconify-icon noobserver icon="ph:qr-code-bold" width="32" + ></iconify-icon> + {$t("accounts.qr")} + </a> </div> </div> @@ -245,10 +256,10 @@ {/if} <span class="font-bold" id="dm-relays"> - {$t("user.settings.preferredDM")} + {$t("user.settings.preferredDM")} </span> <p class="text-secondary mb-1"> - {$t("user.settings.preferredDMDescription")} + {$t("user.settings.preferredDMDescription")} </p> <textarea id="dmRelays" name="dmRelays" rows={3}></textarea> diff --git a/src/routes/(app)/settings/profile/+page.server.ts b/src/routes/(app)/settings/profile/+page.server.ts index 4145935e..e3311c99 100644 --- a/src/routes/(app)/settings/profile/+page.server.ts +++ b/src/routes/(app)/settings/profile/+page.server.ts @@ -1,5 +1,5 @@ import updateUser from "$lib/settings"; export const actions = { - default: updateUser, + default: updateUser, }; diff --git a/src/routes/(app)/settings/profile/+page.svelte b/src/routes/(app)/settings/profile/+page.svelte index e7a60677..5cb4f7ae 100644 --- a/src/routes/(app)/settings/profile/+page.svelte +++ b/src/routes/(app)/settings/profile/+page.svelte @@ -86,7 +86,10 @@ >{$t("user.settings.newPassword")}</label > - <PasswordInput bind:value={password} placeholder="(Leave blank to keep unchanged)" /> + <PasswordInput + bind:value={password} + placeholder="(Leave blank to keep unchanged)" + /> </div> <div> @@ -104,7 +107,8 @@ <div class="relative rounded-full overflow-hidden text-center w-20 h-20 my-auto hover:opacity-80 cursor-pointer" onclick={selectAvatar} - onkeydown={(e) => (e.key === "Enter" || e.key === " ") && selectAvatar()} + onkeydown={(e) => + (e.key === "Enter" || e.key === " ") && selectAvatar()} role="button" tabindex="0" > @@ -118,7 +122,8 @@ <div class="rounded-full border-4 border-base-100 p-4 bg-base-200 w-24 h-24 my-auto hover:opacity-80 cursor-pointer" onclick={selectAvatar} - onkeydown={(e) => (e.key === "Enter" || e.key === " ") && selectAvatar()} + onkeydown={(e) => + (e.key === "Enter" || e.key === " ") && selectAvatar()} role="button" tabindex="0" ></div> diff --git a/src/routes/(app)/settings/security/+page.server.ts b/src/routes/(app)/settings/security/+page.server.ts index 4145935e..e3311c99 100644 --- a/src/routes/(app)/settings/security/+page.server.ts +++ b/src/routes/(app)/settings/security/+page.server.ts @@ -1,5 +1,5 @@ import updateUser from "$lib/settings"; export const actions = { - default: updateUser, + default: updateUser, }; diff --git a/src/routes/(app)/settings/security/+page.svelte b/src/routes/(app)/settings/security/+page.svelte index 7ce68d11..193cd91b 100644 --- a/src/routes/(app)/settings/security/+page.svelte +++ b/src/routes/(app)/settings/security/+page.svelte @@ -149,9 +149,15 @@ }; let verifying = $derived(pin?.length > 5); - $effect(() => { if (verify) checkPin(pin as any); }); - $effect(() => { if (setting2fa) enable2fa(token as any); }); - $effect(() => { if (disabling2fa) disable2fa(token as any); }); + $effect(() => { + if (verify) checkPin(pin as any); + }); + $effect(() => { + if (setting2fa) enable2fa(token as any); + }); + $effect(() => { + if (disabling2fa) disable2fa(token as any); + }); </script> <input type="hidden" name="newpin" value={disablingPin ? "delete" : pin} /> @@ -223,12 +229,7 @@ {/if} {#if confirming2fa || disabling2fa} - <Pin - bind:value={token} - title="Enter 2FA Code" - {cancel} - notify={false} - /> + <Pin bind:value={token} title="Enter 2FA Code" {cancel} notify={false} /> {/if} </div> diff --git a/src/routes/(app)/settings/shopify/+page.server.ts b/src/routes/(app)/settings/shopify/+page.server.ts index 4145935e..e3311c99 100644 --- a/src/routes/(app)/settings/shopify/+page.server.ts +++ b/src/routes/(app)/settings/shopify/+page.server.ts @@ -1,5 +1,5 @@ import updateUser from "$lib/settings"; export const actions = { - default: updateUser, + default: updateUser, }; diff --git a/src/routes/(app)/settings/square/+page.server.ts b/src/routes/(app)/settings/square/+page.server.ts index e00bdf1b..5d4c21e6 100644 --- a/src/routes/(app)/settings/square/+page.server.ts +++ b/src/routes/(app)/settings/square/+page.server.ts @@ -2,17 +2,17 @@ import { auth, get } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, url }) { - let connected; + let connected; - const query = url.searchParams.toString(); + const query = url.searchParams.toString(); - try { - await get(`/square/auth?${query}`, auth(cookies)); - connected = true; - } catch (e) { - const { message } = e as Error; - fail(400, { message }); - } + try { + await get(`/square/auth?${query}`, auth(cookies)); + connected = true; + } catch (e) { + const { message } = e as Error; + fail(400, { message }); + } - if (connected) redirect(307, "/settings/account"); + if (connected) redirect(307, "/settings/account"); } diff --git a/src/routes/(app)/sign/+page.server.ts b/src/routes/(app)/sign/+page.server.ts index b0e319f0..ddafcb60 100644 --- a/src/routes/(app)/sign/+page.server.ts +++ b/src/routes/(app)/sign/+page.server.ts @@ -2,22 +2,22 @@ import { auth, fd, post, types } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export async function load({ cookies, parent, url }) { - const { user } = await parent(); - if (!user) redirect(307, `/register?redirect=${url.pathname}`); + const { user } = await parent(); + if (!user) redirect(307, `/register?redirect=${url.pathname}`); - const invoice = { - address_type: "legacy", - type: types.bitcoin, - }; + const invoice = { + address_type: "legacy", + type: types.bitcoin, + }; - const { text: address } = await post("/invoice", { invoice }, auth(cookies)); + const { text: address } = await post("/invoice", { invoice }, auth(cookies)); - return { address }; + return { address }; } export const actions = { - default: async ({ cookies, request }) => { - const body = await fd(request); - return post("/sign", body, auth(cookies)); - }, + default: async ({ cookies, request }) => { + const body = await fd(request); + return post("/sign", body, auth(cookies)); + }, }; diff --git a/src/routes/(app)/subscription/+server.ts b/src/routes/(app)/subscription/+server.ts index 47dfc770..f25db99a 100644 --- a/src/routes/(app)/subscription/+server.ts +++ b/src/routes/(app)/subscription/+server.ts @@ -2,7 +2,7 @@ import { auth, post } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const body = await request.json(); - const result = await post("/subscription", body, auth(cookies)); - return json(result); + const body = await request.json(); + const result = await post("/subscription", body, auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/subscription/delete/+server.ts b/src/routes/(app)/subscription/delete/+server.ts index f4c8357c..1e6c1fdd 100644 --- a/src/routes/(app)/subscription/delete/+server.ts +++ b/src/routes/(app)/subscription/delete/+server.ts @@ -2,7 +2,7 @@ import { auth, post } from "$lib/utils"; import { json } from "@sveltejs/kit"; export async function POST({ cookies, request }) { - const body = await request.json(); - const result = await post("/subscription/delete", body, auth(cookies)); - return json(result); + const body = await request.json(); + const result = await post("/subscription/delete", body, auth(cookies)); + return json(result); } diff --git a/src/routes/(app)/thread/[id]/+page.server.ts b/src/routes/(app)/thread/[id]/+page.server.ts index 931e9cb8..548c43fb 100644 --- a/src/routes/(app)/thread/[id]/+page.server.ts +++ b/src/routes/(app)/thread/[id]/+page.server.ts @@ -2,11 +2,11 @@ import { get } from "$lib/utils"; import { error } from "@sveltejs/kit"; export async function load({ params }) { - try { - const thread = await get(`/thread/${params.id}`); - return { thread }; - } catch (e) { - console.log(e); - error(500, { message: "Failed to get thread" }); - } + try { + const thread = await get(`/thread/${params.id}`); + return { thread }; + } catch (e) { + console.log(e); + error(500, { message: "Failed to get thread" }); + } } diff --git a/src/routes/(app)/verify/[code]/+page.server.ts b/src/routes/(app)/verify/[code]/+page.server.ts index a7edede6..a782d4f8 100644 --- a/src/routes/(app)/verify/[code]/+page.server.ts +++ b/src/routes/(app)/verify/[code]/+page.server.ts @@ -2,13 +2,12 @@ import { get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export const load = async ({ params: { code } }) => { - let user; - try { - user = await get(`/verify/${code}`); - } catch (e) { - console.log(e); - return { error: "Verification failed" }; - } + try { + await get(`/verify/${code}`); + } catch (e) { + console.log(e); + return { error: "Verification failed" }; + } - redirect(307, "/settings/account?verified=true"); + redirect(307, "/settings/account?verified=true"); }; diff --git a/src/routes/(app)/withdraw/+server.ts b/src/routes/(app)/withdraw/+server.ts index 51f6e3d0..f8e093ef 100644 --- a/src/routes/(app)/withdraw/+server.ts +++ b/src/routes/(app)/withdraw/+server.ts @@ -1,10 +1,10 @@ import { auth, post } from "$lib/utils"; export async function POST({ cookies, request }) { - const body = await request.json(); - await post("/payments", body, auth(cookies)); + const body = await request.json(); + await post("/payments", body, auth(cookies)); - return new Response(JSON.stringify("ok"), { - headers: { "content-type": "application/json" }, - }); + return new Response(JSON.stringify("ok"), { + headers: { "content-type": "application/json" }, + }); } |
