diff options
| author | Adam Soltys <[email protected]> | 2022-07-30 11:13:39 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-07-30 11:13:39 -0700 |
| commit | 5bf4891768f1ee359ee5795272c289b40745aed5 (patch) | |
| tree | c1da5cd4b4f3219162b03c2314b518686b7c69ed /src/routes | |
| parent | 8acc59a86b6ec049dfe07f92fd19eeda726136f3 (diff) | |
| download | coinos-ui-5bf4891768f1ee359ee5795272c289b40745aed5.tar.gz coinos-ui-5bf4891768f1ee359ee5795272c289b40745aed5.zip | |
get invoice by uuid
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/[username]/index.js (renamed from src/routes/[username].js) | 0 | ||||
| -rw-r--r-- | src/routes/[username]/index.svelte (renamed from src/routes/[username].svelte) | 0 | ||||
| -rw-r--r-- | src/routes/[username]/receive.svelte (renamed from src/routes/receive.svelte) | 12 | ||||
| -rw-r--r-- | src/routes/__layout.svelte | 2 | ||||
| -rw-r--r-- | src/routes/invoice/[amount].js | 12 | ||||
| -rw-r--r-- | src/routes/invoice/[id].js | 11 | ||||
| -rw-r--r-- | src/routes/invoice/[id].svelte (renamed from src/routes/invoice/[amount].svelte) | 0 | ||||
| -rw-r--r-- | src/routes/invoice/index.js | 11 |
8 files changed, 34 insertions, 14 deletions
diff --git a/src/routes/[username].js b/src/routes/[username]/index.js index 39a216c2..39a216c2 100644 --- a/src/routes/[username].js +++ b/src/routes/[username]/index.js diff --git a/src/routes/[username].svelte b/src/routes/[username]/index.svelte index fe1f7754..fe1f7754 100644 --- a/src/routes/[username].svelte +++ b/src/routes/[username]/index.svelte diff --git a/src/routes/receive.svelte b/src/routes/[username]/receive.svelte index 0329dea4..9ebc0401 100644 --- a/src/routes/receive.svelte +++ b/src/routes/[username]/receive.svelte @@ -3,12 +3,16 @@ import { AppHeader, Icon } from '$comp'; import { goto } from '$app/navigation'; import { invoiceAmount, invoiceAmountFiat, rate, user } from '$lib/store'; + import { post } from '$lib/utils'; + import { page } from '$app/stores'; let useFiat = true; let amountFiat = 0; let amountSats = 0; let message = ''; + $: amount = useFiat ? Math.round(amountFiat / ($rate / 100000000)) : amountSats; + $: $invoiceAmount = parseInt(amountSats === 0 ? amountFiat / ($rate / 100000000) : amountSats); $: $invoiceAmountFiat = parseInt( amountFiat === 0 ? amountSats * ($rate / 100000000) : amountFiat @@ -76,6 +80,12 @@ } } }; + + let submit = async () => { + let { id } = await post('/invoice', { amount, username: $page.params.username }); + console.log(id) + goto(`/invoice/${id}`); + }; </script> {#if $user} @@ -160,7 +170,7 @@ 0 ? 'opacity-50' : 'opacity-100'}" - on:click={() => goto(`/invoice/${$invoiceAmount}`)} + on:click={submit} disabled={$invoiceAmount === 0}><Icon icon="qr" style="mr-2" /> Show QR</button > <button diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index c01dc848..95b2e0c3 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -14,7 +14,7 @@ onMount(() => { if (protectedRoutes.find((p) => $page.url.pathname.match(p))) { if (!$token) goto('/login'); - user.subscribe((u) => (ready = true)); + user.subscribe((u) => (ready = true)); } else { ready = true; } diff --git a/src/routes/invoice/[amount].js b/src/routes/invoice/[amount].js deleted file mode 100644 index 9e9678a6..00000000 --- a/src/routes/invoice/[amount].js +++ /dev/null @@ -1,12 +0,0 @@ -import { post } from '$lib/utils'; - -const username = 'bob', - network = 'lightning'; - -export async function GET({ params }) { - let { amount } = params; - let { text } = await post('/lightning/invoice', { amount }); - await post('/invoice', { invoice: { text, network }, user: { username } }); - - return { body: { amount, text } }; -} diff --git a/src/routes/invoice/[id].js b/src/routes/invoice/[id].js new file mode 100644 index 00000000..37ef098d --- /dev/null +++ b/src/routes/invoice/[id].js @@ -0,0 +1,11 @@ +import { get } from '$lib/utils'; + +const username = 'bob', + network = 'lightning'; + +export async function GET({ params }) { + let { id } = params; + let { amount, text } = await get(`/invoice?uuid=${id}`); + + return { body: { amount, text } }; +} diff --git a/src/routes/invoice/[amount].svelte b/src/routes/invoice/[id].svelte index d1dea907..d1dea907 100644 --- a/src/routes/invoice/[amount].svelte +++ b/src/routes/invoice/[id].svelte diff --git a/src/routes/invoice/index.js b/src/routes/invoice/index.js new file mode 100644 index 00000000..26bffd37 --- /dev/null +++ b/src/routes/invoice/index.js @@ -0,0 +1,11 @@ +import { post } from '$lib/utils'; + +let network = 'lightning'; + +export async function POST({ request }) { + let { amount, username } = await request.json(); + let { text } = await post('/lightning/invoice', ); + let { uuid: id } = await post('/invoice', { invoice: { text, network }, user: { username } }); + + return { body: { id } }; +} |
