aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-20 16:13:18 -0700
committerAdam Soltys <[email protected]>2024-08-20 16:13:18 -0700
commitb7d9213ffec4aeb09508ca71f02880dca1c56a23 (patch)
treec438cb108b32ce2100ff6659791cf283c9b0eeea /src
parentb549489aa400e623cf93b44f19aacbd62bbc1830 (diff)
downloadcoinos-ui-b7d9213ffec4aeb09508ca71f02880dca1c56a23.tar.gz
coinos-ui-b7d9213ffec4aeb09508ca71f02880dca1c56a23.zip
show spent ecash
Diffstat (limited to 'src')
-rw-r--r--src/lib/parse.js1
-rw-r--r--src/locales/en.json1
-rw-r--r--src/routes/(app)/ecash/[id]/+page.server.js6
-rw-r--r--src/routes/(app)/ecash/[id]/+page.svelte41
-rw-r--r--src/routes/(app)/voucher/[...token]/+page.server.js2
5 files changed, 36 insertions, 15 deletions
diff --git a/src/lib/parse.js b/src/lib/parse.js
index 3470fb52..3c29f2e5 100644
--- a/src/lib/parse.js
+++ b/src/lib/parse.js
@@ -7,6 +7,7 @@ import { redirect } from "@sveltejs/kit";
export default async (t, host, cookies) => {
if (!t) return;
+ console.log("T", t)
if (t.startsWith("http")) redirect(307, t);
if (t.startsWith(host)) redirect(307, `http://${t}`);
diff --git a/src/locales/en.json b/src/locales/en.json
index 20160b0d..2ce485ff 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -293,6 +293,7 @@
}
},
"payments": {
+ "spent": "Already spent",
"mint": "Mint",
"ecash": "Ecash",
"memo": "Notes",
diff --git a/src/routes/(app)/ecash/[id]/+page.server.js b/src/routes/(app)/ecash/[id]/+page.server.js
index c5f24e82..421c8cb6 100644
--- a/src/routes/(app)/ecash/[id]/+page.server.js
+++ b/src/routes/(app)/ecash/[id]/+page.server.js
@@ -4,6 +4,8 @@ import parse from "$lib/parse";
export async function load({ cookies, params, request, url }) {
let { id } = params;
- let token = await get(`/cash/${id}`);
- return { id, token };
+ let { token, status } = await get(`/cash/${id}`);
+ let spent = parseInt(status.spent);
+ let total = parseInt(status.total);
+ return { id, token, spent, total };
}
diff --git a/src/routes/(app)/ecash/[id]/+page.svelte b/src/routes/(app)/ecash/[id]/+page.svelte
index 023276ee..4590fb21 100644
--- a/src/routes/(app)/ecash/[id]/+page.svelte
+++ b/src/routes/(app)/ecash/[id]/+page.svelte
@@ -8,16 +8,17 @@
export let data;
- let { id, rates, user, token } = data;
- let currency = user?.currency || "USD"
+ let { id, rates, user, token, total, spent } = data;
+ let currency = user?.currency || "USD";
let rate = rates[currency];
let { proofs } = getDecodedToken(token).token[0];
- let amount = proofs.reduce((a, b) => a + b.amount, 0);
+ let amount = total - spent;
let link = $page.url.href;
$: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2));
+ $: spentFiat = parseFloat(((spent * rate) / sats).toFixed(2));
</script>
<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
@@ -38,6 +39,20 @@
</div>
{/if}
+ {#if spent > 0}
+ <div class="text-center font-bold text-2xl">
+ <div>
+ {f(spentFiat, currency)}
+ <span class=" text-red-600">{$t("payments.spent")}</span>
+ </div>
+ <div>
+ <span class="text-secondary font-normal text-xl"
+ >⚡️{`${s(spent)}`}</span
+ >
+ </div>
+ </div>
+ {/if}
+
<div class="flex flex-wrap gap-2 text-xl">
<button
type="button"
@@ -59,15 +74,17 @@
<!-- </button> -->
<!-- </a> -->
- <a href={`/voucher/${id}`} class="contents">
- <button
- type="button"
- class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2"
- >
- <Icon icon="receive" style="w-8 my-auto" />
- <div class="my-auto">{$t("payments.redeem")}</div>
- </button>
- </a>
+ {#if spent < total}
+ <a href={`/voucher/${id}`} class="contents">
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2"
+ >
+ <Icon icon="receive" style="w-8 my-auto" />
+ <div class="my-auto">{$t("payments.redeem")}</div>
+ </button>
+ </a>
+ {/if}
<button
class="border rounded-2xl px-6 py-5 w-full break-all text-xl hover:bg-slate-100"
diff --git a/src/routes/(app)/voucher/[...token]/+page.server.js b/src/routes/(app)/voucher/[...token]/+page.server.js
index 5f90ba64..b7a69d67 100644
--- a/src/routes/(app)/voucher/[...token]/+page.server.js
+++ b/src/routes/(app)/voucher/[...token]/+page.server.js
@@ -11,7 +11,7 @@ export async function load({ cookies, params, parent, request, url }) {
if (!user) redirect(307, `/register?redirect=${url.pathname}`);
let { token } = params;
- if (!token.startsWith("cashu")) token = await get(`/cash/${token}`);
+ if (!token?.startsWith("cashu")) ({ token } = await get(`/cash/${token}`));
await parse(token, url.host, cookies);
if (token) error(409, "Token could not be redeemed. Was it already spent?");