aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/parse.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-26 13:08:08 -0800
committerAdam Soltys <[email protected]>2024-11-26 13:20:53 -0800
commit9b3e117eafbba224b86dd7f8b3c56a0370f72d5b (patch)
treea670c3ae954d5075c851126c2aca7a1a45d1b41d /src/lib/parse.ts
parent2761363d694d3f24600abbe656769f64d7a67605 (diff)
downloadcoinos-ui-9b3e117eafbba224b86dd7f8b3c56a0370f72d5b.tar.gz
coinos-ui-9b3e117eafbba224b86dd7f8b3c56a0370f72d5b.zip
bip21 and socket fixes
Diffstat (limited to 'src/lib/parse.ts')
-rw-r--r--src/lib/parse.ts32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index 6483aaa0..7ddb2104 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -1,7 +1,7 @@
import { PUBLIC_DOMAIN } from "$env/static/public";
+import { decode } from "$lib/bip21";
import { get, isLiquid, post, sats } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-import bip21 from "bip21";
import { validate } from "bitcoin-address-validation";
export default async (s, host) => {
@@ -21,6 +21,23 @@ export default async (s, host) => {
} catch (e) {}
}
+ // bitcoin
+ if (
+ t.toLowerCase().startsWith("bitcoin:") ||
+ t.toLowerCase().startsWith("liquidnetwork:")
+ ) {
+ ({
+ address: t,
+ options: { amount },
+ } = decode(t));
+ }
+
+ if (validate(t) || isLiquid(t)) {
+ let r = `/send/bitcoin/${t}`;
+ if (amount) r += `/${Math.round(amount * sats)}`;
+ redirect(307, r);
+ }
+
// lightning
if (t.toLowerCase().startsWith("lightning:"))
t = t.toLowerCase().replace("lightning:", "");
@@ -47,19 +64,6 @@ 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 += `/${Math.round(amount * sats)}`;
- redirect(307, r);
- }
-
if (t.startsWith("cashu")) {
const { id } = await post("/cash", { token: t });
redirect(307, `/ecash/${id}`);