Skip to content

[Frontend] WebSocket Client for Real-Time Escrow and Notification Updates #261

Description

@KuchiMercy

Problem

The frontend currently polls for notifications every 10 seconds (hooks/useNotifications.ts) and has no real-time escrow status updates. The backend already has a WebSocket gateway (gateways/escrow.gateway.ts) broadcasting events, but the frontend has no WebSocket client.

Current State

  • Backend: EscrowGateway broadcasts events via Socket.IO:
    • escrow:status_changed, escrow:funded, escrow:completed
    • escrow:milestone_released, escrow:condition_fulfilled, escrow:condition_confirmed
    • escrow:dispute_filed, escrow:dispute_resolved
    • notification:new
  • Frontend: No Socket.IO client installed, no WebSocket connection logic
  • Frontend: hooks/useNotifications.ts polls every 10 seconds (inefficient)

Acceptance Criteria

  • Install socket.io-client as a dependency
  • Create a lib/websocket.ts client that:
    • Connects to the backend WebSocket server with the JWT auth token
    • Handles reconnection with exponential backoff
    • Provides typed event listeners for all escrow and notification events
    • Manages room subscriptions (join/leave escrow rooms)
  • Create a providers/WebSocketProvider.tsx that:
    • Initializes the socket connection on auth
    • Disconnects on logout/token expiry
    • Provides socket instance via React context
  • Create hooks/useEscrowEvents.ts hook for listening to escrow-specific real-time events
  • Update hooks/useNotifications.ts to use WebSocket notification:new events instead of polling
  • Show connection status indicator (connected/reconnecting/disconnected)
  • Handle edge cases: multiple tabs, token refresh, network errors

Technical Notes

  • Backend Socket.IO namespace: /escrow (verify in gateway config)
  • Auth token passed in handshake.auth.token or handshake.headers.authorization
  • Room format: escrow:{escrowId}

Points: 150 (Medium)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions