refactor: migrate TrumpSignal to TypeScript monorepo and Pages Router
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
'use client'
|
||||
|
||||
import { useWsSubscribe } from './wsContext'
|
||||
|
||||
interface Handlers {
|
||||
// BUG-08 fix: backend now broadcasts SOL/TRUMP/BNB/DOGE/LINK/AAVE ticks
|
||||
// in addition to BTC/ETH — widen asset to string.
|
||||
onPrice?: (asset: string, price: number) => void
|
||||
onNewPost?: (post: object) => void
|
||||
}
|
||||
|
||||
type PriceMsg = { type: 'price'; asset: string; 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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user