From e69768ba8e777fd0b2778aad73e17267870226ea Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 1 Dec 2023 20:04:13 -0800 Subject: prettier --- src/routes/(app)/send/+layout.svelte | 14 +- src/routes/(app)/send/[...text]/+page.server.js | 182 ++++++------- src/routes/(app)/send/[...text]/+page.svelte | 212 ++++++++------- .../bitcoin/[address]/[...amount]/+page.server.js | 45 ++-- .../bitcoin/[address]/[...amount]/+page.svelte | 279 ++++++++++--------- .../send/fund/[name]/[...amount]/+page.server.js | 24 +- .../send/fund/[name]/[...amount]/+page.svelte | 94 +++---- src/routes/(app)/send/invoice/[id]/+page.server.js | 65 +++-- src/routes/(app)/send/invoice/[id]/+page.svelte | 300 +++++++++++---------- .../(app)/send/lightning/[payreq]/+page.server.js | 30 +-- .../(app)/send/lightning/[payreq]/+page.svelte | 181 +++++++------ .../user/[username]/[...amount]/+page.server.js | 81 +++--- .../send/user/[username]/[...amount]/+page.svelte | 166 ++++++------ 13 files changed, 867 insertions(+), 806 deletions(-) (limited to 'src/routes/(app)/send') diff --git a/src/routes/(app)/send/+layout.svelte b/src/routes/(app)/send/+layout.svelte index 47c11f1c..1a587edf 100644 --- a/src/routes/(app)/send/+layout.svelte +++ b/src/routes/(app)/send/+layout.svelte @@ -1,16 +1,16 @@ {#if user.haspin && (!$pin || $pin?.length !== 6)} - + {/if} diff --git a/src/routes/(app)/send/[...text]/+page.server.js b/src/routes/(app)/send/[...text]/+page.server.js index 3ca50bca..9a76f21d 100644 --- a/src/routes/(app)/send/[...text]/+page.server.js +++ b/src/routes/(app)/send/[...text]/+page.server.js @@ -1,100 +1,100 @@ -import { validate } from 'bitcoin-address-validation'; -import bip21 from 'bip21'; -import { auth, get, post } from '$lib/utils'; -import { fail, redirect } from '@sveltejs/kit'; -import { PUBLIC_DOMAIN } from '$env/static/public'; +import { validate } from "bitcoin-address-validation"; +import bip21 from "bip21"; +import { auth, get, post } from "$lib/utils"; +import { fail, redirect } from "@sveltejs/kit"; +import { PUBLIC_DOMAIN } from "$env/static/public"; let parse = async (t, host) => { - if (!t) return; - - if (t.startsWith('http')) throw redirect(307, t); - if (t.startsWith(host)) throw redirect(307, `http://${t}`); - - let amount, user, id; - - t = t.trim(); - t.toLowerCase().startsWith('bitcoin:') && - ({ - address: t, - options: { amount } - } = bip21.decode(t)); - - 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.endsWith('@classic')) { - ({ uuid: id } = await get(`/invoice/classic/${t.replace('@classic', '')}`)); - if (id) throw redirect(307, `/send/invoice/${id}`); - } - - if (t.includes('/fund')) throw redirect(307, t.substring(t.indexOf('/fund'))); - - if (t.toLowerCase().startsWith('lnurl')) throw redirect(307, `/ln/${t}`); - if (t.includes(':')) t = t.split(':')[1]; - - // lightning - if (t.toLowerCase().startsWith('ln')) { - try { - ({ id } = await get(`/invoice/${t}`)); - } catch (e) { - throw redirect(307, `/send/lightning/${t}`); - } - } - - // bitcoin - if (validate(t)) { - try { - ({ id, user } = await get(`/invoice/${t}`)); - } catch (e) { - let r = `/send/bitcoin/${t}`; - if (amount) r += '/' + amount; - throw redirect(307, r); - } - - if (user) throw redirect(307, `/send/${user.username}`); - else if (id) throw redirect(307, `/send/${id}`); - } - - // user - try { - user = await get(`/users/${t.split('/')[0]}`); - if (user.anon) user = null; - } catch (e) {} - - if (user) throw redirect(307, `/send/user/${t}`); - - let fund; - try { - fund = await get(`/fund/${t}`); - } catch (e) {} - - if (fund) throw redirect(307, `/send/fund/${t}`); - - // invoice - let invoice; - try { - invoice = await get(`/invoice/${t}`); - } catch (e) {} - - if (invoice) throw redirect(307, `/send/invoice/${invoice.hash}`); + if (!t) return; + + if (t.startsWith("http")) throw redirect(307, t); + if (t.startsWith(host)) throw redirect(307, `http://${t}`); + + let amount, user, id; + + t = t.trim(); + t.toLowerCase().startsWith("bitcoin:") && + ({ + address: t, + options: { amount }, + } = bip21.decode(t)); + + 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.endsWith("@classic")) { + ({ uuid: id } = await get(`/invoice/classic/${t.replace("@classic", "")}`)); + if (id) throw redirect(307, `/send/invoice/${id}`); + } + + if (t.includes("/fund")) throw redirect(307, t.substring(t.indexOf("/fund"))); + + if (t.toLowerCase().startsWith("lnurl")) throw redirect(307, `/ln/${t}`); + if (t.includes(":")) t = t.split(":")[1]; + + // lightning + if (t.toLowerCase().startsWith("ln")) { + try { + ({ id } = await get(`/invoice/${t}`)); + } catch (e) { + throw redirect(307, `/send/lightning/${t}`); + } + } + + // bitcoin + if (validate(t)) { + try { + ({ id, user } = await get(`/invoice/${t}`)); + } catch (e) { + let r = `/send/bitcoin/${t}`; + if (amount) r += "/" + amount; + throw redirect(307, r); + } + + if (user) throw redirect(307, `/send/${user.username}`); + else if (id) throw redirect(307, `/send/${id}`); + } + + // user + try { + user = await get(`/users/${t.split("/")[0]}`); + if (user.anon) user = null; + } catch (e) {} + + if (user) throw redirect(307, `/send/user/${t}`); + + let fund; + try { + fund = await get(`/fund/${t}`); + } catch (e) {} + + if (fund) throw redirect(307, `/send/fund/${t}`); + + // invoice + let invoice; + try { + invoice = await get(`/invoice/${t}`); + } catch (e) {} + + if (invoice) throw redirect(307, `/send/invoice/${invoice.hash}`); }; export async function load({ cookies, params, request, url }) { - let { text } = params; - await parse(text, url.host); - let contacts = await get('/contacts', auth(cookies)); - return { contacts }; + let { text } = params; + await parse(text, url.host); + let contacts = await get("/contacts", auth(cookies)); + return { contacts }; } export const actions = { - default: async ({ request, url }) => { - const form = await request.formData(); - let t = form.get('text'); - await parse(t, url.host); - return fail(400, { error: true }); - } + default: async ({ request, url }) => { + const form = await request.formData(); + let t = form.get("text"); + await parse(t, url.host); + return fail(400, { error: true }); + }, }; diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index 74afd846..67d4afaa 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -1,125 +1,129 @@
-

- {$t('payments.send')} -

+

+ {$t("payments.send")} +

-
- {#if form?.error} -
-
- {$t('error.unrecognizedInput')} -
-
- {/if} + + {#if form?.error} +
+
+ {$t("error.unrecognizedInput")} +
+
+ {/if} -
- +
+ -