Skip to content

Commit

Permalink
Merge pull request #39 from supriyaamisshra/fix-issue-38
Browse files Browse the repository at this point in the history
Improve home page streams load time.
  • Loading branch information
codenamejason authored Mar 2, 2022
2 parents cbe5123 + 4e00a7b commit f4f0980
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/react-app/src/views/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit f4f0980

Please sign in to comment.