From 2d9d01d6e8d63ee223078874aa3b101b016367ac Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 8 Jul 2025 10:16:22 -0700 Subject: auto pay --- src/routes/(app)/send/[...text]/+page.svelte | 37 +++++++++++++++++----- src/routes/(app)/send/invoice/[id]/+page.server.ts | 14 ++++++-- src/routes/(app)/send/invoice/[id]/+page.svelte | 21 +++++++++++- 3 files changed, 60 insertions(+), 12 deletions(-) (limited to 'src/routes/(app)/send') diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index e5c77647..ae718f7e 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -51,6 +51,20 @@ invalidate("app:contacts"); }; + let trust = async (e, { id, trusted }) => { + e.preventDefault(); + e.stopPropagation(); + + if (trusted) { + await post("/post/trust/delete", { id }); + } else { + await post("/post/trust", { id }); + } + + if (all) all = await get("/contacts"); + invalidate("app:contacts"); + }; + $effect(() => { if (browser && pasted && text) el.click() && (pasted = false); }); @@ -73,7 +87,7 @@ {/if} - +
+
+ + +
{/each} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 3ef933d4..4bb7ded5 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -2,11 +2,19 @@ import getRates from "$lib/rates"; import { auth, fd, get, post, types } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; -export async function load({ cookies, params: { id }, parent }) { +export async function load({ cookies, depends, params: { id }, parent }) { + depends("app:trust"); const { user } = await parent(); const aid = cookies.get("aid") || user.id; - 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) { + const p = await post("/payments", invoice, auth(cookies)); + redirect(307, `/sent/${p.id}`); + } if (invoice.amount && invoice.prompt && invoice.tip === null) redirect(307, `/invoice/${id}/tip`); @@ -31,7 +39,7 @@ export async function load({ cookies, params: { id }, parent }) { const invoiceRate = rates[invoice.currency]; const { balance } = await get(`/account/${aid}`, auth(cookies)); - return { balance, invoice, user, rate, invoiceRate }; + return { balance, invoice, user, rate, invoiceRate, trusted }; } export const actions = { diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 7d167f41..9aac5c8d 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -1,4 +1,5 @@