From 222bbc9080fbb15861cc5c0802449fcf06a53532 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 7 Oct 2023 23:30:52 -0700 Subject: fix more options invoices --- .../[username]/invoice/[hash]/+layout.server.js | 25 --- .../(app)/[username]/invoice/[hash]/+layout.svelte | 1 - .../[username]/invoice/[hash]/+page.server.js | 5 - .../(app)/[username]/invoice/[hash]/+page.svelte | 217 --------------------- .../[username]/invoice/[hash]/paid/+page.svelte | 65 ------ .../[username]/invoice/[hash]/tip/+page.server.js | 11 -- .../[username]/invoice/[hash]/tip/+page.svelte | 201 ------------------- .../[username]/invoice/[id]/+layout.server.js | 31 +++ .../(app)/[username]/invoice/[id]/+layout.svelte | 1 + .../(app)/[username]/invoice/[id]/+page.server.js | 5 + .../(app)/[username]/invoice/[id]/+page.svelte | 217 +++++++++++++++++++++ .../[username]/invoice/[id]/paid/+page.svelte | 64 ++++++ .../[username]/invoice/[id]/tip/+page.server.js | 11 ++ .../(app)/[username]/invoice/[id]/tip/+page.svelte | 201 +++++++++++++++++++ src/routes/(app)/send/invoice/[id]/+page.svelte | 15 +- 15 files changed, 538 insertions(+), 532 deletions(-) delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/+layout.server.js delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/+layout.svelte delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/+page.server.js delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/+page.svelte delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/paid/+page.svelte delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/tip/+page.server.js delete mode 100644 src/routes/(app)/[username]/invoice/[hash]/tip/+page.svelte create mode 100644 src/routes/(app)/[username]/invoice/[id]/+layout.server.js create mode 100644 src/routes/(app)/[username]/invoice/[id]/+layout.svelte create mode 100644 src/routes/(app)/[username]/invoice/[id]/+page.server.js create mode 100644 src/routes/(app)/[username]/invoice/[id]/+page.svelte create mode 100644 src/routes/(app)/[username]/invoice/[id]/paid/+page.svelte create mode 100644 src/routes/(app)/[username]/invoice/[id]/tip/+page.server.js create mode 100644 src/routes/(app)/[username]/invoice/[id]/tip/+page.svelte diff --git a/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js b/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js deleted file mode 100644 index eef24555..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js +++ /dev/null @@ -1,25 +0,0 @@ -import Qr from 'qrcode-base64'; -import { get } from '$lib/utils'; -import { redirect } from '@sveltejs/kit'; - -export async function load({ depends, params, url, parent }) { - depends('app:invoice'); - - let { user } = await parent(); - let { hash } = params; - let invoice = await get(`/invoice/${hash}`); - - if (user && invoice.uid !== user.id && !url.pathname.includes('tip') && !url.searchParams.get('options')) - throw redirect(307, `/send/invoice/${hash}`); - - let { amount, pending, received } = invoice; - amount = parseInt(amount); - - let paid = (!amount && received) || (amount > 0 && (pending >= amount || received >= amount)); - if (paid && !url.pathname.endsWith('paid')) - throw redirect(307, `/${params.username}/invoice/${hash}/paid`); - - let sm = Qr.drawImg(invoice.text || '', { size: 300 }); - - return { hash, invoice, sm, lg: sm }; -} diff --git a/src/routes/(app)/[username]/invoice/[hash]/+layout.svelte b/src/routes/(app)/[username]/invoice/[hash]/+layout.svelte deleted file mode 100644 index 4fa864ce..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/+layout.svelte +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/routes/(app)/[username]/invoice/[hash]/+page.server.js b/src/routes/(app)/[username]/invoice/[hash]/+page.server.js deleted file mode 100644 index 1068f273..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/+page.server.js +++ /dev/null @@ -1,5 +0,0 @@ -import invoice from '$lib/invoice'; - -export const actions = { - default: invoice -}; diff --git a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte b/src/routes/(app)/[username]/invoice/[hash]/+page.svelte deleted file mode 100644 index 508550ba..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/+page.svelte +++ /dev/null @@ -1,217 +0,0 @@ - - -
-
- - - -
- - {#if showQr} -
- - - {/if} - - {#if amount > 0} -
-
- {f(amountFiat, currency)} - - {#if tip} - - +{f(tip * (rate / sats), currency)} - - {/if} -
-
- {`${sat(amount)}`} - - {#if tip} - - +{sat(tip)} - - {/if} -
-
- {/if} - - - -
- - - - - - - -
-
diff --git a/src/routes/(app)/[username]/invoice/[hash]/paid/+page.svelte b/src/routes/(app)/[username]/invoice/[hash]/paid/+page.svelte deleted file mode 100644 index 969fb6c7..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/paid/+page.svelte +++ /dev/null @@ -1,65 +0,0 @@ - - -
-
- -
- {#if received} -

{$t('invoice.paymentSuccessful')}

-

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

-

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

- {/if} - - {#if pending} -

Payment detected

-

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

-

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

- {/if} -
- - -
- - -
{$t('payments.tapAnywhere')}
diff --git a/src/routes/(app)/[username]/invoice/[hash]/tip/+page.server.js b/src/routes/(app)/[username]/invoice/[hash]/tip/+page.server.js deleted file mode 100644 index 814900fb..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/tip/+page.server.js +++ /dev/null @@ -1,11 +0,0 @@ -import invoice from '$lib/invoice'; -import { redirect } from '@sveltejs/kit'; - -export async function load({ parent, params }) { - let { invoice } = await parent(); - if (!invoice.amount) throw redirect(307, `/${params.username}/invoice/${invoice.id}`); -} - -export const actions = { - default: invoice -}; diff --git a/src/routes/(app)/[username]/invoice/[hash]/tip/+page.svelte b/src/routes/(app)/[username]/invoice/[hash]/tip/+page.svelte deleted file mode 100644 index fe6c67be..00000000 --- a/src/routes/(app)/[username]/invoice/[hash]/tip/+page.svelte +++ /dev/null @@ -1,201 +0,0 @@ - - -
-
- - - - - - - - - - -

{$t('invoice.addTipq')}

- {#if !showCustomAmount} -
{Math.round(tipPercent)}%
- - - -
-
- - {f(amountFiat, currency)} - +{f(tipAmount, currency)} - -
- -
- {sat(amount)} - +{sat(tip)} -
-
- - {#if tip} -
- - -
- {:else} - {#each tipAmounts as amount} - - {/each} - {/if} - -
- -
- {/if} - - -
- - {/if} -
- - diff --git a/src/routes/(app)/[username]/invoice/[id]/+layout.server.js b/src/routes/(app)/[username]/invoice/[id]/+layout.server.js new file mode 100644 index 00000000..4d7fd3b8 --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/+layout.server.js @@ -0,0 +1,31 @@ +import Qr from 'qrcode-base64'; +import { get } from '$lib/utils'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ depends, params, url, parent }) { + depends('app:invoice'); + + let { user } = await parent(); + let { id } = params; + let invoice = await get(`/invoice/${id}`); + let options = !!url.searchParams.get('options'); + + if (user && invoice.uid !== user.id && !url.pathname.includes('tip') && !options) { + throw redirect(307, `/send/invoice/${id}`); + } + + let { amount, pending, received } = invoice; + amount = parseInt(amount); + + let paid = (!amount && received) || (amount > 0 && (pending >= amount || received >= amount)); + if (paid && !url.pathname.endsWith('paid')) { + throw redirect( + 307, + `/${params.username}/invoice/${id}/paid` + (options ? '?options=true' : '') + ); + } + + let sm = Qr.drawImg(invoice.text || '', { size: 300 }); + + return { id, invoice, sm, lg: sm }; +} diff --git a/src/routes/(app)/[username]/invoice/[id]/+layout.svelte b/src/routes/(app)/[username]/invoice/[id]/+layout.svelte new file mode 100644 index 00000000..4fa864ce --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/+layout.svelte @@ -0,0 +1 @@ + diff --git a/src/routes/(app)/[username]/invoice/[id]/+page.server.js b/src/routes/(app)/[username]/invoice/[id]/+page.server.js new file mode 100644 index 00000000..1068f273 --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/+page.server.js @@ -0,0 +1,5 @@ +import invoice from '$lib/invoice'; + +export const actions = { + default: invoice +}; diff --git a/src/routes/(app)/[username]/invoice/[id]/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/+page.svelte new file mode 100644 index 00000000..508550ba --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/+page.svelte @@ -0,0 +1,217 @@ + + +
+
+ + + +
+ + {#if showQr} +
+ + + {/if} + + {#if amount > 0} +
+
+ {f(amountFiat, currency)} + + {#if tip} + + +{f(tip * (rate / sats), currency)} + + {/if} +
+
+ {`${sat(amount)}`} + + {#if tip} + + +{sat(tip)} + + {/if} +
+
+ {/if} + + + +
+ + + + + + + +
+
diff --git a/src/routes/(app)/[username]/invoice/[id]/paid/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/paid/+page.svelte new file mode 100644 index 00000000..84e493d9 --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/paid/+page.svelte @@ -0,0 +1,64 @@ + + +
+
+ +
+ {#if received} +

{$t('invoice.paymentSuccessful')}

+

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

+

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

+ {/if} + + {#if pending} +

Payment detected

+

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

+

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

+ {/if} +
+ + +
+ + +
{$t('payments.tapAnywhere')}
diff --git a/src/routes/(app)/[username]/invoice/[id]/tip/+page.server.js b/src/routes/(app)/[username]/invoice/[id]/tip/+page.server.js new file mode 100644 index 00000000..814900fb --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/tip/+page.server.js @@ -0,0 +1,11 @@ +import invoice from '$lib/invoice'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ parent, params }) { + let { invoice } = await parent(); + if (!invoice.amount) throw redirect(307, `/${params.username}/invoice/${invoice.id}`); +} + +export const actions = { + default: invoice +}; diff --git a/src/routes/(app)/[username]/invoice/[id]/tip/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/tip/+page.svelte new file mode 100644 index 00000000..fe6c67be --- /dev/null +++ b/src/routes/(app)/[username]/invoice/[id]/tip/+page.svelte @@ -0,0 +1,201 @@ + + +
+
+ + + + + + + + + + +

{$t('invoice.addTipq')}

+ {#if !showCustomAmount} +
{Math.round(tipPercent)}%
+ + + +
+
+ + {f(amountFiat, currency)} + +{f(tipAmount, currency)} + +
+ +
+ {sat(amount)} + +{sat(tip)} +
+
+ + {#if tip} +
+ + +
+ {:else} + {#each tipAmounts as amount} + + {/each} + {/if} + +
+ +
+ {/if} + + +
+ + {/if} +
+ + diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 554eef6f..a71c697a 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -28,12 +28,13 @@ let submit = () => (loading = true); let external = async () => { - let invoice = { type: 'lightning', amount }; - let { hash } = await post(`/${recipient.username}/invoice`, { - invoice + let invoice = { type: 'lightning', amount, currency }; + let {id }= await post(`/${recipient.username}/invoice`, { + invoice, + user: { username: recipient.username } }); - goto(`/${recipient.username}/invoice/${hash}`, { invalidateAll: true }); + goto(`/${recipient.username}/invoice/${id}?options=true`, { invalidateAll: true }); }; $: rate = data.rate * (rates[user.currency] / rates[data.currency]); @@ -139,7 +140,7 @@ {/if}
-
- -
+
+ +
-- cgit v1.2.3