diff --git a/src/components/projects/FundProject.jsx b/src/components/projects/FundProject.jsx
index 3d33849..96c5422 100644
--- a/src/components/projects/FundProject.jsx
+++ b/src/components/projects/FundProject.jsx
@@ -331,16 +331,19 @@ const SubmissionSection = ({ classes, projectData, projectId, pledges, commitTim
)
}
-function FundProject({ classes, match, history, projectAddedEvents, pledges, profile }) {
+function FundProject({ classes, match, history, projectAddedEvents, pledges }) {
const projectId = match.params.id
- const projectData = useProjectData(projectId, projectAddedEvents)
const { loading, error, data } = useQuery(getProfileById, {
variables: { id: formatProjectId(projectId) }
});
+ const projectData = useProjectData(projectId, projectAddedEvents, data)
+
+ if (loading) return
Loading
+ if (error) return {JSON.stringify(error)}
console.log({loading,error,data})
- const commitTime = convertToHours(profile[0].commitTime)
+ const commitTime = convertToHours(data.profile.commitTime)
return (
({
- profile: database.collections.get('profiles').query(
- Q.where('id_profile', match.params.id)
- ).observe(),
transfers: database.collections.get('lp_events').query(
Q.where('event', 'Transfer')
).observe(),
diff --git a/src/components/projects/hooks.js b/src/components/projects/hooks.js
index c1c04f6..8ecd352 100644
--- a/src/components/projects/hooks.js
+++ b/src/components/projects/hooks.js
@@ -1,6 +1,4 @@
/*global web3*/
-import EmbarkJS from '../../embarkArtifacts/embarkjs'
-import LiquidPledging from '../../embarkArtifacts/contracts/LiquidPledging'
import { useState, useEffect, useMemo, useContext } from 'react'
import { unnest } from 'ramda'
import { timeSinceBlock } from '../../utils/dates'
@@ -29,33 +27,32 @@ async function getProjectCreator(id, events, setState){
}
}
-async function getProjectAssets(projectId, setState, debug=false){
- EmbarkJS.onReady(async (_err) => {
- const projectInfo = await LiquidPledging.methods.getPledgeAdmin(projectId).call()
- const CID = projectInfo.url.split('/').slice(-1)[0]
- if (debug) console.log({CID, projectInfo, ipfs})
- getFilesWeb(CID)
- .then((files) => {
- setState(files)
- const manifest = files[2]
- if (debug) console.log({files}, JSON.parse(manifest.content))
- })
- .catch(async (err) => {
- console.log('IPFS getFiles error: ', err)
- databaseExists('ipfs')
- .catch(() => window.location.reload())
+async function getProjectAssets(data, setState, debug=false){
+ if (!data.profile) return
+ const { profile: { url } } = data
+ const CID = url.split('/').slice(-1)[0]
+ if (debug) console.log({CID, data, ipfs})
+ getFilesWeb(CID)
+ .then((files) => {
+ setState(files)
+ const manifest = files[2]
+ if (debug) console.log({files}, JSON.parse(manifest.content))
+ })
+ .catch(async (err) => {
+ console.log('IPFS getFiles error: ', err)
+ databaseExists('ipfs')
+ .catch(() => window.location.reload())
- getFiles(CID)
- .then((files) => {
- setState(files)
- const manifest = files[2]
- if (debug) console.log({files}, JSON.parse(manifest.content))
- })
- .catch((err) => {
- console.log('IPFS FAILED ON READY', err)
- })
- })
- })
+ getFiles(CID)
+ .then((files) => {
+ setState(files)
+ const manifest = files[2]
+ if (debug) console.log({files}, JSON.parse(manifest.content))
+ })
+ .catch((err) => {
+ console.log('IPFS FAILED ON READY', err)
+ })
+ })
}
async function getPledge(dPledge) {
@@ -112,7 +109,7 @@ const getProjectManifest = assets => {
}
}
-export function useProjectData(projectId, projectAddedEvents) {
+export function useProjectData(projectId, projectAddedEvents, data) {
const [projectAge, setAge] = useState(null)
const [creator, setCreator] = useState(null)
const [projectAssets, setAssets] = useState(null)
@@ -137,8 +134,8 @@ export function useProjectData(projectId, projectAddedEvents) {
}, [projectAddedEvents, projectId])
useEffect(() => {
- getProjectAssets(projectId, setAssets)
- }, [projectId, ipfsReady])
+ getProjectAssets(data, setAssets)
+ }, [ipfsReady, data])
const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets, projectId])