'use client' import { useWsSubscribe } from './wsContext' interface Handlers { onPrice?: (asset: 'BTC' | 'ETH', price: number) => void onNewPost?: (post: object) => void } type PriceMsg = { type: 'price'; asset: 'BTC' | 'ETH'; price: number } type PostMsg = { type: 'new_post'; post: object } /** * Subscribe to price ticks and new-post events from the shared WebSocket. * Delegates to WsProvider's singleton connection — no new socket is opened. */ export function usePriceSocket(handlers: Handlers) { useWsSubscribe('price', (msg) => { const m = msg as PriceMsg handlers.onPrice?.(m.asset, m.price) }) useWsSubscribe('new_post', (msg) => { const m = msg as PostMsg handlers.onNewPost?.(m.post) }) }