aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
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/routes
parentd87ecae6ee46af4790e1f57cd5d82a35ab29e646 (diff)
downloadcoinos-ui-476418f9711ac91760a9ca279a6e671d88e70fc3.tar.gz
coinos-ui-476418f9711ac91760a9ca279a6e671d88e70fc3.zip
handle null tips
Diffstat (limited to 'src/routes')
-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
4 files changed, 26 insertions, 19 deletions
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))