diff options
| author | Adam Soltys <[email protected]> | 2025-07-19 17:59:56 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-07-19 18:07:57 -0700 |
| commit | d87ecae6ee46af4790e1f57cd5d82a35ab29e646 (patch) | |
| tree | 5fa86b7b8902315f625eca493861f3ad97de5a5c /src/routes/(app)/invoice | |
| parent | fea147df07046f240e77075e7c743959d85b1271 (diff) | |
| download | coinos-ui-d87ecae6ee46af4790e1f57cd5d82a35ab29e646.tar.gz coinos-ui-d87ecae6ee46af4790e1f57cd5d82a35ab29e646.zip | |
prompt for tip for auto pays
Diffstat (limited to 'src/routes/(app)/invoice')
| -rw-r--r-- | src/routes/(app)/invoice/[id]/+layout.server.ts | 28 | ||||
| -rw-r--r-- | src/routes/(app)/invoice/[id]/tip/+page.server.ts | 13 |
2 files changed, 18 insertions, 23 deletions
diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index 590e5d4d..d6ab979e 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -12,25 +12,29 @@ export async function load({ cookies, depends, params, url, parent }) { if (id) { invoice = await get(`/invoice/${id}`); const options = !!url.searchParams.get("options"); - - if ( - user && - invoice.uid !== user.id && - !(url.pathname.includes("tip") || url.pathname.includes("memo")) && - !options - ) { - redirect(307, `/send/invoice/${id}`); - } - let { amount, pending, received } = invoice; amount = parseInt(amount); - subject = invoice.user; 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" : "")); + if (invoice.uid === user.id) + redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); + else redirect(307, `/pay/${subject.username}/${invoice.amount}`); + } + + subject = invoice.user; + + if ( + user && + invoice.uid !== user.id && + !(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}`); } } diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 988b6da5..12582b28 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -5,23 +5,14 @@ import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, parent }) { const rates = await getRates(); - let { invoice, subject, user } = await parent(); + const { 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)) { - if (!invoice.prompt && invoice.user.prompt && user.tip > 0) { - invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post( - "/invoice", - { invoice, user: subject }, - auth(cookies), - ); - } - + if (trusted && (pin || !user.haspin) && user.tip > 0) { let p; try { p = await post("/payments", { ...invoice, pin }, auth(cookies)); |
