From b972aa21389c20ab9da1a627612bbc1dafeec366 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 29 Jul 2022 23:40:59 -0700 Subject: dynamic qr lib import and invoice amount param --- src/routes/invoice.js | 12 -- src/routes/invoice.svelte | 248 ------------------------------------ src/routes/invoice/[amount].js | 14 +++ src/routes/invoice/[amount].svelte | 252 +++++++++++++++++++++++++++++++++++++ src/routes/receive.svelte | 2 +- 5 files changed, 267 insertions(+), 261 deletions(-) delete mode 100644 src/routes/invoice.js delete mode 100644 src/routes/invoice.svelte create mode 100644 src/routes/invoice/[amount].js create mode 100644 src/routes/invoice/[amount].svelte diff --git a/src/routes/invoice.js b/src/routes/invoice.js deleted file mode 100644 index 4b3327f6..00000000 --- a/src/routes/invoice.js +++ /dev/null @@ -1,12 +0,0 @@ -import { post } from '$lib/utils'; -import { invoiceAmount } from '$lib/store'; - -const username = 'bob', - network = 'lightning'; - -export async function GET({ params }) { - let { text } = await post('/lightning/invoice', { amount: invoiceAmount }); - await post('/invoice', { invoice: { text, network }, user: { username } }); - - return { body: { text } }; -} diff --git a/src/routes/invoice.svelte b/src/routes/invoice.svelte deleted file mode 100644 index 6dce84fe..00000000 --- a/src/routes/invoice.svelte +++ /dev/null @@ -1,248 +0,0 @@ - - - - -
-
- {#if $invoiceAmount && $invoiceAmountFiat && $rate && text} - -
-

Add a tip?

- -
- {tipAmountFormatted}{`(${tipAmountSats} SATS)`} - {tipPercent}% -
- - { - customTipAmount = ''; - tipPercent = e.target.value; - }} - /> - -
- {#each tipAmounts as amount} - - {/each} - -
- $ - handleCustomTipAmount(e)} - class="bg-primary rounded-2xl py-3 px-10 font-semibold mt-2 mr-1 w-full md:w-auto" - placeholder="Other" - /> - -
-
-
- -
- - -
- Scan to pay insert name here - -
- -
-
- Invoice - {invoiceAmountFiatFormatted} - {`(${invoiceAmountFormatted} SATS)`} -
- -
- Tip - {tipAmountFormatted} - {`(${tipAmountSats} SATS)`} -
- -
- Total - {totalAmountFormatted} - {`(${totalAmountSats} SATS)`} -
-
-
- {:else} -
-
-
- {/if} -
-
- - diff --git a/src/routes/invoice/[amount].js b/src/routes/invoice/[amount].js new file mode 100644 index 00000000..f75a1672 --- /dev/null +++ b/src/routes/invoice/[amount].js @@ -0,0 +1,14 @@ +import { post } from '$lib/utils'; + +const username = 'bob', + network = 'lightning'; + +export async function GET({ params }) { + let { amount } = params; + console.log("AMT", amount); + let { text } = await post('/lightning/invoice', { amount }); + console.log("TXT", text); + await post('/invoice', { invoice: { text, network }, user: { username } }); + + return { body: { amount, text } }; +} diff --git a/src/routes/invoice/[amount].svelte b/src/routes/invoice/[amount].svelte new file mode 100644 index 00000000..dd6ed7fa --- /dev/null +++ b/src/routes/invoice/[amount].svelte @@ -0,0 +1,252 @@ + + + + +
+
+ {#if $invoiceAmount && $invoiceAmountFiat && $rate && text} + +
+

Add a tip?

+ +
+ {tipAmountFormatted}{`(${tipAmountSats} SATS)`} + {tipPercent}% +
+ + { + customTipAmount = ''; + tipPercent = e.target.value; + }} + /> + +
+ {#each tipAmounts as amount} + + {/each} + +
+ $ + handleCustomTipAmount(e)} + class="bg-primary rounded-2xl py-3 px-10 font-semibold mt-2 mr-1 w-full md:w-auto" + placeholder="Other" + /> + +
+
+
+ +
+ + +
+ Scan to pay insert name here + +
+ +
+
+ Invoice + {invoiceAmountFiatFormatted} + {`(${invoiceAmountFormatted} SATS)`} +
+ +
+ Tip + {tipAmountFormatted} + {`(${tipAmountSats} SATS)`} +
+ +
+ Total + {totalAmountFormatted} + {`(${totalAmountSats} SATS)`} +
+
+
+ {:else} +
+
+
+ {/if} +
+
+ + diff --git a/src/routes/receive.svelte b/src/routes/receive.svelte index 095a2ba3..ff156783 100644 --- a/src/routes/receive.svelte +++ b/src/routes/receive.svelte @@ -160,7 +160,7 @@ 0 ? 'opacity-50' : 'opacity-100'}" - on:click={() => goto('/invoice')} + on:click={() => goto(`/invoice/${$invoiceAmount}`)} disabled={$invoiceAmount === 0}> Show QR