import React, { useEffect, useState } from 'react' import { useDispatch, batch } from 'react-redux' import { getVisitorStats } from "../actions/user"; import { getQuotes, getBlockchainData, getEvents, getCurrentOrchestratorInfo, getTickets, getAllEnsDomains, getAllEnsInfo } from "../actions/livepeer"; import { login } from "../actions/session"; // Shows a loading screen on first load and gets fresh data every refreshInterval milliseconds // Refresh every 60 seconds const refreshInterval = 60000; const Startup = (obj) => { const [isLoaded, setIsLoaded] = useState(false); const dispatch = useDispatch(); const refreshAllZeData = () => { console.log("Refreshing Livepeer data..."); batch(() => { dispatch(getQuotes()); dispatch(getEvents()); dispatch(getBlockchainData()); dispatch(getCurrentOrchestratorInfo()); dispatch(getTickets()); }); } const refreshLogin = () => { console.log("Logging in and getting visitor statistics..."); batch(() => { dispatch(login()); dispatch(getVisitorStats()); }); } const refreshENS = () => { console.log("Refreshing ENS data..."); batch(() => { dispatch(getAllEnsDomains()); dispatch(getAllEnsInfo()); }); } useEffect(() => { refreshLogin(); refreshAllZeData(); refreshENS(); setIsLoaded(true); if (refreshInterval) { const interval = setInterval(refreshAllZeData, refreshInterval); return () => clearInterval(interval); } }, [refreshInterval]); const texts = [ "Preloading all the things...", "Preloading all the things...", "Preloading all the things...", "Speaking to the NSA...", "Loading...", "Loading...", "Loading...", "Loading...", "Loading...", "Loading..." ] if (isLoaded) { console.log("Rendering Application"); return obj.children; } else { console.log("Rendering Loading Screen"); return (

{texts[Math.floor(Math.random() * texts.length)]}

) } } export default Startup;