From 60b24b3d5951e159d09f42ed766c404e4b1acc4e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 11 Feb 2023 00:38:55 -0800 Subject: invoice type toggle --- src/lib/invoice.js | 2 +- src/lib/utils.js | 8 ++++ src/locales/en.json | 2 +- .../(app)/[username]/invoice/[hash]/+page.svelte | 43 ++++++++++++++++++++-- .../[username]/payments/[...page]/+page.svelte | 12 +++--- .../[username]/receive/[...param]/+page.svelte | 5 --- src/routes/(app)/payment/[id]/+page.server.js | 4 +- src/routes/(app)/payment/[id]/+page.svelte | 31 +++++++++------- 8 files changed, 75 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/lib/invoice.js b/src/lib/invoice.js index bb75d4cb..23ce1757 100644 --- a/src/lib/invoice.js +++ b/src/lib/invoice.js @@ -11,7 +11,7 @@ export default async ({ cookies, request, url }) => { let invoice = { amount, - tip: parseInt(form.get('tip')), + tip: parseInt(form.get('tip')) || 0, type: form.get('type'), prompt: form.get('prompt') === 'true', rate: parseFloat(form.get('rate')) || rates[form.get('currency')], diff --git a/src/lib/utils.js b/src/lib/utils.js index 80f7fe07..b3bb29ec 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -231,3 +231,11 @@ export function ss(str1, str2) { return 0.0; } + +export const types = { + bitcoin: 'bitcoin', + lightning: 'lightning', + internal: 'internal', + pot: 'pot', + classic: 'classic' +}; diff --git a/src/locales/en.json b/src/locales/en.json index 7e7c235b..17f4b34e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -263,7 +263,7 @@ "id": "Transaction ID", "details": "Transaction Details", "header": "Payments", - "preimage": "Preimage", + "preimage": "Proof of payment", "type": "Type", "time": "Time", "sent": "Sent", diff --git a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte index ad9721e7..b5571f23 100644 --- a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte +++ b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte @@ -1,12 +1,14 @@
+
+ + + +
{:else if p.with} - -
-
- -
-
{p.with.username}
+
+
+
-
+
{p.with.username}
+
{:else if p.type === types.classic} {amount ? $t('payments.next') : $t('payments.sendersChoice')} - -
- {type[0].toUpperCase() + type.substring(1, type.length)} - -
diff --git a/src/routes/(app)/payment/[id]/+page.server.js b/src/routes/(app)/payment/[id]/+page.server.js index cbd7355e..1c90ab69 100644 --- a/src/routes/(app)/payment/[id]/+page.server.js +++ b/src/routes/(app)/payment/[id]/+page.server.js @@ -1,6 +1,6 @@ import { auth, get } from '$lib/utils'; export async function load({ cookies, params }) { - let tx = await get(`/payments/${params.id}`, auth(cookies)); - return { tx }; + let payment = await get(`/payments/${params.id}`, auth(cookies)); + return { payment }; } diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index a961d14d..da21400a 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -6,33 +6,41 @@ import { PUBLIC_EXPLORER as expl } from '$env/static/public'; export let data; - let { user, tx } = data; + let { user, payment: p } = data; let { username } = user; - let { id, amount, created, rate, type, ref, fee, currency } = tx; + let { id, amount, created, rate, type, ref, fee, currency } = p; fee = fee || 0; - let fiat = (Math.abs(amount) * rate) / sats; + let total = amount > 0 ? amount : -amount + fee; + let fiat = (total * rate) / sats; -
+

{$t(amount < 0 ? 'payments.sent' : 'payments.received')}

+ {#if p.with} +
+
+ +
+
{p.with.username}
+
+ {/if} +
-
{$t('payments.amount')}
{f(fiat, currency)} - ⚡️{`${s(Math.abs(amount) + fee)}`} + ⚡️{`${s(total)}`}
-
{$t('payments.date')}
{format(new Date(created), 'MMMM d')}, {format(new Date(created), 'h:mm aaa')} @@ -46,17 +54,14 @@ {ref}
- {:else} + {:else if type === 'bitcoin'}
-
{$t('payments.id')}
- {id} + {id}
-- cgit v1.2.3