diff options
| author | Adam Soltys <[email protected]> | 2025-07-19 22:56:05 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-07-19 22:56:05 -0700 |
| commit | 476418f9711ac91760a9ca279a6e671d88e70fc3 (patch) | |
| tree | 42bcd2dbf4fb8977baad89a6089924e097a0d921 /src/routes/(app)/invoice | |
| parent | d87ecae6ee46af4790e1f57cd5d82a35ab29e646 (diff) | |
| download | coinos-ui-476418f9711ac91760a9ca279a6e671d88e70fc3.tar.gz coinos-ui-476418f9711ac91760a9ca279a6e671d88e70fc3.zip | |
handle null tips
Diffstat (limited to 'src/routes/(app)/invoice')
| -rw-r--r-- | src/routes/(app)/invoice/[id]/tip/+page.server.ts | 24 | ||||
| -rw-r--r-- | src/routes/(app)/invoice/[id]/tip/+page.svelte | 3 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 12582b28..1e159697 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -3,24 +3,40 @@ import getRates from "$lib/rates"; import { auth, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -export async function load({ cookies, parent }) { +export async function load({ cookies, params, parent }) { + const { id } = params; const rates = await getRates(); - const { invoice, subject, user } = await parent(); + 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) && user.tip > 0) { + if (trusted && (pin || !user.haspin)) { let p; + console.log("YE"); try { + if (invoice.tip === null && invoice.user.prompt) { + console.log("OHH"); + if (user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post( + "/invoice", + { invoice, user: subject }, + auth(cookies), + ); + } else { + throw new Error("tip"); + } + } p = await post("/payments", { ...invoice, pin }, auth(cookies)); } catch (e) { const { message } = e as Error; + console.log("MSG", message); + if (message === "tip") redirect(307, `/invoice/${id}/tip`); fail(400, { message }); } - if (p) redirect(307, `/sent/${p.id}`); } } diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index 97d87bb0..4f0f306f 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -102,7 +102,7 @@ <input type="hidden" name="tip" value={tip} /> <input type="hidden" name="username" value={username} /> <input type="hidden" name="rate" value={invoice.rate} /> - <input type="hidden" name="prompt" value="false" /> + <input type="hidden" name="prompt" value={invoice.prompt} /> <input type="hidden" name="type" value={type} /> <input type="hidden" name="hash" value={hash} /> <input type="hidden" name="items" value={JSON.stringify(items)} /> @@ -180,7 +180,6 @@ onclick={() => (showCustomAmount = true)} >{$t("payments.custom")}</button > - <a href={`/invoice/${id}`} class="btn">{$t("payments.cancel")}</a> </div> {/if} |
