From cd174163168c3bbbb0f12596f945a256ad0b45f6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 23 Mar 2023 08:03:07 -0700 Subject: use subject currency --- .../(app)/send/user/[username]/[...amount]/+page.server.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js index f6ffbcd5..0a9dda6e 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js @@ -2,13 +2,16 @@ import { error, fail, redirect } from '@sveltejs/kit'; import { types, sats, fd, auth, get, post } from '$lib/utils'; export async function load({ cookies, params, parent }) { + let subject = await get(`/users/${params.username}`); + if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' }); + let { rates, user } = await parent(); let { username } = params; let [amount, currency] = params.amount.split('/'); if (amount) { - let rate = rates[currency ? currency.toUpperCase() : user.currency]; - if (!rate) throw error(500, "Invalid currency symbol"); + let rate = rates[currency ? currency.toUpperCase() : subject.currency]; + if (!rate) throw error(500, 'Invalid currency symbol'); if (currency) amount = (amount * sats) / rate; let { hash } = await post( @@ -23,8 +26,6 @@ export async function load({ cookies, params, parent }) { throw redirect(307, `/${username}/invoice/${hash}`); } - let subject = await get(`/users/${params.username}`); - if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' }); return { amount, subject }; } -- cgit v1.2.3