From 4fc61539d923cdee874b07a5f1576dad11bd091a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 18 Jul 2025 08:40:39 -0700 Subject: sweep fiat amounts --- src/routes/(app)/fund/[id]/sweep/+page.server.ts | 31 ----------------- src/routes/(app)/fund/[id]/sweep/+page.svelte | 37 -------------------- .../fund/[id]/sweep/[...amount]/+page.server.ts | 40 ++++++++++++++++++++++ .../(app)/fund/[id]/sweep/[...amount]/+page.svelte | 37 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 68 deletions(-) delete mode 100644 src/routes/(app)/fund/[id]/sweep/+page.server.ts delete mode 100644 src/routes/(app)/fund/[id]/sweep/+page.svelte create mode 100644 src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts create mode 100644 src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte diff --git a/src/routes/(app)/fund/[id]/sweep/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/+page.server.ts deleted file mode 100644 index d8415ca4..00000000 --- a/src/routes/(app)/fund/[id]/sweep/+page.server.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { randomName, randomPassword } from "$lib/random"; -import getRates from "$lib/rates"; -import { auth, get, post, register } from "$lib/utils"; -import { redirect } from "@sveltejs/kit"; - -export async function load({ cookies, request, params, parent }) { - let { user } = await parent(); - const { id } = params; - const { amount } = await get(`/fund/${id}`); - const rates = await getRates(); - const rate = rates[user?.currency || "USD"]; - - const username = randomName(); - const password = randomPassword(); - - if (!amount) redirect(307, `/fund/${id}`); - if (!user) { - const ip = request.headers.get("cf-connecting-ip"); - - user = { - username, - password, - fresh: true, - }; - - await register(user, ip, cookies, `/fund/${id}/sweep`); - } - - await post("/take", { amount, id }, auth(cookies)); - return { amount, id, rate, rates, password }; -} diff --git a/src/routes/(app)/fund/[id]/sweep/+page.svelte b/src/routes/(app)/fund/[id]/sweep/+page.svelte deleted file mode 100644 index adba77ae..00000000 --- a/src/routes/(app)/fund/[id]/sweep/+page.svelte +++ /dev/null @@ -1,37 +0,0 @@ - - -
- -
- - -
-
- -
- {$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 new file mode 100644 index 00000000..61a66fd2 --- /dev/null +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -0,0 +1,40 @@ +import { randomName, randomPassword } from "$lib/random"; +import getRates from "$lib/rates"; +import { auth, get, post, register, sats } from "$lib/utils"; +import { error, redirect } from "@sveltejs/kit"; + +export async function load({ cookies, request, params, parent }) { + let { user } = await parent(); + const { id } = params; + let [amount, currency] = params.amount.split("/"); + + const rates = await getRates(); + const rate = rates[user?.currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); + + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.amount; + } else if (currency) { + amount = (amount * sats) / rate; + } + + const username = randomName(); + const password = randomPassword(); + + if (!amount) redirect(307, `/fund/${id}`); + if (!user) { + const ip = request.headers.get("cf-connecting-ip"); + + user = { + username, + password, + fresh: true, + }; + + await register(user, ip, cookies, `/fund/${id}/sweep`); + } + + await post("/take", { amount, id }, auth(cookies)); + return { amount, id, rate, rates, password }; +} diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte new file mode 100644 index 00000000..adba77ae --- /dev/null +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte @@ -0,0 +1,37 @@ + + +
+ +
+ + +
+
+ +
+ {$t("payments.tapAnywhere")} +
-- cgit v1.2.3