aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-07-30 11:13:39 -0700
committerAdam Soltys <[email protected]>2022-07-30 11:13:39 -0700
commit5bf4891768f1ee359ee5795272c289b40745aed5 (patch)
treec1da5cd4b4f3219162b03c2314b518686b7c69ed /src
parent8acc59a86b6ec049dfe07f92fd19eeda726136f3 (diff)
downloadcoinos-ui-5bf4891768f1ee359ee5795272c289b40745aed5.tar.gz
coinos-ui-5bf4891768f1ee359ee5795272c289b40745aed5.zip
get invoice by uuid
Diffstat (limited to 'src')
-rw-r--r--src/components/AppHeader.svelte4
-rw-r--r--src/components/RegisterOrLogin.svelte2
-rw-r--r--src/lib/utils.js5
-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.svelte2
-rw-r--r--src/routes/invoice/[amount].js12
-rw-r--r--src/routes/invoice/[id].js11
-rw-r--r--src/routes/invoice/[id].svelte (renamed from src/routes/invoice/[amount].svelte)0
-rw-r--r--src/routes/invoice/index.js11
11 files changed, 43 insertions, 16 deletions
diff --git a/src/components/AppHeader.svelte b/src/components/AppHeader.svelte
index b096f01e..99eea6d5 100644
--- a/src/components/AppHeader.svelte
+++ b/src/components/AppHeader.svelte
@@ -8,9 +8,11 @@
<header class="bg-gradient-to-r from-primary to-gradient h-[20vh] w-full relative">
<nav class="flex justify-end items-center space-x-4 p-5">
- <button class="bg-white p-2 rounded-full w-12 h-12" on:click={() => goto('/receive')}
+ <a href={`/${$user.username}/receive`}>
+ <button class="bg-white p-2 rounded-full w-12 h-12"
><Icon icon="numpad" style="mx-auto" /></button
>
+ </a>
<button class="bg-white p-2 rounded-full w-12 h-12"
><Icon icon="clock" style="mx-auto" /></button
>
diff --git a/src/components/RegisterOrLogin.svelte b/src/components/RegisterOrLogin.svelte
index f5764a85..56b96499 100644
--- a/src/components/RegisterOrLogin.svelte
+++ b/src/components/RegisterOrLogin.svelte
@@ -22,7 +22,7 @@
if (!r.token) r = await post('/login', { username, password });
$token = r.token;
auth();
- user.subscribe(() => goto('/receive'));
+ user.subscribe(({ username }) => goto(`/${username}/receive`));
};
</script>
diff --git a/src/lib/utils.js b/src/lib/utils.js
index c17b0a98..e9d1b73e 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -6,6 +6,11 @@ export function scroll(section) {
const base = browser ? '' : import.meta.env.VITE_COINOS_URL;
+export const get = (url) =>
+ fetch(base + url, {
+ headers: { accept: 'application/json'}
+ }).then((r) => r.json());
+
export const post = (url, body) =>
fetch(base + url, {
method: 'POST',
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 } };
+}