From 8d33c5fe90f731f0c4326ca787cb1150ac46fcd9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 22 Feb 2024 13:35:50 -0800 Subject: send to tip page --- src/routes/(app)/[username]/(profile)/+page.svelte | 3 +- .../(app)/[username]/invoice/[id]/+page.svelte | 14 +++-- .../(app)/[username]/invoice/[id]/tip/+page.svelte | 3 + .../[username]/settings/[...tab]/+page.server.js | 2 +- .../[username]/settings/[...tab]/+page.svelte | 2 +- src/routes/(app)/login/+page.svelte | 2 +- src/routes/(app)/send/[...text]/+page.server.js | 3 +- src/routes/(app)/send/[...text]/+page.svelte | 2 +- .../(app)/send/bitcoin/[address]/+page.svelte | 11 ++-- .../[amount]/[...feeRate]/+page.server.js | 2 +- src/routes/(app)/send/invoice/[id]/+page.server.js | 37 +++-------- src/routes/(app)/send/invoice/[id]/+page.svelte | 73 ++++++++++++++++------ 12 files changed, 87 insertions(+), 67 deletions(-) (limited to 'src/routes/(app)') diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index bf1090aa..0fbe90ab 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -77,6 +77,7 @@ amount: btc(total, rate), currency, items: items.filter((i) => i.quantity > 0), + prompt: subject.prompt, rate, }; @@ -85,7 +86,7 @@ user: { username: subject.username }, }); - goto(`/${subject.username}/invoice/${id}?options=true`, { + goto(`/${subject.username}/invoice/${id}`, { invalidateAll: true, }); }; diff --git a/src/routes/(app)/[username]/invoice/[id]/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/+page.svelte index dca98c39..56feced6 100644 --- a/src/routes/(app)/[username]/invoice/[id]/+page.svelte +++ b/src/routes/(app)/[username]/invoice/[id]/+page.svelte @@ -51,7 +51,6 @@ user: { username, currency }, } = invoice; - let qr; let tipPercent = 0; @@ -93,7 +92,7 @@ let subbed; onMount(async () => { - $showQr = $showQr && 1 + $showQr = $showQr && 1; if (browser) { last.subscribe((v) => { if (!v || subbed) return; @@ -146,7 +145,10 @@ {#each invoice.items as i}
-
{i.quantity} {i.name}
+
+ {i.quantity} + {i.name} +
{f(i.price * i.quantity, currency)}
@@ -181,7 +183,6 @@
{/if} - -
+ -
diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/+page.svelte index 84f14c39..838c5c04 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/+page.svelte @@ -25,13 +25,10 @@
- - + +

{$t("payments.send")}

diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.js b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.js index 9d86537d..d4498b39 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.js +++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.js @@ -26,7 +26,7 @@ export const actions = { try { let r = await post("/bitcoin/send", await fd(request), auth(cookies)); } catch (e) { - console.log("problem sending bitcoin", e); + console.log("problem sending bitcoin", e); return fail(400, { address, amount, feeRate, message: e.message }); } diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.js b/src/routes/(app)/send/invoice/[id]/+page.server.js index c6b0a9a4..b0cbef45 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.js +++ b/src/routes/(app)/send/invoice/[id]/+page.server.js @@ -2,35 +2,18 @@ import { error, fail, redirect } from "@sveltejs/kit"; import { fd, auth, get, post } from "$lib/utils"; export async function load({ params: { id }, parent, url }) { - let { user } = await parent(); - - let { - amount, - address, - currency, - hash, - rate, - prompt, - tip, - text, - user: recipient, - } = await get(`/invoice/${id}`); - - if (prompt && tip === null) - redirect(307, `/${recipient.username}/invoice/${id}/tip`); - if (recipient.username === user.username) + let { rates, user } = await parent(); + + let invoice = await get(`/invoice/${id}`); + + console.log("OH", invoice, invoice.prompt, invoice.tip); + + if (invoice.prompt && invoice.tip === null) + redirect(307, `/${invoice.user.username}/invoice/${id}/tip`); + if (invoice.user.username === user.username) error(500, { message: "Cannot send to self" }); - return { - amount, - address, - currency, - hash, - tip, - rate, - payreq: text, - recipient, - }; + return { invoice, rates, user }; } export const actions = { diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 64db6eb8..e3ee9297 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -9,22 +9,34 @@ import Numpad from "$comp/Numpad.svelte"; import Spinner from "$comp/Spinner.svelte"; import { page } from "$app/stores"; - import { post, back, f, fiat as toFiat, s, sats, focus } from "$lib/utils"; + import { + btc, + sat, + post, + back, + f, + fiat as toFiat, + s, + sats, + focus, + } from "$lib/utils"; export let data; export let form; - let { address, hash, payreq, recipient, tip, rates, user } = data; + let { invoice, rates, user } = data; + let { address, hash, payreq, user: recipient, tip } = invoice; let { currency } = user; $: reload(data); let reload = (data) => { - ({ address, hash, payreq, recipient, tip, rates, user } = data); + ({ invoice, rates, user } = data); + ({ address, hash, payreq, user: recipient, tip } = invoice); ({ currency } = user); }; - $: rate = data.rate * (rates[user.currency] / rates[data.currency]); + $: rate = invoice.rate * (rates[user.currency] / rates[invoice.currency]); - let amount = form?.amount || data.amount; + let amount = form?.amount || invoice.amount; let a, af, amountFiat = amount * (rate / sats), @@ -86,12 +98,12 @@
{/if} -
+
{#if amount} -
-

- {$t("payments.send")} -

+

+ {$t("payments.send")} +

+

{f(toFiat(amount, rate), currency)} {#if tip} @@ -100,7 +112,7 @@ {/if}

-

+

⚡️{s(amount)} {#if tip} @@ -109,18 +121,39 @@ {/if}

+
-

- {$t("payments.to")} -

+

+ {$t("payments.to")} +

-
- -

- {recipient.username} -

-
+
+ +

+ {recipient.username} +

+ + {#if invoice.items.length} +

+ {$t("payments.for")} +

+ + {#each invoice.items as i} +
+
+ {i.quantity} + {i.name} +
+
+ {f(i.price * i.quantity, invoice.currency)} +
+
+ {sat(btc(i.price * i.quantity, invoice.rate))} +
+
+ {/each} + {/if} {:else}