add query and hook to fetch matching delegate profiles

This commit is contained in:
Barry Gitarts 2019-03-08 16:18:57 -05:00 committed by Barry G
parent 6bc1ccd840
commit 3679ebe555
5 changed files with 26 additions and 5 deletions

View File

@ -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
}

View File

@ -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 (
<div className={classes.root}>
<Title className={classes.title} manifest={manifest} />

View File

@ -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 }
}

View File

@ -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,

View File

@ -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' },