Skip to content

feat(fantasyxi): Add captain injury alerts, live provisional leaderboard, Soroban RPC event daemon, and granular error boundaries (#238, #268, #403, #404) - #409

Merged
Stanley471 merged 4 commits into
Stanley471:mainfrom
Phenoll:fix/issues-238-268-403-404-batch
Oct 24, 2026
Merged

Stanley471 merged 4 commits into
Stanley471:mainfrom
Phenoll:fix/issues-238-268-403-404-batch

Conversation

@Phenoll

@Phenoll Phenoll commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

📝 Summary of Changes

Implemented a comprehensive batch resolution addressing four assigned issues across the backend FPL/Live/Soroban engines and frontend React error boundary architecture:

Solved Issues & Features:

  • Issue Create email notification trigger when squad captain is ruled out injured #238 (Squad Captain Injury Email Notification Trigger):
    • Enhanced FplSyncService (backend/src/services/fpl/fplSyncService.ts) to snapshot existing player statuses prior to bootstrap sync, detect transitions to injured ('i'), doubtful ('d'), or suspended ('s') prior to the upcoming gameweek deadline, query all active squads where the player is designated with isCaptain: true, emit CAPTAIN_INJURY_ALERT domain events, and enqueue CaptainInjuryAlertEmail notifications.
    • Added CaptainInjuryAlertEmail template builder and gameweek/status rate-limiting (via Redis + in-memory idempotency cache) in backend/src/services/email/emailService.ts, plus domain event registration in backend/src/services/events/domainEvents.ts.
  • Issue Implement live provisional leaderboard calculation daemon with real-time match events ingestion #268 (Live Provisional Leaderboard Calculation Daemon with Real-Time Match Events Ingestion):
    • Implemented LiveProvisionalLeaderboardService (backend/src/services/live/liveProvisionalLeaderboardService.ts) using Redis Sorted Sets (ZSET), atomic ZINCRBY pipelines, and an in-memory inverted playerId -> squads index for sub-second rank updates across 1,000+ leagues with zero database read queries during live match event streaming.
    • Added real-time deterministic tie-breaking (totalPoints DESC, livePoints DESC, joinedAt ASC, squadId ASC), SSE/WebSocket rank and point delta diff broadcasting, and end-of-gameweek database reconciliation (reconcileWithDatabase).
    • Integrated provisional live standings into liveService.ts, leaderboardService.ts, live.controller.ts, and live.routes.ts (including SSE streaming endpoint /api/v1/live/gameweek/:gw/leaderboard/:leagueId/stream).
  • Issue Implement Soroban RPC contract event streaming subscriber daemon for deposit confirmations #403 (Soroban RPC Contract Event Streaming Subscriber Daemon for Deposit Confirmations):
    • Implemented decodeSorobanEscrowEvent and DepositQueue (backend/src/queues/depositQueue.ts) supporting both native xdr.ScVal and raw base64-encoded Soroban XDR event topics/payloads (deposit, claimed, m_claimed, refund, DepositRefunded, EmergencyRefund, LeagueRefundClaimed, settle, m_settle, created) with Redis + in-memory idempotency deduplication.
    • Enhanced SorobanEventIndexer (backend/src/workers/eventIndexer.ts), sorobanContractClient.ts, and stellarService.ts to persist pagination cursors (ledger + pagingToken) across restarts in both Redis and PostgreSQL (IndexerCursor), gracefully back off on RPC timeouts without skipping blocks, and dispatch confirmed events through depositQueue.
  • Issue Implement granular React Error Boundary tree with contextual recovery states #404 (Granular React Error Boundary Tree with Contextual Recovery States):
    • Upgraded ErrorBoundary (frontend/src/components/ErrorBoundary.tsx) with contextual name, fallbackTitle, fallbackMessage, compact inline mode, onReset, onError, and resetKeys auto-recovery props, forwarding caught errors and React componentStack traces to client telemetry (trackError / useErrorReporter in frontend/src/lib/telemetry.ts).
    • Wrapped isolated widgets across frontend/src/app/team/page.tsx (PitchView, GameweekCountdown, player selection sidebar), frontend/src/app/leaderboard/page.tsx (LeaderboardTable), frontend/src/app/fixtures/page.tsx (FixturesList), frontend/src/app/leagues/[id]/page.tsx (LeagueStandingsTable, LeagueChat), and frontend/src/components/layout/AppShell.tsx.

📂 Key Files Modified / Added

  • backend/src/services/fpl/fplSyncService.ts: Pre-sync player status snapshot, captain injury/suspension/doubtful transition detection, and affected captain squad lookup.
  • backend/src/services/email/emailService.ts: CaptainInjuryAlertEmail HTML/text template generator and per-gameweek duplicate rate-limiter.
  • backend/src/services/events/domainEvents.ts: Added CAPTAIN_INJURY_ALERT domain event payload and listener binding.
  • backend/src/services/live/liveProvisionalLeaderboardService.ts: High-throughput Redis ZSET + inverted index live provisional leaderboard engine, SSE/WS diff broadcaster, and gameweek close DB reconciliation.
  • backend/src/services/live/liveService.ts, backend/src/services/leaderboard/leaderboardService.ts, backend/src/controllers/live.controller.ts, backend/src/routes/live.routes.ts: Live event stream ingestion, SSE diff streaming route, and provisional leaderboard integration.
  • backend/src/queues/depositQueue.ts: Soroban XDR contract event decoder and idempotent DepositQueue.
  • backend/src/workers/eventIndexer.ts, backend/src/services/financial/sorobanContractClient.ts, backend/src/services/financial/stellarService.ts, backend/prisma/schema.prisma: Dual Redis/PostgreSQL cursor persistence, XDR event decoding, and depositQueue integration.
  • frontend/src/components/ErrorBoundary.tsx & frontend/src/lib/telemetry.ts: Granular React ErrorBoundary with contextual retry/reset states and telemetry componentStack reporting.
  • frontend/src/app/team/page.tsx, frontend/src/app/leaderboard/page.tsx, frontend/src/app/fixtures/page.tsx, frontend/src/app/leagues/[id]/page.tsx, frontend/src/components/layout/AppShell.tsx: Strategic error boundary placements around isolated widgets.
  • backend/src/tests/emailService.test.ts, backend/src/tests/liveProvisionalLeaderboard.test.ts, backend/src/tests/eventIndexer.test.ts, frontend/src/tests/errorBoundary.test.tsx, frontend/src/tests/telemetry.test.ts: Comprehensive unit and stress tests for all four issues.

✅ Verification & Testing

  • Ran automated backend test suite (tsx --test across emailService.test.ts, liveProvisionalLeaderboard.test.ts, eventIndexer.test.ts, leaderboard.test.ts, liveTimelineService.test.ts — 48/48 passing, including 1,000-league / 1,000-event stress test under 50ms with 0 DB reads).
  • Ran automated frontend test suite (tsx --test across errorBoundary.test.tsx and telemetry.test.ts — 23/23 passing).
  • Verified code syntax, database schema constraints, and graceful fallback behavior.

🔗 References

closes #238
closes #268
closes #403
closes #404
closes #238, #268, #403, #404

@vercel

vercel Bot commented Oct 22, 2026

Copy link
Copy Markdown

@Phenoll is attempting to deploy a commit to the stanleyobimma4gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
github-actions Bot requested a review from Stanley471 October 22, 2026 13:05

@Stanley471 Stanley471 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

great pr

@Stanley471
Stanley471 merged commit 3b69d3c into Stanley471:main Oct 24, 2026
7 of 8 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

2 participants