aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/parse.ts11
-rw-r--r--src/routes/(app)/[username]/accepted/[text]/+page.server.ts1
-rw-r--r--src/routes/(app)/invoice/[id]/+layout.server.ts28
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.server.ts13
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.server.ts19
5 files changed, 35 insertions, 37 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index ba264be7..f6405e4a 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -57,10 +57,11 @@ export default async (s, host) => {
t = params.get("lightning");
}
+ let invoice;
if (t.toLowerCase().startsWith("ln")) {
try {
- const inv = await get(`/invoice/${t}`);
- if (inv.user.username === "mint") throw new Error("mint payment");
+ invoice = await get(`/invoice/${t}`);
+ if (invoice.user.username === "mint") throw new Error("mint payment");
} catch (e) {
if (t.toLowerCase().startsWith("lno")) {
const { offer_amount_msat: a } = await get(`/decode/${t}`);
@@ -115,11 +116,9 @@ export default async (s, host) => {
if (fund) redirect(307, `/send/fund/${t}`);
- // invoice
- let invoice;
try {
- invoice = await get(`/invoice/${t}`);
+ invoice ||= await get(`/invoice/${t}`);
} catch (e) {}
- if (invoice) redirect(307, `/send/invoice/${invoice.id}`);
+ if (invoice) redirect(307, `/invoice/${invoice.id}`);
};
diff --git a/src/routes/(app)/[username]/accepted/[text]/+page.server.ts b/src/routes/(app)/[username]/accepted/[text]/+page.server.ts
index ca23ae53..aa25ce7f 100644
--- a/src/routes/(app)/[username]/accepted/[text]/+page.server.ts
+++ b/src/routes/(app)/[username]/accepted/[text]/+page.server.ts
@@ -2,6 +2,5 @@ export async function load({ params, url }) {
const { text } = params;
const query = new URLSearchParams(url.search);
const nfc = !!query.get("nfc");
- console.log("NFC", nfc);
return { nfc, text };
}
diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts
index 590e5d4d..d6ab979e 100644
--- a/src/routes/(app)/invoice/[id]/+layout.server.ts
+++ b/src/routes/(app)/invoice/[id]/+layout.server.ts
@@ -12,25 +12,29 @@ export async function load({ cookies, depends, params, url, parent }) {
if (id) {
invoice = await get(`/invoice/${id}`);
const options = !!url.searchParams.get("options");
-
- if (
- user &&
- invoice.uid !== user.id &&
- !(url.pathname.includes("tip") || url.pathname.includes("memo")) &&
- !options
- ) {
- redirect(307, `/send/invoice/${id}`);
- }
-
let { amount, pending, received } = invoice;
amount = parseInt(amount);
- subject = invoice.user;
const paid =
(!amount && (pending || received)) ||
(amount > 0 && (pending >= amount || received >= amount));
if (paid && !url.pathname.endsWith("paid")) {
- redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : ""));
+ if (invoice.uid === user.id)
+ redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : ""));
+ else redirect(307, `/pay/${subject.username}/${invoice.amount}`);
+ }
+
+ subject = invoice.user;
+
+ if (
+ user &&
+ invoice.uid !== user.id &&
+ !(url.pathname.includes("tip") || url.pathname.includes("memo")) &&
+ !options
+ ) {
+ if (invoice.prompt && invoice.tip === null)
+ redirect(307, `/invoice/${id}/tip`);
+ else redirect(307, `/send/invoice/${id}`);
}
}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
index 988b6da5..12582b28 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts
+++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
@@ -5,23 +5,14 @@ import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, parent }) {
const rates = await getRates();
- let { invoice, subject, user } = await parent();
+ const { invoice, subject, user } = await parent();
if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`);
const pin = cookies.get("pin");
if (user) {
const trust = await get("/trust", auth(cookies));
const trusted = trust.includes(invoice.uid);
- if (trusted && (pin || !user.haspin)) {
- if (!invoice.prompt && invoice.user.prompt && user.tip > 0) {
- invoice.tip = Math.round(invoice.amount * (user.tip / 100));
- invoice = await post(
- "/invoice",
- { invoice, user: subject },
- auth(cookies),
- );
- }
-
+ if (trusted && (pin || !user.haspin) && user.tip > 0) {
let p;
try {
p = await post("/payments", { ...invoice, pin }, auth(cookies));
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts
index ac3c910e..38507343 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.server.ts
+++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts
@@ -15,17 +15,22 @@ export async function load({ cookies, depends, params: { id }, parent }) {
if (trusted && (pin || !user.haspin)) {
let p;
try {
- if (!invoice.tip && invoice.user.prompt && user.tip > 0) {
- invoice.tip = Math.round(invoice.amount * (user.tip / 100));
- invoice = await post(
- "/invoice",
- { invoice, user: subject },
- auth(cookies),
- );
+ if (!invoice.tip && invoice.user.prompt) {
+ if (user.tip > 0) {
+ invoice.tip = Math.round(invoice.amount * (user.tip / 100));
+ invoice = await post(
+ "/invoice",
+ { invoice, user: subject },
+ auth(cookies),
+ );
+ } else {
+ throw new Error("tip");
+ }
}
p = await post("/payments", { ...invoice, pin }, auth(cookies));
} catch (e) {
const { message } = e as Error;
+ if (message === "tip") redirect(307, `/invoice/${id}/tip`);
fail(400, { message });
}
if (p) redirect(307, `/sent/${p.id}`);