export class SubscriptionManager { private currentSubs: any[] = [] private isActive = false async subscribe(relay: any, filters: any[], handlers: { onEvent: (event: NostrEvent) => void, onEose?: () => void }) { if (this.isActive) return this.isActive = true const sub = relay.sub(filters) sub.on('event', handlers.onEvent) if (handlers.onEose) { sub.on('eose', handlers.onEose) } this.currentSubs.push(sub) return sub } unsubscribe() { this.currentSubs.forEach(sub => { try { if (sub?.unsub) sub.unsub() } catch (err) { console.error('Failed to unsubscribe:', err) } }) this.currentSubs = [] this.isActive = false } }