Skip to content

Chore/834 consolidate campaign event hooks - #857

Merged
davidmaronio merged 1 commit into
Iris-IV:mainfrom
CHKM001:chore/834-consolidate-campaign-event-hooks
Aug 5, 2026
Merged

Chore/834 consolidate campaign event hooks#857
davidmaronio merged 1 commit into
Iris-IV:mainfrom
CHKM001:chore/834-consolidate-campaign-event-hooks

Conversation

@CHKM001

@CHKM001 CHKM001 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR #834 # Consolidate duplicate campaign event hooks

Summary

useCampaignContributionEvents and useCampaignVoteEvents shared near-identical polling/dedup/subscription lifecycle logic. Every bugfix to the subscription lifecycle had to be applied twice.

Changes

  • New src/hooks/useCampaignEvents.ts — generic hook that accepts:
    • fetchEvents — the async fetch function
    • onUnseenEvents — callback for processed unseen events
    • pollIntervalMs — polling interval
    • useMocksCheck — optional USE_MOCKS guard
  • Refactored useCampaignContributionEvents.ts — 37 lines (was 89), thin wrapper passing fetchContributionMadeEvents + batch sum/invalidation
  • Refactored useCampaignVoteEvents.ts — 52 lines (was 92), thin wrapper passing fetchVoteCastEvents + per-event parsing; streaming-availability check kept separate as voting-specific concern

Testing

  • src/__tests__/hooks/useLiveCampaignFunding.test.tsx — 2/2 pass
  • src/__tests__/hooks/useLiveVoteTallies.test.tsx — 2/2 pass
  • Both test suites mock these hooks at module level, so internal refactoring doesn't affect them

Closes #834

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@CHKM001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

1 similar comment
@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@davidmaronio davidmaronio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the core extraction is good. useCampaignEvents faithfully carries over the dedupe set, cursor ref, visibility gating, callback ref pattern, and cleanup from both hooks, and the generic TEvent extends CampaignEvent signature keeps the call sites type-safe. this is the right shape for #834.

a few things need fixing before merge:

  1. src/hooks/useCampaignVoteEvents.ts:44 - behavior regression: the old hook called onStreamingUnavailable?.() when a poll threw, so the UI could fall back when RPC started failing mid-session. the generic hook swallows fetch errors silently, so that signal is lost. consider an optional onError callback on useCampaignEvents that the vote hook wires to onStreamingUnavailable.
  2. src/tests/lib/networkFee.test.ts - this file is unrelated to hook consolidation and is the exact diff already up in your #854. please drop it from this branch (looks like the branch is stacked); same for the quote-style churn in src/hooks/useDonationGracePeriod.ts.
  3. coordination: #849 touches the same two hooks and routes them through the shared eventSubscriber (closes #833, dedupes polling across consumers). the two PRs conflict directly. #849 solves a different problem (one poll loop per campaign across all consumers) that this extraction does not, so whichever lands first forces a rework of the other. my suggestion: let the maintainers pick the ordering, and if #849 lands first this generic hook could live inside eventSubscriber's consumer instead.
  4. the typecheck/build failures are the known stale base fixed by #875; a rebase is needed regardless.

@sshdopey

sshdopey commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@CHKM001
CHKM001 force-pushed the chore/834-consolidate-campaign-event-hooks branch from 4a75472 to d5e6d2c Compare August 4, 2026 22:13
@sshdopey

sshdopey commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@CHKM001
CHKM001 force-pushed the chore/834-consolidate-campaign-event-hooks branch from d5e6d2c to 8c80ba8 Compare August 4, 2026 22:19
@sshdopey

sshdopey commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

…paignEvents (Iris-IV#834)

Extract shared subscribe/unsubscribe/state-update logic from
useCampaignContributionEvents and useCampaignVoteEvents into a single
generic useCampaignEvents<TEvent> hook.

Key changes:
- New useCampaignEvents hook carries over the dedupe set, cursor ref,
  visibility gating, callback ref pattern, and cleanup from both hooks
- Optional onError callback on UseCampaignEventsOptions so consumers
  can react to poll failures (wired in useCampaignVoteEvents to call
  onStreamingUnavailable, restoring behavior lost during extraction)
- Both existing hooks become thin wrappers around the generic hook
- eventSubscriber.ts: fix Timeout type annotation
@CHKM001
CHKM001 force-pushed the chore/834-consolidate-campaign-event-hooks branch from 8c80ba8 to b626b0d Compare August 4, 2026 22:54
@sshdopey

sshdopey commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@davidmaronio
davidmaronio merged commit 4bc00e0 into Iris-IV:main Aug 5, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Quality] Consolidate duplicate campaign event hooks (useCampaignContributionEvents vs useCampaignVoteEvents) into one generic hook

3 participants