import { useAllTokenData , useUpdateTokenData , useAddTokenKeys } from './hooks' ; import { useEffect , useMemo } from 'react' ; import { useTopTokenAddresses } from '../../data/tokens/topTokens' ; import { useFetchedTokenDatas } from 'data/tokens/tokenData' ; export default function Updater ( ) { const updateTokenDatas = useUpdateTokenData ( ) ; const addTokenKeys = useAddTokenKeys ( ) ; const allTokenData = useAllTokenData ( ) ; const { loading , error , addresses } = useTopTokenAddresses ( ) ; useEffect ( ( ) => { if ( addresses && ! error && ! loading ) { addTokenKeys ( addresses ) ; } } , [ addTokenKeys , addresses , error , loading ] ) ; const unfetchedTokenAddresses = useMemo ( ( ) => { return Object . keys ( allTokenData ) . reduce ( ( accum , key ) => { const tokenData = allTokenData [ key ] ; if ( ! tokenData || ! tokenData . data || ! tokenData . lastUpdated ) { accum . push ( key ) ; } return accum ; } , [ ] ) ; } , [ allTokenData ] ) ; const { error : tokenDataError , loading : tokenDataLoading , data : tokenDatas } = useFetchedTokenDatas ( unfetchedTokenAddresses ) ; useEffect ( ( ) => { if ( tokenDatas && ! tokenDataError && ! tokenDataLoading ) { updateTokenDatas ( Object . values ( tokenDatas ) ) ; } } , [ tokenDataError , tokenDataLoading , tokenDatas , updateTokenDatas ] ) ; return null ; }