diff --git a/app/actions/profiles.js b/app/actions/profiles.js index 0c7d7c8..57dd6c7 100644 --- a/app/actions/profiles.js +++ b/app/actions/profiles.js @@ -70,3 +70,9 @@ export const getProfilesById = async ids => { return event } +export const getDelegateProfiles = async addr => { + const event = await profilesCollection.query( + Q.where('addr', addr) + ).fetch() + return event +} diff --git a/app/components/projects/BackProject.jsx b/app/components/projects/BackProject.jsx index e9ccfa8..1130cea 100644 --- a/app/components/projects/BackProject.jsx +++ b/app/components/projects/BackProject.jsx @@ -83,7 +83,8 @@ const SubmissionSection = ({ classes }) => ( function BackProject({classes, match, profile, projectAddedEvents}) { const projectId = match.params.id - const { projectAge, projectAssets, manifest } = useProjectData(projectId, profile, projectAddedEvents) + const { projectAge, projectAssets, manifest, delegateProfiles } = useProjectData(projectId, profile, projectAddedEvents) + console.log({delegateProfiles}) return (
diff --git a/app/components/projects/hooks.js b/app/components/projects/hooks.js index c9df399..5fc4238 100644 --- a/app/components/projects/hooks.js +++ b/app/components/projects/hooks.js @@ -1,10 +1,12 @@ import EmbarkJS from 'Embark/EmbarkJS' import web3 from 'Embark/web3' import LiquidPledging from 'Embark/contracts/LiquidPledging' -import { useState, useEffect, useMemo } from 'react' +import { useState, useEffect, useMemo, useContext } from 'react' import { timeSinceBlock } from '../../utils/dates' import { getFiles, ipfs } from '../../utils/ipfs' import { databaseExists } from '../../utils/db' +import { FundingContext } from '../../context' +import { getDelegateProfiles } from '../../actions/profiles' async function getProjectAge(id, events, setState){ const event = events.find(e => e.returnValues.idProject === id) @@ -41,17 +43,28 @@ async function getProjectAssets(projectId, setState){ }) } +async function fetchAndAddDelegateProfiles(account, setState) { + const profiles = await getDelegateProfiles(account) + setState(profiles) +} + const getProjectManifest = assets => assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null export function useProjectData(projectId, profile, projectAddedEvents) { const [projectAge, setAge] = useState(null) const [projectAssets, setAssets] = useState(null) const [ipfsReady, setIpfsState] = useState(null) + const [delegateProfiles, setDelegateProfiles] = useState(null) + const { account } = useContext(FundingContext) useEffect(() => { ipfs.on('ready', () => { setIpfsState(true) }) }, [projectId]) + useEffect(() => { + fetchAndAddDelegateProfiles(account, setDelegateProfiles) + }, [account]) + useEffect(() => { getProjectAge(projectId, projectAddedEvents, setAge) }, [projectAddedEvents]) @@ -62,5 +75,5 @@ export function useProjectData(projectId, profile, projectAddedEvents) { const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets]) - return { projectAge, projectAssets, manifest } + return { projectAge, projectAssets, manifest, delegateProfiles } } diff --git a/app/dapp.js b/app/dapp.js index 30612d9..30d0cdb 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -29,10 +29,11 @@ class App extends React.Component { if (!!isInitialized) { if (environment === 'development') console.log('mock_time:', await LiquidPledging.mock_time.call()) + const account = await web3.eth.getCoinbase() + this.setState({ account }) const lpAllowance = await getLpAllowance() //TODO add block based sync const authorizedPayments = await getAuthorizedPayments() - const account = await web3.eth.getCoinbase() this.syncWithRemote() this.setState({ account, diff --git a/app/model/schema.js b/app/model/schema.js index 345bb2d..34333b1 100644 --- a/app/model/schema.js +++ b/app/model/schema.js @@ -28,7 +28,7 @@ export default appSchema({ name: 'profiles', columns: [ { name: 'event_id', type: 'string' }, - { name: 'addr', type: 'string' }, + { name: 'addr', type: 'string', isIndexed: true }, { name: 'canceled', type: 'boolean' }, { name: 'commit_time', type: 'number' }, { name: 'type', type: 'string' },