diff --git a/src/pages/online/connection.ts b/src/pages/online/connection.ts index 7e39fbd..1428d79 100644 --- a/src/pages/online/connection.ts +++ b/src/pages/online/connection.ts @@ -48,9 +48,9 @@ export default class PeerConnection extends EventEmitter { }; this.peerConnection.onconnectionstatechange = () => { - console.log('Connection state:', this.peerConnection.connectionState); + log('Connection state:', this.peerConnection.connectionState); if (this.peerConnection.connectionState === 'closed') { - console.log(`${this.peerId} connection closed`); + log(`${this.peerId} connection closed`); this.close(); } }; @@ -79,12 +79,12 @@ export default class PeerConnection extends EventEmitter { setDataChannel(dataChannel: RTCDataChannel) { this.dataChannel = dataChannel; - this.dataChannel.onopen = () => console.log('Data channel is open'); + this.dataChannel.onopen = () => log('Data channel is open'); this.dataChannel.onmessage = (event) => { - console.log('Received message:', event.data); + log('Received message:', event.data); }; this.dataChannel.onclose = () => { - console.log('Data channel is closed'); + log('Data channel is closed'); this.close(); }; } @@ -92,30 +92,30 @@ export default class PeerConnection extends EventEmitter { setFileChannel(fileChannel: RTCDataChannel) { this.fileChannel = fileChannel; this.fileChannel.binaryType = 'arraybuffer'; - this.fileChannel.onopen = () => console.log('File channel is open'); + this.fileChannel.onopen = () => log('File channel is open'); this.fileChannel.onmessage = (event) => { - console.log('File channel received message:', event.data); + log('File channel received message:', event.data); if (typeof event.data === 'string') { const metadata = JSON.parse(event.data); if (metadata.type === 'file-metadata') { this.incomingFileMetadata = metadata.metadata; this.receivedFileData = []; this.receivedFileSize = 0; - console.log('Received file metadata:', this.incomingFileMetadata); + log('Received file metadata:', this.incomingFileMetadata); } } else if (event.data instanceof ArrayBuffer) { this.receivedFileData.push(event.data); this.receivedFileSize += event.data.byteLength; - console.log('Received file chunk:', event.data.byteLength, 'bytes'); - console.log('Total received size:', this.receivedFileSize, 'bytes'); + log('Received file chunk:', event.data.byteLength, 'bytes'); + log('Total received size:', this.receivedFileSize, 'bytes'); if (this.incomingFileMetadata) { - console.log('Expected file size:', this.incomingFileMetadata.size, 'bytes'); + log('Expected file size:', this.incomingFileMetadata.size, 'bytes'); if (this.receivedFileSize === this.incomingFileMetadata.size) { - console.log('File fully received, saving file...'); + log('File fully received, saving file...'); this.saveReceivedFile(); } else { - console.log('File not fully received, waiting...'); + log('File not fully received, waiting...'); } } else { console.error('No file metadata available'); @@ -123,7 +123,7 @@ export default class PeerConnection extends EventEmitter { } }; this.fileChannel.onclose = () => { - console.log('File channel is closed'); + log('File channel is closed'); }; } @@ -135,42 +135,42 @@ export default class PeerConnection extends EventEmitter { const confirmString = `Save ${this.incomingFileMetadata.name} from ${this.peerId}?`; if (!confirm(confirmString)) { - console.log('User did not confirm file save'); + log('User did not confirm file save'); this.incomingFileMetadata = null; this.receivedFileData = []; this.receivedFileSize = 0; return; } - console.log('Saving file with metadata:', this.incomingFileMetadata); - console.log('Total received file data size:', this.receivedFileSize); + log('Saving file with metadata:', this.incomingFileMetadata); + log('Total received file data size:', this.receivedFileSize); const blob = new Blob(this.receivedFileData, { type: this.incomingFileMetadata.type }); - console.log('Created Blob:', blob); + log('Created Blob:', blob); const url = URL.createObjectURL(blob); - console.log('Created Object URL:', url); + log('Created Object URL:', url); const a = document.createElement('a'); a.href = url; a.download = this.incomingFileMetadata.name; document.body.appendChild(a); - console.log('Appended anchor element to body:', a); + log('Appended anchor element to body:', a); a.click(); - console.log('Triggered download'); + log('Triggered download'); document.body.removeChild(a); - console.log('Removed anchor element from body'); + log('Removed anchor element from body'); URL.revokeObjectURL(url); - console.log('Revoked Object URL'); + log('Revoked Object URL'); // Reset file data this.incomingFileMetadata = null; this.receivedFileData = []; this.receivedFileSize = 0; - console.log('Reset file data'); + log('Reset file data'); } sendJsonData(jsonData: unknown) { @@ -197,7 +197,7 @@ export default class PeerConnection extends EventEmitter { }, }; fileChannel.onopen = () => { - console.log('File channel is open, sending metadata'); + log('File channel is open, sending metadata'); fileChannel.send(JSON.stringify(metadata)); // Read and send the file as binary data diff --git a/src/pages/online/index.tsx b/src/pages/online/index.tsx index 6ea31f3..d894430 100644 --- a/src/pages/online/index.tsx +++ b/src/pages/online/index.tsx @@ -42,7 +42,7 @@ export default function OnlinePage() { unsub(); newPool.stopPinging(); }; - }, [follows, myNpub, myPubKey, uuid]); + }, [follows, myNpub, myPubKey, uuid]); // TODO how to not reset pool on follows change? if (!myPubKey) { return
Loading...
; diff --git a/src/pages/subscription/useRates.ts b/src/pages/subscription/useRates.ts index b403d90..9710851 100644 --- a/src/pages/subscription/useRates.ts +++ b/src/pages/subscription/useRates.ts @@ -18,8 +18,9 @@ export function useRates(symbol: string, leaveOpen = true) { }); sub.on('event', (ev) => { - if (!latest || ev.created_at > latest.created_at) { - setLatest(ev); + const createdAt = ev.created_at || 0; + if (!latest || createdAt > latest.created_at) { + setLatest(ev as NostrEvent); } if (!leaveOpen) { sub.stop(); diff --git a/src/utils/socialGraph.ts b/src/utils/socialGraph.ts index 16f1b09..9dca024 100644 --- a/src/utils/socialGraph.ts +++ b/src/utils/socialGraph.ts @@ -1,4 +1,4 @@ -import { NDKSubscription, NostrEvent } from '@nostr-dev-kit/ndk'; +import { NDKEvent, NDKSubscription, NostrEvent } from '@nostr-dev-kit/ndk'; import Fuse from 'fuse.js'; import { localState } from 'irisdb'; import { ndk, SocialGraph } from 'irisdb-nostr'; @@ -27,11 +27,12 @@ function getFollowedUserProfiles(myPubKey: string) { }, { closeOnEose: true }, ); - sub.on('event', (ev: NostrEvent) => { + sub.on('event', (ev: NDKEvent) => { queueMicrotask(() => { const lastSeen = latestProfileEvents.get(ev.pubkey) || 0; - if (ev.created_at > lastSeen) { - latestProfileEvents.set(ev.pubkey, ev.created_at); + const createdAt = ev.created_at || 0; + if (createdAt > lastSeen) { + latestProfileEvents.set(ev.pubkey, createdAt); try { const profile = JSON.parse(ev.content); const name = profile.name || profile.username; @@ -60,11 +61,12 @@ localState.get('user/publicKey').on((publicKey?: string) => { }); let latestTime = 0; sub?.on('event', (ev) => { - if (ev.created_at < latestTime) { + const createdAt = ev.created_at || 0; + if (createdAt < latestTime) { return; } - latestTime = ev.created_at; - instance.handleEvent(ev); + latestTime = createdAt; + instance.handleEvent(ev as NostrEvent); setTimeout(() => { getFollowedUserProfiles(publicKey); }, 500);