From 23f0335aeb26b56d835a7134227e43f8798fc3c5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 24 Dec 2024 00:41:51 -0800 Subject: create fund --- src/routes/(app)/fund/[id]/+page.server.ts | 7 +- src/routes/(app)/fund/[id]/+page.svelte | 137 ++++++--------------- .../(app)/fund/[id]/withdraw/+page.server.ts | 15 ++- src/routes/(app)/fund/[id]/withdraw/+page.svelte | 59 +++++---- src/routes/(app)/ln/[lnurl]/+page.server.ts | 9 +- src/routes/(app)/payment/[id]/+page.svelte | 6 +- src/routes/(app)/payments/[...page]/+page.svelte | 110 ++--------------- src/routes/(app)/qr/[text]/+page.svelte | 2 +- src/routes/(app)/send/[...text]/+page.svelte | 8 ++ .../fund/[...name]/[...amount]/+page.server.ts | 28 +++++ .../send/fund/[...name]/[...amount]/+page.svelte | 70 +++++++++++ .../send/fund/[name]/[...amount]/+page.server.ts | 17 --- .../send/fund/[name]/[...amount]/+page.svelte | 66 ---------- 13 files changed, 214 insertions(+), 320 deletions(-) create mode 100644 src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts create mode 100644 src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte delete mode 100644 src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts delete mode 100644 src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte (limited to 'src/routes/(app)') diff --git a/src/routes/(app)/fund/[id]/+page.server.ts b/src/routes/(app)/fund/[id]/+page.server.ts index 668ea3af..9ea33627 100644 --- a/src/routes/(app)/fund/[id]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/+page.server.ts @@ -2,9 +2,12 @@ import getRates from "$lib/rates"; import { auth, get, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export const load = async ({ params: { id } }) => { +export const load = async ({ depends, params: { id }, parent }) => { + depends("app:payments"); const data = await get(`/fund/${id}`); - data.rate = await getRates(); + const rates = await getRates(); + const { user } = await parent(); + data.rate = rates[user?.currency || "USD"]; return data; }; diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index 23dce871..f99b17d7 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -1,28 +1,33 @@
@@ -30,117 +35,55 @@
-
- - {#if id.split("-").length === 4} -

Card {id}

- {:else} - Fund -
-

- {$t("payments.fund")} -

-

{id}

-
- {/if} -
{#if show} - {id} +
+ URL +
{/if}
-
-

- {f(amountFiat, currency)} -

-

- {sat(amount)} -

-
+
- - -
- +
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts index 1e477918..696c52ff 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts +++ b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts @@ -1,9 +1,15 @@ +import getRates from "$lib/rates"; +import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -import { fd, auth, post } from "$lib/utils"; -export async function load({ parent }) { +export async function load({ params, parent }) { const { user } = await parent(); if (!user) redirect(307, "/register"); + const rates = await getRates(); + const rate = rates[user.currency]; + const fund = await get(`/fund/${params.id}`); + const { amount: balance } = fund; + return { ...params, balance, rate }; } export const actions = { @@ -11,8 +17,9 @@ export const actions = { const body = await fd(request); try { await post("/take", body, auth(cookies)); - } catch (e: any) { - return fail(400, { message: e.message }); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); } redirect(307, `/fund/${body.id}`); diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.svelte b/src/routes/(app)/fund/[id]/withdraw/+page.svelte index 89654d23..f6f12b1a 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.svelte +++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte @@ -1,40 +1,35 @@ - + let setMax = (e) => { + e.preventDefault(); + fiat = false; + amount = balance; + }; + {#if form?.message}
@@ -43,22 +38,32 @@ {/if}
- + -
+ -
+
+ +
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts index 681137ad..53445461 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.ts +++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts @@ -7,10 +7,12 @@ export async function load({ params, parent }) { if (!user) redirect(307, "/register"); const rates = await getRates(); + console.log("YO"); let data; try { const { lnurl } = params; data = await get(`/decode?text=${lnurl}`); + console.log("DATA", data); } catch (e) { const { message } = e as Error; error(500, message); @@ -76,8 +78,11 @@ export const actions = { auth(cookies), ); - const c = callback.includes("?") ? "&" : "?"; - await fetch(`${callback}${c}k1=${k1}&pr=${pr}`).then((r) => r.json()); + const url = new URL(callback); + url.searchParams.append("k1", k1); + url.searchParams.append("pr", pr); + + await fetch(url.toString()); redirect(307, "/payments"); }, diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index 279b87e7..63b8ccca 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -112,7 +112,11 @@
- Pot +
{p.memo}
diff --git a/src/routes/(app)/payments/[...page]/+page.svelte b/src/routes/(app)/payments/[...page]/+page.svelte index d53c13c0..09bdf4c7 100644 --- a/src/routes/(app)/payments/[...page]/+page.svelte +++ b/src/routes/(app)/payments/[...page]/+page.svelte @@ -1,6 +1,6 @@
diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index ebc705b5..261a1784 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -94,6 +94,14 @@
{$t("payments.createEcash")}
+ + + + {#if contacts.length} diff --git a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts new file mode 100644 index 00000000..428d8d78 --- /dev/null +++ b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts @@ -0,0 +1,28 @@ +import getRates from "$lib/rates"; +import { auth, fd, post } from "$lib/utils"; +import { fail, redirect } from "@sveltejs/kit"; + +export async function load({ parent, params }) { + let { name, amount } = params; + if (!name) name = crypto.randomUUID(); + const { user } = await parent(); + const rates = await getRates(); + const rate = rates[user.currency]; + return { name, amount, rate }; +} + +export const actions = { + default: async ({ cookies, request }) => { + const body = await fd(request); + let p; + + try { + p = await post("/payments", body, auth(cookies)); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } + + if (p) redirect(307, `/fund/${body.fund}`); + }, +}; diff --git a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte new file mode 100644 index 00000000..314be3ef --- /dev/null +++ b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte @@ -0,0 +1,70 @@ + + +{#if form?.message} +
+ {form.message} +
+{/if} + +
+ + +
+ + + + +
+ + + +
+
+
diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts deleted file mode 100644 index ed39f96b..00000000 --- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { fail, redirect } from "@sveltejs/kit"; -import { auth, fd, post } from "$lib/utils"; - -export const actions = { - default: async ({ cookies, request }) => { - const body = await fd(request); - let p; - - try { - p = await post("/payments", body, auth(cookies)); - } catch (e: any) { - return fail(400, { message: e.message }); - } - - if (p) redirect(307, `/fund/${body.name}`); - }, -}; diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte b/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte deleted file mode 100644 index d1c3b204..00000000 --- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte +++ /dev/null @@ -1,66 +0,0 @@ - - - - -{#if form?.message} -
- {form.message} -
-{/if} - -
- - -
- - - - -
- -
-
-
-- cgit v1.2.3