import { useUpdatePoolData , useAllPoolData , useAddPoolKeys } from './hooks' ; import { useEffect , useMemo } from 'react' ; import { useTopPoolAddresses } from 'data/pools/topPools' ; import { usePoolDatas } from 'data/pools/poolData' ; export default function Updater ( ) { const updatePoolData = useUpdatePoolData ( ) ; const addPoolKeys = useAddPoolKeys ( ) ; const allPoolData = useAllPoolData ( ) ; const { loading , error , addresses } = useTopPoolAddresses ( ) ; useEffect ( ( ) => { if ( addresses && ! error && ! loading ) { addPoolKeys ( addresses ) ; } } , [ addPoolKeys , addresses , error , loading ] ) ; const unfetchedPoolAddresses = useMemo ( ( ) => { return Object . keys ( allPoolData ) . reduce ( ( accum , key ) => { const poolData = allPoolData [ key ] ; if ( ! poolData . data || ! poolData . lastUpdated ) { accum . push ( key ) ; } return accum ; } , [ ] ) ; } , [ allPoolData ] ) ; const { error : poolDataError , loading : poolDataLoading , data : poolDatas } = usePoolDatas ( unfetchedPoolAddresses ) ; useEffect ( ( ) => { if ( poolDatas && ! poolDataError && ! poolDataLoading ) { updatePoolData ( Object . values ( poolDatas ) ) ; } } , [ poolDataError , poolDataLoading , poolDatas , updatePoolData ] ) ; return null ; }