Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/components/PaymentNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,49 @@

const connect = () => {
try {
console.log(`[Telemetry] Attempting WS connection to ${wsUrl}`);
const ws = new WebSocket(wsUrl);
wsRef.current = ws;
ws.onopen = () => {
if (!isMounted) return;
console.info('[Telemetry] WS connection established. Subscribing.');
ws.send(JSON.stringify({ type: 'subscribe', address: publicKey }));
};

ws.onmessage = (event) => {
ws.onmessage = (event: MessageEvent) => {
if (!isMounted) return;
try {
const data = JSON.parse(event.data);
const data = JSON.parse(event.data as string) as Record<string, any>;

Check warning on line 43 in src/components/PaymentNotification.tsx

View workflow job for this annotation

GitHub Actions / ESLint & Prettier

Unexpected any. Specify a different type
if (data.type === 'payment_confirmed' || data.event === 'payment_received') {
const memo = data.memo || data.paymentMemo;
const txHash = data.txHash || data.transaction_hash || 'tx_' + Date.now().toString(36);
const memo = String(data.memo || data.paymentMemo || '');
const txHash = String(data.txHash || data.transaction_hash || 'tx_' + Date.now().toString(36));

console.info(`[Telemetry] Payment confirmed via WS. Hash: ${txHash}`);

if (activeTransaction && activeTransaction.memo === memo) {
if ('vibrate' in navigator) {
if (typeof navigator !== 'undefined' && 'vibrate' in navigator) {
try { navigator.vibrate([100, 50, 100, 50, 200]); } catch { /* ignore */ }
}
setConfirmedTx({ tx: activeTransaction, txHash });
onPaymentConfirmed(activeTransaction, txHash);
}
}
} catch (e) {
console.error(e);
console.error('[Telemetry] Failed to parse WS message:', e);
}
};

ws.onclose = () => {
ws.onclose = (event: CloseEvent) => {
if (!isMounted) return;
console.warn(`[Telemetry] WS connection closed. Code: ${event.code}. Reconnecting in 4s...`);
reconnectTimer = setTimeout(connect, 4000);
};
} catch {
/* ignore */

ws.onerror = (event: Event) => {
console.error('[Telemetry] WS error encountered:', event);
};
} catch (error) {
console.error('[Telemetry] Critical WS initialization error:', error);
}
};
connect();
Expand Down
Loading