diff options
| author | Jurjen de Vries <[email protected]> | 2025-09-11 00:48:15 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-11 00:48:15 +0200 |
| commit | 0c69c9848c6b98c92609d209103efc60003c9723 (patch) | |
| tree | 445121def885f13d0f80c06864ad2ff4d5ef95a1 /src/lib/parse.ts | |
| parent | 2abcf6e435fca5d86960f3ba4228002bfb0a19e6 (diff) | |
| parent | 9277b2921e09ee9dd5f39cf4af30a2330f4d95d1 (diff) | |
| download | coinos-ui-0c69c9848c6b98c92609d209103efc60003c9723.tar.gz coinos-ui-0c69c9848c6b98c92609d209103efc60003c9723.zip | |
Merge branch 'coinos:master' into master
Diffstat (limited to 'src/lib/parse.ts')
| -rw-r--r-- | src/lib/parse.ts | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts index ba264be7..9c18504a 100644 --- a/src/lib/parse.ts +++ b/src/lib/parse.ts @@ -8,11 +8,18 @@ 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); if (t.startsWith(host)) redirect(307, `http://${t}`); + if (t.includes("lightning=")) { + const url = new URL(t); + const params = new URLSearchParams(url.search); + t = params.get("lightning"); + } + if (t.startsWith("lightning:")) t = t.replace("lightning:", ""); if (t.endsWith(`@${PUBLIC_DOMAIN}`)) t = t.split("@")[0]; if (t.includes("@") && t.includes(".")) { @@ -51,16 +58,10 @@ export default async (s, host) => { if (t.toLowerCase().startsWith("lnurl")) redirect(307, `/ln/${t}`); if (t.includes(":")) t = t.split(":")[1]; - if (t.includes("lightning=")) { - const url = new URL(t); - const params = new URLSearchParams(url.search); - t = params.get("lightning"); - } - 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}`); @@ -70,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) @@ -115,11 +118,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}`); }; |
