fix: hopefully..
This commit is contained in:
parent
2554321183
commit
7e55b2ad95
|
|
@ -257,38 +257,34 @@
|
|||
watchedAddress = address;
|
||||
watchedTxids = [];
|
||||
|
||||
const query = { crypto: coin };
|
||||
const q = btoa(JSON.stringify(query));
|
||||
const url = `${SOCK_API}/sse?q=${q}`;
|
||||
|
||||
eventSource = new EventSource(url);
|
||||
// Raw SSE — no query filter at all
|
||||
eventSource = new EventSource(`${SOCK_API}/sse`);
|
||||
console.log('SSE: connected, watching for', address);
|
||||
|
||||
eventSource.onmessage = (e) => {
|
||||
try {
|
||||
const event = JSON.parse(e.data);
|
||||
if (event.type === 'block') {
|
||||
onBlock(event);
|
||||
} else {
|
||||
} else if (event.type === 'tx') {
|
||||
onTx(event);
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
|
||||
eventSource.onerror = () => {
|
||||
// EventSource auto-reconnects
|
||||
};
|
||||
eventSource.onerror = () => {};
|
||||
}
|
||||
|
||||
/** Check if any tx output matches our payment address. */
|
||||
function onTx(event) {
|
||||
if (!watchedAddress) return;
|
||||
const outputs = event.data?.out ?? [];
|
||||
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;
|
||||
if (!txHash || watchedTxids.includes(txHash)) return;
|
||||
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 = `
|
||||
<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>
|
||||
|
|
@ -298,13 +294,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
/** Check if a new block includes any of our confirming txids. */
|
||||
function onBlock(event) {
|
||||
if (watchedTxids.length === 0) return;
|
||||
const blockTxs = event.data?.tx ?? [];
|
||||
const found = watchedTxids.some(t => blockTxs.includes(t));
|
||||
if (found) {
|
||||
console.log('SSE: block contains one of our txids');
|
||||
if (watchedTxids.some(t => blockTxs.includes(t))) {
|
||||
console.log('SSE: block confirmed our tx');
|
||||
pollStatus();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue