Skip to content

feat: implement useHorizonSSE hook for real-time transaction streaming #3

Description

@rayeberechi

Summary

useTransactions currently does a one-shot Horizon fetch. Horizon supports Server-Sent Events (SSE) for streaming new transactions in real time. This hook should wrap that capability.

Implementation Steps

  1. Create src/hooks/useHorizonSSE.ts.
  2. Signature: useHorizonSSE(publicKey: string | null, network: StellarNetwork, onRecord: (tx: TransactionRecord) => void): { close: () => void }.
  3. Use Horizon.Server.transactions().forAccount(publicKey).cursor('now').stream({ onmessage, onerror }) from @stellar/stellar-sdk.
  4. Call close() in the useEffect cleanup to prevent memory leaks.
  5. Map the raw Horizon record to TransactionRecord using the same mapping logic as useTransactions.
  6. Export from src/index.ts.
  7. Write a unit test using vi.mock('@stellar/stellar-sdk') to simulate the stream emitting one record and verify onRecord is called.

Definition of Done

  • Hook opens SSE stream on mount and closes on unmount.
  • onRecord called with correctly typed TransactionRecord.
  • No memory leaks (cleanup verified in test).
  • TypeScript strict mode passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    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