From 0e0f39af2e6585d7b61cf67652cdc0c2b2f06eb8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 18 Jan 2023 19:44:27 -0800 Subject: pots --- src/routes/(app)/invoice/+server.js | 5 + src/routes/(app)/invoice/[hash]/+layout.server.js | 19 ++ src/routes/(app)/invoice/[hash]/+layout.svelte | 1 + src/routes/(app)/invoice/[hash]/+page.server.js | 5 + src/routes/(app)/invoice/[hash]/+page.svelte | 158 +++++++++++++ src/routes/(app)/invoice/[hash]/paid/+page.svelte | 62 +++++ .../(app)/invoice/[hash]/tip/+page.server.js | 11 + src/routes/(app)/invoice/[hash]/tip/+page.svelte | 252 +++++++++++++++++++++ src/routes/(app)/invoice/[id]/+layout.server.js | 19 -- src/routes/(app)/invoice/[id]/+layout.svelte | 1 - src/routes/(app)/invoice/[id]/+page.server.js | 5 - src/routes/(app)/invoice/[id]/+page.svelte | 158 ------------- src/routes/(app)/invoice/[id]/paid/+page.svelte | 62 ----- src/routes/(app)/invoice/[id]/tip/+page.server.js | 11 - src/routes/(app)/invoice/[id]/tip/+page.svelte | 252 --------------------- 15 files changed, 513 insertions(+), 508 deletions(-) create mode 100644 src/routes/(app)/invoice/+server.js create mode 100644 src/routes/(app)/invoice/[hash]/+layout.server.js create mode 100644 src/routes/(app)/invoice/[hash]/+layout.svelte create mode 100644 src/routes/(app)/invoice/[hash]/+page.server.js create mode 100644 src/routes/(app)/invoice/[hash]/+page.svelte create mode 100644 src/routes/(app)/invoice/[hash]/paid/+page.svelte create mode 100644 src/routes/(app)/invoice/[hash]/tip/+page.server.js create mode 100644 src/routes/(app)/invoice/[hash]/tip/+page.svelte delete mode 100644 src/routes/(app)/invoice/[id]/+layout.server.js delete mode 100644 src/routes/(app)/invoice/[id]/+layout.svelte delete mode 100644 src/routes/(app)/invoice/[id]/+page.server.js delete mode 100644 src/routes/(app)/invoice/[id]/+page.svelte delete mode 100644 src/routes/(app)/invoice/[id]/paid/+page.svelte delete mode 100644 src/routes/(app)/invoice/[id]/tip/+page.server.js delete mode 100644 src/routes/(app)/invoice/[id]/tip/+page.svelte (limited to 'src/routes/(app)/invoice') diff --git a/src/routes/(app)/invoice/+server.js b/src/routes/(app)/invoice/+server.js new file mode 100644 index 00000000..1321739e --- /dev/null +++ b/src/routes/(app)/invoice/+server.js @@ -0,0 +1,5 @@ +import { auth, post } from '$lib/utils'; +import { json } from '@sveltejs/kit'; + +export let POST = async ({ cookies: c, request: r }) => + json(await post('/invoice', await r.json(), auth(c))); diff --git a/src/routes/(app)/invoice/[hash]/+layout.server.js b/src/routes/(app)/invoice/[hash]/+layout.server.js new file mode 100644 index 00000000..61a479ab --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+layout.server.js @@ -0,0 +1,19 @@ +import Qr from 'qrcode-base64'; +import { get } from '$lib/utils'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ depends, params, url }) { + depends('app:invoice'); + + let { hash } = params; + let invoice = await get(`/invoice?hash=${hash}`); + let { amount, received } = invoice; + amount = parseInt(amount); + + let paid = (!amount && received) || (amount > 0 && received >= amount); + if (paid && !url.pathname.endsWith('paid')) throw redirect(307, `/invoice/${hash}/paid`); + + let sm = Qr.drawImg(invoice.text, { size: 300 }); + + return { hash, invoice, sm, lg: sm }; +} diff --git a/src/routes/(app)/invoice/[hash]/+layout.svelte b/src/routes/(app)/invoice/[hash]/+layout.svelte new file mode 100644 index 00000000..4fa864ce --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+layout.svelte @@ -0,0 +1 @@ + diff --git a/src/routes/(app)/invoice/[hash]/+page.server.js b/src/routes/(app)/invoice/[hash]/+page.server.js new file mode 100644 index 00000000..1068f273 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+page.server.js @@ -0,0 +1,5 @@ +import invoice from '$lib/invoice'; + +export const actions = { + default: invoice +}; diff --git a/src/routes/(app)/invoice/[hash]/+page.svelte b/src/routes/(app)/invoice/[hash]/+page.svelte new file mode 100644 index 00000000..28ff27c0 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+page.svelte @@ -0,0 +1,158 @@ + + + + +
+
+ +
+ +
+ +
+ + {#if address} +
{address}
+ {/if} + +
+ + + {#if user && user.username !== username} + + + + {/if} +
+ +
+ {#if invoice.tip} +
+ {$t('invoice.invoice')} + + {f(amountFiat, currency)} + {`${sat(amount)}`} + +
+ +
+ {$t('invoice.tip')} + {f(tipAmount, currency)} + {`${sat(tip)}`} + +
+ {/if} + + {#if amount > 0} +
+ {$t('invoice.total')} + {f(amountFiat + parseFloat(tipAmount), currency)} + {`${sat(tip + amount)}`} +
+ {/if} +
+
+ + diff --git a/src/routes/(app)/invoice/[hash]/paid/+page.svelte b/src/routes/(app)/invoice/[hash]/paid/+page.svelte new file mode 100644 index 00000000..2ccbc971 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/paid/+page.svelte @@ -0,0 +1,62 @@ + + +
+
+ +
+ {#if received} +

{$t('invoice.paymentSuccessful')}

+

+ {f(amountFiat, currency)} + {#if tip} + + {f(tipFiat, currency)} + {/if} +

+

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

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

Payment detected

+

+ {f(pendingFiat, currency)} + {#if tip} + + {f(tipFiat, currency)} + {/if} +

+

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

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

{$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)/invoice/[id]/+layout.server.js b/src/routes/(app)/invoice/[id]/+layout.server.js deleted file mode 100644 index 78d8481e..00000000 --- a/src/routes/(app)/invoice/[id]/+layout.server.js +++ /dev/null @@ -1,19 +0,0 @@ -import Qr from 'qrcode-base64'; -import { get } from '$lib/utils'; -import { redirect } from '@sveltejs/kit'; - -export async function load({ depends, params, url }) { - depends('app:invoice'); - - let { id } = params; - let invoice = await get(`/invoice?id=${id}`); - let { amount, received } = invoice; - amount = parseInt(amount); - - let paid = (!amount && received) || (amount > 0 && received >= amount); - if (paid && !url.pathname.endsWith('paid')) throw redirect(307, `/invoice/${id}/paid`); - - let sm = Qr.drawImg(invoice.text, { size: 300 }); - - return { id, invoice, sm, lg: sm }; -} diff --git a/src/routes/(app)/invoice/[id]/+layout.svelte b/src/routes/(app)/invoice/[id]/+layout.svelte deleted file mode 100644 index 4fa864ce..00000000 --- a/src/routes/(app)/invoice/[id]/+layout.svelte +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/routes/(app)/invoice/[id]/+page.server.js b/src/routes/(app)/invoice/[id]/+page.server.js deleted file mode 100644 index 1068f273..00000000 --- a/src/routes/(app)/invoice/[id]/+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)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte deleted file mode 100644 index 28ff27c0..00000000 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ /dev/null @@ -1,158 +0,0 @@ - - - - -
-
- -
- -
- -
- - {#if address} -
{address}
- {/if} - -
- - - {#if user && user.username !== username} - - - - {/if} -
- -
- {#if invoice.tip} -
- {$t('invoice.invoice')} - - {f(amountFiat, currency)} - {`${sat(amount)}`} - -
- -
- {$t('invoice.tip')} - {f(tipAmount, currency)} - {`${sat(tip)}`} - -
- {/if} - - {#if amount > 0} -
- {$t('invoice.total')} - {f(amountFiat + parseFloat(tipAmount), currency)} - {`${sat(tip + amount)}`} -
- {/if} -
-
- - diff --git a/src/routes/(app)/invoice/[id]/paid/+page.svelte b/src/routes/(app)/invoice/[id]/paid/+page.svelte deleted file mode 100644 index 2ccbc971..00000000 --- a/src/routes/(app)/invoice/[id]/paid/+page.svelte +++ /dev/null @@ -1,62 +0,0 @@ - - -
-
- -
- {#if received} -

{$t('invoice.paymentSuccessful')}

-

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

-

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

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

Payment detected

-

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

-

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

- {/if} -
- - -
- - -
{$t('payments.tapAnywhere')}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.js b/src/routes/(app)/invoice/[id]/tip/+page.server.js deleted file mode 100644 index c78e5020..00000000 --- a/src/routes/(app)/invoice/[id]/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 }) { - let { invoice } = await parent(); - if (!invoice.amount) throw redirect(307, `/invoice/${invoice.id}`); -} - -export const actions = { - default: invoice -}; diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte deleted file mode 100644 index 308720ab..00000000 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ /dev/null @@ -1,252 +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} -
- - -- cgit v1.2.3