From 4e00a7b89656e0fd7250bdaec033d664603d373e Mon Sep 17 00:00:00 2001 From: Supriya Mishra Date: Wed, 2 Mar 2022 03:08:21 +0530 Subject: [PATCH] - Fixes issue #38, by improving load time from ~30+ seconds to ~5 seconds. --- packages/react-app/src/views/Home.jsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/react-app/src/views/Home.jsx b/packages/react-app/src/views/Home.jsx index 9713d16..d9a6a62 100644 --- a/packages/react-app/src/views/Home.jsx +++ b/packages/react-app/src/views/Home.jsx @@ -70,19 +70,21 @@ export default function Home({ const [sData, setData] = useState([]); - let copy = JSON.parse(JSON.stringify(streams)); - useEffect(async () => { - // Get an instance for each Stream contract - for (let b in streams) { - const summary = await resolveStreamSummary(streams[b].stream, mainnetProvider); - copy[b].push(summary.cap); - copy[b].percent = summary.percent; - } - setData(copy); + // parallely load all available streams data + Promise.all( + streams.map(async (stream) => { + const summary = await resolveStreamSummary(stream.stream, mainnetProvider); + return {...stream, 3: summary.cap, percent: summary.percent}; + }) + ).then(results => { + setData(results); - // Wait until list is almost fully loaded to render - if (copy.length >= 18) setReady(true); + // Wait until list is almost fully loaded to render + if (results.length >= 18) { + setReady(true); + } + }); }, [streams]); const createNewStream = async () => {