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)/send/invoice | |
| parent | 3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff) | |
| download | coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip | |
linting
Diffstat (limited to 'src/routes/(app)/send/invoice')
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.ts | 118 |
1 files changed, 59 insertions, 59 deletions
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}`); + }, }; |
