From eb66f787b48a2a52ece890e356fd022380f64c2e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 20 Aug 2025 23:20:02 -0700 Subject: set tip --- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 27 +++++++++++++--------- src/routes/(app)/invoice/[id]/tip/+page.svelte | 13 +---------- src/routes/(app)/send/invoice/[id]/+page.server.ts | 6 +---- 3 files changed, 18 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 1e159697..23e3a07c 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,6 +1,5 @@ -import invoice from "$lib/invoice"; import getRates from "$lib/rates"; -import { auth, get, post } from "$lib/utils"; +import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { @@ -15,17 +14,11 @@ export async function load({ cookies, params, parent }) { const trusted = trust.includes(invoice.uid); 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), - ); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); } else { throw new Error("tip"); } @@ -33,7 +26,6 @@ export async function load({ cookies, params, parent }) { 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 }); } @@ -47,5 +39,18 @@ export async function load({ cookies, params, parent }) { } export const actions = { - default: invoice, + 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), + ); + + 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 4f0f306f..a1ea3586 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -97,19 +97,8 @@
- - + - - - - - - - - {#if invoice.memoPrompt} - - {/if}

{$t("invoice.addTipq")}

{#if !showCustomAmount} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 38507343..70b007a8 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -18,11 +18,7 @@ export async function load({ cookies, depends, params: { id }, parent }) { if (!invoice.tip && invoice.user.prompt) { if (user.tip > 0) { invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post( - "/invoice", - { invoice, user: subject }, - auth(cookies), - ); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); } else { throw new Error("tip"); } -- cgit v1.2.3