diff options
| author | Adam Soltys <[email protected]> | 2024-10-31 10:08:25 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-31 10:08:25 -0700 |
| commit | d63d502755fa71f9da04247500d78139fd61fbb9 (patch) | |
| tree | 7ae4bc0ba782c147d7e021d934fa55e13659b3c4 /src | |
| parent | 243abb0a3d29e8e34e263eec843488e3bdb468a4 (diff) | |
| download | coinos-ui-d63d502755fa71f9da04247500d78139fd61fbb9.tar.gz coinos-ui-d63d502755fa71f9da04247500d78139fd61fbb9.zip | |
check invoice type
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/parse.ts | 21 | ||||
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.ts | 4 |
2 files changed, 12 insertions, 13 deletions
diff --git a/src/lib/parse.ts b/src/lib/parse.ts index 6e38150c..fcce7e1e 100644 --- a/src/lib/parse.ts +++ b/src/lib/parse.ts @@ -10,8 +10,7 @@ export default async (t, host) => { if (t.startsWith("http")) redirect(307, t); if (t.startsWith(host)) redirect(307, `http://${t}`); - let amount; - let user; + let amount, user; t = t.trim(); t.toLowerCase().startsWith("bitcoin:") && @@ -30,14 +29,6 @@ export default async (t, host) => { if (t.includes("/fund")) redirect(307, t.substring(t.indexOf("/fund"))); - // invoice - let invoice; - try { - invoice = await get(`/invoice/${t}`); - } catch (e) {} - - if (invoice) redirect(307, `/send/invoice/${invoice.id}`); - // lightning if (t.toLowerCase().startsWith("lightning:")) t = t.toLowerCase().replace("lightning:", ""); @@ -55,7 +46,7 @@ export default async (t, host) => { // bitcoin if (validate(t) || isLiquid(t)) { let r = `/send/bitcoin/${t}`; - if (amount) r += `/${amount}`; + if (amount) r += "/" + amount; redirect(307, r); } @@ -78,4 +69,12 @@ export default async (t, host) => { } catch (e) {} if (fund) redirect(307, `/send/fund/${t}`); + + // invoice + let invoice; + try { + invoice = await get(`/invoice/${t}`); + } catch (e) {} + + if (invoice) redirect(307, `/send/invoice/${invoice.id}`); }; diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index c65a6c7b..55228025 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -1,4 +1,4 @@ -import { auth, fd, get, post } from "$lib/utils"; +import { auth, fd, get, post, types } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; export async function load({ cookies, params: { id }, parent }) { @@ -14,7 +14,7 @@ export async function load({ cookies, params: { id }, parent }) { redirect(307, `/invoice/${id}/memo`); if (invoice.aid === aid) error(500, { message: "Cannot send to self" }); - else if (user) redirect(307, `/send/${invoice.type}/${invoice.hash}`); + else if (user && invoice.type !== types.lightning) redirect(307, `/send/${invoice.type}/${invoice.hash}`); if (!user) redirect(307, `/invoice/${id}`); |
