From 25ac9d65b346dafb3b1c733cce44feb1c3564aa8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 16 Jul 2025 00:05:35 -0700 Subject: fix pin issue --- src/locales/en.json | 1 + src/routes/(app)/invoice/[id]/tip/+page.server.ts | 18 +++++++++++----- src/routes/(app)/invoice/[id]/tip/+page.svelte | 12 ++++++++--- src/routes/(app)/send/invoice/[id]/+page.server.ts | 24 ++++++++++++++-------- src/routes/(app)/send/invoice/[id]/+page.svelte | 12 ++++++----- 5 files changed, 46 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/locales/en.json b/src/locales/en.json index 72c3cd41..77b2cb20 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -407,6 +407,7 @@ } }, "payments": { + "custom": "Custom", "trustUser": "Send and enable auto-pay", "gift": "Gift all funds", "giftLink": "Gift link", diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 286d7c35..988b6da5 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,18 +1,19 @@ import invoice from "$lib/invoice"; import getRates from "$lib/rates"; import { auth, get, post } from "$lib/utils"; -import { redirect } from "@sveltejs/kit"; +import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, parent }) { 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) { - if (invoice.prompt && invoice.tip === null && user.tip > 0) { + 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", @@ -21,8 +22,15 @@ export async function load({ cookies, parent }) { ); } - const p = await post("/payments", invoice, auth(cookies)); - redirect(307, `/sent/${p.id}`); + let p; + try { + 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}`); } } diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index d609d86a..97d87bb0 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -127,7 +127,10 @@
-
{s(amount, locale)}
@@ -170,12 +173,15 @@ {/if}
-
+
(showCustomAmount = true)} + >{$t("payments.custom")} + + {$t("payments.cancel")}
{/if} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 18379943..ac3c910e 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -1,24 +1,32 @@ import getRates from "$lib/rates"; import { auth, fd, get, post, types } from "$lib/utils"; -import { error, redirect } from "@sveltejs/kit"; +import { error, fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, depends, params: { id }, parent }) { depends("app:trust"); - const { user } = await parent(); + const { subject, user } = await parent(); const aid = cookies.get("aid") || user.id; + const pin = cookies.get("pin"); - const 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) { + if (trusted && (pin || !user.haspin)) { let p; try { - p = await post("/payments", invoice, auth(cookies)); + if (!invoice.tip && invoice.user.prompt && user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post( + "/invoice", + { invoice, user: subject }, + auth(cookies), + ); + } + p = await post("/payments", { ...invoice, pin }, auth(cookies)); } catch (e) { const { message } = e as Error; - console.log("payment failed", id, e); - error(500, message); + fail(400, { message }); } if (p) redirect(307, `/sent/${p.id}`); } @@ -60,7 +68,7 @@ export const actions = { } catch (e) { const { message } = e as Error; console.log("payment failed", id, e); - error(500, message); + error(500, { message }); } redirect(307, `/sent/${p.id}`); diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 9aac5c8d..d5fd00a8 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -207,10 +207,12 @@ - + + {#if !trusted} + + {/if}
-- cgit v1.2.3