import { updateProtocolData , updateChartData , updateTransactions } from './actions' ; import { AppState , AppDispatch } from './../index' ; import { ProtocolData } from './reducer' ; import { useCallback } from 'react' ; import { useDispatch , useSelector } from 'react-redux' ; import { ChartDayData , Transaction } from 'types' ; import { useActiveNetworkVersion } from 'state/application/hooks' ; import { useFetchAggregateProtocolData } from 'data/protocol/overview' ; export function useProtocolData ( ) { const [ activeNetwork ] = useActiveNetworkVersion ( ) ; const protocolData = useSelector ( ( state ) => state . protocol [ activeNetwork . id ] ?. data ) ; const dispatch = useDispatch < AppDispatch > ( ) ; const setProtocolData = useCallback ( ( protocolData ) => dispatch ( updateProtocolData ( { protocolData , networkId : activeNetwork . id } ) ) , [ activeNetwork . id , dispatch ] ) ; return [ protocolData , setProtocolData ] ; } export function useProtocolChartData ( ) { const [ activeNetwork ] = useActiveNetworkVersion ( ) ; const chartData = useSelector ( ( state ) => state . protocol [ activeNetwork . id ] ?. chartData ) ; const dispatch = useDispatch < AppDispatch > ( ) ; const setChartData = useCallback ( ( chartData ) => dispatch ( updateChartData ( { chartData , networkId : activeNetwork . id } ) ) , [ activeNetwork . id , dispatch ] ) ; return [ chartData , setChartData ] ; } export function useProtocolTransactions ( ) { const [ activeNetwork ] = useActiveNetworkVersion ( ) ; const transactions = useSelector ( ( state ) => state . protocol [ activeNetwork . id ] ?. transactions ) ; const dispatch = useDispatch < AppDispatch > ( ) ; const setTransactions = useCallback ( ( transactions ) => dispatch ( updateTransactions ( { transactions , networkId : activeNetwork . id } ) ) , [ activeNetwork . id , dispatch ] ) ; return [ transactions , setTransactions ] ; } export function useAggregateOverviewData ( ) { useFetchAggregateProtocolData ( ) ; }