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/routes/(app)/send/[...text]/+page.server.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/routes/(app)/send') 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 3403bf5c6090109725493b4c7a4fef28266beda8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 15 Feb 2023 19:57:47 -0800 Subject: messages on dashboard --- src/components/Balance.svelte | 2 +- src/lib/nostr.js | 3 +- .../(app)/[username]/(profile)/+page.server.js | 23 ++- src/routes/(app)/[username]/(profile)/+page.svelte | 191 +++++++++++++++------ .../[username]/settings/[...tab]/+page.server.js | 1 + src/routes/(app)/buy/+page.server.js | 19 ++ src/routes/(app)/buy/+page.svelte | 126 ++++++++++++++ .../(app)/send/lightning/[payreq]/+page.svelte | 2 +- 8 files changed, 306 insertions(+), 61 deletions(-) create mode 100644 src/routes/(app)/buy/+page.server.js create mode 100644 src/routes/(app)/buy/+page.svelte (limited to 'src/routes/(app)/send') diff --git a/src/components/Balance.svelte b/src/components/Balance.svelte index e95e5dde..5d993c28 100644 --- a/src/components/Balance.svelte +++ b/src/components/Balance.svelte @@ -9,7 +9,7 @@
{#if isNaN($animatedRate)} -
---
+
—
{:else} {f((user.balance * $animatedRate) / sats, user.currency)} {/if} diff --git a/src/lib/nostr.js b/src/lib/nostr.js index de19b477..13251856 100644 --- a/src/lib/nostr.js +++ b/src/lib/nostr.js @@ -80,7 +80,7 @@ export let decrypt = async ({ event, user }) => { return Buffer.from(message).toString('utf8'); } catch (e) { - console.log(e); + // console.log(e); } }; @@ -119,6 +119,7 @@ let getPrivateKey = async (user) => { seed = mnemonicToSeedSync(mnemonic); key = bip32.fromSeed(seed); child = key.derivePath("m/44'/1237'/0'/0/0"); + return child.privateKey; }; diff --git a/src/routes/(app)/[username]/(profile)/+page.server.js b/src/routes/(app)/[username]/(profile)/+page.server.js index c68cfecc..d1fa2f41 100644 --- a/src/routes/(app)/[username]/(profile)/+page.server.js +++ b/src/routes/(app)/[username]/(profile)/+page.server.js @@ -1,22 +1,33 @@ import { auth, get } from '$lib/utils'; export async function load({ cookies, params, parent, url }) { - let { subject } = await parent(); + let { user, subject } = await parent(); let { pubkey } = subject; + let { since = 0 } = params; - let events = []; + let messages = []; + + if (user) { + try { + messages = await get(`/${user.pubkey}/${since}/messages`); + } catch (e) { + console.log(`failed to fetch nostr messages`, e); + } + } + + let notes = []; try { - events = await get(`/${pubkey}/notes`); + notes = await get(`/${pubkey}/notes`); } catch (e) { - console.log(`failed to fetch nostr events for ${pubkey}`, e); + console.log(`failed to fetch nostr notes for ${pubkey}`, e); } - events.map((e) => { + notes.map((e) => { e.seen = e.created_at; }); let { invoices, sent, received } = await get('/requests', auth(cookies)); - return { invoices, events, sent, received }; + return { invoices, messages, notes, sent, received }; } diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index c704c00d..45fe1d84 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -1,75 +1,162 @@ -
+
{#if user?.id === subject.id} - - {/if} -
+
+ {#if user.balance > 0 && false} +

Balance

+
+ +
+ {:else} +
+

Welcome

+ +

+ Get started by making a deposit or getting someone to pay you in Bitcoin! +

-
- {#each invoices as { amount, currency, rate, request: { requester, recipient }, hash }} - {@const requested = user.username === requester?.username} - -
-
-
- {#if requested} - + {/if} + + {#if invoices.length} +
+

Invoices

+ {#each invoices as { amount, currency, rate, request: { requester, recipient }, hash }} + {@const requested = user.username === requester?.username} + + + {/if} + {#if received.length} +
+

Requests

- {#each received as { id, invoice, memo, requester: r }} - -
-
-
+ {#each received as { id, invoice, memo, requester: r }} + +
- -
-

{r.username}

-

{memo}

+
+
+ +
+

{r.username}

+

{memo}

+
+
+
+
+
-
- + + {/each} +
+ {/if} + + {#if latest.length} +
+

Messages

+ {#each latest as { content, user }} +
+
+
+
{user.username}
+ {content}
-
- - {/each} + {/each} +
+ {/if}
+ + diff --git a/src/routes/(app)/[username]/settings/[...tab]/+page.server.js b/src/routes/(app)/[username]/settings/[...tab]/+page.server.js index dd16459f..94240adc 100644 --- a/src/routes/(app)/[username]/settings/[...tab]/+page.server.js +++ b/src/routes/(app)/[username]/settings/[...tab]/+page.server.js @@ -9,6 +9,7 @@ export function load({ params, url }) { export const actions = { default: async ({ cookies, request }) => { let form = Object.fromEntries(await request.formData()); + form.prompt = form.prompt === 'on' let user = { ...(await get('/me', auth(cookies))), ...form }; try { diff --git a/src/routes/(app)/buy/+page.server.js b/src/routes/(app)/buy/+page.server.js new file mode 100644 index 00000000..e03d6c0a --- /dev/null +++ b/src/routes/(app)/buy/+page.server.js @@ -0,0 +1,19 @@ +import { env } from '$env/dynamic/private'; +import { error, redirect } from '@sveltejs/kit'; +import { post, auth } from '$lib/utils'; +import { createTicket } from '$lib/ticket'; + +export const actions = { + default: async ({ cookies, request }) => { + let form = await request.formData(); + + await post('/buy', { + number: form.get('number').replace(/\s+/g, ''), + month: form.get('expiry').slice(0, 2), + year: form.get('expiry').slice(-2), + cvc: form.get('cvc') + }, auth(cookies)); + + throw redirect(307, `/launch/thanks/${asset}`); + } +}; diff --git a/src/routes/(app)/buy/+page.svelte b/src/routes/(app)/buy/+page.svelte new file mode 100644 index 00000000..34cfc2e5 --- /dev/null +++ b/src/routes/(app)/buy/+page.svelte @@ -0,0 +1,126 @@ + + +
+
+ + + +
+ +
+
+
+ +

Buy Bitcoin

+
+

Purchase up to $500 worth of Bitcoin from us.

+ +

+ If you want more, try Kraken + or + ShakePay or ask + around at our next + meetup. +

+ +
{ + loading = true; + return ({ update }) => update() && (loading = false); + }} + > + + + + + + + + + + +
+ +
+
+
+
+
diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/+page.svelte index 6ae699d2..e9502636 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/+page.svelte @@ -89,7 +89,7 @@
{/if} {:else} -
+
{/if} -
+
-

{$t('payments.sendTo')}

+

{$t('payments.send')}

{address}

- + + + @@ -45,11 +49,18 @@ -
+
+ +
- {fiat ? amountConverted : amountFiatConverted} + {fiat ? amountSatsConverted : amountFiatConverted}
{/if} -
+
-

{$t('payments.send')}

+

{$t('payments.sendTo')}

{address}

- - - + @@ -49,18 +45,11 @@ let max = () => (amount = balance); -
- - +
- {fiat ? amountSatsConverted : amountFiatConverted} + {fiat ? sat(amount) : f(amountFiat, currency)}
+ -- cgit v1.2.3 From dd94f1ee35e2204a27975846a990a2fa6dc629a3 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 21 Feb 2023 16:46:14 -0800 Subject: react to amount changes --- src/lib/parse.js | 0 src/routes/(app)/send/lightning/[payreq]/+page.svelte | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 src/lib/parse.js (limited to 'src/routes/(app)/send') diff --git a/src/lib/parse.js b/src/lib/parse.js deleted file mode 100644 index e69de29b..00000000 diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/+page.svelte index e9502636..01f1d1c1 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/+page.svelte @@ -13,10 +13,11 @@ let { alias } = data; let { currency } = data.user; - let amount = form?.amount || data.amount; let a; let maxfee = 100; + $: amount = form?.amount || data.amount; + let loading; let submit = () => (loading = true); $: update(form); -- cgit v1.2.3 From f9d76e8846c27d9eeb3959c3b77d91d9e444bcc0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 21 Feb 2023 17:05:30 -0800 Subject: max send button --- src/components/Numpad.svelte | 30 ++++++++++++---------- .../bitcoin/[address]/[...amount]/+page.svelte | 27 +++++++++++++------ 2 files changed, 35 insertions(+), 22 deletions(-) (limited to 'src/routes/(app)/send') diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index 3647914e..47bd9375 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -57,7 +57,7 @@ amountFiat = amountFiat.slice(0, amountFiat.length - 1); if (amountFiat.length === 0) { amountFiat = 0; - amountSats = 0; + amount = 0; } } } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > $selectedRate) { @@ -70,25 +70,27 @@ } else { if (value === '.') { return; - } else if (!amountSats && value !== '<' && value !== '0') { - amountSats = parseInt(value); + } else if (!amount && value !== '<' && value !== '0') { + amount = parseInt(value); } else if (value === '<') { - if (amountSats !== 0) { - amountSats = Math.floor(amountSats / 10); - if (amountSats.length === 0) { - amountSats = 0; + if (amount !== 0) { + amount = Math.floor(amount / 10); + if (amount.length === 0) { + amount = 0; amountFiat = 0; } } - } else if (value !== '<' && parseInt(amountSats + value) > sats) { + } else if (value !== '<' && parseInt(amount + value) > sats) { warning($t('user.receive.lessThan1BTCWarning')); } else { + console.log('CLICK', amount.toString(), value); amount = parseInt(amount.toString() + value); + console.log('AMOUNT', amount); } } }; - $: html = fiat ? amountFiat : s(amountSats); + $: html = fiat ? amountFiat : s(amount); let prev = ''; @@ -123,10 +125,10 @@ if (fiat) { amountFiat = html; } else { - amountSats = parseInt(html.replace(/,/g, '')); + amount = parseInt(html.replace(/,/g, '')); } - if (!amountSats) amountSats = null; + if (!amount) amount = null; setTimeout(() => { if (!fiat) { @@ -182,11 +184,11 @@ type="button" on:click={() => { if (fiat) { - amountSats = parseInt((amountFiat / ($selectedRate / sats)).toFixed(0)); + amount = parseInt((amountFiat / ($selectedRate / sats)).toFixed(0)); } else { amountFiat = - (amountSats * ($selectedRate / sats)).toFixed(2) > 0.0 - ? (amountSats * ($selectedRate / sats)).toFixed(2) + (amount * ($selectedRate / sats)).toFixed(2) > 0.0 + ? (amount * ($selectedRate / sats)).toFixed(2) : 0; } fiat = !fiat; diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte index 96d5cab7..cabe895f 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte @@ -3,15 +3,16 @@ import { enhance } from '$app/forms'; import { Icon, Numpad, Spinner } from '$comp'; import { page } from '$app/stores'; - import { back } from '$lib/utils'; + import { back, s, sat } from '$lib/utils'; import { pin } from '$lib/store'; export let data; export let form; let { address, amount } = $page.params; - let { currency } = data.user; + let { balance, currency } = data.user; let loading, submit; + let fiat; let toggle = () => (loading = true); @@ -21,7 +22,10 @@ loading = false; }; - let max = () => (amount = balance); + let max = () => { + fiat = false; + amount = balance; + };
{/if} -
+
-

{$t('payments.sendTo')}

+

{$t('payments.send')}

{address}

- + @@ -48,11 +52,18 @@ -
+
+ +