From adf27ffe9f7ab061b72c6cc54ca49213aa5d27fe Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 26 Sep 2022 21:28:04 -0700 Subject: invoice updates --- src/components/Qr.svelte | 5 +- src/components/RegisterOrLogin.svelte | 2 +- src/routes/[username]/receive/+page.svelte | 3 +- src/routes/invoice/+server.js | 14 +- src/routes/invoice/[id]/+page.server.js | 1 + src/routes/invoice/[id]/+page.svelte | 227 +++++++++++++++-------------- src/routes/launch/+page.svelte | 5 +- src/routes/launch/purchase/+page.svelte | 6 +- src/routes/register/+page.server.js | 4 +- 9 files changed, 143 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/src/components/Qr.svelte b/src/components/Qr.svelte index 2b37dc9d..e590a228 100644 --- a/src/components/Qr.svelte +++ b/src/components/Qr.svelte @@ -17,8 +17,11 @@ backgroundOptions: { color: 'rgba(0, 0, 0, 0)' }, + cornersSquareOptions: { + type: 'extra-rounded' + }, dotsOptions: { - type: 'rounded' + type: 'extra-rounded' }, image, diff --git a/src/components/RegisterOrLogin.svelte b/src/components/RegisterOrLogin.svelte index e1a0d60c..b40700ad 100644 --- a/src/components/RegisterOrLogin.svelte +++ b/src/components/RegisterOrLogin.svelte @@ -24,7 +24,7 @@ $: if ($user) goto(`/${username}/receive`); - let focus = (el) => setTimeout(() => el.focus()); + let focus = (el) => setTimeout(() => el.focus());
diff --git a/src/routes/[username]/receive/+page.svelte b/src/routes/[username]/receive/+page.svelte index 17b59f1f..a1dc0a0e 100644 --- a/src/routes/[username]/receive/+page.svelte +++ b/src/routes/[username]/receive/+page.svelte @@ -75,9 +75,10 @@ let submit = async () => { loading = true; - let { uuid } = await post('/invoice', { + let { uuid } = await post('/invoice', { amount, rate: $selectedRate, + prompt: true, username: $page.params.username }); goto(`/invoice/${uuid}`); diff --git a/src/routes/invoice/+server.js b/src/routes/invoice/+server.js index c408c4e5..4538256c 100644 --- a/src/routes/invoice/+server.js +++ b/src/routes/invoice/+server.js @@ -1,8 +1,16 @@ import { auth, get, post } from '$lib/utils'; export async function POST({ request, parent }) { - let { amount, currency, network = 'lightning', rate, tip, username } = await request.json(); - let invoice = { amount, currency, network, rate, tip }; + let { + amount, + currency, + network = 'lightning', + prompt, + rate, + tip, + username + } = await request.json(); + let invoice = { amount, currency, network, prompt, rate, tip }; if (network === 'lightning') { invoice.text = (await post('/lightning/invoice', { amount }, auth(request))).text; @@ -10,7 +18,7 @@ export async function POST({ request, parent }) { invoice.address = (await get('/address?network=bitcoin&type=bech32')).address; } - console.log("INVOICE", invoice) + console.log('INVOICE', invoice); return new Response( JSON.stringify(await post('/invoice', { invoice, user: { username } }, auth(request))), diff --git a/src/routes/invoice/[id]/+page.server.js b/src/routes/invoice/[id]/+page.server.js index e123c7d7..3adba31a 100644 --- a/src/routes/invoice/[id]/+page.server.js +++ b/src/routes/invoice/[id]/+page.server.js @@ -1,6 +1,7 @@ import { get } from '$lib/utils'; export async function load({ params }) { + console.log('PARAMS', params); let { id } = params; return { id, invoice: await get(`/invoice?uuid=${id}`) }; } diff --git a/src/routes/invoice/[id]/+page.svelte b/src/routes/invoice/[id]/+page.svelte index d935affb..e8b1dd16 100644 --- a/src/routes/invoice/[id]/+page.svelte +++ b/src/routes/invoice/[id]/+page.svelte @@ -14,7 +14,8 @@ let { amount, rate, - status, + received, + prompt, text, tip, user: { username, currency } @@ -31,7 +32,8 @@ ({ amount, rate, - status, + received, + prompt, text, tip, user: { username, currency } @@ -44,7 +46,7 @@ $: tip = Math.round((amount / 100) * tipPercent); - $invoices[id] = { amount, id, rate, status, text, tip, username }; + $invoices[id] = { amount, id, rate, received, text, tip, username }; $: amountFiat = parseFloat(((amount * rate) / 100000000).toFixed(2)); @@ -67,15 +69,16 @@ let update = async () => { await tick(); - let r = await post(`/invoice`, { + let { uuid } = await post(`/invoice`, { amount: parseInt(amount + tip), + prompt, rate, tip, text, username }); - goto(`/invoice/${r}`); + goto(`/invoice/${uuid}`); }; $: totalAmountFormatted = f(amountFiat + parseFloat(tipAmount), currency); @@ -154,7 +157,33 @@ } -{#if $invoices[id]?.status !== 'paid'} +{#if $invoices[id]?.received >= amount} +
+ {#if typeof window !== 'undefined'} +
+ +
+ {/if} +

{$t('invoice.paymentSuccessful')}

+

+ {totalAmountFormatted} +

+

({totalAmountSats} SAT)

+ +
+{:else}
- -
-

{$t('invoice.addTipq')}

- {#if !showCustomAmount} -
- {tipAmountFormatted}{`(${tipAmountSats} SAT)`} +
+ + - {Math.round(tipPercent)}%
- - (showMobileTip = false)} - /> - {/if} -
+

{$t('invoice.addTipq')}

{#if !showCustomAmount} - {#each tipAmounts as amount} - - {/each} - {/if} - {#if showCustomAmount} -
- $ - handleCustomTipAmount(e)} - class="pl-10" - placeholder="Other" - /> - - -
- {:else}
- {tipAmountFormatted}{`(${tipAmountSats} SAT)`} + {Math.round(tipPercent)}%
+ + (showMobileTip = false)} + /> {/if} +
+ {#if !showCustomAmount} + {#each tipAmounts as amount} + + {/each} + {/if} + {#if showCustomAmount} +
+ $ + handleCustomTipAmount(e)} + class="pl-10" + placeholder="Other" + /> + + +
+ {:else} +
+ +
+ {/if} +
-
- -{:else} -
- {#if typeof window !== 'undefined'} -
- -
- {/if} -

{$t('invoice.paymentSuccessful')}

-

- {totalAmountFormatted} -

-

({totalAmountSats} SAT)

- -
{/if}