diff options
| author | Adam Soltys <[email protected]> | 2024-12-05 19:20:36 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-05 19:20:36 -0800 |
| commit | a9b44cbae79e9c01cff07964a45e1c7efa7fb241 (patch) | |
| tree | 5caa996fc2eca705fb793e79d63bfbf5f9f93e48 /src/routes/(app)/send/invoice | |
| parent | 6422ef30f14e1baf5d1995de69c777efcad77e32 (diff) | |
| download | coinos-ui-a9b44cbae79e9c01cff07964a45e1c7efa7fb241.tar.gz coinos-ui-a9b44cbae79e9c01cff07964a45e1c7efa7fb241.zip | |
cached rates
Diffstat (limited to 'src/routes/(app)/send/invoice')
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.ts | 14 | ||||
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.svelte | 6 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 2798a234..4047ed3d 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -1,9 +1,10 @@ +import getRates from "$lib/rates"; import { auth, fd, get, post, types } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; export async function load({ cookies, params: { id }, parent }) { const aid = cookies.get("aid"); - const { rates, user } = await parent(); + const { user } = await parent(); const invoice = await get(`/invoice/${id}`); @@ -20,7 +21,11 @@ export async function load({ cookies, params: { id }, parent }) { if (!user) redirect(307, `/invoice/${id}`); - return { invoice, rates, user }; + const rates = await getRates(); + const rate = rates[user.currency]; + const invoiceRate = rates[invoice.currency]; + + return { invoice, user, rate, invoiceRate }; } export const actions = { @@ -31,9 +36,10 @@ export const actions = { body.hash = id; p = await post("/payments", body, auth(cookies)); - } catch (e: any) { + } catch (e) { + const { message } = e as Error; console.log("payment failed", id, e); - error(500, e.message); + error(500, message); } redirect(307, `/sent/${p.id}`); diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 1267d71b..d3603d64 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -15,14 +15,12 @@ import { btc, sat, post, back, f, toFiat, s, sats, focus } from "$lib/utils"; let { data, form } = $props(); - let { invoice, rates, user } = $state(data); + let { invoice, user } = $state(data); let { address, hash, payreq, user: recipient, tip } = $state(invoice); let { currency } = $state(user); let { amount } = $state(form || invoice); - let rate = $derived( - invoice.rate * (rates[user.currency] / rates[invoice.currency]), - ); + let rate = $derived(invoice.rate * (data.rate / data.invoiceRate)); let a = $state(), af = $state(), |
