From e55b44b42a5e384a807a2703d4744dd1392f227e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 9 Nov 2022 09:53:33 -0800 Subject: refactor settings --- src/routes/(app)/invoice/[id]/+layout.server.js | 10 +++- src/routes/(app)/invoice/[id]/+page.svelte | 21 +++---- src/routes/(app)/invoice/[id]/paid/+page.svelte | 68 +++++++++++++--------- src/routes/(app)/invoice/[id]/pending/+page.svelte | 56 ------------------ 4 files changed, 59 insertions(+), 96 deletions(-) delete mode 100644 src/routes/(app)/invoice/[id]/pending/+page.svelte (limited to 'src/routes/(app)/invoice') diff --git a/src/routes/(app)/invoice/[id]/+layout.server.js b/src/routes/(app)/invoice/[id]/+layout.server.js index 4b6cf97e..dacc44e6 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.js +++ b/src/routes/(app)/invoice/[id]/+layout.server.js @@ -1,9 +1,17 @@ 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'); -export async function load({ params }) { let { id } = params; let invoice = await get(`/invoice?uuid=${id}`); + let { amount, received, pending } = invoice; + + let paid = (!amount && (received || pending)) || (amount > 0 && received + pending >= amount); + if (paid && !url.pathname.endsWith('paid')) throw redirect(307, `/invoice/${id}/paid`); + let sm = Qr.drawImg(invoice.text, { size: 300 }); let lg = Qr.drawImg(invoice.text, { size: 1200 }); diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte index dec33b62..fadf7270 100644 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ b/src/routes/(app)/invoice/[id]/+page.svelte @@ -1,7 +1,7 @@
-

{$t('invoice.paymentSuccessful')}

-

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

-

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

- + {#if received} +

{$t('invoice.paymentSuccessful')}

+

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

+

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

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

Payment detected

+

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

+

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

+ {/if} + + + +
diff --git a/src/routes/(app)/invoice/[id]/pending/+page.svelte b/src/routes/(app)/invoice/[id]/pending/+page.svelte deleted file mode 100644 index d3970dab..00000000 --- a/src/routes/(app)/invoice/[id]/pending/+page.svelte +++ /dev/null @@ -1,56 +0,0 @@ - - -
-
- -
- -

Payment detected

- -
-

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

-

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

-
- -

Pending confirmation

- - -
-- cgit v1.2.3