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/routes/(app)/payment/[id]/+page.server.js | 4 ++-- src/routes/(app)/payment/[id]/+page.svelte | 31 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) (limited to 'src/routes/(app)/payment') 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 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/routes/(app)/payment') 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 From 808d5706bf59636deb49011a00ea0f4846ea7592 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 15 Feb 2023 22:47:36 -0800 Subject: payment page --- src/routes/(app)/[username]/(profile)/+page.svelte | 1 - src/routes/(app)/payment/[id]/+page.svelte | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/routes/(app)/payment') diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index 7d231321..0421782c 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -34,7 +34,6 @@ {#if user?.id === subject.id}
{#if user.balance > 0} -

Balance

diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index 7b2bdb26..8125c63c 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -9,8 +9,9 @@ let { user, payment: p } = data; let { username } = user; let { id, amount, created, rate, type, ref, ourfee, fee, currency } = p; + let a = Math.abs(amount); + fee = fee || 0; - amount = Math.abs(amount); - - - - - - - - + {#if user.eligible} + + + + {/if}
{/if} @@ -138,17 +146,23 @@
{/if} - {#if latest.length} -
-

Messages

- {#each latest as { content, user }} -
-
- + {#if latest.length && user.id === subject.id} +
+ {#each latest as { content, pubkey, author, recipient }} + {@const user = author.id === user.id ? recipient : author} + +
+
+ +
+
+
{user.username}
+
+ {content} +
+
-
{user.username}
- {content} -
+ {/each}
{/if} diff --git a/src/routes/(app)/[username]/(profile)/messages/+page.server.js b/src/routes/(app)/[username]/(profile)/messages/+page.server.js deleted file mode 100644 index 63116099..00000000 --- a/src/routes/(app)/[username]/(profile)/messages/+page.server.js +++ /dev/null @@ -1,16 +0,0 @@ -import { get } from '$lib/utils'; - -export async function load({ params, parent, url }) { - let { user, subject } = await parent(); - let { since = 0 } = params; - - let messages = []; - - try { - messages = await get(`/nostr/${user.pubkey}/${subject.pubkey}/${since}/messages`); - } catch (e) { - console.log(`failed to fetch nostr messages`, e); - } - - return { newMessages: messages }; -} diff --git a/src/routes/(app)/[username]/(profile)/messages/+page.svelte b/src/routes/(app)/[username]/(profile)/messages/+page.svelte deleted file mode 100644 index db7b1ced..00000000 --- a/src/routes/(app)/[username]/(profile)/messages/+page.svelte +++ /dev/null @@ -1,123 +0,0 @@ - - -
-

- {$t('payments.sendMessage')} -

- -
- {#each events as data} - {@const ours = data.pubkey === user.pubkey} - {@const theirs = !ours} -
- {#if data.message} - {data.message} - {:else} - - - {/if} -
-
- {format(new Date(data.created_at * 1000), 'MMM d')}, - {format(new Date(data.created_at * 1000), 'h:mm aa')} -
- {/each} -
- -
- - - - -
-
- - diff --git a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte index b5571f23..2ff92687 100644 --- a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte +++ b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte @@ -152,9 +152,9 @@ {/if}
- {txt.substr(0, 10)}...{txt.substr(-10)}
diff --git a/src/routes/(app)/[username]/messages/+page.server.js b/src/routes/(app)/[username]/messages/+page.server.js new file mode 100644 index 00000000..7b651389 --- /dev/null +++ b/src/routes/(app)/[username]/messages/+page.server.js @@ -0,0 +1,19 @@ +import { get } from '$lib/utils'; + +export async function load({ params, parent, url }) { + let { user, subject } = await parent(); + let { since = 0 } = params; + + let messages = []; + + try { + messages = await get(`/${user.pubkey}/${since}/messages`); + messages = messages + .filter((m) => m.recipient.id === subject.id || m.author.id === subject.id) + .sort((a, b) => a.created_at - b.created_at); + } catch (e) { + console.log(`failed to fetch nostr messages`, e); + } + + return { messages, user }; +} diff --git a/src/routes/(app)/[username]/messages/+page.svelte b/src/routes/(app)/[username]/messages/+page.svelte new file mode 100644 index 00000000..f8f64aea --- /dev/null +++ b/src/routes/(app)/[username]/messages/+page.svelte @@ -0,0 +1,126 @@ + + +
+ {#if messages.length && ready} +
+ {#each messages as event} + {@const ours = event.pubkey === user.pubkey} + {@const theirs = !ours} +
+
+ {#await decrypt({ event, user })} + - + {:then message} + {message} + {/await} +
+
+ +
+
+
+ {format(new Date(event.created_at * 1000), 'MMM d')}, + {format(new Date(event.created_at * 1000), 'h:mm aa')} +
+ {/each} +
+ {/if} + +
+ + + + +
+
+ + diff --git a/src/routes/(app)/[username]/payments/[...page]/+page.svelte b/src/routes/(app)/[username]/payments/[...page]/+page.svelte index 2068c306..aacba81e 100644 --- a/src/routes/(app)/[username]/payments/[...page]/+page.svelte +++ b/src/routes/(app)/[username]/payments/[...page]/+page.svelte @@ -182,7 +182,7 @@ {:else if p.with}
- +
{p.with.username}
diff --git a/src/routes/(app)/buy/+page.svelte b/src/routes/(app)/buy/+page.svelte index 323d5ef0..2f556ada 100644 --- a/src/routes/(app)/buy/+page.svelte +++ b/src/routes/(app)/buy/+page.svelte @@ -1,13 +1,33 @@
@@ -114,6 +134,17 @@
+ +
+
+
+
1
+ Bitcoin +
+
= {f($animatedRate, currency)}
+
+

3% credit card fee applies

+
diff --git a/src/routes/(app)/login/+page.svelte b/src/routes/(app)/login/+page.svelte index 9a1e41da..75998cd0 100644 --- a/src/routes/(app)/login/+page.svelte +++ b/src/routes/(app)/login/+page.svelte @@ -1,5 +1,4 @@
@@ -25,15 +21,20 @@ {#if received}

{$t('invoice.paymentSuccessful')}

- {f(amountFiat, currency)} + {f(fiat(received - tip, rate), currency)} {#if tip} - + {f(tipFiat, currency)} + + + {f(fiat(tip, rate), currency)} + {/if}

- {sat(received - tip)} + ⚡️{s(received - tip)} + {#if tip} - +{sat(tip)} + + + ⚡️{s(tip)} + {/if}

{/if} @@ -41,15 +42,17 @@ {#if pending}

Payment detected

- {f(pendingFiat, currency)} + {f(fiat(pending, rate), currency)} {#if tip} - + {f(tipFiat, currency)} + + {f(fiat(tip, rate), currency)} {/if}

- {sat(pending - tip)} + ⚡️{s(pending - tip)} {#if tip} - +{sat(tip)} + + + ⚡️{s(tip)} + {/if}

{/if} diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index 2988ddb5..b8a23605 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -8,7 +8,7 @@ export let data; let { user, payment: p } = data; let { username } = user; - let { id, amount, created, rate, type, ref, ourfee, fee, currency } = p; + let { id, amount, created, rate, type, ref, tip, ourfee, fee, currency } = p; let a = Math.abs(amount); fee = fee || 0; @@ -26,12 +26,14 @@ {#if p.with}
{amount > 0 ? 'From' : 'To'} +
-
{p.with.username}
+
{p.with.username}
+
{/if} @@ -39,7 +41,19 @@ Amount
{f(fiat(a, rate), currency)} - ⚡️{`${s(a)}`} + {#if tip} + + + {f(fiat(tip, rate), currency)} + + {/if} + ⚡️{`${s(a)}`} + + {#if tip} + + + ⚡️{s(tip)} + + {/if} +
diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js index 6fbe9c7c..92a754ae 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.server.js @@ -23,7 +23,7 @@ export const actions = { seen[ts] = 1; setTimeout(() => delete seen[ts], 30000); - await post('/bitcoin/send', { pin, tx }, auth(cookies)); + await post('/bitcoin/send', { pin, subtract, tx }, auth(cookies)); } catch (e) { return fail(400, { message: e.message }); } diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte index 0a6733de..b3a944f4 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte @@ -4,7 +4,7 @@ import { enhance } from '$app/forms'; import { Toggle, Slider, Icon, Numpad, Spinner } from '$comp'; import { page } from '$app/stores'; - import { fiat as af, f, back, s, sat } from '$lib/utils'; + import { fiat as toFiat, f, back, s, sat } from '$lib/utils'; import { pin, selectedRate } from '$lib/store'; export let data; @@ -12,15 +12,17 @@ let { address, amount } = $page.params; let { balance, currency } = data.user; - let loading, submit, fiat, confirmed, feeRate, min, max, fee, stale, subtract; + let loading, submit, fiat, confirmed, feeRate, min, max, fee, ourfee, stale, subtract, adjusting; let toggle = () => (loading = true); + let toggleAdjusting = () => (adjusting = !adjusting); $: update(form); let update = () => { loading = false; if (form?.message?.includes('pin')) $pin = undefined; - if (form) ({ min, max, feeRate, fee, subtract } = form); + if (form) ({ min, max, feeRate, fee, ourfee, subtract } = form); + if (!ourfee) ourfee = 0; if (feeRate) confirmed = true; stale = false; }; @@ -57,22 +59,26 @@

{$t('payments.send')}

-
{address}
+
{address}
{#if confirmed}

- {f(af(amount, $selectedRate), currency)} + {f(toFiat(amount, $selectedRate), currency)}

-

{sat(amount)}

+

⚡️{s(amount)}

with fee

-

- {f(af(fee, $selectedRate), currency)} -

-

{sat(fee)}

+ +
+

+ {f(toFiat(fee + ourfee, $selectedRate), currency)} +

+

⚡️{s(fee + ourfee)}

+ +
{:else} @@ -88,7 +94,7 @@ - {#if confirmed} + {#if confirmed && adjusting}
Slower (~40 blocks)
Faster (~1 block)
@@ -98,7 +104,7 @@
- +
{/if} diff --git a/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte b/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte index bb11ddde..da761cc2 100644 --- a/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte @@ -16,7 +16,7 @@ let submit = () => (loading = true); $: update(form); let update = () => { - if (form?.message.includes('pin')) $pin = undefined; + if (form?.message?.includes('pin')) $pin = undefined; loading = false; }; diff --git a/src/routes/(app)/sent/+page.svelte b/src/routes/(app)/sent/+page.svelte index 79a0aa6e..72511487 100644 --- a/src/routes/(app)/sent/+page.svelte +++ b/src/routes/(app)/sent/+page.svelte @@ -1,5 +1,5 @@ @@ -23,12 +22,25 @@

Sent!

- {f(fiat, user.currency)} + {f(fiat(amount, rate), currency)} + {#if tip} + + + {f(fiat(tip, rate), currency)} + + {/if}

-

{sat(amount)}

+

+ ⚡️{s(amount)} + + {#if tip} + + + ⚡️{s(tip)} + + {/if} +

- +
-- cgit v1.2.3 From 301770cb05331c8cbb32f60b11c62a79c9d28df3 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 27 Feb 2023 19:28:59 -0800 Subject: prettier --- src/components/AppHeader.svelte | 1 - src/components/LandingHeader.svelte | 26 +++++++-------- .../(app)/[username]/invoice/[hash]/+page.svelte | 36 +++++++-------------- src/routes/(app)/payment/[id]/+page.svelte | 37 +++++++++++----------- .../bitcoin/[address]/[...amount]/+page.svelte | 10 ++++-- src/routes/(app)/sent/+page.svelte | 2 +- 6 files changed, 52 insertions(+), 60 deletions(-) (limited to 'src/routes/(app)/payment') diff --git a/src/components/AppHeader.svelte b/src/components/AppHeader.svelte index 74afd7b9..51c70851 100644 --- a/src/components/AppHeader.svelte +++ b/src/components/AppHeader.svelte @@ -15,7 +15,6 @@ let menuButtons; if (user) menuButtons = [ - { key: 'nav.profile', icon: 'profile', href: `/${user.username}` }, { key: 'nav.settings', icon: 'settings', href: `/${user.username}/settings` }, { key: 'nav.support', icon: 'support', href: `/support` }, { key: 'nav.signOut', icon: 'logout', href: `/logout` } diff --git a/src/components/LandingHeader.svelte b/src/components/LandingHeader.svelte index f9db5ea0..ed7907c1 100644 --- a/src/components/LandingHeader.svelte +++ b/src/components/LandingHeader.svelte @@ -40,29 +40,29 @@ {/if} - {#if !user} + {#if user} {:else} {/if}
diff --git a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte index 2ff92687..fff2b22c 100644 --- a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte +++ b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte @@ -7,7 +7,6 @@ import { last } from '$lib/store'; import { Avatar, Icon, Heart, Image } from '$comp'; import { t } from '$lib/translations'; - import screenfull from 'screenfull'; import { goto, invalidate } from '$app/navigation'; export let data; @@ -67,14 +66,6 @@ $: link = type === 'bitcoin' ? text : `lightning:${text}`; $: txt = type === 'bitcoin' ? hash : text; - let full; - let toggle = () => { - screenfull.toggle(qr); - full = !full; - if (full) src = lg; - else src = sm; - }; - let toggleType = async () => { invoice.type = invoice.type === types.lightning ? types.bitcoin : types.lightning; ({ hash } = await post(`/${username}/invoice`, { @@ -111,21 +102,18 @@
Bitcoin
-
-
- {txt} -
-
+ +
+ + {#if amount > 0} diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index b8a23605..2e170a43 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -26,14 +26,14 @@ {#if p.with}
{amount > 0 ? 'From' : 'To'} - - {/if} @@ -42,18 +42,19 @@
{f(fiat(a, rate), currency)} {#if tip} - - + {f(fiat(tip, rate), currency)} - + + + {f(fiat(tip, rate), currency)} + {/if} - ⚡️{`${s(a)}`} - - {#if tip} - - + ⚡️{s(tip)} - - {/if} - + ⚡️{`${s(a)}`} + + {#if tip} + + + ⚡️{s(tip)} + + {/if} +
diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte index b3a944f4..77d5fde6 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte @@ -22,7 +22,7 @@ loading = false; if (form?.message?.includes('pin')) $pin = undefined; if (form) ({ min, max, feeRate, fee, ourfee, subtract } = form); - if (!ourfee) ourfee = 0; + if (!ourfee) ourfee = 0; if (feeRate) confirmed = true; stale = false; }; @@ -77,7 +77,9 @@ {f(toFiat(fee + ourfee, $selectedRate), currency)}

⚡️{s(fee + ourfee)}

- +
{:else} @@ -104,7 +106,9 @@
- +
{/if} diff --git a/src/routes/(app)/sent/+page.svelte b/src/routes/(app)/sent/+page.svelte index 72511487..760d2e1d 100644 --- a/src/routes/(app)/sent/+page.svelte +++ b/src/routes/(app)/sent/+page.svelte @@ -7,7 +7,7 @@ export let data; let { payments, user } = data; - let { currency, username } = user; + let { currency, username } = user; let payment = payments[0]; let { amount, rate, tip } = payment; -- cgit v1.2.3