diff options
Diffstat (limited to 'src/routes/(app)/fund')
| -rw-r--r-- | src/routes/(app)/fund/[id]/+layout.server.ts | 12 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/+page.server.ts | 13 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/+page.svelte | 26 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/access/+page.server.ts | 3 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/access/+page.svelte | 13 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts | 36 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte | 27 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/gift/+page.server.ts | 6 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/gift/+page.svelte | 40 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/+page.server.ts | 13 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/+page.svelte | 41 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts | 56 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte | 36 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/withdraw/+page.svelte | 8 |
14 files changed, 228 insertions, 102 deletions
diff --git a/src/routes/(app)/fund/[id]/+layout.server.ts b/src/routes/(app)/fund/[id]/+layout.server.ts new file mode 100644 index 00000000..3669eb7d --- /dev/null +++ b/src/routes/(app)/fund/[id]/+layout.server.ts @@ -0,0 +1,12 @@ +import getRates from "$lib/rates"; +import { get } from "$lib/utils"; + +export const load = async ({ depends, params: { id }, parent }) => { + depends("app:payments"); + const data = await get(`/fund/${id}`); + data.managers = await get(`/fund/${id}/managers`); + const rates = await getRates(); + const { user } = await parent(); + data.rate = rates[user?.currency || "USD"]; + return data; +}; diff --git a/src/routes/(app)/fund/[id]/+page.server.ts b/src/routes/(app)/fund/[id]/+page.server.ts index a4f402af..cd2bd979 100644 --- a/src/routes/(app)/fund/[id]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/+page.server.ts @@ -1,17 +1,6 @@ -import getRates from "$lib/rates"; -import { auth, get, post } from "$lib/utils"; +import { auth, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export const load = async ({ depends, params: { id }, parent }) => { - depends("app:payments"); - const data = await get(`/fund/${id}`); - data.managers = await get(`/fund/${id}/managers`); - const rates = await getRates(); - const { user } = await parent(); - data.rate = rates[user?.currency || "USD"]; - return data; -}; - export const actions = { default: async ({ cookies, locals, params }) => { const { user } = locals; diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index f1a1838e..a22e4b93 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -79,32 +79,6 @@ </a> {/if} </div> - <div class="flex flex-wrap gap-2" data-sveltekit-prefetch="off"> - <div class="grow"> - <a href={`/send/fund/${id}`}> - <button class="btn"> - <iconify-icon noobserver icon="ph:plus-bold" width="32" - ></iconify-icon> - {$t("payments.addFunds")} - </button> - </a> - </div> - {#if !managers.length || managers.some((m) => m.id === user?.id)} - <div class="grow"> - <a href={`/fund/${id}/withdraw`}> - <button class="btn"> - <iconify-icon - noobserver - icon="ph:hand-coins-bold" - width="32" - flip="horizontal" - ></iconify-icon> - {$t("payments.takeFunds")} - </button> - </a> - </div> - {/if} - </div> <div class="flex gap-2" data-sveltekit-prefetch="off"> <a href={`/qr/${href}`} class="btn !w-auto grow"> <iconify-icon noobserver icon="ph:link-bold" width="32" diff --git a/src/routes/(app)/fund/[id]/access/+page.server.ts b/src/routes/(app)/fund/[id]/access/+page.server.ts index c38cb29b..36191643 100644 --- a/src/routes/(app)/fund/[id]/access/+page.server.ts +++ b/src/routes/(app)/fund/[id]/access/+page.server.ts @@ -11,11 +11,8 @@ export const actions = { const form = await fd(request); try { - console.log("SUBMITTING", form); const managers = await post("/fund/managers", form, auth(cookies)); - console.log(managers); - return { managers }; } catch (e) { const { message } = e as Error; diff --git a/src/routes/(app)/fund/[id]/access/+page.svelte b/src/routes/(app)/fund/[id]/access/+page.svelte index a2ea9dff..cc2921c5 100644 --- a/src/routes/(app)/fund/[id]/access/+page.svelte +++ b/src/routes/(app)/fund/[id]/access/+page.svelte @@ -6,10 +6,15 @@ let { data } = $props(); let { id, managers } = $derived(data); + let m = $state(data.managers); + $effect(() => (m = data.managers)); let username = $state(); - let del = async ({ id }) => { + let del = async (e, user) => { + e.preventDefault(); try { - await post("/post/fund/access/delete", { id }); + m = await post(`/post/fund/${id}/managers/delete`, { + id: user.id, + }); } catch (e) { fail(e.message); } @@ -25,14 +30,14 @@ Fund managers </h1> - {#each managers as c} + {#each m as c} <a href={`/${c.username}`} class="contents"> <div class="flex hover:bg-base-200 p-2 items-center"> <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> - <button onclick={() => del(c)} class="ml-auto"> + <button onclick={(e) => del(e, c)} class="ml-auto"> <iconify-icon icon="ph:trash-bold" width="32"></iconify-icon> </button> </div> diff --git a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts new file mode 100644 index 00000000..e5683ae6 --- /dev/null +++ b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts @@ -0,0 +1,36 @@ +import getRates from "$lib/rates"; +import { auth, get, post, sats } from "$lib/utils"; +import { error, redirect } from "@sveltejs/kit"; + +export async function load({ cookies, params, parent }) { + const { user } = await parent(); + const { id } = params; + let [amount, currency] = params.amount.split("/"); + let fiat; + + if (!currency) currency = user?.currency; + if (currency) currency = currency.toUpperCase(); + + const rates = await getRates(); + const rate = rates[currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); + + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.amount; + } else if (currency) { + fiat = amount; + amount = Math.round((fiat * sats) / rate); + } + + if (!amount) redirect(307, `/fund/${id}`); + + try { + await post("/authorize", { amount, currency, fiat, id }, auth(cookies)); + } catch (e) { + console.log("caught", e); + redirect(307, `/fund/${id}`); + } + + return { amount, currency, id, rate, rates }; +} diff --git a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte new file mode 100644 index 00000000..b94c1ce9 --- /dev/null +++ b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.svelte @@ -0,0 +1,27 @@ +<script> + import { onMount } from "svelte"; + import Amount from "$comp/Amount.svelte"; + import Success from "$comp/Success.svelte"; + import { scale } from "svelte/transition"; + import { toFiat, f, s } from "$lib/utils"; + import Icon from "$comp/Icon.svelte"; + import { t } from "$lib/translations"; + import { loc } from "$lib/utils"; + + let { data } = $props(); + + let { amount, currency, id, user, rate, rates } = data; + let locale = $derived(loc(user)); +</script> + +<div class="container px-4 text-center mx-auto"> + <Success {amount} {rate} {currency} {locale} title="Authorized" /> +</div> + +<a href={`/fund/${id}`} aria-label="Continue"> + <div class="opacity-0 w-screen h-screen fixed top-24 left-0 z-50"></div> +</a> + +<div class="flex justify-center mt-4"> + {$t("payments.tapAnywhere")} +</div> diff --git a/src/routes/(app)/fund/[id]/gift/+page.server.ts b/src/routes/(app)/fund/[id]/gift/+page.server.ts new file mode 100644 index 00000000..bd39d82b --- /dev/null +++ b/src/routes/(app)/fund/[id]/gift/+page.server.ts @@ -0,0 +1,6 @@ +export const load = async ({ params, parent }) => { + const p = await parent(); + const { amount, rate } = p; + const { id } = params; + return { amount, id, rate }; +}; diff --git a/src/routes/(app)/fund/[id]/gift/+page.svelte b/src/routes/(app)/fund/[id]/gift/+page.svelte new file mode 100644 index 00000000..7c65d314 --- /dev/null +++ b/src/routes/(app)/fund/[id]/gift/+page.svelte @@ -0,0 +1,40 @@ +<script> + import Amount from "$comp/Amount.svelte"; + import { t } from "$lib/translations"; + import { page } from "$app/stores"; + import Icon from "$comp/Icon.svelte"; + import Qr from "$comp/Qr.svelte"; + import { loc, copy } from "$lib/utils"; + + let { data } = $props(); + let { id, user, amount, rate } = $derived(data); + let text = $page.url.href.replace("gift", "sweep"); + let currency = user ? user.currency : "CAD"; + let locale = loc(user); +</script> + +<div class="container px-4 max-w-4xl mx-auto space-y-5 pb-10"> + <h1 class="text-center text-2xl font-semibold">{$t("payments.gift")}</h1> + + <Amount {amount} {currency} {rate} {locale} /> + + <div class="text-secondary shadow-lg p-8 mx-auto text-center space-y-2"> + <p>{$t("payments.giftDesc1")}</p> + <p>{$t("payments.giftDesc2")}</p> + </div> + + <div class="flex gap-1 min-w-0 items-center"> + <button + type="button" + class="btn break-all !h-auto flex-nowrap p-4 font-normal shrink !w-auto max-w-full" + onclick={() => copy(text)} + > + <iconify-icon noobserver icon="ph:copy-bold" width="32"></iconify-icon> + <div class="my-auto break-all min-w-0 !w-auto max-w-full">{text}</div> + </button> + + <a href={`/qr/${encodeURIComponent(text)}`} class="btn !w-auto"> + <iconify-icon icon="ph:qr-code-bold" width={32}></iconify-icon> + </a> + </div> +</div> diff --git a/src/routes/(app)/fund/[id]/sweep/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/+page.server.ts deleted file mode 100644 index 5bb42fa4..00000000 --- a/src/routes/(app)/fund/[id]/sweep/+page.server.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { get, auth, post } from "$lib/utils"; -import { redirect } from "@sveltejs/kit"; - -export async function load({ cookies, params, parent }) { - const { user } = await parent(); - const { id } = params; - const { amount } = await get(`/fund/${id}`); - - if (!amount) redirect(307, `/fund/${id}`); - if (!user) redirect(307, `/register?redirect=/fund/${id}/sweep`); - await post("/take", { amount, id }, auth(cookies)); - return { amount, id }; -} diff --git a/src/routes/(app)/fund/[id]/sweep/+page.svelte b/src/routes/(app)/fund/[id]/sweep/+page.svelte deleted file mode 100644 index cd89f6ae..00000000 --- a/src/routes/(app)/fund/[id]/sweep/+page.svelte +++ /dev/null @@ -1,41 +0,0 @@ -<script> - import { scale } from "svelte/transition"; - import { toFiat, f, s } from "$lib/utils"; - import Icon from "$comp/Icon.svelte"; - import { t } from "$lib/translations"; - - let { data } = $props(); - - let { amount, id, user, rates } = data; - let { currency } = user; - let rate = $derived(rates[currency]); -</script> - -<div class="container px-4 max-w-xl mx-auto mt-10 space-y-5 text-center"> - <div class="w-full flex"> - <a href="/" class="mx-auto"> - <Icon icon="logo" /> - </a> - </div> - - <div class="flex w-full py-5 max-w-[200px] mx-auto" in:scale={{ start: 0.5 }}> - <Icon icon="check" style="mx-auto" /> - </div> - <h1 class="text-3xl md:text-4xl font-bold mb-6"> - {$t("payments.fundsClaimed")} - </h1> - <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> - -<a href={`/payments`}> - <div class="opacity-0 w-screen h-screen fixed top-0 left-0 z-50"></div> -</a> - -<div class="flex justify-center"> - {$t("payments.tapAnywhere")} -</div> diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts new file mode 100644 index 00000000..8cc463c2 --- /dev/null +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -0,0 +1,56 @@ +import { randomName, randomPassword } from "$lib/random"; +import getRates from "$lib/rates"; +import { auth, get, post, register, sats } from "$lib/utils"; +import { error, redirect } from "@sveltejs/kit"; +import { env } from "$env/dynamic/private"; + +export async function load({ cookies, request, params, parent }) { + let { user } = await parent(); + const { id } = params; + let [amount, currency] = params.amount.split("/"); + + if (!currency) currency = user?.currency; + if (currency) currency = currency.toUpperCase(); + const rates = await getRates(); + const rate = rates[currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); + + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.authorization || balance.amount; + } else if (currency) { + amount = Math.round((amount * sats) / rate); + } + + const username = randomName() + Math.floor(Math.random() * 99) + 1; + const password = randomPassword(); + + if (!amount) redirect(307, `/fund/${id}`); + if (!user) { + const ip = request.headers.get("cf-connecting-ip"); + + user = { + username, + password, + fresh: true, + }; + + let redirectUrl = `/fund/${id}/sweep`; + if (params.amount && !params.currency) redirectUrl += `/${params.amount}`; + if (params.currency) redirectUrl += `/${params.amount}/params.currency}`; + + const extraHeaders: Record<string, string> = {}; + if (env.INTERNAL_API_KEY) + extraHeaders["x-api-key"] = env.INTERNAL_API_KEY; + + await register(user, ip, cookies, redirectUrl, undefined, extraHeaders); + } + + try { + ({ amount } = await post("/take", { amount, id }, auth(cookies))); + } catch (e) { + redirect(307, `/fund/${id}`); + } + + return { amount, currency, id, rate, rates, password }; +} diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte new file mode 100644 index 00000000..7a7d5402 --- /dev/null +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte @@ -0,0 +1,36 @@ +<script> + import { onMount } from "svelte"; + import { password } from "$lib/store"; + import Amount from "$comp/Amount.svelte"; + import Success from "$comp/Success.svelte"; + import { scale } from "svelte/transition"; + import { toFiat, f, s } from "$lib/utils"; + import Icon from "$comp/Icon.svelte"; + import { t } from "$lib/translations"; + import { loc } from "$lib/utils"; + + let { data } = $props(); + + let { amount, currency, id, user, rate, rates, password: pw } = data; + let locale = $derived(loc(user)); + + onMount(() => ($password = pw)); +</script> + +<div class="container px-4 text-center mx-auto"> + <Success + {amount} + {rate} + {currency} + {locale} + title={$t("payments.received")} + /> +</div> + +<a href={`/${user.username}`} aria-label="Continue"> + <div class="opacity-0 w-screen h-screen fixed top-24 left-0 z-50"></div> +</a> + +<div class="flex justify-center mt-4"> + {$t("payments.tapAnywhere")} +</div> diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.svelte b/src/routes/(app)/fund/[id]/withdraw/+page.svelte index 78f9b16c..69a74a3f 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.svelte +++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte @@ -6,15 +6,17 @@ import Numpad from "$comp/Numpad.svelte"; import Spinner from "$comp/Spinner.svelte"; import { page } from "$app/stores"; - import { s } from "$lib/utils"; + import { loc, s } from "$lib/utils"; import { fiat, pin } from "$lib/store"; let { data, form } = $props(); - let { currency } = $derived(data.user); + let { user } = $derived(data); + let { currency } = $derived(user); let loading = $state(); let { id, balance, rate } = $derived(data); let { amount } = $state(data); + let locale = loc(user); let submit = $state(); let submitting = $state(); @@ -39,7 +41,7 @@ {/if} <div class="container px-4 mt-20 max-w-xl mx-auto"> - <Numpad bind:amount {currency} {fiat} {rate} {submit} /> + <Numpad bind:amount {currency} {fiat} {rate} {submit} {locale} /> <form use:enhance={handler(toggle)} method="POST" class="space-y-5"> <input name="id" value={id} type="hidden" /> |
