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/locales/en.json | 3 ++ src/routes/(app)/fund/[id]/+page.svelte | 2 +- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 21 ++++++++++-- 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 +++++++++++- src/routes/(app)/settings/account/+page.svelte | 15 ++++++++- 7 files changed, 97 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/locales/en.json b/src/locales/en.json index c4ca5e17..922d24b3 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -296,6 +296,8 @@ "placeholder": "Enter an address, invoice or username" }, "settings": { + "tip": "Default tip", + "tipDesc": "Default tip percentage when auto-paying trusted users", "nostr": "Nostr", "name": "Name", "integrations": "Integrations", @@ -398,6 +400,7 @@ } }, "payments": { + "trustUser": "Send and enable auto-pay", "sweep": "Sweep link", "lockedBalance": "Locked balance", "insufficientFunds": "Insufficient funds", diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index 614616af..7f465512 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -112,7 +112,7 @@
{$t("payments.shareLink")}
+
+ + +
{/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 @@