From d4c3d52fdde5fef8f72c1f572f1ce7c70da86b23 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 19 Sep 2024 15:55:38 -0700 Subject: progress on accounts --- src/routes/(app)/invoice/+page.server.ts | 7 ++- src/routes/(app)/invoice/[id]/+layout.server.ts | 42 +++++++++-------- src/routes/(app)/invoice/[id]/+page.svelte | 56 +++++++++++------------ src/routes/(app)/invoice/[id]/tip/+page.server.ts | 2 +- src/routes/(app)/invoice/[id]/tip/+page.svelte | 3 ++ 5 files changed, 56 insertions(+), 54 deletions(-) (limited to 'src/routes/(app)/invoice') diff --git a/src/routes/(app)/invoice/+page.server.ts b/src/routes/(app)/invoice/+page.server.ts index 05851430..98bbe8c3 100644 --- a/src/routes/(app)/invoice/+page.server.ts +++ b/src/routes/(app)/invoice/+page.server.ts @@ -3,19 +3,18 @@ import { error, redirect } from "@sveltejs/kit"; import type { Invoice } from "$lib/types"; export let load = async ({ cookies, parent }) => { - let account = cookies.get("account"); + let account_id = cookies.get("account_id"); let { subject, user, rates } = await parent(); let invoice: Invoice = { - account, - type: account ? "bitcoin" : "lightning", + account_id, rate: rates[user?.currency || subject?.currency], }; if (!user) user = subject; try { - invoice = await post("/invoice", { invoice, account, user }, auth(cookies)); + invoice = await post("/invoice", { invoice, account_id, user }, auth(cookies)); } catch (e) { console.log(e); error(500, "Failed to generate invoice"); diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index a00515a0..55c44f36 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -7,30 +7,32 @@ export async function load({ depends, params, url, parent }) { let { subject, user } = await parent(); let { id } = params; - let invoice = await get(`/invoice/${id}`); - let options = !!url.searchParams.get("options"); + let invoice; - if ( - user && - invoice.uid !== user.id && - !(url.pathname.includes("tip") || url.pathname.includes("memo")) && - !options - ) { - console.log("YO") - redirect(307, `/send/invoice/${id}`); - } + if (id) { + invoice = await get(`/invoice/${id}`); + let options = !!url.searchParams.get("options"); - let { amount, pending, received } = invoice; - amount = parseInt(amount); + if ( + user && + invoice.uid !== user.id && + !(url.pathname.includes("tip") || url.pathname.includes("memo")) && + !options + ) { + redirect(307, `/send/invoice/${id}`); + } - let paid = - (!amount && (pending || received)) || - (amount > 0 && (pending >= amount || received >= amount)); - if (paid && !url.pathname.endsWith("paid")) { - redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); - } + let { amount, pending, received } = invoice; + amount = parseInt(amount); - let src = Qr.drawImg(invoice.text || "", { size: 500 }); + let paid = + (!amount && (pending || received)) || + (amount > 0 && (pending >= amount || received >= amount)); + if (paid && !url.pathname.endsWith("paid")) { + redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); + } + } + let src = Qr.drawImg(invoice?.text || "", { size: 500 }); return { id, invoice, subject, src }; } diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte index 96ff6406..321129a8 100644 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ b/src/routes/(app)/invoice/[id]/+page.svelte @@ -40,7 +40,7 @@ $: refresh(data); let { invoice, id, subject, user, src } = data; let { - account, + account_id, amount, hash, type, @@ -56,7 +56,7 @@ let refresh = async (data) => { ({ invoice, id, user, src } = data); ({ - account, + account_id, amount, hash, type, @@ -82,7 +82,7 @@ send("subscribe", invoice); }); - if ($amountPrompt && !tip) toggleAmount(); + if ($amountPrompt && tip === null) toggleAmount(); } }); @@ -236,10 +236,10 @@ - {#if !account} -
+ {#if account_id === user.id} +
Lightning
-
- {/if} - {#if type === types.liquid} -
-
- {$t("payments.onlyLbtc")} - L-BTC, - {$t("payments.dontDeposit")} -
+ {#if user?.id === invoice?.user?.id} + + + + {/if}
- {/if} - {#if user?.id === invoice?.user?.id} - - - + {#if type === types.liquid} +
+
+ {$t("payments.onlyLbtc")} + L-BTC, + {$t("payments.dontDeposit")} +
+
+ {/if} {/if} diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 8417de91..48ebf970 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,7 +1,7 @@ import invoice from "$lib/invoice"; import { redirect } from "@sveltejs/kit"; -export async function load({ parent, params }) { +export async function load({ parent }) { let { invoice } = await parent(); if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index 35b24bf1..e4510693 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -59,6 +59,7 @@ $: refresh(data); let { invoice, id, user, rates } = data; let { + account_id, amount, hash, items, @@ -81,6 +82,7 @@ ({ invoice, id } = data); ({ + account_id, amount, hash, items, @@ -111,6 +113,7 @@
+ -- cgit v1.2.3