Overview
Currently useAssetBalances fetches balances once on mount and exposes a manual refetch(). This issue tracks adding a useAccountStream hook that subscribes to Horizon's Server-Sent Events (SSE) stream so balances update in real time when payments are received.
What needs to be built
API shape
const {
balances, // AssetBalanceType[]
loading, // boolean
error, // string | null
streaming, // boolean — true while SSE is active
stop, // () => void — manually close the stream
} = useAccountStream();
Example usage
import { useAccountStream } from "@stellar-pay/ui";
function LiveBalances() {
const { balances, streaming } = useAccountStream();
return (
<div>
{streaming && <span>● Live</span>}
{balances.map(b => <div key={b.asset.code}>{b.balance}</div>)}
</div>
);
}
Acceptance criteria
- Balance updates within 1–2 seconds of an incoming payment
- Stream closes cleanly on unmount (no memory leaks)
- Falls back to polling if SSE connection drops
Why this matters
This is a core SDP use case — disbursement recipients need to see their balance update the moment funds arrive without manually refreshing.
Overview
Currently
useAssetBalancesfetches balances once on mount and exposes a manualrefetch(). This issue tracks adding auseAccountStreamhook that subscribes to Horizon's Server-Sent Events (SSE) stream so balances update in real time when payments are received.What needs to be built
useAccountStream(publicKey?)inpackages/ui/src/hooks/server.accounts().accountId(publicKey).stream()src/index.tsAPI shape
Example usage
Acceptance criteria
Why this matters
This is a core SDP use case — disbursement recipients need to see their balance update the moment funds arrive without manually refreshing.