From 979d9dd27a147bae13ba953a7e260412fa024f57 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 14 Feb 2023 11:19:12 -0800 Subject: handle sending to user --- src/lib/utils.js | 2 ++ src/routes/(app)/[username]/(profile)/+page.svelte | 1 - src/routes/(app)/payment/[id]/+page.svelte | 42 ++++++++++++++++------ src/routes/(app)/send/[...text]/+page.server.js | 5 +-- 4 files changed, 36 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/lib/utils.js b/src/lib/utils.js index b3bb29ec..86f722b9 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -147,6 +147,8 @@ export const login = async (user, cookies) => { export const auth = (cookies) => ({ authorization: `Bearer ${cookies.get('token')}` }); +export const fiat = (amount, rate) => (amount * rate) / sats; + export const f = (s, currency) => new Intl.NumberFormat('en-US', { style: 'currency', diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index baab8ba1..c704c00d 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -5,7 +5,6 @@ export let data; let { events, invoices, sent, received, subject, user } = data; - console.log(invoices);
diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index da21400a..7b2bdb26 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -1,6 +1,6 @@ -
+

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

@@ -34,13 +32,33 @@ {/if}
-
- {f(fiat, currency)} - ⚡️{`${s(total)}`} + Amount +
+ {f(fiat(amount, rate), currency)} + ⚡️{`${s(amount)}`} +
+
+ +
+ Network fee +
+ {f(fiat(fee, rate), currency)} + ⚡️{`${s(fee)}`}
+ {#if ourfee > 0} +
+ Platform fee +
+ {f(fiat(ourfee, rate), currency)} + ⚡️{`${s(ourfee)}`} +
+
+ {/if} +
+ Date
{format(new Date(created), 'MMMM d')}, {format(new Date(created), 'h:mm aaa')} @@ -49,6 +67,7 @@ {#if type === 'lightning'}
+ Proof
{$t('payments.preimage')}
{ref} @@ -56,12 +75,13 @@
{:else if type === 'bitcoin'}
+ Txid
-
diff --git a/src/routes/(app)/send/[...text]/+page.server.js b/src/routes/(app)/send/[...text]/+page.server.js index d09b4da9..b1089a5b 100644 --- a/src/routes/(app)/send/[...text]/+page.server.js +++ b/src/routes/(app)/send/[...text]/+page.server.js @@ -45,14 +45,15 @@ let parse = async (t, host) => { // bitcoin if (validate(t)) { try { - ({ id } = await get(`/invoice/${t}`)); + ({ id, user } = await get(`/invoice/${t}`)); } catch (e) { let r = `/send/bitcoin/${t}`; if (amount) r += '/' + amount; throw redirect(307, r); } - if (id) throw redirect(307, `/send/${id}`); + if (user) throw redirect(307, `/send/${user.username}`); + else if (id) throw redirect(307, `/send/${id}`); } // user -- cgit v1.2.3