aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/invoice
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/(app)/invoice')
-rw-r--r--src/routes/(app)/invoice/+page.server.ts2
-rw-r--r--src/routes/(app)/invoice/[id]/+layout.ts (renamed from src/routes/(app)/invoice/[id]/+layout.server.ts)25
-rw-r--r--src/routes/(app)/invoice/[id]/+page.svelte4
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.server.ts5
4 files changed, 21 insertions, 15 deletions
diff --git a/src/routes/(app)/invoice/+page.server.ts b/src/routes/(app)/invoice/+page.server.ts
index 9cf2088a..db54ff8b 100644
--- a/src/routes/(app)/invoice/+page.server.ts
+++ b/src/routes/(app)/invoice/+page.server.ts
@@ -5,7 +5,7 @@ import { error, redirect } from "@sveltejs/kit";
export const load = async ({ cookies, parent, url }) => {
const aid = url.searchParams.get("aid") || cookies.get("aid");
- if (aid) cookies.set("aid", aid, { path: "/", maxAge: 86400 });
+ if (aid) cookies.set("aid", aid, { path: "/", maxAge: 86400, httpOnly: false });
let { subject, user } = await parent();
const lnurl = url.searchParams.has("lnurl");
diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.ts
index 24b7f1b0..411486c7 100644
--- a/src/routes/(app)/invoice/[id]/+layout.server.ts
+++ b/src/routes/(app)/invoice/[id]/+layout.ts
@@ -1,24 +1,23 @@
-import getRates from "$lib/rates";
import { get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-export async function load({ cookies, depends, params, url, parent }) {
+export async function load({ params, url, parent, depends }) {
depends("app:invoice");
- const token = cookies.get("token");
- let { subject, user } = await parent();
+ const { user, token, theme } = await parent();
const { id } = params;
let invoice;
+ let subject;
if (id === "lnurl") {
- const rates = await getRates();
+ subject = user;
invoice = {
aid: user.id,
uid: user.id,
amount: 0,
tip: 0,
- rate: rates[user?.currency || "USD"],
- text: "",
+ rate: 0,
+ text: `${user.username}@${url.host}`,
hash: "",
type: "lightning",
items: [],
@@ -42,7 +41,6 @@ export async function load({ cookies, depends, params, url, parent }) {
subject = invoice.user;
- const aid = cookies.get("aid") || user?.id;
if (
user &&
invoice.uid !== user?.id &&
@@ -56,6 +54,13 @@ export async function load({ cookies, depends, params, url, parent }) {
}
}
- const theme = cookies.get("theme") || "light";
- return { id, invoice, subject, user, token, theme };
+ let qrDataUrl: string | undefined;
+ if (invoice?.text) {
+ try {
+ const QRCode = await import("qrcode");
+ qrDataUrl = await QRCode.toDataURL(invoice.text, { width: 600, margin: 1 });
+ } catch {}
+ }
+
+ return { id, invoice, subject, user, token, theme, qrDataUrl };
}
diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte
index 988ba647..7ce7c4e8 100644
--- a/src/routes/(app)/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/invoice/[id]/+page.svelte
@@ -32,7 +32,7 @@
let user = $derived(data.user);
let hasArk = $derived(data.hasArk);
let invoice = $derived(data.invoice);
- let src = $derived(data.src);
+ let qrDataUrl = $derived(data.qrDataUrl);
let { aid, amount, rate, tip, hash, text, type } = $derived(invoice);
let memo = $state();
let { username, currency } = $derived(invoice.user);
@@ -185,7 +185,7 @@
<div class="invoice container mx-auto max-w-xl px-4 pb-4 space-y-2">
<InvoiceData
- {src}
+ {qrDataUrl}
{link}
{txt}
invoice={displayInvoice}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
index 91ccebca..84b218f3 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts
+++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
@@ -4,8 +4,9 @@ import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
const { id } = params;
- const rates = await getRates();
- let { invoice, subject, user } = await parent();
+ const [rates, { user }] = await Promise.all([getRates(), parent()]);
+ let invoice = await get(`/invoice/${id}`, auth(cookies));
+ const subject = invoice.user;
if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`);
const pin = cookies.get("pin");