aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/invoice
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-26 13:08:08 -0800
committerAdam Soltys <[email protected]>2024-11-26 13:20:53 -0800
commit0bf630c39fe290ea2718eab7a0759d978c736ef9 (patch)
treea670c3ae954d5075c851126c2aca7a1a45d1b41d /src/routes/(app)/invoice
parent41ee0027e1767e4d116330bdee2e0456fd45f940 (diff)
downloadcoinos-ui-0bf630c39fe290ea2718eab7a0759d978c736ef9.tar.gz
coinos-ui-0bf630c39fe290ea2718eab7a0759d978c736ef9.zip
bip21 and socket fixes
Diffstat (limited to 'src/routes/(app)/invoice')
-rw-r--r--src/routes/(app)/invoice/[id]/[email protected]110
-rw-r--r--src/routes/(app)/invoice/[id]/+page.svelte22
2 files changed, 15 insertions, 117 deletions
diff --git a/src/routes/(app)/invoice/[id]/[email protected] b/src/routes/(app)/invoice/[id]/[email protected]
deleted file mode 100644
index 13b121d8..00000000
--- a/src/routes/(app)/invoice/[id]/[email protected]
+++ /dev/null
@@ -1,110 +0,0 @@
-<script>
- import { SvelteToast } from "@zerodevx/svelte-toast";
- import { onDestroy, onMount } from "svelte";
- import { close, connect, send } from "$lib/socket";
- import {
- last,
- invoice,
- request,
- ndef,
- passwordPrompt,
- password,
- pin,
- theme as themeStore,
- } from "$lib/store";
- import { page } from "$app/stores";
- import { browser } from "$app/environment";
- import LoadingSplash from "$comp/LoadingSplash.svelte";
- import AppHeader from "$comp/AppHeader.svelte";
- import Invoice from "$comp/Invoice.svelte";
- import Password from "$comp/Password.svelte";
- import { getCookie, warning, protectedRoutes } from "$lib/utils";
- import { t, locale, loading } from "$lib/translations";
- import { goto, onNavigate } from "$app/navigation";
-
- let { data, children } = $props();
-
- let { user, subject, token } = $derived(data);
- let { theme } = $state(data);
-
- $themeStore = theme;
- $effect(() => (theme = $themeStore));
- $effect(() => browser && connect(token));
-
- onMount(async () => {
- if (browser) {
- checkSocket();
- $pin = getCookie("pin");
-
- if (window.NDEFReader && user.nfc) {
- try {
- $ndef = new NDEFReader();
- await $ndef.scan();
-
- $ndef.addEventListener("readingerror", (e) => {
- console.log("nfc error", e);
- });
-
- $ndef.addEventListener("reading", ({ message, serialNumber }) => {
- goto(`/send/${message}`);
- });
- } catch (error) {
- console.log("Argh! " + error);
- }
- }
- }
- });
-
- let lost,
- checkTimer,
- expireTimer,
- counter = 0;
-
- let checkSocket = () => {
- counter++;
- lost = Date.now() - $last > 30000;
- if (lost) connect(token);
- if (counter > 5) {
- send("heartbeat", token);
- counter = 0;
- }
-
- checkTimer = setTimeout(checkSocket, 1000);
- };
-
- onDestroy(() => {
- if (browser) {
- close();
- clearTimeout(checkTimer);
- clearTimeout(expireTimer);
- }
- });
-</script>
-
-{#if browser && user && $passwordPrompt}
- <Password {user} />
-{/if}
-
-<svelte:head>
- {#if subject}
- <title>coinos - {subject.username}</title>
- <meta name="lightning" content={`lnurlp:${subject.username}@coinos.io`} />
- {:else}
- <title>coinos</title>
- {/if}
-
- {#if subject?.profile}
- <meta name="og:image" content={`/api/public/${subject.profile}.webp`} />
- {:else}
- <meta property="og:image" content="/images/logo.webp" />
- {/if}
-</svelte:head>
-
-<SvelteToast options={{ reversed: true, intro: { y: 192 } }} />
-
-<main class="pb-4 min-h-dvh" data-theme={theme}>
- <AppHeader {user} {subject} />
- {#if !$loading}
- {@render children?.()}
- {/if}
-</main>
diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte
index 8c6e2b75..3ad20f68 100644
--- a/src/routes/(app)/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/invoice/[id]/+page.svelte
@@ -56,13 +56,21 @@
});
let setType = async (type) => {
- invoice.type = type;
- ({ id } = await post(`/invoice`, {
- invoice,
- user: { username, currency },
- }));
+ $showQr = true;
+ if (type === types.lightning && !amount)
+ goto(`/${username}/receive`, { invalidateAll: true, noScroll: true });
+ else {
+ invoice.type = type;
+ ({ id } = await post(`/invoice`, {
+ invoice,
+ user: { username, currency },
+ }));
- goto(`./${id}?options=true`, { invalidateAll: true, noScroll: true });
+ goto(`/invoice/${id}?options=true`, {
+ invalidateAll: true,
+ noScroll: true,
+ });
+ }
};
let setAmount = async (e) => {
@@ -74,7 +82,7 @@
if (typeof $amountPrompt === "undefined") $amountPrompt = true;
invoice.amount = newAmount;
invoice.tip = 0;
-
+
({ id } = await post(`/invoice`, {
invoice,
user: { username, currency },