From 7c8cbe1c0b41d223e20823e2896230575a46bad9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 17 May 2024 09:21:45 -0700 Subject: updates from master --- .../[username]/invoice/[id]/+layout.server.js | 3 +- .../(app)/[username]/invoice/[id]/+page.svelte | 141 ++++++++++++--------- .../[username]/invoice/[id]/memo/+page.server.js | 13 ++ .../[username]/invoice/[id]/memo/+page.svelte | 95 ++++++++++++++ .../(app)/[username]/invoice/[id]/tip/+page.svelte | 9 +- src/routes/(app)/send/+layout.svelte | 4 +- src/routes/(app)/send/invoice/[id]/+page.server.js | 42 +++--- src/routes/(app)/send/invoice/[id]/+page.svelte | 110 ++++++++++------ src/service-worker.js | 5 + 9 files changed, 293 insertions(+), 129 deletions(-) create mode 100644 src/routes/(app)/[username]/invoice/[id]/memo/+page.server.js create mode 100644 src/routes/(app)/[username]/invoice/[id]/memo/+page.svelte create mode 100644 src/service-worker.js (limited to 'src') diff --git a/src/routes/(app)/[username]/invoice/[id]/+layout.server.js b/src/routes/(app)/[username]/invoice/[id]/+layout.server.js index 6f9ae4a2..c9920052 100644 --- a/src/routes/(app)/[username]/invoice/[id]/+layout.server.js +++ b/src/routes/(app)/[username]/invoice/[id]/+layout.server.js @@ -13,7 +13,7 @@ export async function load({ depends, params, url, parent }) { if ( user && invoice.uid !== user.id && - !url.pathname.includes("tip") && + !(url.pathname.includes("tip") || url.pathname.includes("memo")) && !options ) { redirect(307, `/send/invoice/${id}`); @@ -34,5 +34,6 @@ export async function load({ depends, params, url, parent }) { } let src = Qr.drawImg(invoice.text || "", { size: 340 }); + return { id, invoice, src }; } diff --git a/src/routes/(app)/[username]/invoice/[id]/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/+page.svelte index 1457025d..1a569039 100644 --- a/src/routes/(app)/[username]/invoice/[id]/+page.svelte +++ b/src/routes/(app)/[username]/invoice/[id]/+page.svelte @@ -1,7 +1,8 @@ -
- {#if showQr} +
+ {#if $showQr}
{/if} + {#each invoice.items as i} +
+
{i.quantity}
+
+ {i.name} +
+
+ {f(i.price * i.quantity, currency)} +
+
+ {sat(btc(i.price * i.quantity, rate))} +
+
+ {/each} + {#if amount > 0}
@@ -154,7 +164,7 @@ {/if}
- ⚡️{`${s(amount)}`} @@ -167,10 +177,57 @@
{/if} -
+ + +
+ + + + + + + + + + + + + + + + +
+ +
- -
- - - - - -
diff --git a/src/routes/(app)/send/+layout.svelte b/src/routes/(app)/send/+layout.svelte index 0f412759..9e14fa39 100644 --- a/src/routes/(app)/send/+layout.svelte +++ b/src/routes/(app)/send/+layout.svelte @@ -9,8 +9,8 @@ let cancel = () => goto(`/${user.username}`); -{#if user.haspin && (!$pin || $pin?.length !== 6)} +{#if user?.haspin && (!$pin || $pin?.length !== 6)} {/if} - \ No newline at end of file + diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.js b/src/routes/(app)/send/invoice/[id]/+page.server.js index 88017362..933993a2 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.js +++ b/src/routes/(app)/send/invoice/[id]/+page.server.js @@ -2,35 +2,22 @@ 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}`); + + if (invoice.prompt && invoice.tip === null) + redirect(307, `/${invoice.user.username}/invoice/${id}/tip`); + + if (invoice.memoPrompt && invoice.memo === null) + redirect(307, `/${invoice.user.username}/invoice/${id}/memo`); + + if (invoice.user.username === user?.username) error(500, { message: "Cannot send to self" }); - return { - amount, - address, - currency, - hash, - tip, - rate, - payreq: text, - recipient, - }; + if (!user) redirect(307, `/${invoice.user.username}/invoice/${id}`); + + return { invoice, rates, user }; } export const actions = { @@ -41,6 +28,7 @@ export const actions = { await post("/payments", body, auth(cookies)); } catch (e) { + console.log("payment failed", id, e); return fail(400, { message: e.message }); } diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index c2163a81..de08ac54 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), @@ -35,13 +47,17 @@ amountFiat = af; }; - let loading; - let submit = () => (loading = true); + let submitting; + let submit = () => (submitting = true); let external = async () => { - let invoice = { type: "lightning", amount, currency }; let { id } = await post(`/${recipient.username}/invoice`, { - invoice, + invoice: { + ...invoice, + type: "lightning", + amount, + currency, + }, user: { username: recipient.username }, }); @@ -52,12 +68,12 @@ $: update(form); let update = () => { - if (form?.message.includes("pin")) $pin = undefined; - loading = false; + if (form?.message?.includes("pin")) $pin = undefined; + submitting = false; }; // onMount(async () => { - // if (browser && window.NDEFReader) { + // if (browser && window.NDEFReader && user.nfc) { // try { // let ndef = new NDEFReader(); // await ndef.scan(); @@ -86,12 +102,12 @@
{/if} -
+
{#if amount} -
-

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

+

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

+

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

-

+

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

+
-

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

+

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

-
- {#if recipient.username.includes("@classic")} - Bitcoin - {:else} - - {/if} -

- {recipient.username.replace("@classic", "")} -

-
+
+ +

+ {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} -
+
{#if amount}
-
+
diff --git a/src/service-worker.js b/src/service-worker.js new file mode 100644 index 00000000..51cbd1f8 --- /dev/null +++ b/src/service-worker.js @@ -0,0 +1,5 @@ +import { build, files, version } from "$service-worker"; + +self.addEventListener("install", (event) => {}); +self.addEventListener("activate", (event) => {}); + self.addEventListener("fetch", (event) => {}); -- cgit v1.2.3