- Created .gitignore to exclude sensitive files and directories. - Added API documentation in API_DOCUMENTATION.md. - Included deployment instructions in DEPLOYMENT.md. - Established project structure documentation in PROJECT_STRUCTURE.md. - Updated README.md with project status and team information. - Added recommendations and status tracking documents. - Introduced testing guidelines in TESTING.md. - Set up CI workflow in .github/workflows/ci.yml. - Created Dockerfile for backend and frontend setups. - Added various service and utility files for backend functionality. - Implemented frontend components and pages for user interface. - Included mobile app structure and services. - Established scripts for deployment across multiple chains.
31 lines
674 B
TypeScript
31 lines
674 B
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import { wsClient } from '@/lib/websocket'
|
|
|
|
export function useRealtimeData(type: string) {
|
|
const [data, setData] = useState<any>(null)
|
|
const [connected, setConnected] = useState(false)
|
|
|
|
useEffect(() => {
|
|
const handler = (newData: any) => {
|
|
setData(newData)
|
|
}
|
|
|
|
wsClient.subscribe(type, handler)
|
|
setConnected(wsClient.isConnected())
|
|
|
|
const checkConnection = setInterval(() => {
|
|
setConnected(wsClient.isConnected())
|
|
}, 1000)
|
|
|
|
return () => {
|
|
wsClient.unsubscribe(type, handler)
|
|
clearInterval(checkConnection)
|
|
}
|
|
}, [type])
|
|
|
|
return { data, connected }
|
|
}
|
|
|