From e69768ba8e777fd0b2778aad73e17267870226ea Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 1 Dec 2023 20:04:13 -0800 Subject: prettier --- .../user/[username]/[...amount]/+page.server.js | 81 +++++----- .../send/user/[username]/[...amount]/+page.svelte | 166 ++++++++++----------- 2 files changed, 124 insertions(+), 123 deletions(-) (limited to 'src/routes/(app)/send/user') diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js index a01cdcfc..1f3a0420 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js @@ -1,46 +1,47 @@ -import { error, fail, redirect } from '@sveltejs/kit'; -import { types, sats, fd, auth, get, post } from '$lib/utils'; +import { error, fail, redirect } from "@sveltejs/kit"; +import { types, sats, fd, auth, get, post } from "$lib/utils"; export async function load({ cookies, params, parent }) { - let subject = await get(`/users/${params.username}`); - - let { rates, user } = await parent(); - let { username } = params; - let [amount, currency] = params.amount.split('/'); - - if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' }); - - let rate; - if (amount) { - rate = rates[currency ? currency.toUpperCase() : subject.currency]; - if (!rate) throw error(500, 'Invalid currency symbol'); - if (currency) amount = (amount * sats) / rate; - - let { hash } = await post( - '/invoice', - { - invoice: { amount, prompt: false, type: types.lightning }, - user: { username } - }, - auth(cookies) - ); - - throw redirect(307, `/${username}/invoice/${hash}`); - } - - return { amount, rate, subject }; + let subject = await get(`/users/${params.username}`); + + let { rates, user } = await parent(); + let { username } = params; + let [amount, currency] = params.amount.split("/"); + + if (subject.username === user?.username) + throw error(500, { message: "Cannot send to self" }); + + let rate; + if (amount) { + rate = rates[currency ? currency.toUpperCase() : subject.currency]; + if (!rate) throw error(500, "Invalid currency symbol"); + if (currency) amount = (amount * sats) / rate; + + let { hash } = await post( + "/invoice", + { + invoice: { amount, prompt: false, type: types.lightning }, + user: { username }, + }, + auth(cookies) + ); + + throw redirect(307, `/${username}/invoice/${hash}`); + } + + return { amount, rate, subject }; } export const actions = { - default: async ({ cookies, request }) => { - try { - let body = await fd(request); - await post('/payments', body, auth(cookies)); - } catch (e) { - console.log(e); - return fail(400, { message: e.message }); - } - - throw redirect(307, '/sent'); - } + default: async ({ cookies, request }) => { + try { + let body = await fd(request); + await post("/payments", body, auth(cookies)); + } catch (e) { + console.log(e); + return fail(400, { message: e.message }); + } + + throw redirect(307, "/sent"); + }, }; diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte index 32a13939..cb458323 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte @@ -1,103 +1,103 @@ {#if form?.message} -
- {form.message} -
+
+ {form.message} +
{/if}
- + -
- - - - + + + + + -
- {#if amount} - - {:else} - - {/if} -
-
+
+ {#if amount} + + {:else} + + {/if} +
+
-- cgit v1.2.3