aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/invoice
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-19 15:55:38 -0700
committerAdam Soltys <[email protected]>2024-09-19 15:55:38 -0700
commitd4c3d52fdde5fef8f72c1f572f1ce7c70da86b23 (patch)
treef523771b8645ed2e76dc08be4521788c59561397 /src/routes/(app)/invoice
parent072cb81c886d7461a6e1ffce9d658d1463ca6315 (diff)
downloadcoinos-ui-d4c3d52fdde5fef8f72c1f572f1ce7c70da86b23.tar.gz
coinos-ui-d4c3d52fdde5fef8f72c1f572f1ce7c70da86b23.zip
progress on accounts
Diffstat (limited to 'src/routes/(app)/invoice')
-rw-r--r--src/routes/(app)/invoice/+page.server.ts7
-rw-r--r--src/routes/(app)/invoice/[id]/+layout.server.ts42
-rw-r--r--src/routes/(app)/invoice/[id]/+page.svelte56
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.server.ts2
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.svelte3
5 files changed, 56 insertions, 54 deletions
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 @@
</div>
</div>
- {#if !account}
- <div class="flex justify-around text-secondary">
+ {#if account_id === user.id}
+ <div class="grid grid-cols-2 justify-around text-secondary">
<button
- class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
+ class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 justify-center"
class:bg-primary={type === types.bitcoin}
class:text-black={type === types.bitcoin}
on:click={() => setType(types.bitcoin)}
@@ -249,7 +249,7 @@
</button>
<button
- class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
+ class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 justify-center"
class:bg-primary={type === types.liquid}
class:text-black={type === types.liquid}
on:click={() => setType(types.liquid)}
@@ -259,7 +259,7 @@
</button>
<button
- class="hover:bg-primary flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
+ class="hover:bg-primary flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 justify-center"
class:bg-primary={type === types.lightning}
class:text-black={type === types.lightning}
on:click={() => setType(types.lightning)}
@@ -269,30 +269,28 @@
</div>
<div class="my-auto text-lg">Lightning</div>
</button>
- </div>
- {/if}
- {#if type === types.liquid}
- <div class="flex justify-center">
- <div class="my-auto text-xl text-center text-secondary">
- {$t("payments.onlyLbtc")}
- <span class="text-teal-500 font-bold">L-BTC</span>,
- {$t("payments.dontDeposit")}
- </div>
+ {#if user?.id === invoice?.user?.id}
+ <a href={`/receive`} class="block contents">
+ <button
+ class="hover:bg-primary flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 justify-center"
+ >
+ <img src="/images/cash.png" class="w-8 my-auto" />
+ <div class="my-auto text-lg">E-cash</div>
+ </button>
+ </a>
+ {/if}
</div>
- {/if}
- {#if user?.id === invoice?.user?.id}
- <a href={`/receive`} class="block">
- <button
- class="flex gap-2 text-center break-all rounded-2xl hover:opacity-80 py-5 px-6 w-full mx-auto justify-center border text-xl whitespace-nowrap text-secondary"
- >
- <Icon icon="voucher" style="w-8 my-auto" />
- <div class="my-auto">
- {$t("payments.redeemVoucher")}
- </div></button
- >
- </a>
+ {#if type === types.liquid}
+ <div class="flex justify-center">
+ <div class="my-auto text-xl text-center text-secondary">
+ {$t("payments.onlyLbtc")}
+ <span class="text-teal-500 font-bold">L-BTC</span>,
+ {$t("payments.dontDeposit")}
+ </div>
+ </div>
+ {/if}
{/if}
</div>
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 @@
<div class="container px-4 max-w-lg text-center mx-auto">
<form method="POST" use:enhance class:invisible={submitting}>
+ <input type="hidden" name="account_id" value={account_id} />
<input type="hidden" name="amount" value={amount} />
<input type="hidden" name="tip" value={tip} />
<input type="hidden" name="username" value={username} />