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/user | |
| parent | 7d9bc1f54dfd04172e8d6d43ebc2efd6f407e833 (diff) | |
| download | coinos-ui-216a600224fde22ce76b367557a02094ec693886.tar.gz coinos-ui-216a600224fde22ce76b367557a02094ec693886.zip | |
prettier
Diffstat (limited to 'src/routes/(app)/send/user')
| -rw-r--r-- | src/routes/(app)/send/user/[username]/[...amount]/+page.server.js | 67 | ||||
| -rw-r--r-- | src/routes/(app)/send/user/[username]/[...amount]/+page.svelte | 166 |
2 files changed, 117 insertions, 116 deletions
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> |
