aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/parse.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-20 16:59:33 -0800
committerAdam Soltys <[email protected]>2024-11-20 16:59:33 -0800
commit38a85c8d8e854a7ac935c232b7e3e046e08bc002 (patch)
treec7df509d4e1daeb306743200f9755b690dec9f99 /src/lib/parse.ts
parente9bd1f4e0593f5e7381892349d8ca9fd5bfec320 (diff)
downloadcoinos-ui-38a85c8d8e854a7ac935c232b7e3e046e08bc002.tar.gz
coinos-ui-38a85c8d8e854a7ac935c232b7e3e046e08bc002.zip
fix bip21 parsing
Diffstat (limited to 'src/lib/parse.ts')
-rw-r--r--src/lib/parse.ts15
1 files changed, 8 insertions, 7 deletions
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);
}