diff options
| author | Adam Soltys <[email protected]> | 2025-08-10 18:53:09 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-08-10 18:53:09 -0700 |
| commit | 633e3a3d94777440f07ed00a88abc1ac388bb2f0 (patch) | |
| tree | c26fe53768fdd538eac16364a68a2ed4f51b413a /src/routes/(app) | |
| parent | 5f2c4e41c181e52cdf822b1c5ee0e7ce99b94fa3 (diff) | |
| download | coinos-ui-633e3a3d94777440f07ed00a88abc1ac388bb2f0.tar.gz coinos-ui-633e3a3d94777440f07ed00a88abc1ac388bb2f0.zip | |
authorizations
Diffstat (limited to 'src/routes/(app)')
3 files changed, 67 insertions, 3 deletions
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]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index 47dfdaab..78df3461 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -9,15 +9,16 @@ export async function load({ cookies, request, params, parent }) { let [amount, currency] = params.amount.split("/"); if (!currency) currency = user?.currency; + if (currency) currency = currency.toUpperCase(); const rates = await getRates(); - const rate = rates[currency?.toUpperCase() || "USD"]; + const rate = rates[currency || "USD"]; if (currency && !rate) error(500, "Invalid currency symbol"); if (!amount) { const balance = await get(`/fund/${id}`); - amount = balance.amount; + amount = balance.authorization || balance.amount; } else if (currency) { - amount = (amount * sats) / rate; + amount = Math.round((amount * sats) / rate); } const username = randomName() + Math.floor(Math.random() * 99) + 1; |
