diff options
Diffstat (limited to 'src/routes/(app)/fund')
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts | 11 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte | 3 |
2 files changed, 9 insertions, 5 deletions
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 61a66fd2..8a8e71ee 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -8,8 +8,9 @@ export async function load({ cookies, request, params, parent }) { const { id } = params; let [amount, currency] = params.amount.split("/"); + if (!currency) currency = user?.currency; const rates = await getRates(); - const rate = rates[user?.currency || "USD"]; + const rate = rates[currency?.toUpperCase() || "USD"]; if (currency && !rate) error(500, "Invalid currency symbol"); if (!amount) { @@ -35,6 +36,10 @@ export async function load({ cookies, request, params, parent }) { await register(user, ip, cookies, `/fund/${id}/sweep`); } - await post("/take", { amount, id }, auth(cookies)); - return { amount, id, rate, rates, password }; + try { + 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 index adba77ae..7a7d5402 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte @@ -11,8 +11,7 @@ let { data } = $props(); - let { amount, id, user, rate, rates, password: pw } = data; - let { currency } = user; + let { amount, currency, id, user, rate, rates, password: pw } = data; let locale = $derived(loc(user)); onMount(() => ($password = pw)); |
