diff options
| author | Adam Soltys <[email protected]> | 2024-08-20 16:13:18 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-20 16:13:18 -0700 |
| commit | b7d9213ffec4aeb09508ca71f02880dca1c56a23 (patch) | |
| tree | c438cb108b32ce2100ff6659791cf283c9b0eeea /src/routes | |
| parent | b549489aa400e623cf93b44f19aacbd62bbc1830 (diff) | |
| download | coinos-ui-b7d9213ffec4aeb09508ca71f02880dca1c56a23.tar.gz coinos-ui-b7d9213ffec4aeb09508ca71f02880dca1c56a23.zip | |
show spent ecash
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/(app)/ecash/[id]/+page.server.js | 6 | ||||
| -rw-r--r-- | src/routes/(app)/ecash/[id]/+page.svelte | 41 | ||||
| -rw-r--r-- | src/routes/(app)/voucher/[...token]/+page.server.js | 2 |
3 files changed, 34 insertions, 15 deletions
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?"); |
