aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-07-25 21:32:44 -0700
committerAdam Soltys <[email protected]>2022-07-25 21:32:44 -0700
commiteb9a9c048ebcda09df0ba31745b9d9a5b543596f (patch)
tree4f6e01f85f8b442b6688638a17194d3ff7118c1f /src
parent5640d62d160cb6e00289db28d7ff25b6881db71d (diff)
downloadcoinos-ui-eb9a9c048ebcda09df0ba31745b9d9a5b543596f.tar.gz
coinos-ui-eb9a9c048ebcda09df0ba31745b9d9a5b543596f.zip
invoice endpoint
Diffstat (limited to 'src')
-rw-r--r--src/lib/socket.js10
-rw-r--r--src/lib/store.js4
-rw-r--r--src/routes/__layout.svelte19
-rw-r--r--src/routes/invoice.js20
-rw-r--r--src/routes/invoice.svelte13
-rw-r--r--src/routes/receive.svelte5
6 files changed, 69 insertions, 2 deletions
diff --git a/src/lib/socket.js b/src/lib/socket.js
new file mode 100644
index 00000000..978c053a
--- /dev/null
+++ b/src/lib/socket.js
@@ -0,0 +1,10 @@
+import { rate } from "$lib/store";
+export const messages = (data) => ({
+ rate() {
+ rate.set(data);
+ },
+
+ payment() {
+ console.log(data);
+ }
+});
diff --git a/src/lib/store.js b/src/lib/store.js
index e69de29b..e44aeaa6 100644
--- a/src/lib/store.js
+++ b/src/lib/store.js
@@ -0,0 +1,4 @@
+import { writable } from "svelte/store";
+
+export const rate = writable();
+export const ws = writable();
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte
index 2e511e00..0168bb7c 100644
--- a/src/routes/__layout.svelte
+++ b/src/routes/__layout.svelte
@@ -1,5 +1,24 @@
<script>
import '../app.css';
+ import { onMount } from 'svelte';
+ import { rate, ws } from "$lib/store";
+ import { messages } from "$lib/socket";
+
+ let token =
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImJvYiIsImlhdCI6MTY1ODc5NDkxMX0._zFTEADrbLffcXa5sIMrJtJ483VdIiYmsdt2ofibxu4';
+
+ onMount(async () => {
+ $ws = new WebSocket(`ws://localhost:3119/ws`);
+
+ $ws.onmessage = (msg) => {
+ let { type, data } = JSON.parse(msg.data);
+ messages(data)[type] && messages(data)[type]();
+ };
+
+ $ws.onopen = () => {
+ ws.send(JSON.stringify({ type: 'login', data: token }));
+ };
+ });
</script>
<slot />
diff --git a/src/routes/invoice.js b/src/routes/invoice.js
new file mode 100644
index 00000000..fa493fe1
--- /dev/null
+++ b/src/routes/invoice.js
@@ -0,0 +1,20 @@
+import got from 'got';
+
+const username = 'bob',
+ network = 'lightning';
+
+export async function GET({ params }) {
+ let text = await got
+ .post('http://localhost:3119/lightning/invoice', {
+ json: { amount: 100 }
+ })
+ .text();
+
+ let body = await got
+ .post('http://localhost:3119/invoice', {
+ json: { invoice: { text, network }, user: { username } }
+ })
+ .json();
+
+ return { body };
+}
diff --git a/src/routes/invoice.svelte b/src/routes/invoice.svelte
new file mode 100644
index 00000000..6ea9e67f
--- /dev/null
+++ b/src/routes/invoice.svelte
@@ -0,0 +1,13 @@
+<script>
+ import { rate } from "$lib/store";
+ import { onMount } from "svelte";
+
+ onMount(() => {
+
+ });
+ </script>
+
+ QR code
+
+ {$rate}
+
diff --git a/src/routes/receive.svelte b/src/routes/receive.svelte
index 8d0e95fa..7aa8536f 100644
--- a/src/routes/receive.svelte
+++ b/src/routes/receive.svelte
@@ -1,6 +1,7 @@
<script>
// in the future we will want to allow users to set their fiat currency in the settings
import { AppHeader, Icon } from '$comp';
+ import { goto } from "$app/navigation";
let useFiat = true;
let amountFiat = 0;
@@ -62,8 +63,8 @@
<!-- buttons -->
<div class="space-y-3">
<button
- class="bg-black text-white rounded-xl w-full h-[48px] flex justify-center items-center font-semibold text-sm"
- ><Icon icon="qr" style="mr-2" /> Show QR</button
+ class="bg-black text-white rounded-xl w-full h-[48px] flex justify-center items-center font-semibold text-sm" on:click={() => goto('/invoice')}
+ ><Icon icon="qr" style="mr-2" /> Show QR</button
>
<button
class="bg-primary rounded-xl w-full h-[48px] flex justify-center items-center font-semibold text-sm"