aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/ln
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-31 09:34:16 -0700
committerAdam Soltys <[email protected]>2024-10-31 09:34:16 -0700
commit243abb0a3d29e8e34e263eec843488e3bdb468a4 (patch)
treebe55931ba0f3c110c3001f56a5339cb63e78b761 /src/routes/(app)/ln
parent4742e72ec25823ceeea7848fb2e1f868bed7f472 (diff)
downloadcoinos-ui-243abb0a3d29e8e34e263eec843488e3bdb468a4.tar.gz
coinos-ui-243abb0a3d29e8e34e263eec843488e3bdb468a4.zip
biome
Diffstat (limited to 'src/routes/(app)/ln')
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.ts110
1 files changed, 57 insertions, 53 deletions
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts
index 4ac55e44..b405f427 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.ts
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts
@@ -2,76 +2,80 @@ 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) redirect(307, "/register");
+ const { user } = await parent();
+ if (!user) redirect(307, "/register");
- let data;
+ let data;
- try {
- let { lnurl } = params;
- data = await get(`/decode?text=${lnurl}`);
- } catch (e: any) {
- error(500, e.message);
- }
+ try {
+ const { lnurl } = params;
+ data = await get(`/decode?text=${lnurl}`);
+ } catch (e: any) {
+ error(500, e.message);
+ }
- if (!["payRequest", "withdrawRequest"].includes(data.tag))
- error(500, "We only support LNURLp and LNURLw at this time");
+ if (!["payRequest", "withdrawRequest"].includes(data.tag))
+ error(500, "We only support LNURLp and LNURLw at this time");
- return data;
+ return data;
}
export const actions = {
- pay: async ({ fetch, request }) => {
- let error;
+ pay: async ({ fetch, request }) => {
+ let error;
- let { callback, amount, minSendable, maxSendable, comment } =
- await fd(request);
- minSendable = Math.round(minSendable / 1000);
- maxSendable = Math.round(maxSendable / 1000);
+ let { callback, amount, minSendable, maxSendable, comment } =
+ 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 url = `${callback}?amount=${amount * 1000}`;
- if (comment) url += `&comment=${comment}`;
+ let url = `${callback}?amount=${amount * 1000}`;
+ if (comment) url += `&comment=${comment}`;
- let { pr } = await fetch(url).then((r) => r.json());
- redirect(307, `/send/lightning/${pr}`);
- },
+ const { pr } = await fetch(url).then((r) => r.json());
+ 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 };
+ const invoice = { amount, type: "lightning" };
+ const user = { username, currency };
- let { text: pr } = await post("/invoice", { invoice, user }, auth(cookies));
+ const { 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());
+ const c = callback.includes("?") ? "&" : "?";
+ await fetch(`${callback}${c}k1=${k1}&pr=${pr}`).then((r) => r.json());
- redirect(307, `/payments`);
- },
+ redirect(307, "/payments");
+ },
};