From b03c338500e8caeacf870b5edb3ec32795dd3d4d Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 7 Mar 2019 11:42:25 -0500 Subject: [PATCH] add faster load time to project page --- app/components/projects/Project.jsx | 4 ++-- app/components/projects/hooks.js | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/components/projects/Project.jsx b/app/components/projects/Project.jsx index b509977..f9c4927 100644 --- a/app/components/projects/Project.jsx +++ b/app/components/projects/Project.jsx @@ -213,14 +213,14 @@ function Project({ classes, match, profile, transfers, pledges, projectAddedEven title="media-description" />}
- + /> : }
{`${totalPledged.toLocaleString()} ${amountsPledged[0] ? amountsPledged[0][0] : ''}`} diff --git a/app/components/projects/hooks.js b/app/components/projects/hooks.js index 366d14a..20b539c 100644 --- a/app/components/projects/hooks.js +++ b/app/components/projects/hooks.js @@ -1,4 +1,6 @@ +import EmbarkJS from 'Embark/EmbarkJS' import web3 from 'Embark/web3' +import LiquidPledging from 'Embark/contracts/LiquidPledging' import { useState, useEffect, useMemo } from 'react' import { timeSinceBlock } from '../../utils/dates' import { getFiles } from '../../utils/ipfs' @@ -9,16 +11,18 @@ async function getProjectAge(id, events, setState){ setState(timeSinceBlock(timestamp, 'days')) } -async function getProjectAssets(hash, setState){ - console.log({hash}) - const CID = hash.split('/').slice(-1)[0] - getFiles(CID) - .then((files) => { - setState(files) - const manifest = files[2] - console.log({files}, JSON.parse(manifest.content)) - }) - .catch(console.log) +async function getProjectAssets(projectId, setState){ + EmbarkJS.onReady(async (err) => { + const projectInfo = await LiquidPledging.methods.getPledgeAdmin(projectId).call() + const CID = projectInfo.url.split('/').slice(-1)[0] + getFiles(CID) + .then((files) => { + setState(files) + const manifest = files[2] + console.log({files}, JSON.parse(manifest.content)) + }) + .catch(console.log) + }) } const getProjectManifest = assets => assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null @@ -32,8 +36,8 @@ export function useProjectData(projectId, profile, projectAddedEvents) { }, [projectAddedEvents]) useEffect(() => { - if (profile[0]) getProjectAssets(profile[0].url, setAssets) - }, [profile]) + getProjectAssets(projectId, setAssets) + }, [projectId]) const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets])