diff options
| author | Adam Soltys <[email protected]> | 2024-10-18 09:08:07 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-18 09:09:14 -0700 |
| commit | 002cd9134d2e23bec34f838f6d6fefba41f2d530 (patch) | |
| tree | 92fa0e0ab54ce1a715d25f458de8b8ed8cc70bd5 /src/lib/parse.ts | |
| parent | f6bfe889d91bc6e36b0300d7b618f10158efe176 (diff) | |
| download | coinos-ui-002cd9134d2e23bec34f838f6d6fefba41f2d530.tar.gz coinos-ui-002cd9134d2e23bec34f838f6d6fefba41f2d530.zip | |
biome format
Diffstat (limited to 'src/lib/parse.ts')
| -rw-r--r-- | src/lib/parse.ts | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts index 0ab3e809..fcce7e1e 100644 --- a/src/lib/parse.ts +++ b/src/lib/parse.ts @@ -1,80 +1,80 @@ +import { PUBLIC_DOMAIN } from "$env/static/public"; import { get, isLiquid, post } from "$lib/utils"; +import { redirect } from "@sveltejs/kit"; import bip21 from "bip21"; import { validate } from "bitcoin-address-validation"; -import { PUBLIC_DOMAIN } from "$env/static/public"; -import { redirect } from "@sveltejs/kit"; export default async (t, host) => { - if (!t) return; + if (!t) return; - if (t.startsWith("http")) redirect(307, t); - if (t.startsWith(host)) redirect(307, `http://${t}`); + if (t.startsWith("http")) redirect(307, t); + if (t.startsWith(host)) redirect(307, `http://${t}`); - let amount, user; + let amount, user; - t = t.trim(); - t.toLowerCase().startsWith("bitcoin:") && - ({ - address: t, - options: { amount }, - } = bip21.decode(t)); + t = t.trim(); + 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]; - if (t.includes("@") && t.includes(".")) { - try { - t = await get(`/encode?address=${t}`); - } catch (e) {} - } + if (t.startsWith("lightning:")) t = t.replace("lightning:", ""); + if (t.endsWith(`@${PUBLIC_DOMAIN}`)) t = t.split("@")[0]; + if (t.includes("@") && t.includes(".")) { + try { + t = await get(`/encode?address=${t}`); + } catch (e) {} + } - if (t.includes("/fund")) redirect(307, t.substring(t.indexOf("/fund"))); + if (t.includes("/fund")) redirect(307, t.substring(t.indexOf("/fund"))); - // lightning - if (t.toLowerCase().startsWith("lightning:")) - t = t.toLowerCase().replace("lightning:", ""); - if (t.toLowerCase().startsWith("lnurl")) redirect(307, `/ln/${t}`); - if (t.includes(":")) t = t.split(":")[1]; + // lightning + if (t.toLowerCase().startsWith("lightning:")) + t = t.toLowerCase().replace("lightning:", ""); + if (t.toLowerCase().startsWith("lnurl")) redirect(307, `/ln/${t}`); + if (t.includes(":")) t = t.split(":")[1]; - if (t.toLowerCase().startsWith("ln")) { - try { - await get(`/invoice/${t}`); - } catch (e) { - redirect(307, `/send/lightning/${t}`); - } - } + if (t.toLowerCase().startsWith("ln")) { + try { + await get(`/invoice/${t}`); + } catch (e) { + redirect(307, `/send/lightning/${t}`); + } + } - // bitcoin - if (validate(t) || isLiquid(t)) { - let r = `/send/bitcoin/${t}`; - if (amount) r += "/" + amount; - redirect(307, r); - } + // bitcoin + if (validate(t) || isLiquid(t)) { + let r = `/send/bitcoin/${t}`; + if (amount) r += "/" + amount; + redirect(307, r); + } - if (t.startsWith("cashu")) { - let { id } = await post("/cash", { token: t }); - redirect(307, `/ecash/${id}`); - } + if (t.startsWith("cashu")) { + const { id } = await post("/cash", { token: t }); + redirect(307, `/ecash/${id}`); + } - // user - try { - user = await get(`/users/${t.split("/")[0]}`); - if (user.anon) user = null; - } catch (e) {} + // user + try { + user = await get(`/users/${t.split("/")[0]}`); + if (user.anon) user = null; + } catch (e) {} - if (user) redirect(307, `/pay/${t}`); + if (user) redirect(307, `/pay/${t}`); - let fund; - try { - fund = await get(`/fund/${t}`); - } catch (e) {} + let fund; + try { + fund = await get(`/fund/${t}`); + } catch (e) {} - if (fund) redirect(307, `/send/fund/${t}`); + if (fund) redirect(307, `/send/fund/${t}`); - // invoice - let invoice; - try { - invoice = await get(`/invoice/${t}`); - } catch (e) {} + // invoice + let invoice; + try { + invoice = await get(`/invoice/${t}`); + } catch (e) {} - if (invoice) redirect(307, `/send/invoice/${invoice.id}`); + if (invoice) redirect(307, `/send/invoice/${invoice.id}`); }; |
