From 2d9d01d6e8d63ee223078874aa3b101b016367ac Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 8 Jul 2025 10:16:22 -0700 Subject: auto pay --- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index c3be68f0..de24c639 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,12 +1,29 @@ import invoice from "$lib/invoice"; import getRates from "$lib/rates"; +import { auth, get, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export async function load({ parent }) { +export async function load({ cookies, parent }) { const rates = await getRates(); - const { invoice, subject } = await parent(); + let { invoice, subject, user } = await parent(); if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); + const trust = await get("/trust", auth(cookies)); + const trusted = trust.includes(invoice.uid); + if (trusted) { + if (invoice.prompt && invoice.tip === null && user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post( + "/invoice", + { invoice, user: subject }, + auth(cookies), + ); + } + + const p = await post("/payments", invoice, auth(cookies)); + redirect(307, `/sent/${p.id}`); + } + const rate = rates[subject?.currency]; const invoiceRate = rates[invoice.currency]; return { rate, invoiceRate }; -- cgit v1.2.3 From 5b458624745c7ea80d1e63c9a6ef77075763ff5f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 10 Jul 2025 12:36:50 -0700 Subject: user onboarding --- .../app/src/main/java/io/coinos/MainActivity.java | 5 ++ .../java/io/coinos/nfcwriter/NfcWriterPlugin.java | 62 ++++++++++++++++++++++ capacitor.config.json | 7 ++- src/lib/utils.ts | 2 +- src/locales/en.json | 7 ++- src/routes/(app)/+layout.svelte | 45 ++++++++++------ src/routes/(app)/[username]/(profile)/+page.svelte | 22 +++++++- src/routes/(app)/fund/[id]/sweep/+page.server.ts | 10 ++-- src/routes/(app)/fund/[id]/sweep/+page.svelte | 6 ++- src/routes/(app)/funder/+page.svelte | 55 +++++++++++++++++++ src/routes/(app)/invoice/[id]/tip/+page.server.ts | 28 +++++----- src/routes/(app)/settings/profile/+page.svelte | 16 +++++- src/routes/(app)/settings/security/+page.svelte | 12 ----- 13 files changed, 225 insertions(+), 52 deletions(-) create mode 100644 android/app/src/main/java/io/coinos/nfcwriter/NfcWriterPlugin.java create mode 100644 src/routes/(app)/funder/+page.svelte (limited to 'src/routes/(app)/invoice') diff --git a/android/app/src/main/java/io/coinos/MainActivity.java b/android/app/src/main/java/io/coinos/MainActivity.java index 501d2e0f..271ee363 100644 --- a/android/app/src/main/java/io/coinos/MainActivity.java +++ b/android/app/src/main/java/io/coinos/MainActivity.java @@ -23,11 +23,16 @@ import android.nfc.NfcAdapter; import java.nio.charset.Charset; import java.util.Arrays; +import io.coinos.nfcwriter.NfcWriterPlugin; + public class MainActivity extends BridgeActivity { + private NfcAdapter nfcAdapter; + @Override protected void onCreate(Bundle savedInstanceState) { // ✅ Let Capacitor inflate its layout and wire everything super.onCreate(savedInstanceState); + registerPlugin(NfcWriterPlugin.class); WebView webView = bridge.getWebView(); // This works *after* super.onCreate() diff --git a/android/app/src/main/java/io/coinos/nfcwriter/NfcWriterPlugin.java b/android/app/src/main/java/io/coinos/nfcwriter/NfcWriterPlugin.java new file mode 100644 index 00000000..d2954e9b --- /dev/null +++ b/android/app/src/main/java/io/coinos/nfcwriter/NfcWriterPlugin.java @@ -0,0 +1,62 @@ +// src/android/NfcWriterPlugin.java +package io.coinos.nfcwriter; + +import android.nfc.NfcAdapter; +import android.nfc.Tag; +import android.nfc.NfcAdapter.ReaderCallback; +import android.os.Bundle; +import android.util.Log; + +import com.getcapacitor.Plugin; +import com.getcapacitor.PluginCall; +import com.getcapacitor.PluginMethod; +import com.getcapacitor.annotation.CapacitorPlugin; + +@CapacitorPlugin(name = "NfcWriter") +public class NfcWriterPlugin extends Plugin { + private NfcAdapter nfcAdapter; + + @Override + public void load() { + super.load(); + nfcAdapter = NfcAdapter.getDefaultAdapter(getContext()); + } + + @PluginMethod + public void enableExclusiveNfcMode(PluginCall call) { + if (nfcAdapter == null) { + call.reject("NFC adapter not available"); + return; + } + + nfcAdapter.enableReaderMode( + getActivity(), + new ReaderCallback() { + @Override + public void onTagDiscovered(Tag tag) { + Log.d("NfcWriter", "Tag discovered"); + bridge.getWebView().post(() -> { + bridge.getWebView().evaluateJavascript( + "window.dispatchEvent(new CustomEvent('nativeNfcTagDiscovered'))", + null + ); + }); + } + }, + NfcAdapter.FLAG_READER_NFC_A | + NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK | + NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS, + null + ); + + call.resolve(); + } + + @PluginMethod + public void disableExclusiveNfcMode(PluginCall call) { + if (nfcAdapter != null) { + nfcAdapter.disableReaderMode(getActivity()); + } + call.resolve(); + } +} diff --git a/capacitor.config.json b/capacitor.config.json index a31c19db..99458def 100644 --- a/capacitor.config.json +++ b/capacitor.config.json @@ -2,13 +2,16 @@ "appId": "io.coinos", "appName": "Coinos", "server": { - "hostname": "coinos.io", - "url": "https://coinos.io/start" + "hostname": "dev.coinos.io", + "url": "https://dev.coinos.io/start" }, "android": { "webContentsDebuggingEnabled": true, "allowMixedContent": true, "useBrowserHistory": true, "immersive": false + }, + "plugins": { + "NfcWriter": {} } } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 31d93fde..28a219e1 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -486,5 +486,5 @@ export const register = async (user, ip, cookies, loginRedirect) => { }); if (error) return svelteFail(400, { error }); - redirect(303, loginRedirect || `/${user.username}`); + redirect(303, loginRedirect || `/${user.username}`); }; diff --git a/src/locales/en.json b/src/locales/en.json index 922d24b3..88de69da 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -350,7 +350,12 @@ "locale": "Language", "username": "Username", "email": "Email", - "newPassword": "Change Password", + "newPassword": "New Password", + "newPasswordDesc": "(Leave blank to keep unchanged)", + "yourUsername": "Your username is", + "yourPassword": "and your password is", + "welcome": "Welcome!", + "clickBelow": "Click below to finish setting up your account", "about": "About", "aboutPlaceholder": "A little something about you or your business address and hours", "emailNotifications": "Email Notifications", diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index af4dbf2c..830e5291 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -46,22 +46,35 @@ checkSocket(); $pin = getCookie("pin"); - if (window.NDEFReader && user.nfc) { - try { - $ndef = new NDEFReader(); - await $ndef.scan(); - - $ndef.addEventListener("readingerror", (e) => { - console.log("nfc error", e); - }); - - $ndef.addEventListener("reading", ({ message, serialNumber }) => { - goto(`/send/${message}`); - }); - } catch (error) { - console.log("Argh! " + error); - } - } + // if (window.NDEFReader) { + // try { + // $ndef = new NDEFReader(); + // await $ndef.scan(); + // + // $ndef.addEventListener("readingerror", (e) => { + // console.log("nfc error", e); + // }); + // + // $ndef.addEventListener("reading", ({ message, serialNumber }) => { + // console.log("MESSAGE", message); + // + // const record = message.records[0]; + // + // if (record.recordType === "url") { + // const textDecoder = new TextDecoder(); + // const url = textDecoder.decode(record.data); + // console.log("URL:", url); + // + // // Navigate to the URL or use it however you want + // goto(`/send/${encodeURIComponent(url)}`); + // } else { + // console.error("Unsupported record type:", record.recordType); + // } + // }); + // } catch (error) { + // console.log("Argh! " + error); + // } + // } } }); diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index d064c3a9..31320197 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -6,7 +6,7 @@ import Account from "$comp/Account.svelte"; import Balance from "$comp/Balance.svelte"; import { t } from "$lib/translations"; - import { installPrompt } from "$lib/store"; + import { installPrompt, password } from "$lib/store"; import { afterNavigate, preloadData } from "$app/navigation"; import { page } from "$app/stores"; @@ -32,6 +32,24 @@
+ {#if user?.fresh} +
+

{$t("user.settings.welcome")}

+
+ {$t("user.settings.yourUsername")} {user?.username} + {#if $password} + {$t("user.settings.yourPassword")} + {$password}{/if} +
+ +
{$t("user.settings.clickBelow")}
+ + + + Settings +
+ {/if} {#if user?.id && user.id === subject.id}
{#each accounts as account, i} @@ -55,6 +73,8 @@ {/if}
+ +
{#if user?.username !== subject.username && (!subject.anon || subject.lud16)} + import { onMount } from "svelte"; + import { password } from "$lib/store"; import Amount from "$comp/Amount.svelte"; import Success from "$comp/Success.svelte"; import { scale } from "svelte/transition"; @@ -9,9 +11,11 @@ let { data } = $props(); - let { amount, id, user, rate, rates } = data; + let { amount, id, user, rate, rates, password: pw } = data; let { currency } = user; let locale = $derived(loc(user)); + + onMount(() => ($password = pw));
diff --git a/src/routes/(app)/funder/+page.svelte b/src/routes/(app)/funder/+page.svelte new file mode 100644 index 00000000..e6549360 --- /dev/null +++ b/src/routes/(app)/funder/+page.svelte @@ -0,0 +1,55 @@ + + +HI + +{#if here}HERE{/if} +{#if ready}go{/if} +{#if success}done{/if} diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index de24c639..286d7c35 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -8,20 +8,22 @@ export async function load({ cookies, parent }) { let { invoice, subject, user } = await parent(); if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); - const trust = await get("/trust", auth(cookies)); - const trusted = trust.includes(invoice.uid); - if (trusted) { - if (invoice.prompt && invoice.tip === null && user.tip > 0) { - invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post( - "/invoice", - { invoice, user: subject }, - auth(cookies), - ); - } + if (user) { + const trust = await get("/trust", auth(cookies)); + const trusted = trust.includes(invoice.uid); + if (trusted) { + if (invoice.prompt && invoice.tip === null && user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post( + "/invoice", + { invoice, user: subject }, + auth(cookies), + ); + } - const p = await post("/payments", invoice, auth(cookies)); - redirect(307, `/sent/${p.id}`); + const p = await post("/payments", invoice, auth(cookies)); + redirect(307, `/sent/${p.id}`); + } } const rate = rates[subject?.currency]; diff --git a/src/routes/(app)/settings/profile/+page.svelte b/src/routes/(app)/settings/profile/+page.svelte index bee50d39..ec9855d0 100644 --- a/src/routes/(app)/settings/profile/+page.svelte +++ b/src/routes/(app)/settings/profile/+page.svelte @@ -3,16 +3,18 @@ import { avatar, banner as bannerStore } from "$lib/store"; import { t } from "$lib/translations"; import { page } from "$app/stores"; + import PasswordInput from "$comp/PasswordInput.svelte"; let { data } = $props(); let { user } = $derived(data); let { id } = user; - let { about, banner, picture, display, username } = - $state(user); + let { about, banner, picture, display, username } = $state(user); let avatarFile, avatarInput = $state(), bannerFile, + password = $state(), + revealPassword = $state(), bannerInput = $state(); let selectAvatar = () => avatarInput.click(); @@ -64,6 +66,16 @@
+ + +
+ + + +
+
- - -
- - - -
Date: Wed, 16 Jul 2025 00:05:35 -0700 Subject: fix pin issue --- src/locales/en.json | 1 + src/routes/(app)/invoice/[id]/tip/+page.server.ts | 18 +++++++++++----- src/routes/(app)/invoice/[id]/tip/+page.svelte | 12 ++++++++--- src/routes/(app)/send/invoice/[id]/+page.server.ts | 24 ++++++++++++++-------- src/routes/(app)/send/invoice/[id]/+page.svelte | 12 ++++++----- 5 files changed, 46 insertions(+), 21 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/src/locales/en.json b/src/locales/en.json index 72c3cd41..77b2cb20 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -407,6 +407,7 @@ } }, "payments": { + "custom": "Custom", "trustUser": "Send and enable auto-pay", "gift": "Gift all funds", "giftLink": "Gift link", diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 286d7c35..988b6da5 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,18 +1,19 @@ import invoice from "$lib/invoice"; import getRates from "$lib/rates"; import { auth, get, post } from "$lib/utils"; -import { redirect } from "@sveltejs/kit"; +import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, parent }) { const rates = await getRates(); 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) { - if (invoice.prompt && invoice.tip === null && user.tip > 0) { + 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", @@ -21,8 +22,15 @@ export async function load({ cookies, parent }) { ); } - const p = await post("/payments", invoice, auth(cookies)); - redirect(307, `/sent/${p.id}`); + let p; + try { + p = await post("/payments", { ...invoice, pin }, auth(cookies)); + } catch (e) { + const { message } = e as Error; + 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 d609d86a..97d87bb0 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -127,7 +127,10 @@
-
{s(amount, locale)}
@@ -170,12 +173,15 @@ {/if}
-
+ {/if} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 18379943..ac3c910e 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -1,24 +1,32 @@ import getRates from "$lib/rates"; import { auth, fd, get, post, types } from "$lib/utils"; -import { error, redirect } from "@sveltejs/kit"; +import { error, fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, depends, params: { id }, parent }) { depends("app:trust"); - const { user } = await parent(); + const { subject, user } = await parent(); const aid = cookies.get("aid") || user.id; + const pin = cookies.get("pin"); - const invoice = await get(`/invoice/${id}`); + let invoice = await get(`/invoice/${id}`); const trust = await get("/trust", auth(cookies)); const trusted = trust.includes(invoice.uid); - if (trusted) { + if (trusted && (pin || !user.haspin)) { let p; try { - p = await post("/payments", invoice, auth(cookies)); + 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), + ); + } + p = await post("/payments", { ...invoice, pin }, auth(cookies)); } catch (e) { const { message } = e as Error; - console.log("payment failed", id, e); - error(500, message); + fail(400, { message }); } if (p) redirect(307, `/sent/${p.id}`); } @@ -60,7 +68,7 @@ export const actions = { } catch (e) { const { message } = e as Error; console.log("payment failed", id, e); - error(500, message); + error(500, { message }); } redirect(307, `/sent/${p.id}`); diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 9aac5c8d..d5fd00a8 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -207,10 +207,12 @@ - + + {#if !trusted} + + {/if}
-- cgit v1.2.3 From d87ecae6ee46af4790e1f57cd5d82a35ab29e646 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 19 Jul 2025 17:59:56 -0700 Subject: prompt for tip for auto pays --- src/lib/parse.ts | 11 ++++----- .../[username]/accepted/[text]/+page.server.ts | 1 - src/routes/(app)/invoice/[id]/+layout.server.ts | 28 ++++++++++++---------- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 13 ++-------- src/routes/(app)/send/invoice/[id]/+page.server.ts | 19 +++++++++------ 5 files changed, 35 insertions(+), 37 deletions(-) (limited to 'src/routes/(app)/invoice') 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}`); -- cgit v1.2.3 From 476418f9711ac91760a9ca279a6e671d88e70fc3 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 19 Jul 2025 22:56:05 -0700 Subject: handle null tips --- src/lib/invoice.ts | 2 +- src/lib/parse.ts | 4 +++- src/routes/(app)/[username]/receive/+page.svelte | 2 +- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 24 +++++++++++++++++++---- src/routes/(app)/invoice/[id]/tip/+page.svelte | 3 +-- src/routes/(app)/ln/[lnurl]/+page.server.ts | 16 ++++----------- 6 files changed, 30 insertions(+), 21 deletions(-) (limited to 'src/routes/(app)/invoice') 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 @@ - + @@ -180,7 +180,6 @@ onclick={() => (showCustomAmount = true)} >{$t("payments.custom")} - {$t("payments.cancel")}
{/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)) -- cgit v1.2.3 From eb66f787b48a2a52ece890e356fd022380f64c2e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 20 Aug 2025 23:20:02 -0700 Subject: set tip --- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 27 +++++++++++++--------- src/routes/(app)/invoice/[id]/tip/+page.svelte | 13 +---------- src/routes/(app)/send/invoice/[id]/+page.server.ts | 6 +---- 3 files changed, 18 insertions(+), 28 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 1e159697..23e3a07c 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,6 +1,5 @@ -import invoice from "$lib/invoice"; import getRates from "$lib/rates"; -import { auth, get, post } from "$lib/utils"; +import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { @@ -15,17 +14,11 @@ export async function load({ cookies, params, parent }) { const trusted = trust.includes(invoice.uid); 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), - ); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); } else { throw new Error("tip"); } @@ -33,7 +26,6 @@ export async function load({ cookies, params, parent }) { 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 }); } @@ -47,5 +39,18 @@ export async function load({ cookies, params, parent }) { } export const actions = { - default: invoice, + default: async ({ cookies, request }) => { + const form = await fd(request); + const invoice = { + tip: form.tip ?? null, + }; + + const { id } = await post( + `/invoice/${form.id}`, + { invoice }, + auth(cookies), + ); + + redirect(307, `/invoice/${id}`); + }, }; diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index 4f0f306f..a1ea3586 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -97,19 +97,8 @@
- - + - - - - - - - - {#if invoice.memoPrompt} - - {/if}

{$t("invoice.addTipq")}

{#if !showCustomAmount} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 38507343..70b007a8 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -18,11 +18,7 @@ export async function load({ cookies, depends, params: { id }, parent }) { 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), - ); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); } else { throw new Error("tip"); } -- cgit v1.2.3 From 74f8a634073fc04be9983f0e0c39ad46b8df5b67 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 26 Aug 2025 21:53:38 -0700 Subject: fix autopay with tip logic --- src/routes/(app)/invoice/[id]/tip/+page.server.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 23e3a07c..851d3f1b 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -19,14 +19,13 @@ export async function load({ cookies, params, parent }) { if (user.tip > 0) { invoice.tip = Math.round(invoice.amount * (user.tip / 100)); invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); - } else { - throw new Error("tip"); + p = await post("/payments", { ...invoice, pin }, auth(cookies)); } + } else { + p = await post("/payments", { ...invoice, pin }, auth(cookies)); } - 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}`); -- cgit v1.2.3 From 76b781b2870e793cdeae85088b2d70e6a271e6a4 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 9 Sep 2025 09:18:11 -0700 Subject: check for user in invoice route --- bun.lockb | Bin 292357 -> 292349 bytes src/routes/(app)/invoice/[id]/+layout.server.ts | 4 ++-- src/routes/(app)/invoice/[id]/+page.svelte | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/bun.lockb b/bun.lockb index 8dd85e14..e557130e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index d6ab979e..df8693be 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -19,7 +19,7 @@ export async function load({ cookies, depends, params, url, parent }) { (!amount && (pending || received)) || (amount > 0 && (pending >= amount || received >= amount)); if (paid && !url.pathname.endsWith("paid")) { - if (invoice.uid === user.id) + if (invoice.uid === user?.id) redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); else redirect(307, `/pay/${subject.username}/${invoice.amount}`); } @@ -28,7 +28,7 @@ export async function load({ cookies, depends, params, url, parent }) { if ( user && - invoice.uid !== user.id && + invoice.uid !== user?.id && !(url.pathname.includes("tip") || url.pathname.includes("memo")) && !options ) { diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte index 0cb5aeac..29dd815d 100644 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ b/src/routes/(app)/invoice/[id]/+page.svelte @@ -56,16 +56,18 @@ let subbed = false; + $effect(() => { + if (!browser) return; + last.subscribe((v) => { + if (!v || subbed) return; + subbed = true; + send("subscribe", invoice); + }); + }); + onMount(async () => { - if (browser) { - last.subscribe((v) => { - if (!v || subbed) return; - subbed = true; - send("subscribe", invoice); - }); - - if ($amountPrompt && !amount) toggleAmount(); - } + if (!browser) return; + if ($amountPrompt && !amount) toggleAmount(); }); let update = async () => { -- cgit v1.2.3 From a8d18ab66a8beb203b8ff0a056810000a3e069ea Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 9 Sep 2025 12:38:40 -0700 Subject: redirect to paid route --- src/components/Numpad.svelte | 1 - src/routes/(app)/invoice/[id]/+layout.server.ts | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index 0290b9e2..c321e0bc 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -63,7 +63,6 @@ return `${whole}${dec}${cents}`; } - // --- NEW: normalize sats to remove leading zeros but keep single "0" function normalizeSats(str) { const digits = (str ?? "").replace(/[^\d]/g, ""); const noLead = digits.replace(/^0+(?=\d)/, ""); diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index df8693be..ab41dddc 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -19,9 +19,7 @@ export async function load({ cookies, depends, params, url, parent }) { (!amount && (pending || received)) || (amount > 0 && (pending >= amount || received >= amount)); if (paid && !url.pathname.endsWith("paid")) { - if (invoice.uid === user?.id) - redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); - else redirect(307, `/pay/${subject.username}/${invoice.amount}`); + redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); } subject = invoice.user; @@ -34,7 +32,9 @@ export async function load({ cookies, depends, params, url, parent }) { ) { if (invoice.prompt && invoice.tip === null) redirect(307, `/invoice/${id}/tip`); - else redirect(307, `/send/invoice/${id}`); + else { + redirect(307, `/send/invoice/${id}`); + } } } -- cgit v1.2.3