From 38a85c8d8e854a7ac935c232b7e3e046e08bc002 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 20 Nov 2024 16:59:33 -0800 Subject: fix bip21 parsing --- src/lib/parse.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/lib/parse.ts') diff --git a/src/lib/parse.ts b/src/lib/parse.ts index 762997a4..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]; @@ -58,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); } -- cgit v1.2.3