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/invoice | |
| parent | 7d9bc1f54dfd04172e8d6d43ebc2efd6f407e833 (diff) | |
| download | coinos-ui-216a600224fde22ce76b367557a02094ec693886.tar.gz coinos-ui-216a600224fde22ce76b367557a02094ec693886.zip | |
prettier
Diffstat (limited to 'src/routes/(app)/send/invoice')
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.js | 65 | ||||
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.svelte | 272 |
2 files changed, 181 insertions, 156 deletions
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> |
