aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts11
-rw-r--r--src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte3
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.ts28
3 files changed, 25 insertions, 17 deletions
diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts
index 61a66fd2..8a8e71ee 100644
--- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts
+++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts
@@ -8,8 +8,9 @@ export async function load({ cookies, request, params, parent }) {
const { id } = params;
let [amount, currency] = params.amount.split("/");
+ if (!currency) currency = user?.currency;
const rates = await getRates();
- const rate = rates[user?.currency || "USD"];
+ const rate = rates[currency?.toUpperCase() || "USD"];
if (currency && !rate) error(500, "Invalid currency symbol");
if (!amount) {
@@ -35,6 +36,10 @@ export async function load({ cookies, request, params, parent }) {
await register(user, ip, cookies, `/fund/${id}/sweep`);
}
- await post("/take", { amount, id }, auth(cookies));
- return { amount, id, rate, rates, password };
+ try {
+ await post("/take", { amount, id }, auth(cookies));
+ } catch (e) {
+ redirect(307, `/fund/${id}`);
+ }
+ return { amount, currency, id, rate, rates, password };
}
diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte
index adba77ae..7a7d5402 100644
--- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte
+++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte
@@ -11,8 +11,7 @@
let { data } = $props();
- let { amount, id, user, rate, rates, password: pw } = data;
- let { currency } = user;
+ let { amount, currency, id, user, rate, rates, password: pw } = data;
let locale = $derived(loc(user));
onMount(() => ($password = pw));
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts
index 1ee182b1..b77a84e7 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.ts
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts
@@ -23,17 +23,17 @@ export async function load({ params, parent }) {
}
let { callback, minSendable, maxSendable, comment, tag } = data;
- if (callback.includes(PUBLIC_DOMAIN)) {
- const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1];
- // const inv = await post("/invoice", {
- // invoice: { type: types.lightning, amount: minSendable / 1000 },
- // user: { username },
- // });
- // const { id: iid } = inv;
- let redir = `/pay/${username}`;
- if (minSendable === maxSendable && minSendable > 0) redir += `/${minSendable / 1000}`;
- redirect(307, redir);
- }
+ // if (callback.includes(PUBLIC_DOMAIN)) {
+ // const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1];
+ // // const inv = await post("/invoice", {
+ // // invoice: { type: types.lightning, amount: minSendable / 1000 },
+ // // user: { username },
+ // // });
+ // // const { id: iid } = inv;
+ // let redir = `/pay/${username}`;
+ // if (minSendable === maxSendable && minSendable > 0) redir += `/${minSendable / 1000}`;
+ // redirect(307, redir);
+ // }
if (tag === "payRequest" && minSendable === maxSendable) {
minSendable = Math.round(minSendable / 1000);
maxSendable = Math.round(maxSendable / 1000);
@@ -43,7 +43,10 @@ export async function load({ params, parent }) {
if (comment) url += `&comment=${comment}`;
const { pr } = await fetch(url).then((r) => (r as Response).json());
- console.log("PR", pr);
+
+ const invoice = await get(`/invoice/${pr}`);
+ if (invoice) redirect(307, `/invoice/${invoice.id}`);
+
let path = `/send/lightning/${pr}`;
if (comment) path += `/${encodeURIComponent(comment)}`;
redirect(307, path);
@@ -75,6 +78,7 @@ export const actions = {
if (comment) url += `&comment=${comment}`;
const { pr } = await fetch(url).then((r) => r.json());
+
let path = `/send/lightning/${pr}`;
if (comment) path += `/${encodeURIComponent(comment)}`;
redirect(307, path);