aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-07-19 22:56:05 -0700
committerAdam Soltys <[email protected]>2025-07-19 22:56:05 -0700
commit476418f9711ac91760a9ca279a6e671d88e70fc3 (patch)
tree42bcd2dbf4fb8977baad89a6089924e097a0d921 /src
parentd87ecae6ee46af4790e1f57cd5d82a35ab29e646 (diff)
downloadcoinos-ui-476418f9711ac91760a9ca279a6e671d88e70fc3.tar.gz
coinos-ui-476418f9711ac91760a9ca279a6e671d88e70fc3.zip
handle null tips
Diffstat (limited to 'src')
-rw-r--r--src/lib/invoice.ts2
-rw-r--r--src/lib/parse.ts4
-rw-r--r--src/routes/(app)/[username]/receive/+page.svelte2
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.server.ts24
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.svelte3
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.ts16
6 files changed, 30 insertions, 21 deletions
diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts
index d7576e82..91a69d88 100644
--- a/src/lib/invoice.ts
+++ b/src/lib/invoice.ts
@@ -15,7 +15,7 @@ export default async ({ cookies, request }) => {
items: JSON.parse(form.get("items")),
memo: form.get("memo"),
memoPrompt: form.get("memoPrompt"),
- tip: parseInt(form.get("tip")) || 0,
+ tip: form.get("tip") ?? null,
type: form.get("type"),
prompt: form.get("prompt") === "true",
rate: parseFloat(form.get("rate")) || rates[form.get("currency")],
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index f6405e4a..b4bf837c 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -8,6 +8,7 @@ export default async (s, host) => {
if (!s) return;
let t = s.trim();
let amount;
+ let invoice;
let user;
if (t.startsWith("http")) redirect(307, t);
@@ -57,7 +58,6 @@ export default async (s, host) => {
t = params.get("lightning");
}
- let invoice;
if (t.toLowerCase().startsWith("ln")) {
try {
invoice = await get(`/invoice/${t}`);
@@ -71,6 +71,8 @@ export default async (s, host) => {
}
}
+ if (invoice) redirect(307, `/invoice/${invoice.id}`);
+
if (t.match(/^🥜([\uFE00-\uFE0F]|[\uE0100-\uE01EF]+)$/)) {
t = Array.from(t)
.slice(1)
diff --git a/src/routes/(app)/[username]/receive/+page.svelte b/src/routes/(app)/[username]/receive/+page.svelte
index b5b3153b..9b7ffc00 100644
--- a/src/routes/(app)/[username]/receive/+page.svelte
+++ b/src/routes/(app)/[username]/receive/+page.svelte
@@ -94,7 +94,7 @@
if (typeof $amountPrompt === "undefined") $amountPrompt = true;
amount = newAmount;
invoice.amount = newAmount;
- invoice.tip = 0;
+ invoice.tip = null;
await update();
};
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
index 12582b28..1e159697 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts
+++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
@@ -3,24 +3,40 @@ import getRates from "$lib/rates";
import { auth, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
-export async function load({ cookies, parent }) {
+export async function load({ cookies, params, parent }) {
+ const { id } = params;
const rates = await getRates();
- const { invoice, subject, user } = await parent();
+ let { 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) && user.tip > 0) {
+ if (trusted && (pin || !user.haspin)) {
let p;
+ console.log("YE");
try {
+ if (invoice.tip === null && invoice.user.prompt) {
+ console.log("OHH");
+ 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;
+ console.log("MSG", message);
+ if (message === "tip") redirect(307, `/invoice/${id}/tip`);
fail(400, { message });
}
-
if (p) redirect(307, `/sent/${p.id}`);
}
}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte
index 97d87bb0..4f0f306f 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.svelte
+++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte
@@ -102,7 +102,7 @@
<input type="hidden" name="tip" value={tip} />
<input type="hidden" name="username" value={username} />
<input type="hidden" name="rate" value={invoice.rate} />
- <input type="hidden" name="prompt" value="false" />
+ <input type="hidden" name="prompt" value={invoice.prompt} />
<input type="hidden" name="type" value={type} />
<input type="hidden" name="hash" value={hash} />
<input type="hidden" name="items" value={JSON.stringify(items)} />
@@ -180,7 +180,6 @@
onclick={() => (showCustomAmount = true)}
>{$t("payments.custom")}</button
>
-
<a href={`/invoice/${id}`} class="btn">{$t("payments.cancel")}</a>
</div>
{/if}
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts
index b77a84e7..84aa415e 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.ts
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts
@@ -1,6 +1,6 @@
import { PUBLIC_DOMAIN } from "$env/static/public";
import getRates from "$lib/rates";
-import { auth, fd, get, post, types } from "$lib/utils";
+import { auth, fd, get, post } from "$lib/utils";
import { bech32 } from "@scure/base";
import { error, fail, redirect } from "@sveltejs/kit";
const { decode, fromWords } = bech32;
@@ -23,17 +23,6 @@ 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 (tag === "payRequest" && minSendable === maxSendable) {
minSendable = Math.round(minSendable / 1000);
maxSendable = Math.round(maxSendable / 1000);
@@ -50,6 +39,9 @@ export async function load({ params, parent }) {
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))