diff options
| author | Adam Soltys <[email protected]> | 2023-01-18 19:44:27 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-18 19:44:27 -0800 |
| commit | 67c4af186fec0423664b18847921eb9696a1eeef (patch) | |
| tree | 85e0fb00f3aa89fdde1cbb667bf801564bff7610 /src/routes/(app)/pot | |
| parent | b1ad12734eeafc36a07bd76f649a98ae9ade5723 (diff) | |
| download | coinos-ui-67c4af186fec0423664b18847921eb9696a1eeef.tar.gz coinos-ui-67c4af186fec0423664b18847921eb9696a1eeef.zip | |
pots
Diffstat (limited to 'src/routes/(app)/pot')
| -rw-r--r-- | src/routes/(app)/pot/[name]/+page.server.js | 23 | ||||
| -rw-r--r-- | src/routes/(app)/pot/[name]/+page.svelte | 96 | ||||
| -rw-r--r-- | src/routes/(app)/pot/[name]/withdraw/+page.server.js | 21 | ||||
| -rw-r--r-- | src/routes/(app)/pot/[name]/withdraw/+page.svelte | 55 |
4 files changed, 195 insertions, 0 deletions
diff --git a/src/routes/(app)/pot/[name]/+page.server.js b/src/routes/(app)/pot/[name]/+page.server.js new file mode 100644 index 00000000..8f8b9d8f --- /dev/null +++ b/src/routes/(app)/pot/[name]/+page.server.js @@ -0,0 +1,23 @@ +import { error, redirect } from '@sveltejs/kit'; +import { auth, get, post } from '$lib/utils'; +import Qr from 'qrcode-base64'; + +export let load = async ({ params: { name }, url }) => { + let { amount, payments } = await get(`/pot/${name}`); + + let src = Qr.drawImg(url.href, { size: 300 }); + return { amount, payments, src }; +}; + +export const actions = { + default: async ({ cookies, locals, params, request }) => { + let { user } = locals; + + if (user) { + await post('/redeem', params, auth(cookies)); + throw redirect(307, `/${user.username}/payments`); + } + + throw redirect(307, '/register'); + } +}; diff --git a/src/routes/(app)/pot/[name]/+page.svelte b/src/routes/(app)/pot/[name]/+page.svelte new file mode 100644 index 00000000..48dc9b31 --- /dev/null +++ b/src/routes/(app)/pot/[name]/+page.svelte @@ -0,0 +1,96 @@ +<script> + import { format } from 'date-fns'; + import { enhance } from '$app/forms'; + import { page } from '$app/stores'; + import { Avatar, Icon } from '$comp'; + import { toast } from '@zerodevx/svelte-toast'; + import { t } from '$lib/translations'; + import { copy, f, s, sat, sats } from '$lib/utils'; + import { loginRedirect, selectedRate } from '$lib/store'; + + export let data; + + let { amount, src, payments, rates, user } = data; + let { name } = $page.params; + + toast.pop(0); + + let currency = user ? user.currency : 'CAD'; + let rate = rates[currency]; + + $: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2)); + $loginRedirect = $page.url.pathname; +</script> + +<div class="container px-4 max-w-xl mx-auto mt-10 space-y-5"> + <div class="w-full flex"> + <a href="/" class="mx-auto"> + <Icon icon="logo" /> + </a> + </div> + + <div class="flex justify-center items-center text-center"> + <div class="shadow-xl rounded-3xl px-10 pt-5 pb-10 space-y-5 w-full mx-5"> + <div class="relative"> + <!-- <p class="absolute right-0 top-1 underline"><Icon icon="settings" /></p> --> + <h1 class="text-2xl md:text-3xl font-semibold">Public Pot</h1> + </div> + <p class="text-secondary">Anyone who knows the URL for this pot can add or take out funds</p> + <div class="flex justify-center gap-4"> + <div class="my-auto"> + <h2 class="text-2xl md:text-3xl font-semibold"> + {f(amountFiat, currency)} + </h2> + <h3 class="text-secondary md:text-lg mt-1"> + {sat(amount)} + </h3> + </div> + </div> + <div class="mx-auto my-auto flex gap-2 justify-center" data-sveltekit-prefetch="off"> + <a href={`/send/pot/${name}`}> + <button class="text-lg rounded-full border py-3 px-7 font-bold hover:opacity-80"> + Chip in + </button> + </a> + <a href={`/pot/${name}/withdraw`}> + <button class="text-lg rounded-full border py-3 px-7 font-bold hover:opacity-80"> + Dip in + </button> + </a> + </div> + <div class="text-base"> + {#each payments as p} + <a href={`/${p.user.username}`}> + <div class="flex h-24 hover:bg-gray-100 px-4"> + <div class="flex grow"> + <div class="flex my-auto"> + <div class="my-auto"> + <Avatar user={p.user} size={12} /> + </div> + <div class="ml-1 text-secondary my-auto"> + {p.user.username} + {p.amount > 0 ? 'took out' : 'threw in'} + </div> + </div> + <div class="text-secondary my-auto"> + {sat(p.amount)} + </div> + </div> + + <div class="text-secondary text-right text-sm my-auto"> + <div> + {format(new Date(p.created), 'h:mm aaa')} + </div> + <div> + {format(new Date(p.created), 'MMM d')} + </div> + </div> + </div> + </a> + {:else} + <p class="text-secondary text-lg text-center">{$t('payments.empty')}</p> + {/each} + </div> + </div> + </div> +</div> diff --git a/src/routes/(app)/pot/[name]/withdraw/+page.server.js b/src/routes/(app)/pot/[name]/withdraw/+page.server.js new file mode 100644 index 00000000..6534e07b --- /dev/null +++ b/src/routes/(app)/pot/[name]/withdraw/+page.server.js @@ -0,0 +1,21 @@ +import { invalid, redirect } from '@sveltejs/kit'; +import { auth, post } from '$lib/utils'; + +export async function load({ parent }) { + let { user } = await parent(); + if (!user) throw redirect(307, '/register'); +} + +export const actions = { + default: async ({ cookies, request }) => { + let body = Object.fromEntries(await request.formData()); + + try { + await post('/withdraw', body, auth(cookies)); + } catch (e) { + return invalid(400, { message: e.message }); + } + + throw redirect(307, `/pot/${body.name}`); + } +}; diff --git a/src/routes/(app)/pot/[name]/withdraw/+page.svelte b/src/routes/(app)/pot/[name]/withdraw/+page.svelte new file mode 100644 index 00000000..bb11ddde --- /dev/null +++ b/src/routes/(app)/pot/[name]/withdraw/+page.svelte @@ -0,0 +1,55 @@ +<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'; + + export let data; + export let form; + + let { amount, name } = $page.params; + let { currency } = data.user; + let loading; + + 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" /> +</button> + +{#if form?.message} + <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} /> + + <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> |
