From 633e3a3d94777440f07ed00a88abc1ac388bb2f0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 10 Aug 2025 18:53:09 -0700 Subject: authorizations --- .../[id]/authorize/[...amount]/+page.server.ts | 36 ++++++++++++++++++++++ .../fund/[id]/authorize/[...amount]/+page.svelte | 27 ++++++++++++++++ .../fund/[id]/sweep/[...amount]/+page.server.ts | 7 +++-- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts create mode 100644 src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte (limited to 'src') diff --git a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts new file mode 100644 index 00000000..e5683ae6 --- /dev/null +++ b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts @@ -0,0 +1,36 @@ +import getRates from "$lib/rates"; +import { auth, get, post, sats } from "$lib/utils"; +import { error, redirect } from "@sveltejs/kit"; + +export async function load({ cookies, params, parent }) { + const { user } = await parent(); + const { id } = params; + let [amount, currency] = params.amount.split("/"); + let fiat; + + if (!currency) currency = user?.currency; + if (currency) currency = currency.toUpperCase(); + + const rates = await getRates(); + const rate = rates[currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); + + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.amount; + } else if (currency) { + fiat = amount; + amount = Math.round((fiat * sats) / rate); + } + + if (!amount) redirect(307, `/fund/${id}`); + + try { + await post("/authorize", { amount, currency, fiat, id }, auth(cookies)); + } catch (e) { + console.log("caught", e); + redirect(307, `/fund/${id}`); + } + + return { amount, currency, id, rate, rates }; +} diff --git a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte new file mode 100644 index 00000000..b94c1ce9 --- /dev/null +++ b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte @@ -0,0 +1,27 @@ + + +
+ +
+ + +
+
+ +
+ {$t("payments.tapAnywhere")} +
diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index 47dfdaab..78df3461 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -9,15 +9,16 @@ export async function load({ cookies, request, params, parent }) { let [amount, currency] = params.amount.split("/"); if (!currency) currency = user?.currency; + if (currency) currency = currency.toUpperCase(); const rates = await getRates(); - const rate = rates[currency?.toUpperCase() || "USD"]; + const rate = rates[currency || "USD"]; if (currency && !rate) error(500, "Invalid currency symbol"); if (!amount) { const balance = await get(`/fund/${id}`); - amount = balance.amount; + amount = balance.authorization || balance.amount; } else if (currency) { - amount = (amount * sats) / rate; + amount = Math.round((amount * sats) / rate); } const username = randomName() + Math.floor(Math.random() * 99) + 1; -- cgit v1.2.3