diff options
Diffstat (limited to 'src/routes/(app)')
4 files changed, 48 insertions, 101 deletions
diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index 087c8c95..289d1859 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -23,6 +23,11 @@ let amountFiat = $derived(parseFloat(((amount * rate) / sats).toFixed(2))); $effect(() => ($loginRedirect = $page.url.pathname)); + // Funds are discontinued: the notice only appears once someone tries to + // act on the fund (Manage, or an old withdraw/authorize link redirecting + // here with ?discontinued). + let discontinued = $state($page.url.searchParams.has("discontinued")); + let show = $state(); let toggle = () => (show = !show); let href = $derived(encodeURIComponent($page.url.href)); @@ -37,12 +42,14 @@ <div class="md:shadow-xl rounded-3xl md:px-10 pt-5 pb-10 space-y-5 w-full md:mx-5" > - <div class="alert alert-warning text-left"> - <iconify-icon icon="ph:info-bold" width="24"></iconify-icon> - <span> - {notFound ? $t("funds.notFound") : $t("funds.discontinued")} - </span> - </div> + {#if notFound || discontinued} + <div class="alert alert-warning text-left"> + <iconify-icon icon="ph:info-bold" width="24"></iconify-icon> + <span> + {notFound ? $t("funds.notFound") : $t("funds.discontinued")} + </span> + </div> + {/if} {#if !notFound} {#if show} <div class="max-w-[360px] mx-auto"> @@ -75,6 +82,24 @@ <div>{$t("funds.anyone")}</div> {/if} </div> + + {#if (user && !managers.length) || managers.some((m) => m.id === user?.id)} + <button + type="button" + onclick={() => (discontinued = true)} + class="btn !w-auto ml-auto text-secondary grow" + > + <iconify-icon icon="ph:gear-bold" width={32}></iconify-icon> + {$t("funds.manage")} + </button> + {/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" + ></iconify-icon> + <div class="my-auto">{$t("payments.shareLink")}</div> + </a> </div> <Payments {payments} fund={true} {locale} {user} /> {/if} diff --git a/src/routes/(app)/fund/[id]/access/+page.server.ts b/src/routes/(app)/fund/[id]/access/+page.server.ts index 36191643..d409061d 100644 --- a/src/routes/(app)/fund/[id]/access/+page.server.ts +++ b/src/routes/(app)/fund/[id]/access/+page.server.ts @@ -1,9 +1,9 @@ -import { auth, fd, get, post } from "$lib/utils"; -import { fail } from "@sveltejs/kit"; +import { auth, fd, post } from "$lib/utils"; +import { fail, redirect } from "@sveltejs/kit"; -export const load = async ({ params: { id } }) => { - const managers = await get(`/fund/${id}/managers`); - return { managers, id }; +// Funds are discontinued; managers can no longer be changed. +export const load = ({ params: { id } }) => { + redirect(307, `/fund/${id}?discontinued`); }; export const actions = { diff --git a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts index e5683ae6..82faa387 100644 --- a/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/authorize/[...amount]/+page.server.ts @@ -1,36 +1,7 @@ -import getRates from "$lib/rates"; -import { auth, get, post, sats } from "$lib/utils"; -import { error, redirect } from "@sveltejs/kit"; +import { 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 }; -} +// Funds are discontinued; old withdraw/authorize links land on the fund page +// with the notice instead. +export const load = ({ params: { id } }) => { + redirect(307, `/fund/${id}?discontinued`); +}; diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index 8cc463c2..82faa387 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -1,56 +1,7 @@ -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"; +import { redirect } from "@sveltejs/kit"; -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 }; -} +// Funds are discontinued; old withdraw/authorize links land on the fund page +// with the notice instead. +export const load = ({ params: { id } }) => { + redirect(307, `/fund/${id}?discontinued`); +}; |
