feat: implement WebSocket real-time data integration for TVL and swap… - #119
Merged
Lakes41 merged 1 commit intoJul 30, 2026
Merged
Conversation
closes Adamantine-guild#95) - Create WebSocket service with exponential backoff reconnection (1s-30s) - Create useWebSocketSubscription(channel, onMessage) generic hook - Create useRealtimeTVL hook that pushes TVL updates into React Query cache - Create useRealtimeSwaps hook with rolling 50-event buffer - Add RecentSwaps component showing live swap events with connection status - Update ProtocolStatsBar with real-time TVL updates and Live/Cache indicator - Auto-connect on first subscribe, auto-disconnect on last unsubscribe - Proper cleanup on unmount to preserve memory
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #95: WebSocket Integration for Real-Time Data
Overview
Replaced HTTP polling with a seamless WebSocket integration that subscribes to TVL and swap event channels, pushing updates to the frontend instantly. Eliminates repetitive HTTP requests and artificial latency from 30s polling intervals.
Changes Made
New Files
lib/services/websocket.ts— WebSocket client service with:WebSocketAPI (no extra dependencies)subscribe/unsubscribemessages)lib/hooks/useWebSocketSubscription.ts— Generic React hookuseWebSocketSubscription(channel, onMessage)that:onMessagecallback for each pushed event{ connected }status for UI indicatorslib/hooks/useRealtimeTVL.ts— Specialized hook for real-time TVL updates:'tvl'channel['protocolStats']) on each pushed eventProtocolStatsBardata flowlib/hooks/useRealtimeSwaps.ts— Specialized hook for real-time swap events:'swaps'channelcomponents/dashboard/RecentSwaps.tsx— UI component displaying:Modified Files
components/dashboard/ProtocolStatsBar.tsxuseRealtimeTVLto receive live TVL updates via WebSocketapp/dashboard/page.tsx<RecentSwaps />section wrapped in<ErrorBoundary>ProtocolStatsBarandRecentSwapssubscribe to WebSocket channelsWebSocket Protocol
Connection Lifecycle
NEXT_PUBLIC_WS_URLonMessagehandler dispatches to subscribersAcceptance Criteria
closes #95