fix: hopefully..
This commit is contained in:
parent
2554321183
commit
7e55b2ad95
|
|
@ -257,38 +257,34 @@
|
||||||
watchedAddress = address;
|
watchedAddress = address;
|
||||||
watchedTxids = [];
|
watchedTxids = [];
|
||||||
|
|
||||||
const query = { crypto: coin };
|
// Raw SSE — no query filter at all
|
||||||
const q = btoa(JSON.stringify(query));
|
eventSource = new EventSource(`${SOCK_API}/sse`);
|
||||||
const url = `${SOCK_API}/sse?q=${q}`;
|
console.log('SSE: connected, watching for', address);
|
||||||
|
|
||||||
eventSource = new EventSource(url);
|
|
||||||
|
|
||||||
eventSource.onmessage = (e) => {
|
eventSource.onmessage = (e) => {
|
||||||
try {
|
try {
|
||||||
const event = JSON.parse(e.data);
|
const event = JSON.parse(e.data);
|
||||||
if (event.type === 'block') {
|
if (event.type === 'block') {
|
||||||
onBlock(event);
|
onBlock(event);
|
||||||
} else {
|
} else if (event.type === 'tx') {
|
||||||
onTx(event);
|
onTx(event);
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
|
|
||||||
eventSource.onerror = () => {
|
eventSource.onerror = () => {};
|
||||||
// EventSource auto-reconnects
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if any tx output matches our payment address. */
|
|
||||||
function onTx(event) {
|
function onTx(event) {
|
||||||
if (!watchedAddress) return;
|
if (!watchedAddress) return;
|
||||||
const outputs = event.data?.out ?? [];
|
const outputs = event.data?.out ?? [];
|
||||||
for (const out of outputs) {
|
for (const out of outputs) {
|
||||||
if (out?.script?.address !== watchedAddress) continue;
|
const addr = out?.script?.address;
|
||||||
|
if (!addr || addr !== watchedAddress) continue;
|
||||||
const txHash = event.data?.tx?.hash ?? null;
|
const txHash = event.data?.tx?.hash ?? null;
|
||||||
if (!txHash || watchedTxids.includes(txHash)) return;
|
if (!txHash || watchedTxids.includes(txHash)) return;
|
||||||
watchedTxids.push(txHash);
|
watchedTxids.push(txHash);
|
||||||
console.log('SSE: tx detected for our address:', txHash, `(${watchedTxids.length} total)`);
|
console.log('SSE: tx', txHash, 'matches our address');
|
||||||
document.getElementById('pay-status').innerHTML = `
|
document.getElementById('pay-status').innerHTML = `
|
||||||
<span class="w-2 h-2 rounded-full bg-blue-500 animate-pulse"></span>
|
<span class="w-2 h-2 rounded-full bg-blue-500 animate-pulse"></span>
|
||||||
<span class="text-blue-400">Transaction detected, waiting for confirmation...</span>
|
<span class="text-blue-400">Transaction detected, waiting for confirmation...</span>
|
||||||
|
|
@ -298,13 +294,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if a new block includes any of our confirming txids. */
|
|
||||||
function onBlock(event) {
|
function onBlock(event) {
|
||||||
if (watchedTxids.length === 0) return;
|
if (watchedTxids.length === 0) return;
|
||||||
const blockTxs = event.data?.tx ?? [];
|
const blockTxs = event.data?.tx ?? [];
|
||||||
const found = watchedTxids.some(t => blockTxs.includes(t));
|
if (watchedTxids.some(t => blockTxs.includes(t))) {
|
||||||
if (found) {
|
console.log('SSE: block confirmed our tx');
|
||||||
console.log('SSE: block contains one of our txids');
|
|
||||||
pollStatus();
|
pollStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue