diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts (renamed from src/routes/(app)/fund/[id]/sweep/+page.server.ts) | 15 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte (renamed from src/routes/(app)/fund/[id]/sweep/+page.svelte) | 0 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/routes/(app)/fund/[id]/sweep/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index d8415ca4..61a66fd2 100644 --- a/src/routes/(app)/fund/[id]/sweep/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -1,14 +1,23 @@ import { randomName, randomPassword } from "$lib/random"; import getRates from "$lib/rates"; -import { auth, get, post, register } from "$lib/utils"; -import { redirect } from "@sveltejs/kit"; +import { auth, get, post, register, sats } from "$lib/utils"; +import { error, redirect } from "@sveltejs/kit"; export async function load({ cookies, request, params, parent }) { let { user } = await parent(); const { id } = params; - const { amount } = await get(`/fund/${id}`); + let [amount, currency] = params.amount.split("/"); + const rates = await getRates(); const rate = rates[user?.currency || "USD"]; + if (currency && !rate) error(500, "Invalid currency symbol"); + + if (!amount) { + const balance = await get(`/fund/${id}`); + amount = balance.amount; + } else if (currency) { + amount = (amount * sats) / rate; + } const username = randomName(); const password = randomPassword(); diff --git a/src/routes/(app)/fund/[id]/sweep/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte index adba77ae..adba77ae 100644 --- a/src/routes/(app)/fund/[id]/sweep/+page.svelte +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte |
