aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/ln
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
committerAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
commit13466248004327e9a026cb89f94926f9b060d1c1 (patch)
tree47b4972c33809ccdf866b043c92cd3e0ecf5dcd0 /src/routes/(app)/ln
parent3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff)
downloadcoinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz
coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip
linting
Diffstat (limited to 'src/routes/(app)/ln')
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.ts176
1 files changed, 88 insertions, 88 deletions
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts
index 7348f96c..ae784401 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.ts
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts
@@ -6,120 +6,120 @@ import { error, fail, redirect } from "@sveltejs/kit";
const { decode, fromWords } = bech32;
export async function load({ params, parent }) {
- const { user } = await parent();
- const rates = await getRates();
+ const { user } = await parent();
+ const rates = await getRates();
- let data;
- const { lnurl } = params;
+ let data;
+ const { lnurl } = params;
- const url = Buffer.from(fromWords(decode(lnurl, 20000).words)).toString();
+ const url = Buffer.from(fromWords(decode(lnurl, 20000).words)).toString();
- try {
- data = await get(`/decode?text=${lnurl}`);
- } catch (e) {
- const { message } = e as Error;
- error(500, message);
- }
+ try {
+ data = await get(`/decode?text=${lnurl}`);
+ } catch (e) {
+ const { message } = e as Error;
+ error(500, message);
+ }
- let { callback, minSendable, maxSendable, comment, tag } = data;
- if (tag === "payRequest" && minSendable === maxSendable) {
- minSendable = Math.round(minSendable / 1000);
- maxSendable = Math.round(maxSendable / 1000);
- const amount = minSendable;
+ let { callback, minSendable, maxSendable, comment, tag } = data;
+ if (tag === "payRequest" && minSendable === maxSendable) {
+ minSendable = Math.round(minSendable / 1000);
+ maxSendable = Math.round(maxSendable / 1000);
+ const amount = minSendable;
- const urlObj = new URL(callback);
- urlObj.searchParams.set("amount", (amount * 1000).toString());
- if (comment) {
- urlObj.searchParams.set("comment", comment);
- }
- const url = urlObj.toString();
+ const urlObj = new URL(callback);
+ urlObj.searchParams.set("amount", (amount * 1000).toString());
+ if (comment) {
+ urlObj.searchParams.set("comment", comment);
+ }
+ const url = urlObj.toString();
- const { pr } = await fetch(url).then((r) => (r as Response).json());
+ const { pr } = await fetch(url).then((r) => (r as Response).json());
- let invoice;
- try {
- invoice = await get(`/invoice/${pr}`);
- } catch (e) {}
+ let invoice;
+ try {
+ invoice = await get(`/invoice/${pr}`);
+ } catch {}
- if (invoice) redirect(307, `/invoice/${invoice.id}`);
+ if (invoice) redirect(307, `/invoice/${invoice.id}`);
- let path = `/send/lightning/${pr}`;
- if (comment) path += `/${encodeURIComponent(comment)}`;
- redirect(307, path);
- } else if (callback.includes(PUBLIC_DOMAIN)) {
- const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1];
- redirect(307, `/pay/${username}`);
- }
+ let path = `/send/lightning/${pr}`;
+ if (comment) path += `/${encodeURIComponent(comment)}`;
+ redirect(307, path);
+ } else if (callback.includes(PUBLIC_DOMAIN)) {
+ const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1];
+ redirect(307, `/pay/${username}`);
+ }
- 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");
- data.rate = rates[user?.currency || "USD"];
- return data;
+ data.rate = rates[user?.currency || "USD"];
+ 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}`;
- const { pr } = await fetch(url).then((r) => r.json());
+ const { pr } = await fetch(url).then((r) => r.json());
- let path = `/send/lightning/${pr}`;
- if (comment) path += `/${encodeURIComponent(comment)}`;
- redirect(307, path);
- },
+ let path = `/send/lightning/${pr}`;
+ if (comment) path += `/${encodeURIComponent(comment)}`;
+ redirect(307, path);
+ },
- 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 });
- const invoice = { amount, type: "lightning" };
- const user = { username, currency };
+ const invoice = { amount, type: "lightning" };
+ const user = { username, currency };
- const { text: pr } = await post(
- "/invoice",
- { invoice, user },
- auth(cookies),
- );
+ const { text: pr } = await post(
+ "/invoice",
+ { invoice, user },
+ auth(cookies),
+ );
- const url = new URL(callback);
- url.searchParams.append("k1", k1);
- url.searchParams.append("pr", pr);
+ const url = new URL(callback);
+ url.searchParams.append("k1", k1);
+ url.searchParams.append("pr", pr);
- await fetch(url.toString());
+ await fetch(url.toString());
- redirect(307, "/payments");
- },
+ redirect(307, "/payments");
+ },
};