Update package dependencies and refactor types in Nostr-related components

- Upgrade @types/node to version 22.18.1 and add @types/qrcode version 1.5.5 in package.json and package-lock.json.
- Refactor cleanupInterval and reconnectInterval types from NodeJS.Timeout to number in various Nostr-related files for better type compatibility.
- Enhance error handling in useNostrclientHub and useNostrChat components by specifying error parameter types.
This commit is contained in:
padreug 2025-09-04 22:48:43 +02:00
parent a551f46c90
commit 54b013490e
8 changed files with 65 additions and 28 deletions

View file

@ -109,7 +109,7 @@ export function useNostrChat() {
}
// Set up periodic cleanup
let cleanupInterval: NodeJS.Timeout | null = null
let cleanupInterval: number | null = null
// Clean up resources
const cleanup = () => {
@ -375,7 +375,7 @@ export function useNostrChat() {
// Set up periodic cleanup of malformed messages
if (!cleanupInterval) {
cleanupInterval = setInterval(cleanupMalformedMessages, 5 * 60 * 1000) // Every 5 minutes
cleanupInterval = setInterval(cleanupMalformedMessages, 5 * 60 * 1000) as unknown as number // Every 5 minutes
console.log('Set up periodic cleanup of malformed messages')
}

View file

@ -129,12 +129,12 @@ export function useNostrclientHub() {
connectionStatus.value = 'disconnected'
})
nostrclientHub.on('error', (err) => {
nostrclientHub.on('error', (err: any) => {
error.value = err
connectionStatus.value = 'error'
})
nostrclientHub.on('connectionError', (err) => {
nostrclientHub.on('connectionError', (err: any) => {
error.value = err
connectionStatus.value = 'error'
})
@ -144,19 +144,19 @@ export function useNostrclientHub() {
connectionStatus.value = 'error'
})
nostrclientHub.on('event', ({ subscriptionId, event }) => {
nostrclientHub.on('event', ({ subscriptionId, event }: any) => {
console.log('Received event for subscription:', subscriptionId, event.id)
})
nostrclientHub.on('eose', ({ subscriptionId }) => {
nostrclientHub.on('eose', ({ subscriptionId }: any) => {
console.log('EOSE received for subscription:', subscriptionId)
})
nostrclientHub.on('notice', ({ message }) => {
nostrclientHub.on('notice', ({ message }: any) => {
console.log('Notice from nostrclient:', message)
})
nostrclientHub.on('eventPublished', ({ eventId }) => {
nostrclientHub.on('eventPublished', ({ eventId }: any) => {
console.log('Event published successfully:', eventId)
})
}

View file

@ -144,7 +144,7 @@ export function useTicketPurchase() {
// Start payment status check
async function startPaymentStatusCheck(eventId: string, hash: string) {
isPaymentPending.value = true
let checkInterval: NodeJS.Timeout | null = null
let checkInterval: number | null = null
const checkPayment = async () => {
try {
@ -174,7 +174,7 @@ export function useTicketPurchase() {
await checkPayment()
// Then check every 2 seconds
checkInterval = setInterval(checkPayment, 2000)
checkInterval = setInterval(checkPayment, 2000) as unknown as number
}
// Stop payment status check

View file

@ -1,6 +1,31 @@
import { EventEmitter } from 'events'
import type { Filter, Event } from 'nostr-tools'
// Simple EventEmitter for browser compatibility
class EventEmitter {
private events: { [key: string]: Function[] } = {}
on(event: string, listener: Function) {
if (!this.events[event]) {
this.events[event] = []
}
this.events[event].push(listener)
}
emit(event: string, ...args: any[]) {
if (this.events[event]) {
this.events[event].forEach(listener => listener(...args))
}
}
removeAllListeners(event?: string) {
if (event) {
delete this.events[event]
} else {
this.events = {}
}
}
}
export interface NostrclientConfig {
url: string
privateKey?: string // For private WebSocket endpoint
@ -25,7 +50,7 @@ export class NostrclientHub extends EventEmitter {
private ws: WebSocket | null = null
private config: NostrclientConfig
private subscriptions: Map<string, SubscriptionConfig> = new Map()
private reconnectInterval?: NodeJS.Timeout
private reconnectInterval?: number
private reconnectAttempts = 0
private readonly maxReconnectAttempts = 5
private readonly reconnectDelay = 5000
@ -324,7 +349,7 @@ export class NostrclientHub extends EventEmitter {
this.reconnectInterval = setTimeout(async () => {
await this.connect()
}, delay)
}, delay) as unknown as number
}
}

View file

@ -63,8 +63,8 @@ export class RelayHub extends EventEmitter {
private connectedRelays: Map<string, Relay> = new Map()
private subscriptions: Map<string, any> = new Map()
public isInitialized = false
private reconnectInterval?: NodeJS.Timeout
private healthCheckInterval?: NodeJS.Timeout
private reconnectInterval?: number
private healthCheckInterval?: number
private mobileVisibilityHandler?: () => void
// Connection state
@ -400,7 +400,7 @@ export class RelayHub extends EventEmitter {
this.reconnectInterval = setTimeout(async () => {
await this.connect()
}, this.reconnectDelay)
}, this.reconnectDelay) as unknown as number
}
/**
@ -413,7 +413,7 @@ export class RelayHub extends EventEmitter {
this.healthCheckInterval = setInterval(() => {
this.performHealthCheck()
}, this.healthCheckIntervalMs)
}, this.healthCheckIntervalMs) as unknown as number
}
/**

View file

@ -27,7 +27,7 @@ class PaymentMonitorService {
error: null
})
private monitoringInterval: NodeJS.Timeout | null = null
private monitoringInterval: number | null = null
private updateCallbacks: Map<string, (update: PaymentUpdate) => void> = new Map()
// Computed properties
@ -98,7 +98,7 @@ class PaymentMonitorService {
// Set up interval for periodic checks
this.monitoringInterval = setInterval(async () => {
await this.checkAllPayments()
}, 30000) // Check every 30 seconds
}, 30000) as unknown as number // Check every 30 seconds
}
/**