From 4373f870ad528811a9e0bb1a6749b01d5a7ec051 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 24 Sep 2024 15:57:04 -0700 Subject: stylin --- .../(app)/send/bitcoin/[address]/+layout.server.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/routes/(app)/send') diff --git a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts index 6c22f5f1..a6edf8b0 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts +++ b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts @@ -1,12 +1,23 @@ import { auth, get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export async function load({ cookies, params }) { +export async function load({ cookies, params, parent }) { + let { user } = await parent(); let aid = cookies.get("aid"); let { address } = params; let { balance } = await get(`/account/${aid}`, auth(cookies)); - let invoice = await get(`/invoice/${address}`); - let recipient = await get(`/user/${invoice.uid}`); - if (invoice.aid === invoice.uid) redirect(307, `/send/${recipient.username}`); + + try { + let invoice = await get(`/invoice/${address}`); + + if (invoice) { + let recipient = await get(`/users/${invoice.uid}`); + if (recipient?.id !== user.id) + redirect(307, `/pay/${recipient.username}`); + } + } catch (e) { + // invoice not found + } + return { balance }; } -- cgit v1.2.3