get ipfs hash from graph query

This commit is contained in:
Barry Gitarts 2019-08-09 21:35:08 -04:00 committed by Barry G
parent 309d301938
commit a54fdcdca9
2 changed files with 34 additions and 37 deletions

View File

@ -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 <div>Loading</div>
if (error) return <div>{JSON.stringify(error)}</div>
console.log({loading,error,data})
const commitTime = convertToHours(profile[0].commitTime)
const commitTime = convertToHours(data.profile.commitTime)
return (
<div className={classes.root}>
<SubmissionSection
@ -357,9 +360,6 @@ function FundProject({ classes, match, history, projectAddedEvents, pledges, pro
const StyledProject = withStyles(styles)(FundProject)
export default withDatabase(withObservables(['match'], ({ database, match }) => ({
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(),

View File

@ -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])