From 227edce28d6b2c326716b48d1c651bd1803cebae Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 11:49:38 +0000 Subject: [PATCH] fix: also subscribe to eventStore.timeline() to process existing zaps The insert$ stream only fires for NEW events being added. If events were already in the eventStore (from cache or previous session), we wouldn't see them. Now subscribing to both: - insert$ - catches new events in real-time as they're added - timeline() - emits ALL matching events (existing + new) This ensures we process: 1. Zaps already in the eventStore from previous sessions 2. Zaps that loaded from relays before our subscription was active 3. New zaps arriving in real-time Added logging to distinguish between new (insert$) and all (timeline) events. --- src/services/supporters.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/services/supporters.ts b/src/services/supporters.ts index dc6a5f3..b46cc95 100644 --- a/src/services/supporters.ts +++ b/src/services/supporters.ts @@ -109,8 +109,7 @@ class SupportersService { }, ]); - // Subscribe to insert stream from eventStore - // This catches events as they're added in real-time + // Subscribe to insert stream from eventStore for real-time new events const eventSubscription = eventStore.insert$.subscribe( (event: NostrEvent) => { // Filter for zaps to Grimoire @@ -121,13 +120,29 @@ class SupportersService { ) ) { console.log( - `[Supporters] Received zap event ${event.id.slice(0, 8)} from eventStore.insert$`, + `[Supporters] Received NEW zap event ${event.id.slice(0, 8)} from eventStore.insert$`, ); this.processZapReceipt(event); } }, ); + // Also subscribe to timeline to process ALL existing events + const timeline = eventStore.timeline([ + { + kinds: [9735], + "#p": [GRIMOIRE_DONATE_PUBKEY], + }, + ]); + + const timelineSubscription = timeline.subscribe(async (events) => { + console.log( + `[Supporters] Timeline has ${events.length} total zap events`, + ); + // Process all existing events (includes both old and new) + await Promise.all(events.map((event) => this.processZapReceipt(event))); + }); + // Start the loader (pushes events to store) const loaderSubscription = loader().subscribe({ error: (error) => { @@ -138,9 +153,10 @@ class SupportersService { }, }); - // Combine subscriptions for cleanup + // Combine all subscriptions for cleanup this.subscription = eventSubscription; - if (this.subscription && loaderSubscription) { + if (this.subscription) { + this.subscription.add(timelineSubscription); this.subscription.add(loaderSubscription); } } catch (error) {