diff options
Diffstat (limited to 'src/routes/(app)/send')
| -rw-r--r-- | src/routes/(app)/send/bitcoin/[address]/+layout.server.ts | 19 |
1 files changed, 15 insertions, 4 deletions
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 }; } |
