diff options
Diffstat (limited to 'src/lib/parse.ts')
| -rw-r--r-- | src/lib/parse.ts | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts index cdfa4d62..e4bd3497 100644 --- a/src/lib/parse.ts +++ b/src/lib/parse.ts @@ -1,5 +1,5 @@ import { PUBLIC_DOMAIN } from "$env/static/public"; -import { get, isLiquid, post } from "$lib/utils"; +import { get, sats, isLiquid, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; import bip21 from "bip21"; import { validate } from "bitcoin-address-validation"; @@ -21,11 +21,6 @@ export default async (s, host) => { let user; t = t.trim(); - if (t.toLowerCase().startsWith("bitcoin:")) - ({ - address: t, - options: { amount }, - } = bip21.decode(t)); if (t.startsWith("lightning:")) t = t.replace("lightning:", ""); if (t.endsWith(`@${PUBLIC_DOMAIN}`)) t = t.split("@")[0]; @@ -44,11 +39,12 @@ export default async (s, host) => { if (t.includes(":")) t = t.split(":")[1]; if (t.toLowerCase().startsWith("lno")) { - const { invoice } = await get(`/offer/${t}`); - redirect(307, `/send/lightning/${invoice}`); + const { offer_amount_msat: a } = await get(`/decode/${t}`); + if (a) ({ invoice: t } = await post("/fetchinvoice", { offer: t })); + redirect(307, `/send/lightning/${t}`); } - if (t.toLowerCase().startsWith("lno")) { + if (t.toLowerCase().startsWith("ln")) { try { await get(`/invoice/${t}`); } catch (e) { @@ -57,9 +53,15 @@ export default async (s, host) => { } // bitcoin + if (t.toLowerCase().startsWith("bitcoin:")) + ({ + address: t, + options: { amount }, + } = bip21.decode(t)); + if (validate(t) || isLiquid(t)) { let r = `/send/bitcoin/${t}`; - if (amount) r += `/${amount}`; + if (amount) r += `/${Math.round(amount * sats)}`; redirect(307, r); } |
