aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/socket.ts9
-rw-r--r--src/lib/store.ts3
-rw-r--r--src/routes/(app)/[username]/receive/+page.svelte12
3 files changed, 21 insertions, 3 deletions
diff --git a/src/lib/socket.ts b/src/lib/socket.ts
index 077fb856..3e71e1ce 100644
--- a/src/lib/socket.ts
+++ b/src/lib/socket.ts
@@ -1,7 +1,7 @@
import { goto, invalidate } from "$app/navigation";
import { navigating, page } from "$app/stores";
import { PUBLIC_SOCKET } from "$env/static/public";
-import { event, importing, invoice, last, paymentSignal, request } from "$lib/store";
+import { event, importing, invoice, last, lastPayment, paymentSignal, request } from "$lib/store";
import { s, sleep, success, wait } from "$lib/utils";
import cookies from "js-cookie";
import { get } from "svelte/store";
@@ -54,6 +54,8 @@ export const messages = (data) => ({
return;
}
+ if (amount > 0 && iid) lastPayment.set({ iid, amount, confirmed });
+
const {
url: { pathname },
} = get(page);
@@ -66,7 +68,10 @@ export const messages = (data) => ({
pathname.includes("/receive") ||
pathname.includes("/invoice")
) {
- if (!get(navigating)) goto(`/invoice/${iid}`);
+ if (!get(navigating) && iid) {
+ const target = confirmed ? `/invoice/${iid}/paid` : `/invoice/${iid}`;
+ goto(target);
+ }
} else success(`${confirmed ? "Received" : "Detected"} ⚡️${s(amount)}!`);
}
},
diff --git a/src/lib/store.ts b/src/lib/store.ts
index 57bb9735..df2c1eba 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -98,3 +98,6 @@ export const showQr = persistLocal("showQr", true);
export const save = writable();
export const importing = writable(new Set<string>());
export const paymentSignal = writable(0);
+export const lastPayment = writable<{ iid: string; amount: number; confirmed: boolean } | null>(
+ null,
+);
diff --git a/src/routes/(app)/[username]/receive/+page.svelte b/src/routes/(app)/[username]/receive/+page.svelte
index 14489c13..a0ab38a2 100644
--- a/src/routes/(app)/[username]/receive/+page.svelte
+++ b/src/routes/(app)/[username]/receive/+page.svelte
@@ -3,7 +3,7 @@
import { btc, loc, post, copy, fail, f, get, types, sat, s, sats } from "$lib/utils";
import { tick, onMount, onDestroy } from "svelte";
import { browser } from "$app/environment";
- import { last, showQr, amountPrompt } from "$lib/store";
+ import { last, lastPayment, showQr, amountPrompt } from "$lib/store";
import Avatar from "$comp/Avatar.svelte";
import InvoiceData from "$comp/InvoiceData.svelte";
import InvoiceActions from "$comp/InvoiceActions.svelte";
@@ -109,10 +109,20 @@
let txt = $derived([types.bitcoin, types.liquid].includes(type) ? hash : text);
onMount(() => {
+ $lastPayment = null;
if ($amountPrompt && !amount) toggleAmount();
let address_type = $page.url.searchParams.get("address_type");
if (address_type) setType(types.bitcoin, address_type);
});
+
+ $effect(() => {
+ if ($lastPayment?.iid) {
+ const { iid, confirmed } = $lastPayment;
+ const target = confirmed ? `/invoice/${iid}/paid` : `/invoice/${iid}`;
+ $lastPayment = null;
+ goto(target);
+ }
+ });
</script>
<div class="invoice container mx-auto max-w-xl px-4 space-y-2">