From ae87f1d43c6d2cf34bd2ea6fd7b4d28af6d2aa91 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 10 Nov 2023 21:33:49 -0800 Subject: nav update --- src/routes/(app)/fund/[id]/+page.server.js | 23 ++++ src/routes/(app)/fund/[id]/+page.svelte | 138 +++++++++++++++++++++ src/routes/(app)/fund/[id]/sweep/+page.server.js | 14 +++ src/routes/(app)/fund/[id]/sweep/+page.svelte | 37 ++++++ .../(app)/fund/[id]/withdraw/+page.server.js | 20 +++ src/routes/(app)/fund/[id]/withdraw/+page.svelte | 58 +++++++++ src/routes/(app)/fund/[id]/withdraw/+server.js | 6 + 7 files changed, 296 insertions(+) create mode 100644 src/routes/(app)/fund/[id]/+page.server.js create mode 100644 src/routes/(app)/fund/[id]/+page.svelte create mode 100644 src/routes/(app)/fund/[id]/sweep/+page.server.js create mode 100644 src/routes/(app)/fund/[id]/sweep/+page.svelte create mode 100644 src/routes/(app)/fund/[id]/withdraw/+page.server.js create mode 100644 src/routes/(app)/fund/[id]/withdraw/+page.svelte create mode 100644 src/routes/(app)/fund/[id]/withdraw/+server.js (limited to 'src/routes/(app)/fund') diff --git a/src/routes/(app)/fund/[id]/+page.server.js b/src/routes/(app)/fund/[id]/+page.server.js new file mode 100644 index 00000000..4194deed --- /dev/null +++ b/src/routes/(app)/fund/[id]/+page.server.js @@ -0,0 +1,23 @@ +import { error, redirect } from '@sveltejs/kit'; +import { auth, get, post } from '$lib/utils'; +import Qr from 'qrcode-base64'; + +export let load = async ({ params: { id }, url }) => { + let { amount, payments } = await get(`/fund/${id}`); + + let src = Qr.drawImg(url.href, { size: 300 }); + return { amount, payments, src }; +}; + +export const actions = { + default: async ({ cookies, locals, params, request }) => { + let { user } = locals; + + if (user) { + await post('/redeem', params, auth(cookies)); + throw redirect(307, `/${user.username}/payments`); + } + + throw redirect(307, '/register'); + } +}; diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte new file mode 100644 index 00000000..d2d3079c --- /dev/null +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -0,0 +1,138 @@ + + +
+
+
+
+ + {#if id.split('-').length === 4} +

Card {id}

+ {:else} + Fund +
+

{$t('payments.fund')}

+

{id}

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

+ {f(amountFiat, currency)} +

+

+ {sat(amount)} +

+
+
+ +
+ + +
+ +
+
+
diff --git a/src/routes/(app)/fund/[id]/sweep/+page.server.js b/src/routes/(app)/fund/[id]/sweep/+page.server.js new file mode 100644 index 00000000..9fd244a3 --- /dev/null +++ b/src/routes/(app)/fund/[id]/sweep/+page.server.js @@ -0,0 +1,14 @@ +import { get, auth, post } from '$lib/utils'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ cookies, params, parent }) { + let { user } = await parent(); + let { id } = params; + let { amount } = await get(`/fund/${id}`); + + + if (!amount) throw redirect(307, `/fund/${id}`); + if (!user) throw redirect(307, `/register?redirect=/fund/${id}/sweep`); + await post('/take', { amount, id }, auth(cookies)); + return { amount, id }; +} diff --git a/src/routes/(app)/fund/[id]/sweep/+page.svelte b/src/routes/(app)/fund/[id]/sweep/+page.svelte new file mode 100644 index 00000000..64bed4dd --- /dev/null +++ b/src/routes/(app)/fund/[id]/sweep/+page.svelte @@ -0,0 +1,37 @@ + + +
+
+ + + +
+ +
+ +
+

{$t('payments.fundsClaimed')}

+

+ {f(fiat(amount, rate), currency)} +

+

+ ⚡️{s(amount)} +

+
+ + +
+ + +
{$t('payments.tapAnywhere')}
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.server.js b/src/routes/(app)/fund/[id]/withdraw/+page.server.js new file mode 100644 index 00000000..476149f2 --- /dev/null +++ b/src/routes/(app)/fund/[id]/withdraw/+page.server.js @@ -0,0 +1,20 @@ +import { fail, json, redirect } from '@sveltejs/kit'; +import { fd, auth, post } from '$lib/utils'; + +export async function load({ parent }) { + let { user } = await parent(); + if (!user) throw redirect(307, '/register'); +} + +export const actions = { + default: async ({ cookies, request }) => { + let body = await fd(request); + try { + await post('/take', body, auth(cookies)); + } catch (e) { + return fail(400, { message: e.message }); + } + + throw 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 new file mode 100644 index 00000000..9cad945a --- /dev/null +++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte @@ -0,0 +1,58 @@ + + + + +{#if form?.message} +
+ {form.message} +
+{/if} + +
+ + +
+ + + + +
+ +
+
+
diff --git a/src/routes/(app)/fund/[id]/withdraw/+server.js b/src/routes/(app)/fund/[id]/withdraw/+server.js new file mode 100644 index 00000000..0f9a23f3 --- /dev/null +++ b/src/routes/(app)/fund/[id]/withdraw/+server.js @@ -0,0 +1,6 @@ +import { json } from '@sveltejs/kit'; +import { auth, post } from '$lib/utils'; + +export async function POST({ cookies, request }) { + return json(await post('/take', await request.json(), auth(cookies))); +} -- cgit v1.2.3