aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/ln
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-01 20:04:13 -0800
committerAdam Soltys <[email protected]>2023-12-01 20:04:13 -0800
commit216a600224fde22ce76b367557a02094ec693886 (patch)
treed1189bbaa39db204633523132a7d4767b952717d /src/routes/(app)/ln
parent7d9bc1f54dfd04172e8d6d43ebc2efd6f407e833 (diff)
downloadcoinos-ui-216a600224fde22ce76b367557a02094ec693886.tar.gz
coinos-ui-216a600224fde22ce76b367557a02094ec693886.zip
prettier
Diffstat (limited to 'src/routes/(app)/ln')
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.js96
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.svelte14
-rw-r--r--src/routes/(app)/ln/withdrawal/sent/+page.svelte31
3 files changed, 79 insertions, 62 deletions
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.js b/src/routes/(app)/ln/[lnurl]/+page.server.js
index ddd714bf..332bc9e3 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.js
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.js
@@ -1,63 +1,75 @@
-import { fd, auth, get, post } from '$lib/utils';
-import { error, fail, redirect } from '@sveltejs/kit';
+import { fd, auth, get, post } from "$lib/utils";
+import { error, fail, redirect } from "@sveltejs/kit";
export async function load({ params, parent }) {
- let { user } = await parent();
- if (!user) throw redirect(307, '/register');
+ let { user } = await parent();
+ if (!user) throw redirect(307, "/register");
- let data;
+ let data;
- try {
- let { lnurl } = params;
- data = await get(`/decode?text=${lnurl}`);
- } catch (e) {
- throw error(500, e.message);
- }
+ try {
+ let { lnurl } = params;
+ data = await get(`/decode?text=${lnurl}`);
+ } catch (e) {
+ throw error(500, e.message);
+ }
- if (!['payRequest', 'withdrawRequest'].includes(data.tag))
- throw error(500, 'We only support LNURLp and LNURLw at this time');
+ if (!["payRequest", "withdrawRequest"].includes(data.tag))
+ throw error(500, "We only support LNURLp and LNURLw at this time");
- return data;
+ return data;
}
export const actions = {
- pay: async ({ cookies, fetch, request }) => {
- let error;
+ pay: async ({ cookies, fetch, request }) => {
+ let error;
- let { callback, amount, minSendable, maxSendable } = await fd(request);
- minSendable = Math.round(minSendable / 1000);
- maxSendable = Math.round(maxSendable / 1000);
+ let { callback, amount, minSendable, maxSendable } = await fd(request);
+ minSendable = Math.round(minSendable / 1000);
+ maxSendable = Math.round(maxSendable / 1000);
- if (amount < minSendable) error = `Amount must be at least ${minSendable} sats`;
- if (amount > maxSendable) error = `Amount must be at most ${maxSendable} sats`;
- if (error) return fail(400, { error });
+ if (amount < minSendable)
+ error = `Amount must be at least ${minSendable} sats`;
+ if (amount > maxSendable)
+ error = `Amount must be at most ${maxSendable} sats`;
+ if (error) return fail(400, { error });
- let { pr } = await fetch(`${callback}?amount=${amount * 1000}`).then((r) => r.json());
- throw redirect(307, `/send/lightning/${pr}`);
- },
+ let { pr } = await fetch(`${callback}?amount=${amount * 1000}`).then((r) =>
+ r.json()
+ );
+ throw redirect(307, `/send/lightning/${pr}`);
+ },
- withdraw: async ({ cookies, fetch, request }) => {
- let error;
+ withdraw: async ({ cookies, fetch, request }) => {
+ let error;
- let { callback, amount, username, currency, minWithdrawable, maxWithdrawable, k1 } = await fd(
- request
- );
+ let {
+ callback,
+ amount,
+ username,
+ currency,
+ minWithdrawable,
+ maxWithdrawable,
+ k1,
+ } = await fd(request);
- minWithdrawable = Math.round(minWithdrawable / 1000);
- maxWithdrawable = Math.round(maxWithdrawable / 1000);
+ minWithdrawable = Math.round(minWithdrawable / 1000);
+ maxWithdrawable = Math.round(maxWithdrawable / 1000);
- if (amount < minWithdrawable) error = `Amount must be at least ${minWithdrawable} sats`;
- if (amount > maxWithdrawable) error = `Amount must be at most ${maxWithdrawable} sats`;
- if (error) return fail(400, { error });
+ if (amount < minWithdrawable)
+ error = `Amount must be at least ${minWithdrawable} sats`;
+ if (amount > maxWithdrawable)
+ error = `Amount must be at most ${maxWithdrawable} sats`;
+ if (error) return fail(400, { error });
- let invoice = { amount, type: 'lightning' };
- let user = { username, currency };
+ let invoice = { amount, type: "lightning" };
+ let user = { username, currency };
- let { text: pr } = await post('/invoice', { invoice, user }, auth(cookies));
+ let { text: pr } = await post("/invoice", { invoice, user }, auth(cookies));
- let c = callback.includes('?') ? '&' : '?';
- await fetch(`${callback}${c}k1=${k1}&pr=${pr}`).then((r) => r.json());
+ let c = callback.includes("?") ? "&" : "?";
+ await fetch(`${callback}${c}k1=${k1}&pr=${pr}`).then((r) => r.json());
- throw redirect(307, `/ln/withdrawal/sent`);
- }
+ throw redirect(307, `/ln/withdrawal/sent`);
+ },
};
diff --git a/src/routes/(app)/ln/[lnurl]/+page.svelte b/src/routes/(app)/ln/[lnurl]/+page.svelte
index 7656c9fb..9b733f89 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.svelte
+++ b/src/routes/(app)/ln/[lnurl]/+page.svelte
@@ -1,11 +1,11 @@
<script>
- import { Lnurlp, Lnurlw } from '$comp';
- export let data;
- let { tag } = data;
+ import { Lnurlp, Lnurlw } from "$comp";
+ export let data;
+ let { tag } = data;
</script>
-{#if tag === 'payRequest'}
- <Lnurlp {data} />
-{:else if tag === 'withdrawRequest'}
- <Lnurlw {data} />
+{#if tag === "payRequest"}
+ <Lnurlp {data} />
+{:else if tag === "withdrawRequest"}
+ <Lnurlw {data} />
{/if}
diff --git a/src/routes/(app)/ln/withdrawal/sent/+page.svelte b/src/routes/(app)/ln/withdrawal/sent/+page.svelte
index 84e6a7e0..c527c017 100644
--- a/src/routes/(app)/ln/withdrawal/sent/+page.svelte
+++ b/src/routes/(app)/ln/withdrawal/sent/+page.svelte
@@ -1,23 +1,28 @@
<script>
- import { scale } from 'svelte/transition';
- import { Icon } from '$comp';
- import { toast } from '@zerodevx/svelte-toast';
- import { t } from '$lib/translations';
+ import { scale } from "svelte/transition";
+ import { Icon } from "$comp";
+ import { toast } from "@zerodevx/svelte-toast";
+ import { t } from "$lib/translations";
- export let data;
- let { user } = data;
- toast.pop(0);
+ export let data;
+ let { user } = data;
+ toast.pop(0);
</script>
<div class="text-center mt-20 md:mt-0">
- <div class="flex w-full max-w-[200px] mx-auto py-20" in:scale={{ start: 0.5 }}>
- <Icon icon="check" style="mx-auto" />
- </div>
- <h1 class="text-3xl md:text-4xl font-bold mb-6">Request Sent!</h1>
+ <div
+ class="flex w-full max-w-[200px] mx-auto py-20"
+ in:scale={{ start: 0.5 }}
+ >
+ <Icon icon="check" style="mx-auto" />
+ </div>
+ <h1 class="text-3xl md:text-4xl font-bold mb-6">Request Sent!</h1>
</div>
<a href={`/${user.username}/payments`}>
- <div class="opacity-0 w-screen h-screen fixed top-0 left-0 z-50" />
+ <div class="opacity-0 w-screen h-screen fixed top-0 left-0 z-50" />
</a>
-<div class="fixed bottom-10 w-full text-center">{$t('payments.tapAnywhere')}</div>
+<div class="fixed bottom-10 w-full text-center">
+ {$t("payments.tapAnywhere")}
+</div>