From 17d2c4b23f6ec1857a486872e1d156a62fdb3cca Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 7 Jan 2023 23:15:04 -0800 Subject: tx page --- src/locales/en.json | 10 +- .../[username]/transactions/[...page]/+page.svelte | 119 +++++++++++---------- src/routes/(app)/invoice/[id]/+page.svelte | 4 +- src/routes/(app)/tx/[id]/+page.server.js | 6 ++ src/routes/(app)/tx/[id]/+page.svelte | 62 +++++++++++ .../(app)/voucher/[redeemcode]/+page.server.js | 2 +- 6 files changed, 141 insertions(+), 62 deletions(-) create mode 100644 src/routes/(app)/tx/[id]/+page.server.js create mode 100644 src/routes/(app)/tx/[id]/+page.svelte (limited to 'src') diff --git a/src/locales/en.json b/src/locales/en.json index 5714adff..ec89d1c4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -258,10 +258,14 @@ } }, "transactions": { + "amount": "Amount", + "date": "Date", + "id": "Transaction ID", + "details": "Transaction Details", "header": "Transactions", - "AMOUNT": "AMOUNT", - "TYPE": "TYPE", - "TIME": "TIME", + "preimage": "Preimage", + "type": "Type", + "time": "Time", "sent": "Sent", "received": "Received", "empty": "No transactions yet.", diff --git a/src/routes/(app)/[username]/transactions/[...page]/+page.svelte b/src/routes/(app)/[username]/transactions/[...page]/+page.svelte index 2ea151d5..89207134 100644 --- a/src/routes/(app)/[username]/transactions/[...page]/+page.svelte +++ b/src/routes/(app)/[username]/transactions/[...page]/+page.svelte @@ -13,6 +13,11 @@ let { start, end, user } = data; let change = ({ target: { value } }) => goto(value); + let link = (tx) => { + if (tx.redeemcode) return `/voucher/${tx.redeemcode}`; + if (tx.with) return '/' + tx.with.username; + return `/tx/${tx.hash}`; + }; let presets = [ { title: $t('transactions.day'), start: sub(new Date(), { days: 1 }), end: null }, @@ -101,75 +106,77 @@
{#each $txns as tx} -
-
-
- {f(tx.amount * (tx.rate / sats), tx.currency)} - - {#if tx.tip} - - +{f(tx.tip * (tx.rate / sats), tx.currency)} - - {/if} -
+ +
+
+
+ {f(tx.amount * (tx.rate / sats), tx.currency)} + + {#if tx.tip} + + +{f(tx.tip * (tx.rate / sats), tx.currency)} + + {/if} +
-
- {sat(tx.amount)} +
+ {sat(tx.amount)} - {#if tx.tip} - - +{sat(tx.tip)} - - {/if} + {#if tx.tip} + + +{sat(tx.tip)} + + {/if} +
-
-
- {#if tx.redeemcode} - -
-
- +
+ {#if tx.redeemcode} + +
+
+ +
+ +
Voucher
+
+
+ {:else if tx.with} + +
+
+ +
+
{tx.with.username}
+
+ {:else} +
+ {#if tx.network === 'lightning'} +
⚡️
+ {:else} +
+ +
+ {/if} -
Voucher
-
- - {:else if tx.with} - -
- + {tx.amount > 0 ? (tx.confirmed ? 'Received' : 'Pending') : 'Sent'}
-
{tx.with.username}
-
- {:else} -
- {#if tx.network === 'lightning'} -
⚡️
- {:else} -
- -
- {/if} + {/if} +
-
- {tx.amount > 0 ? (tx.confirmed ? 'Received' : 'Pending') : 'Sent'} -
+
+
+ {format(parseISO(tx.createdAt), 'h:mm aaa')} +
+
+ {format(parseISO(tx.createdAt), 'MMM d')}
- {/if} -
- -
-
- {format(parseISO(tx.createdAt), 'h:mm aaa')} -
-
- {format(parseISO(tx.createdAt), 'MMM d')}
-
+ {:else}

{$t('transactions.empty')}

{/each} diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte index e99d6747..5eadb179 100644 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ b/src/routes/(app)/invoice/[id]/+page.svelte @@ -22,7 +22,7 @@ prompt, text, tip, - user: { username, currency } + user: { username, currency, uuid } } = invoice; let showQr = !amount; @@ -43,7 +43,7 @@ prompt, text, tip, - user: { username, currency } + user: { username, currency, uuid } } = invoice); tipPercent = (tip / amount) * 100; diff --git a/src/routes/(app)/tx/[id]/+page.server.js b/src/routes/(app)/tx/[id]/+page.server.js new file mode 100644 index 00000000..7db5d4f1 --- /dev/null +++ b/src/routes/(app)/tx/[id]/+page.server.js @@ -0,0 +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 }; +} diff --git a/src/routes/(app)/tx/[id]/+page.svelte b/src/routes/(app)/tx/[id]/+page.svelte new file mode 100644 index 00000000..fc793916 --- /dev/null +++ b/src/routes/(app)/tx/[id]/+page.svelte @@ -0,0 +1,62 @@ + + + + +
+

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

+ +
+
{$t('transactions.amount')}
+
+ {f(fiat, currency)} + ⚡️{`${s(Math.abs(amount) + fee)}`} +
+
+ +
+
{$t('transactions.date')}
+
+ {format(parseISO(createdAt), 'MMMM d')}, + {format(parseISO(createdAt), 'h:mm aaa')} +
+
+ + {#if network === 'lightning'} +
+
{$t('transactions.preimage')}
+
+ {preimage} +
+
+ {:else} +
+
{$t('transactions.id')}
+
+
+ {hash} +
+ +
+
+ {/if} +
diff --git a/src/routes/(app)/voucher/[redeemcode]/+page.server.js b/src/routes/(app)/voucher/[redeemcode]/+page.server.js index 0af98538..27c8a8c1 100644 --- a/src/routes/(app)/voucher/[redeemcode]/+page.server.js +++ b/src/routes/(app)/voucher/[redeemcode]/+page.server.js @@ -3,7 +3,7 @@ import { auth, get, post } from '$lib/utils'; import Qr from 'qrcode-base64'; export let load = async ({ params: { redeemcode }, url }) => { - let payment = await get(`/payment/${redeemcode}`); + let payment = await get(`/voucher/${redeemcode}`); console.log(payment); let src = Qr.drawImg(url.href, { size: 300 }); -- cgit v1.2.3