Skip to content

Pr/combined features 359 360 361 319#387

Merged
ogazboiz merged 8 commits into
LabsCrypt:mainfrom
Christopherdominic:pr/combined-features-359-360-361-319
Apr 28, 2026
Merged

Pr/combined features 359 360 361 319#387
ogazboiz merged 8 commits into
LabsCrypt:mainfrom
Christopherdominic:pr/combined-features-359-360-361-319

Conversation

@Christopherdominic
Copy link
Copy Markdown
Contributor

This PR combines 4 feature implementations that enhance FlowFi's event tracking, user experience, and Soroban contract integration.

Issues Closed
Closes #359 - Add FEE_COLLECTED event handler and treasury fee reporting to admin metrics
Closes #360 - Wire NotificationDropdown to live SSE events with unread count badge
Closes #361 - Create stream activity history page
Closes #319 - Wire top_up_stream to Soroban contract in dashboard (remove prompt/alert hack)
🎯 Feature 1: FEE_COLLECTED Event Handler & Treasury Reporting (#359)
Backend Changes
soroban-event-worker.ts

Added fee_collected case in processEvent() switch statement
Implemented handleFeeCollected() method that:
Decodes stream_id, treasury, fee_amount, and token from contract events
Writes FEE_COLLECTED StreamEvent records to database
Broadcasts stream.fee_collected SSE event to admin channel
admin.routes.ts

Extended GET /v1/admin/metrics endpoint with:
totalFeesCollectedByToken: Object mapping token addresses to total fees collected
feesLast24h: Object mapping token addresses to fees collected in last 24 hours
Aggregates fees per token for comprehensive treasury reporting
api-types.ts

Added FEE_COLLECTED to StreamEventType union type
Impact
Protocol fee revenue is now tracked and visible to admins
Treasury reporting is possible with per-token fee breakdowns
No impact on existing event handlers
🔔 Feature 2: Live SSE Notifications with Unread Badge (#360)
Frontend Changes
NotificationDropdown.tsx

Integrated useStreamEvents hook for real-time event streaming
Added unread count state management:
Increments on incoming events while dropdown is closed
Clears when dropdown opens
Enhanced UI with unread badge:
Shows count (e.g., "3") or "9+" for 10+ notifications
Red circular badge with white text
Prepends live events to notification list (max 20, newest first)
Handles all event types: CREATED, TOPPED_UP, WITHDRAWN, CANCELLED, COMPLETED
User Experience
Users see real-time notification badge without opening dropdown
No polling required - events arrive instantly via SSE
Badge provides immediate feedback on stream activity
📊 Feature 3: Stream Activity History Page (#361)
New Page
page.tsx

Full-page activity history view at /activity route
Fetches all events where user is sender or recipient
Filter tabs: All / Created / Top-ups / Withdrawals / Cancellations / Completed
CSV export functionality using csvExport utility
Shows event count and filtered count
Responsive design with loading states
Enhanced Component
ActivityHistory.tsx

Added clickable stream ID links to /streams/[id]
Color-coded event type badges:
CREATED: Blue
TOPPED_UP: Green
WITHDRAWN: Purple
CANCELLED: Red
COMPLETED: Emerald
Transaction hash with Stellar Explorer link (opens in new tab)
Formatted amounts using fromStroops utility
Enhanced hover states and transitions
Features
Complete activity audit trail
Easy filtering by event type
One-click CSV export for accounting/reporting
Direct links to stream details and blockchain explorer
💰 Feature 4: Soroban Top-Up Integration (#319)
Frontend Changes
dashboard-view.tsx

Replaced prompt() and alert() hack with proper modal flow
Updated handleTopUp to open TopUpModal with stream data
Leverages existing handleTopUpConfirm for Soroban integration
User Flow
User clicks "Add Funds" button on stream card
TopUpModal opens with:
Current stream balance display
Amount input with validation
Preview of new total balance
User confirms → sorobanTopUp() called via Freighter
Transaction lifecycle shown: signing → submitted → confirmed
Stream card updates with new balance on success
Technical Details
Uses TopUpModal component (already existed, now properly wired)
Calls sorobanTopUp(session, { streamId, amount })
Converts amount to base units (stroops) automatically
Shows toast notifications for success/error states
Updates local state optimistically via topUpStreamLocally()
🧪 Testing Checklist
Fee Collection (#359)
Fee events written to database with correct amounts
Admin metrics endpoint returns fee data by token
SSE broadcasts to admin channel on fee collection
No regression in existing event handlers
Live Notifications (#360)
Unread badge appears on new events
Badge clears when dropdown opens
Events appear in real-time without refresh
All event types handled correctly
Activity History (#361)
All user events displayed on /activity page
Filter tabs work for all event types
CSV export downloads correct data
Links to stream details and Stellar Explorer work
Top-Up Integration (#319)
Modal opens with correct stream data
Amount validation works (positive numbers only)
Freighter transaction flow completes
Stream balance updates after successful top-up
Error handling shows appropriate messages
📝 Migration Notes
No database migrations required - FEE_COLLECTED event type is handled by existing StreamEvent table schema.

🚀 Deployment Notes
Backend changes are backward compatible
Frontend changes require no environment variable updates
SSE connections will automatically reconnect on deployment
No breaking changes to existing APIs

- Add fee_collected case in processEvent() to handle protocol fees
- Decode stream_id, treasury, fee_amount, and token from event
- Write FEE_COLLECTED StreamEvent records to database
- Broadcast stream.fee_collected SSE event to admin channel
- Extend GET /v1/admin/metrics with totalFeesCollectedByToken and feesLast24h
- Aggregate fees per token address for treasury reporting

Closes LabsCrypt#359
- Use useStreamEvents hook to receive real-time events
- Maintain unread count in local state, increment while dropdown closed
- Show unread count badge on bell icon (red dot with number)
- Clear unread count when dropdown opens
- Prepend live events to notification list (max 20, newest first)
- Handle all event types including PAUSED and RESUMED

Closes LabsCrypt#360
- Add /activity route showing full stream activity across all streams
- Fetch all events where user is sender or recipient
- Filter tabs: All / Created / Top-ups / Withdrawals / Cancellations / Completed
- Each row: stream ID (link to detail), event type badge, amount, timestamp
- Transaction hash with Stellar Explorer link
- CSV export button using csvExport utility
- Enhanced ActivityHistory component with color-coded badges and links

Closes LabsCrypt#361
- Remove prompt() and alert() from handleTopUp
- Use TopUpModal with proper amount input and validation
- Call sorobanTopUp(session, { streamId, amount }) via Freighter
- Show transaction lifecycle states (signing → submitted → confirmed)
- Update stream card balance on success via handleTopUpConfirm
- Real Soroban transaction submitted and tracked

Closes LabsCrypt#319
@ogazboiz ogazboiz merged commit 7b24e40 into LabsCrypt:main Apr 28, 2026
6 of 9 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

3 participants