diff options
| author | Adam Soltys <[email protected]> | 2023-12-01 20:04:13 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-12-01 20:04:13 -0800 |
| commit | 216a600224fde22ce76b367557a02094ec693886 (patch) | |
| tree | d1189bbaa39db204633523132a7d4767b952717d /src/routes/(app)/send | |
| parent | 7d9bc1f54dfd04172e8d6d43ebc2efd6f407e833 (diff) | |
| download | coinos-ui-216a600224fde22ce76b367557a02094ec693886.tar.gz coinos-ui-216a600224fde22ce76b367557a02094ec693886.zip | |
prettier
Diffstat (limited to 'src/routes/(app)/send')
13 files changed, 808 insertions, 747 deletions
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 @@ <script> - import { goto } from '$app/navigation'; - import { Pin } from '$comp'; - import { pin } from '$lib/store'; + import { goto } from "$app/navigation"; + import { Pin } from "$comp"; + import { pin } from "$lib/store"; - export let data; + export let data; - let { user } = data; - let cancel = () => goto(`/${user.username}`); + let { user } = data; + let cancel = () => goto(`/${user.username}`); </script> {#if user.haspin && (!$pin || $pin?.length !== 6)} - <Pin bind:value={$pin} {cancel} /> + <Pin bind:value={$pin} {cancel} /> {/if} <slot /> 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) return; - if (t.startsWith('http')) throw redirect(307, t); - if (t.startsWith(host)) throw redirect(307, `http://${t}`); + if (t.startsWith("http")) throw redirect(307, t); + if (t.startsWith(host)) throw redirect(307, `http://${t}`); - let amount, user, id; + let amount, user, id; - 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.endsWith(`@${PUBLIC_DOMAIN}`)) t = t.split('@')[0]; - if (t.includes('@') && t.includes('.')) { - try { - t = await get(`/encode?address=${t}`); - } catch (e) {} - } + 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.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.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]; + 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}`); - } - } + // 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); - } + // 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}`); - } + 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) {} + // user + try { + user = await get(`/users/${t.split("/")[0]}`); + if (user.anon) user = null; + } catch (e) {} - if (user) throw redirect(307, `/send/user/${t}`); + if (user) throw redirect(307, `/send/user/${t}`); - let fund; - try { - fund = await get(`/fund/${t}`); - } catch (e) {} + let fund; + try { + fund = await get(`/fund/${t}`); + } catch (e) {} - if (fund) throw redirect(307, `/send/fund/${t}`); + if (fund) throw 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) throw redirect(307, `/send/invoice/${invoice.hash}`); + 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 @@ <script> - import { page } from '$app/stores'; - import { fly } from 'svelte/transition'; - import { enhance } from '$app/forms'; - import { tick } from 'svelte'; - import { browser } from '$app/environment'; - import { t } from '$lib/translations'; - import { AppHeader, Avatar, Icon, Spinner } from '$comp'; - import { back, fail } from '$lib/utils'; + import { page } from "$app/stores"; + import { fly } from "svelte/transition"; + import { enhance } from "$app/forms"; + import { tick } from "svelte"; + import { browser } from "$app/environment"; + import { t } from "$lib/translations"; + import { AppHeader, Avatar, Icon, Spinner } from "$comp"; + import { back, fail } from "$lib/utils"; - export let data; - export let form; - data.subject = data.user; + export let data; + export let form; + data.subject = data.user; - let { contacts } = data; - let w; + let { contacts } = data; + let w; - let el, textarea, text; - let placeholder = $t('user.send.placeholder'); + let el, textarea, text; + let placeholder = $t("user.send.placeholder"); - $: $page && setTimeout(() => w > 800 && textarea?.focus(), 0); - let keypress = (e) => e.key === 'Enter' && (e.preventDefault() || el.click()); + $: $page && setTimeout(() => w > 800 && textarea?.focus(), 0); + let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click()); - let paste = async () => { - text = await navigator.clipboard.readText(); - }; + let paste = async () => { + text = await navigator.clipboard.readText(); + }; </script> <svelte:window bind:innerWidth={w} /> <AppHeader {data} /> <div class="container px-4 max-w-lg mx-auto space-y-5 mt-20"> - <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold"> - {$t('payments.send')} - </h1> + <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold"> + {$t("payments.send")} + </h1> - <form method="POST" use:enhance> - {#if form?.error} - <div class="mb-5"> - <div class="text-red-600"> - {$t('error.unrecognizedInput')} - </div> - </div> - {/if} + <form method="POST" use:enhance> + {#if form?.error} + <div class="mb-5"> + <div class="text-red-600"> + {$t("error.unrecognizedInput")} + </div> + </div> + {/if} - <div class="mb-2"> - <input type="hidden" name="text" bind:value={text} /> + <div class="mb-2"> + <input type="hidden" name="text" bind:value={text} /> - <textarea - {placeholder} - on:keypress={keypress} - class="w-full p-4 border rounded-xl h-48" - bind:value={text} - bind:this={textarea} - /> - </div> + <textarea + {placeholder} + on:keypress={keypress} + class="w-full p-4 border rounded-xl h-48" + bind:value={text} + bind:this={textarea} + /> + </div> - <div class="flex justify-end"> - {#if text?.length} - <a href={`/qr/${encodeURIComponent(text)}`}> - <button - type="button" - class="flex border rounded-full px-6 py-2 font-bold hover:opacity-80 mr-1" - > - <Icon icon="qr" style="mr-2 w-6 my-auto invert" /> - <div class="my-auto">{$t('user.send.makeQR')}</div> - </button> - </a> - {/if} + <div class="flex justify-end"> + {#if text?.length} + <a href={`/qr/${encodeURIComponent(text)}`}> + <button + type="button" + class="flex border rounded-full px-6 py-2 font-bold hover:opacity-80 mr-1" + > + <Icon icon="qr" style="mr-2 w-6 my-auto invert" /> + <div class="my-auto">{$t("user.send.makeQR")}</div> + </button> + </a> + {/if} - <a href="/scan"> - <button - type="button" - class="flex border rounded-full px-6 py-2 font-bold hover:opacity-80 mr-1" - > - <Icon icon="camera" style="mr-2 w-6 my-auto" /> - <div class="my-auto">{$t('user.send.scan')}</div> - </button> - </a> + <a href="/scan"> + <button + type="button" + class="flex border rounded-full px-6 py-2 font-bold hover:opacity-80 mr-1" + > + <Icon icon="camera" style="mr-2 w-6 my-auto" /> + <div class="my-auto">{$t("user.send.scan")}</div> + </button> + </a> - <button - type="button" - class="flex border rounded-full px-6 py-2 font-bold hover:opacity-80 mr-1" - on:click={paste} - > - <Icon icon="paste" style="mr-2 w-6 my-auto" /> - <div class="my-auto">{$t('user.send.paste')}</div> - </button> + <button + type="button" + class="flex border rounded-full px-6 py-2 font-bold hover:opacity-80 mr-1" + on:click={paste} + > + <Icon icon="paste" style="mr-2 w-6 my-auto" /> + <div class="my-auto">{$t("user.send.paste")}</div> + </button> - <button - bind:this={el} - type="submit" - class="{!text - ? 'opacity-50' - : 'opacity-100 hover:opacity-80'} bg-black text-white border rounded-full px-6 py-2 font-bold" - > - {$t('user.send.next')} - </button> - </div> - </form> + <button + bind:this={el} + type="submit" + class="{!text + ? 'opacity-50' + : 'opacity-100 hover:opacity-80'} bg-black text-white border rounded-full px-6 py-2 font-bold" + > + {$t("user.send.next")} + </button> + </div> + </form> - {#if contacts.length} - <div class="space-y-5"> - <h1 class="px-3 md:px-0 text-xl font-semibold mt-10">{$t('user.send.contacts')}</h1> - <div> - {#each contacts as c} - <a href={`/send/${c.username}`}> - <div class="border-b p-2 last:border-b-0 hover:bg-gray-100 rounded-2xl"> - <div class="flex"> - <div> - <div class="flex"> - <Avatar user={c} size={20} disabled={true} /> - <div class="my-auto text-left"> - <p class="ml-1 text-lg break-words">{c.username}</p> - </div> - </div> - </div> - </div> - </div> - </a> - {/each} - </div> - </div> - {/if} + {#if contacts.length} + <div class="space-y-5"> + <h1 class="px-3 md:px-0 text-xl font-semibold mt-10"> + {$t("user.send.contacts")} + </h1> + <div> + {#each contacts as c} + <a href={`/send/${c.username}`}> + <div + class="border-b p-2 last:border-b-0 hover:bg-gray-100 rounded-2xl" + > + <div class="flex"> + <div> + <div class="flex"> + <Avatar user={c} size={20} disabled={true} /> + <div class="my-auto text-left"> + <p class="ml-1 text-lg break-words">{c.username}</p> + </div> + </div> + </div> + </div> + </div> + </a> + {/each} + </div> + </div> + {/if} </div> diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js index 92a754ae..5cb86aec 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js @@ -1,33 +1,32 @@ -import { fail, redirect } from '@sveltejs/kit'; -import { auth, post, fd } from '$lib/utils'; +import { fail, redirect } from "@sveltejs/kit"; +import { auth, post, fd } from "$lib/utils"; let seen = {}; export const actions = { - default: async ({ cookies, request }) => { - try { - let { address, amount, confirmed, feeRate, subtract, pin, stale, ts } = await await fd( - request - ); - if (seen[ts]) return fail(400, { message: 'Duplicate form submission' }); + default: async ({ cookies, request }) => { + try { + let { address, amount, confirmed, feeRate, subtract, pin, stale, ts } = + await await fd(request); + if (seen[ts]) return fail(400, { message: "Duplicate form submission" }); - let estimate = await post( - '/bitcoin/fee', - { address, amount, feeRate, subtract }, - auth(cookies) - ); + let estimate = await post( + "/bitcoin/fee", + { address, amount, feeRate, subtract }, + auth(cookies) + ); - let { tx } = estimate; + let { tx } = estimate; - if (stale || !confirmed) return fail(400, estimate); + if (stale || !confirmed) return fail(400, estimate); - seen[ts] = 1; - setTimeout(() => delete seen[ts], 30000); + seen[ts] = 1; + setTimeout(() => delete seen[ts], 30000); - await post('/bitcoin/send', { pin, subtract, tx }, auth(cookies)); - } catch (e) { - return fail(400, { message: e.message }); - } + await post("/bitcoin/send", { pin, subtract, tx }, auth(cookies)); + } catch (e) { + return fail(400, { message: e.message }); + } - throw redirect(307, '/sent'); - } + throw redirect(307, "/sent"); + }, }; diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte index 342eeebe..da11a22c 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte @@ -1,142 +1,159 @@ <script> - import { tick } from 'svelte'; - import { t } from '$lib/translations'; - import { enhance } from '$app/forms'; - import { Toggle, Slider, Icon, Numpad, Spinner } from '$comp'; - import { page } from '$app/stores'; - import { fiat as toFiat, f, back, s, sat } from '$lib/utils'; - import { pin } from '$lib/store'; + import { tick } from "svelte"; + import { t } from "$lib/translations"; + import { enhance } from "$app/forms"; + import { Toggle, Slider, Icon, Numpad, Spinner } from "$comp"; + import { page } from "$app/stores"; + import { fiat as toFiat, f, back, s, sat } from "$lib/utils"; + import { pin } from "$lib/store"; - export let data; - export let form; + export let data; + export let form; - let { rates } = data; - let { address, amount } = $page.params; - let { balance, currency } = data.user; - let loading, submit, fiat, confirmed, feeRate, min, max, fee, ourfee, stale, subtract, adjusting; + let { rates } = data; + let { address, amount } = $page.params; + let { balance, currency } = data.user; + let loading, + submit, + fiat, + confirmed, + feeRate, + min, + max, + fee, + ourfee, + stale, + subtract, + adjusting; - $: rate = rates[currency]; + $: rate = rates[currency]; - let toggle = () => (loading = true); - let toggleAdjusting = () => (adjusting = !adjusting); + let toggle = () => (loading = true); + let toggleAdjusting = () => (adjusting = !adjusting); - $: update(form); - let update = () => { - loading = false; - if (form?.message?.includes('pin')) $pin = undefined; - if (form) ({ min, max, feeRate, fee, ourfee, subtract } = form); - if (!ourfee) ourfee = 0; - if (feeRate) confirmed = true; - stale = false; - }; + $: update(form); + let update = () => { + loading = false; + if (form?.message?.includes("pin")) $pin = undefined; + if (form) ({ min, max, feeRate, fee, ourfee, subtract } = form); + if (!ourfee) ourfee = 0; + if (feeRate) confirmed = true; + stale = false; + }; - let setMax = () => { - fiat = false; - amount = balance; - subtract = true; - }; + let setMax = () => { + fiat = false; + amount = balance; + subtract = true; + }; - $: if (amount + fee > balance) subtract = true; + $: if (amount + fee > balance) subtract = true; - let timeout; - let handle = (e) => { - stale = true; - feeRate = e.target.value; - clearTimeout(timeout); - timeout = setTimeout(() => { - tick().then(() => submit.click()); - }, 200); - }; + let timeout; + let handle = (e) => { + stale = true; + feeRate = e.target.value; + clearTimeout(timeout); + timeout = setTimeout(() => { + tick().then(() => submit.click()); + }, 200); + }; </script> <button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={back}> - <Icon icon="arrow-left" style="w-10" /> + <Icon icon="arrow-left" style="w-10" /> </button> {#if form?.message} - <div class="text-red-600 text-center"> - {form.message} - </div> + <div class="text-red-600 text-center"> + {form.message} + </div> {/if} <div class="container px-4 mt-20 max-w-xl mx-auto space-y-5 text-center"> - <h1 class="text-3xl md:text-4xl font-semibold mb-2">{$t('payments.send')}</h1> + <h1 class="text-3xl md:text-4xl font-semibold mb-2">{$t("payments.send")}</h1> - <div class="text-lg text-secondary break-all">{address}</div> + <div class="text-lg text-secondary break-all">{address}</div> - {#if confirmed} - <div class="text-center"> - <h2 class="text-2xl md:text-3xl font-semibold"> - {f(toFiat(amount, rate), currency)} - </h2> - <h3 class="text-secondary md:text-lg mb-6 mt-1">⚡️{s(amount)}</h3> - </div> + {#if confirmed} + <div class="text-center"> + <h2 class="text-2xl md:text-3xl font-semibold"> + {f(toFiat(amount, rate), currency)} + </h2> + <h3 class="text-secondary md:text-lg mb-6 mt-1">⚡️{s(amount)}</h3> + </div> - <div class="text-center"> - <h2 class="text-secondary mb-5 text-lg">with fee</h2> + <div class="text-center"> + <h2 class="text-secondary mb-5 text-lg">with fee</h2> - <div class="relative"> - <h2 class="text-xl font-semibold"> - {f(toFiat(fee + ourfee, rate), currency)} - </h2> - <h3 class="text-secondary mb-6 mt-1">⚡️{s(fee + ourfee)}</h3> - <button class="absolute right-1/4 top-0 text-secondary p-4" on:click={toggleAdjusting} - ><Icon icon="settings" style="opacity-30" /></button - > - </div> - </div> - {:else} - <Numpad bind:amount bind:fiat {currency} {submit} bind:rate /> - {/if} + <div class="relative"> + <h2 class="text-xl font-semibold"> + {f(toFiat(fee + ourfee, rate), currency)} + </h2> + <h3 class="text-secondary mb-6 mt-1">⚡️{s(fee + ourfee)}</h3> + <button + class="absolute right-1/4 top-0 text-secondary p-4" + on:click={toggleAdjusting} + ><Icon icon="settings" style="opacity-30" /></button + > + </div> + </div> + {:else} + <Numpad bind:amount bind:fiat {currency} {submit} bind:rate /> + {/if} - <form method="POST" use:enhance on:submit={toggle}> - <input name="ts" value={Date.now()} type="hidden" /> - <input name="address" value={address} type="hidden" /> - <input name="amount" value={amount} type="hidden" /> - <input name="pin" value={$pin} type="hidden" /> - <input name="confirmed" value={confirmed} type="hidden" /> - <input name="feeRate" value={feeRate} type="hidden" /> - <input name="stale" value={stale} type="hidden" /> - <input name="subtract" value={subtract} type="hidden" /> + <form method="POST" use:enhance on:submit={toggle}> + <input name="ts" value={Date.now()} type="hidden" /> + <input name="address" value={address} type="hidden" /> + <input name="amount" value={amount} type="hidden" /> + <input name="pin" value={$pin} type="hidden" /> + <input name="confirmed" value={confirmed} type="hidden" /> + <input name="feeRate" value={feeRate} type="hidden" /> + <input name="stale" value={stale} type="hidden" /> + <input name="subtract" value={subtract} type="hidden" /> - {#if confirmed && adjusting} - <div class="relative mt-10 mb-20"> - <div class="absolute top-5 left-0 text-secondary">Slower (~40 blocks)</div> - <div class="absolute top-5 right-0 text-secondary">Faster (~1 block)</div> - <Slider bind:value={feeRate} {handle} {min} {max} /> - </div> - <div class="flex justify-center gap-2 mb-10"> - <div class="my-auto"> - <Toggle id="subtract" checked={subtract} bind:value={subtract} /> - </div> - <label for="subtract" class="text-secondary text-lg my-auto mb-2" - >Take fee from amount</label - > - </div> - {/if} + {#if confirmed && adjusting} + <div class="relative mt-10 mb-20"> + <div class="absolute top-5 left-0 text-secondary"> + Slower (~40 blocks) + </div> + <div class="absolute top-5 right-0 text-secondary"> + Faster (~1 block) + </div> + <Slider bind:value={feeRate} {handle} {min} {max} /> + </div> + <div class="flex justify-center gap-2 mb-10"> + <div class="my-auto"> + <Toggle id="subtract" checked={subtract} bind:value={subtract} /> + </div> + <label for="subtract" class="text-secondary text-lg my-auto mb-2" + >Take fee from amount</label + > + </div> + {/if} - <div class="flex justify-center gap-2"> - {#if !confirmed} - <button - type="button" - class="hover:opacity-80 bg-black text-white rounded-2xl py-3 px-4 mt-2 border font-bold" - on:click|preventDefault={setMax} - on:keydown={setMax}>Max ⚡️{s(balance)}</button - > - {/if} + <div class="flex justify-center gap-2"> + {#if !confirmed} + <button + type="button" + class="hover:opacity-80 bg-black text-white rounded-2xl py-3 px-4 mt-2 border font-bold" + on:click|preventDefault={setMax} + on:keydown={setMax}>Max ⚡️{s(balance)}</button + > + {/if} - <button - bind:this={submit} - type="submit" - class="opacity-100 hover:opacity-80 rounded-2xl border py-3 font-bold mt-2 bg-black text-white px-4 w-24" - disabled={loading} - > - {#if confirmed} - {$t('payments.send')} - {:else} - {$t('payments.next')} - {/if} - </button> - </div> - </form> + <button + bind:this={submit} + type="submit" + class="opacity-100 hover:opacity-80 rounded-2xl border py-3 font-bold mt-2 bg-black text-white px-4 w-24" + disabled={loading} + > + {#if confirmed} + {$t("payments.send")} + {:else} + {$t("payments.next")} + {/if} + </button> + </div> + </form> </div> diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.js b/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.js index 2cb3c4a9..3318a60b 100644 --- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.js @@ -1,17 +1,17 @@ -import { fail, redirect } from '@sveltejs/kit'; -import { auth, fd, post } from '$lib/utils'; +import { fail, redirect } from "@sveltejs/kit"; +import { auth, fd, post } from "$lib/utils"; export const actions = { - default: async ({ cookies, request }) => { - let body = await fd(request); - let p; + default: async ({ cookies, request }) => { + let body = await fd(request); + let p; - try { - p = await post('/payments', body, auth(cookies)); - } catch (e) { - return fail(400, { message: e.message }); - } + try { + p = await post("/payments", body, auth(cookies)); + } catch (e) { + return fail(400, { message: e.message }); + } - if (p) throw redirect(307, `/fund/${body.name}`); - } + if (p) throw redirect(307, `/fund/${body.name}`); + }, }; diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte b/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte index 6aecf8f3..886e93d2 100644 --- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte @@ -1,58 +1,58 @@ <script> - import { t } from '$lib/translations'; - import { enhance } from '$app/forms'; - import { Icon, Numpad, Spinner } from '$comp'; - import { page } from '$app/stores'; - import { back } from '$lib/utils'; - import { pin } from '$lib/store'; + import { t } from "$lib/translations"; + import { enhance } from "$app/forms"; + import { Icon, Numpad, Spinner } from "$comp"; + import { page } from "$app/stores"; + import { back } from "$lib/utils"; + import { pin } from "$lib/store"; - export let data; - export let form; + export let data; + export let form; - let { amount, name } = $page.params; - let { rates } = data; - let { currency } = data.user; - let loading; + let { amount, name } = $page.params; + let { rates } = data; + let { currency } = data.user; + let loading; - $: rate = rates[currency]; + $: rate = rates[currency]; - let submit = () => (loading = true); - $: update(form); - let update = () => { - if (form?.message?.includes('pin')) $pin = undefined; - loading = false; - }; + let submit = () => (loading = true); + $: update(form); + let update = () => { + if (form?.message?.includes("pin")) $pin = undefined; + loading = false; + }; </script> <button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={back}> - <Icon icon="arrow-left" style="w-10" /> + <Icon icon="arrow-left" style="w-10" /> </button> {#if form?.message} - <div class="text-red-600 text-center"> - {form.message} - </div> + <div class="text-red-600 text-center"> + {form.message} + </div> {/if} <div class="container px-4 mt-20 max-w-xl mx-auto"> - <Numpad bind:amount {currency} bind:rate /> + <Numpad bind:amount {currency} bind:rate /> - <form method="POST" use:enhance on:submit={submit}> - <input name="name" value={name} type="hidden" /> - <input name="amount" value={amount} type="hidden" /> - <input name="pin" value={$pin} type="hidden" /> + <form method="POST" use:enhance on:submit={submit}> + <input name="name" value={name} type="hidden" /> + <input name="amount" value={amount} type="hidden" /> + <input name="pin" value={$pin} type="hidden" /> - <div class="flex w-full"> - <button - type="submit" - class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" - > - {#if loading} - <Spinner /> - {:else} - {$t('payments.send')} - {/if} - </button> - </div> - </form> + <div class="flex w-full"> + <button + type="submit" + class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" + > + {#if loading} + <Spinner /> + {:else} + {$t("payments.send")} + {/if} + </button> + </div> + </form> </div> diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.js b/src/routes/(app)/send/invoice/[id]/+page.server.js index 4cbbb03f..aa284328 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.js +++ b/src/routes/(app)/send/invoice/[id]/+page.server.js @@ -1,37 +1,48 @@ -import { error, fail, redirect } from '@sveltejs/kit'; -import { fd, auth, get, post } from '$lib/utils'; +import { error, fail, redirect } from "@sveltejs/kit"; +import { fd, auth, get, post } from "$lib/utils"; export async function load({ params: { id }, parent, url }) { - let { user } = await parent(); + let { user } = await parent(); - let { - amount, - address, - currency, - hash, - rate, - prompt, - tip, - text, - user: recipient - } = await get(`/invoice/${id}`); + let { + amount, + address, + currency, + hash, + rate, + prompt, + tip, + text, + user: recipient, + } = await get(`/invoice/${id}`); - if (prompt && tip === null) throw redirect(307, `/${recipient.username}/invoice/${id}/tip`); - if (recipient.username === user.username) throw error(500, { message: 'Cannot send to self' }); - return { amount, address, currency, hash, tip, rate, payreq: text, recipient }; + if (prompt && tip === null) + throw redirect(307, `/${recipient.username}/invoice/${id}/tip`); + if (recipient.username === user.username) + throw error(500, { message: "Cannot send to self" }); + return { + amount, + address, + currency, + hash, + tip, + rate, + payreq: text, + recipient, + }; } export const actions = { - default: async ({ cookies, params: { id }, request }) => { - try { - let body = await fd(request); - body.hash = id; + default: async ({ cookies, params: { id }, request }) => { + try { + let body = await fd(request); + body.hash = id; - await post('/payments', body, auth(cookies)); - } catch (e) { - return fail(400, { message: e.message }); - } + await post("/payments", body, auth(cookies)); + } catch (e) { + return fail(400, { message: e.message }); + } - throw redirect(307, '/sent'); - } + throw redirect(307, "/sent"); + }, }; diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 02ab9d41..d29f1c96 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -1,154 +1,168 @@ <script> - import { onDestroy, onMount } from 'svelte'; - import { t } from '$lib/translations'; - import { goto, invalidateAll } from '$app/navigation'; - import { pin } from '$lib/store'; - import { enhance } from '$app/forms'; - import { Avatar, Icon, Numpad, Spinner } from '$comp'; - import { page } from '$app/stores'; - import { post, back, f, fiat as toFiat, s, sats } from '$lib/utils'; - export let data; - export let form; + import { onDestroy, onMount } from "svelte"; + import { t } from "$lib/translations"; + import { goto, invalidateAll } from "$app/navigation"; + import { pin } from "$lib/store"; + import { enhance } from "$app/forms"; + import { Avatar, Icon, Numpad, Spinner } from "$comp"; + import { page } from "$app/stores"; + import { post, back, f, fiat as toFiat, s, sats } from "$lib/utils"; + export let data; + export let form; - let { address, hash, rate, payreq, recipient, tip, rates, user } = data; - let { currency } = user; + let { address, hash, rate, payreq, recipient, tip, rates, user } = data; + let { currency } = user; - let amount = form?.amount || data.amount; - let a, - af, - amountFiat = amount * (rate / sats), - fiat = !amount; + let amount = form?.amount || data.amount; + let a, + af, + amountFiat = amount * (rate / sats), + fiat = !amount; - let setAmount = () => { - amount = a; - amountFiat = af; - }; + let setAmount = () => { + amount = a; + amountFiat = af; + }; - let loading; - let submit = () => (loading = true); + let loading; + let submit = () => (loading = true); - let external = async () => { - let invoice = { type: 'lightning', amount, currency }; - let { id } = await post(`/${recipient.username}/invoice`, { - invoice, - user: { username: recipient.username } - }); + let external = async () => { + let invoice = { type: "lightning", amount, currency }; + let { id } = await post(`/${recipient.username}/invoice`, { + invoice, + user: { username: recipient.username }, + }); - goto(`/${recipient.username}/invoice/${id}?options=true`, { invalidateAll: true }); - }; + goto(`/${recipient.username}/invoice/${id}?options=true`, { + invalidateAll: true, + }); + }; - $: rate = data.rate * (rates[user.currency] / rates[data.currency]); + $: rate = data.rate * (rates[user.currency] / rates[data.currency]); - $: update(form); - let update = () => { - if (form?.message.includes('pin')) $pin = undefined; - loading = false; - }; + $: update(form); + let update = () => { + if (form?.message.includes("pin")) $pin = undefined; + loading = false; + }; - // onMount(async () => { - // if (browser && window.NDEFReader) { - // try { - // let ndef = new NDEFReader(); - // await ndef.scan(); - // - // ndef.addEventListener('readingerror', (e) => { - // console.log('nfc error', e); - // }); - // - // ndef.addEventListener('reading', ({ message, serialNumber }) => { - // console.log(message, serialNumber); - // }); - // } catch (e) { - // console.log('NFC error', e); - // } - // } - // }); + // onMount(async () => { + // if (browser && window.NDEFReader) { + // try { + // let ndef = new NDEFReader(); + // await ndef.scan(); + // + // ndef.addEventListener('readingerror', (e) => { + // console.log('nfc error', e); + // }); + // + // ndef.addEventListener('reading', ({ message, serialNumber }) => { + // console.log(message, serialNumber); + // }); + // } catch (e) { + // console.log('NFC error', e); + // } + // } + // }); </script> <button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={back}> - <Icon icon="arrow-left" style="w-10" /> + <Icon icon="arrow-left" style="w-10" /> </button> {#if form?.message} - <div class="text-red-600 text-center"> - {form.message} - </div> + <div class="text-red-600 text-center"> + {form.message} + </div> {/if} <div class="container px-4 mt-20 max-w-xl mx-auto"> - {#if amount} - <div class="text-center mb-8"> - <h1 class="text-xl md:text-2xl text-secondary mb-2"> - {$t('payments.send')} - </h1> - <h2 class="text-2xl md:text-3xl font-semibold"> - {f(toFiat(amount, rate), currency)} - {#if tip} - <span class="text-lg"> - + {f(toFiat(tip, rate), currency)} - </span> - {/if} - </h2> - <h3 class="text-secondary md:text-lg mb-6 mt-1"> - ⚡️{s(amount)} + {#if amount} + <div class="text-center mb-8"> + <h1 class="text-xl md:text-2xl text-secondary mb-2"> + {$t("payments.send")} + </h1> + <h2 class="text-2xl md:text-3xl font-semibold"> + {f(toFiat(amount, rate), currency)} + {#if tip} + <span class="text-lg"> + + {f(toFiat(tip, rate), currency)} + </span> + {/if} + </h2> + <h3 class="text-secondary md:text-lg mb-6 mt-1"> + ⚡️{s(amount)} - {#if tip} - <span class="text-lg"> - + ⚡️{s(tip)} - </span> - {/if} - </h3> + {#if tip} + <span class="text-lg"> + + ⚡️{s(tip)} + </span> + {/if} + </h3> - <h1 class="text-xl md:text-2xl text-secondary mb-2">{$t('payments.to')}</h1> + <h1 class="text-xl md:text-2xl text-secondary mb-2"> + {$t("payments.to")} + </h1> - <div class="flex p-1 gap-2 justify-center"> - {#if recipient.username.includes('@classic')} - <img - src="/images/classic.png" - class="w-24 border-4 border-transparent mr-1" - alt="Bitcoin" - /> - {:else} - <Avatar user={recipient} size={'20'} /> - {/if} - <p class="text-4xl break-words my-auto">{recipient.username.replace('@classic', '')}</p> - </div> - </div> - {:else} - <Numpad bind:amount={a} bind:amountFiat={af} {currency} bind:fiat bind:rate /> - {/if} + <div class="flex p-1 gap-2 justify-center"> + {#if recipient.username.includes("@classic")} + <img + src="/images/classic.png" + class="w-24 border-4 border-transparent mr-1" + alt="Bitcoin" + /> + {:else} + <Avatar user={recipient} size={"20"} /> + {/if} + <p class="text-4xl break-words my-auto"> + {recipient.username.replace("@classic", "")} + </p> + </div> + </div> + {:else} + <Numpad + bind:amount={a} + bind:amountFiat={af} + {currency} + bind:fiat + bind:rate + /> + {/if} - <form method="POST" use:enhance on:submit={submit}> - <input name="address" value={address} type="hidden" /> - <input name="amount" value={amount} type="hidden" /> - <input name="payreq" value={payreq} type="hidden" /> - <input name="username" value={recipient.username} type="hidden" /> - <input name="pin" value={$pin} type="hidden" /> + <form method="POST" use:enhance on:submit={submit}> + <input name="address" value={address} type="hidden" /> + <input name="amount" value={amount} type="hidden" /> + <input name="payreq" value={payreq} type="hidden" /> + <input name="username" value={recipient.username} type="hidden" /> + <input name="pin" value={$pin} type="hidden" /> - <div class="flex w-full"> - {#if amount} - <button - type="submit" - class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" - > - {#if loading} - <Spinner /> - {:else} - {$t('payments.send')} - {/if} - </button> - {:else} - <button - type="button" - class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" - on:click={setAmount} - > - {$t('payments.next')} - </button> - {/if} - </div> - </form> - <div class="flex my-20"> - <button class="mx-auto" on:click={external}>{$t('payments.moreOptions')}</button> - </div> + <div class="flex w-full"> + {#if amount} + <button + type="submit" + class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" + > + {#if loading} + <Spinner /> + {:else} + {$t("payments.send")} + {/if} + </button> + {:else} + <button + type="button" + class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" + on:click={setAmount} + > + {$t("payments.next")} + </button> + {/if} + </div> + </form> + <div class="flex my-20"> + <button class="mx-auto" on:click={external} + >{$t("payments.moreOptions")}</button + > + </div> </div> diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.server.js b/src/routes/(app)/send/lightning/[payreq]/+page.server.js index d358bbca..d9e791e1 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.server.js +++ b/src/routes/(app)/send/lightning/[payreq]/+page.server.js @@ -1,24 +1,24 @@ -import { fail, redirect } from '@sveltejs/kit'; -import { fd, auth, post } from '$lib/utils'; +import { fail, redirect } from "@sveltejs/kit"; +import { fd, auth, post } from "$lib/utils"; export async function load({ params }) { - return post('/parse', params); + return post("/parse", params); } export const actions = { - setAmount: async ({ cookies, request }) => fd(request), + setAmount: async ({ cookies, request }) => fd(request), - send: async ({ cookies, request }) => { - try { - let body = await fd(request); + send: async ({ cookies, request }) => { + try { + let body = await fd(request); - await post('/payments', body, auth(cookies)); - } catch (e) { - if (e.message.includes('unusable')) - e.message = 'Failed to route payment, try sending a lower amount'; - return fail(400, { message: e.message }); - } + await post("/payments", body, auth(cookies)); + } catch (e) { + if (e.message.includes("unusable")) + e.message = "Failed to route payment, try sending a lower amount"; + return fail(400, { message: e.message }); + } - throw redirect(307, '/sent'); - } + throw redirect(307, "/sent"); + }, }; diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/+page.svelte index e232ef05..185597c7 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/+page.svelte @@ -1,105 +1,120 @@ <script> - import { t } from '$lib/translations'; - import { enhance } from '$app/forms'; - import { Icon, Numpad, Spinner } from '$comp'; - import { page } from '$app/stores'; - import { back, s } from '$lib/utils'; - import { pin } from '$lib/store'; + import { t } from "$lib/translations"; + import { enhance } from "$app/forms"; + import { Icon, Numpad, Spinner } from "$comp"; + import { page } from "$app/stores"; + import { back, s } from "$lib/utils"; + import { pin } from "$lib/store"; - export let data; - export let form; + export let data; + export let form; - let { payreq } = $page.params; - let { alias, rates } = data; + let { payreq } = $page.params; + let { alias, rates } = data; - let { currency } = data.user; - let a; - let maxfee = 500; + let { currency } = data.user; + let a; + let maxfee = 500; - $: amount = form?.amount || data.amount; - $: rate = rates[currency]; + $: amount = form?.amount || data.amount; + $: rate = rates[currency]; - let loading; - let submit = () => (loading = true); - $: update(form); - let update = () => { - if (form?.message?.includes('pin')) $pin = undefined; - loading = false; - }; + let loading; + let submit = () => (loading = true); + $: update(form); + let update = () => { + if (form?.message?.includes("pin")) $pin = undefined; + loading = false; + }; - let show; - let toggle = () => (show = !show); + let show; + let toggle = () => (show = !show); </script> <button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={back}> - <Icon icon="arrow-left" style="w-10" /> + <Icon icon="arrow-left" style="w-10" /> </button> {#if form?.message} - <div class="text-red-600 text-center"> - {form.message} - </div> + <div class="text-red-600 text-center"> + {form.message} + </div> {/if} <div class="container px-4 mt-20 max-w-xl mx-auto"> - {#if amount} - <div class="text-center mb-8"> - <h1 class="text-xl md:text-2xl text-secondary mb-2">{$t('payments.send')}</h1> - <p class="text-6xl break-words mb-4"> - ⚡️{s(amount)} - </p> - <h1 class="text-xl md:text-2xl text-secondary mb-2">{$t('payments.to')}</h1> - <p class="text-4xl break-words">{alias}</p> - </div> + {#if amount} + <div class="text-center mb-8"> + <h1 class="text-xl md:text-2xl text-secondary mb-2"> + {$t("payments.send")} + </h1> + <p class="text-6xl break-words mb-4"> + ⚡️{s(amount)} + </p> + <h1 class="text-xl md:text-2xl text-secondary mb-2"> + {$t("payments.to")} + </h1> + <p class="text-4xl break-words">{alias}</p> + </div> - <form method="POST" use:enhance on:submit={submit} action="?/send" class="space-y-5"> - <input name="payreq" value={payreq} type="hidden" /> - <input name="amount" value={amount} type="hidden" /> - <input name="pin" value={$pin} type="hidden" /> - <input name="maxfee" value={maxfee} type="hidden" /> + <form + method="POST" + use:enhance + on:submit={submit} + action="?/send" + class="space-y-5" + > + <input name="payreq" value={payreq} type="hidden" /> + <input name="amount" value={amount} type="hidden" /> + <input name="pin" value={$pin} type="hidden" /> + <input name="maxfee" value={maxfee} type="hidden" /> - <div class="flex w-full"> - <button - type="submit" - class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" - disabled={loading} - > - {#if loading} - <Spinner /> - {:else} - {$t('payments.send')} - {/if} - </button> - </div> - </form> + <div class="flex w-full"> + <button + type="submit" + class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" + disabled={loading} + > + {#if loading} + <Spinner /> + {:else} + {$t("payments.send")} + {/if} + </button> + </div> + </form> - {#if show} - <div class="relative w-96 mx-auto"> - <label for="maxfee">Max fee</label> - <input name="maxfee" bind:value={maxfee} /> + {#if show} + <div class="relative w-96 mx-auto"> + <label for="maxfee">Max fee</label> + <input name="maxfee" bind:value={maxfee} /> - <div - class="absolute right-[2px] top-[25px] text-gray-600 rounded-r-2xl p-4 h-[54px] my-auto border-l " - > - ⚡️ - </div> - </div> - {:else} - <div class="flex w-full mt-5"> - <button class="mx-auto" on:click={toggle}>Settings</button> - </div> - {/if} - {:else} - <form method="POST" action="?/setAmount" class="w-[300px] mx-auto" use:enhance> - <input type="hidden" value={a} name="amount" /> - <Numpad bind:amount={a} {currency} {rate} /> - <button - type="submit" - class="bg-black text-white rounded-xl h-[48px] flex w-full justify-center items-center font-semibold + <div + class="absolute right-[2px] top-[25px] text-gray-600 rounded-r-2xl p-4 h-[54px] my-auto border-l" + > + ⚡️ + </div> + </div> + {:else} + <div class="flex w-full mt-5"> + <button class="mx-auto" on:click={toggle}>Settings</button> + </div> + {/if} + {:else} + <form + method="POST" + action="?/setAmount" + class="w-[300px] mx-auto" + use:enhance + > + <input type="hidden" value={a} name="amount" /> + <Numpad bind:amount={a} {currency} {rate} /> + <button + type="submit" + class="bg-black text-white rounded-xl h-[48px] flex w-full justify-center items-center font-semibold opacity-100 hover:opacity-80" - > - Next - </button> - </form> - {/if} + > + Next + </button> + </form> + {/if} </div> diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js index a01cdcfc..1f3a0420 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js @@ -1,46 +1,47 @@ -import { error, fail, redirect } from '@sveltejs/kit'; -import { types, sats, fd, auth, get, post } from '$lib/utils'; +import { error, fail, redirect } from "@sveltejs/kit"; +import { types, sats, fd, auth, get, post } from "$lib/utils"; export async function load({ cookies, params, parent }) { - let subject = await get(`/users/${params.username}`); + let subject = await get(`/users/${params.username}`); - let { rates, user } = await parent(); - let { username } = params; - let [amount, currency] = params.amount.split('/'); + let { rates, user } = await parent(); + let { username } = params; + let [amount, currency] = params.amount.split("/"); - if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' }); + if (subject.username === user?.username) + throw error(500, { message: "Cannot send to self" }); - let rate; - if (amount) { - rate = rates[currency ? currency.toUpperCase() : subject.currency]; - if (!rate) throw error(500, 'Invalid currency symbol'); - if (currency) amount = (amount * sats) / rate; + let rate; + if (amount) { + rate = rates[currency ? currency.toUpperCase() : subject.currency]; + if (!rate) throw error(500, "Invalid currency symbol"); + if (currency) amount = (amount * sats) / rate; - let { hash } = await post( - '/invoice', - { - invoice: { amount, prompt: false, type: types.lightning }, - user: { username } - }, - auth(cookies) - ); + let { hash } = await post( + "/invoice", + { + invoice: { amount, prompt: false, type: types.lightning }, + user: { username }, + }, + auth(cookies) + ); - throw redirect(307, `/${username}/invoice/${hash}`); - } + throw redirect(307, `/${username}/invoice/${hash}`); + } - return { amount, rate, subject }; + return { amount, rate, subject }; } export const actions = { - default: async ({ cookies, request }) => { - try { - let body = await fd(request); - await post('/payments', body, auth(cookies)); - } catch (e) { - console.log(e); - return fail(400, { message: e.message }); - } + default: async ({ cookies, request }) => { + try { + let body = await fd(request); + await post("/payments", body, auth(cookies)); + } catch (e) { + console.log(e); + return fail(400, { message: e.message }); + } - throw redirect(307, '/sent'); - } + throw redirect(307, "/sent"); + }, }; diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte index 32a13939..cb458323 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte @@ -1,103 +1,103 @@ <script> - import { t } from '$lib/translations'; - import { goto } from '$app/navigation'; - import { pin } from '$lib/store'; - import { enhance } from '$app/forms'; - import { AppHeader, Avatar, Icon, Numpad, Spinner } from '$comp'; - import { page } from '$app/stores'; - import { f, post, s, sat, sats } from '$lib/utils'; + import { t } from "$lib/translations"; + import { goto } from "$app/navigation"; + import { pin } from "$lib/store"; + import { enhance } from "$app/forms"; + import { AppHeader, Avatar, Icon, Numpad, Spinner } from "$comp"; + import { page } from "$app/stores"; + import { f, post, s, sat, sats } from "$lib/utils"; - export let data; - export let form; + export let data; + export let form; - let { subject, rate, rates, user } = data; - let currency = user.currency || subject.currency || 'USD'; - let next; + let { subject, rate, rates, user } = data; + let currency = user.currency || subject.currency || "USD"; + let next; - let amount = form?.amount || data.amount; - let a, - af, - fiat = !amount, - hash, - amountFiat = 0; + let amount = form?.amount || data.amount; + let a, + af, + fiat = !amount, + hash, + amountFiat = 0; - $: r = rate || rates[user.currency || subject.currency]; + $: r = rate || rates[user.currency || subject.currency]; - let setAmount = async () => { - amount = a; - amountFiat = parseFloat(af).toFixed(2); - rate = fiat ? (sats * amountFiat) / amount : r; - ({ hash } = await post(`/${subject.username}/invoice`, { - invoice: { - amount, - hash: 'internal', - rate: rates[subject.currency], - prompt: subject.prompt, - type: 'internal' - }, - user: subject - })); + let setAmount = async () => { + amount = a; + amountFiat = parseFloat(af).toFixed(2); + rate = fiat ? (sats * amountFiat) / amount : r; + ({ hash } = await post(`/${subject.username}/invoice`, { + invoice: { + amount, + hash: "internal", + rate: rates[subject.currency], + prompt: subject.prompt, + type: "internal", + }, + user: subject, + })); - goto(`/${subject.username}/invoice/${hash}`); - }; + goto(`/${subject.username}/invoice/${hash}`); + }; - let loading; - let submit = () => (loading = true); + let loading; + let submit = () => (loading = true); - $: update(form); - let update = () => { - if (form?.message?.includes('pin')) $pin = undefined; - loading = false; - }; + $: update(form); + let update = () => { + if (form?.message?.includes("pin")) $pin = undefined; + loading = false; + }; </script> <AppHeader {data} /> {#if form?.message} - <div class="text-red-600 text-center"> - {form.message} - </div> + <div class="text-red-600 text-center"> + {form.message} + </div> {/if} <div class="container px-4 mt-20 max-w-xl mx-auto space-y-8"> - <Numpad - bind:amount={a} - bind:amountFiat={af} - {currency} - bind:fiat - bind:rate={r} - bind:submit={next} - /> + <Numpad + bind:amount={a} + bind:amountFiat={af} + {currency} + bind:fiat + bind:rate={r} + bind:submit={next} + /> - <form method="POST" use:enhance on:submit={submit}> - <input name="amount" value={amount} type="hidden" /> - <input name="username" value={subject.username} type="hidden" /> - <input name="pin" value={$pin} type="hidden" /> - <input name="hash" value={hash} type="hidden" /> + <form method="POST" use:enhance on:submit={submit}> + <input name="amount" value={amount} type="hidden" /> + <input name="username" value={subject.username} type="hidden" /> + <input name="pin" value={$pin} type="hidden" /> + <input name="hash" value={hash} type="hidden" /> - <div class="flex w-full"> - {#if amount} - <button - type="submit" - class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" - > - {#if loading} - <Spinner /> - {:else} - {$t('payments.send')} - {/if} - </button> - {:else} - <button - type="button" - bind:this={next} - class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" - on:click={setAmount} - on:keydown={setAmount} - > - Next - </button> - {/if} - </div> - </form> + <div class="flex w-full"> + {#if amount} + <button + type="submit" + class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" + > + {#if loading} + <Spinner /> + {:else} + {$t("payments.send")} + {/if} + </button> + {:else} + <button + type="button" + bind:this={next} + class="opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold mx-auto mt-2 bg-black text-white px-4 w-24" + on:click={setAmount} + on:keydown={setAmount} + > + Next + </button> + {/if} + </div> + </form> </div> |
