add query and hook to fetch matching delegate profiles
This commit is contained in:
parent
6bc1ccd840
commit
3679ebe555
|
@ -70,3 +70,9 @@ export const getProfilesById = async ids => {
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getDelegateProfiles = async addr => {
|
||||||
|
const event = await profilesCollection.query(
|
||||||
|
Q.where('addr', addr)
|
||||||
|
).fetch()
|
||||||
|
return event
|
||||||
|
}
|
||||||
|
|
|
@ -83,7 +83,8 @@ const SubmissionSection = ({ classes }) => (
|
||||||
|
|
||||||
function BackProject({classes, match, profile, projectAddedEvents}) {
|
function BackProject({classes, match, profile, projectAddedEvents}) {
|
||||||
const projectId = match.params.id
|
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 (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Title className={classes.title} manifest={manifest} />
|
<Title className={classes.title} manifest={manifest} />
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import EmbarkJS from 'Embark/EmbarkJS'
|
import EmbarkJS from 'Embark/EmbarkJS'
|
||||||
import web3 from 'Embark/web3'
|
import web3 from 'Embark/web3'
|
||||||
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
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 { timeSinceBlock } from '../../utils/dates'
|
||||||
import { getFiles, ipfs } from '../../utils/ipfs'
|
import { getFiles, ipfs } from '../../utils/ipfs'
|
||||||
import { databaseExists } from '../../utils/db'
|
import { databaseExists } from '../../utils/db'
|
||||||
|
import { FundingContext } from '../../context'
|
||||||
|
import { getDelegateProfiles } from '../../actions/profiles'
|
||||||
|
|
||||||
async function getProjectAge(id, events, setState){
|
async function getProjectAge(id, events, setState){
|
||||||
const event = events.find(e => e.returnValues.idProject === id)
|
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
|
const getProjectManifest = assets => assets ? JSON.parse(assets.find(a => a.name.toLowerCase() === 'manifest.json').content) : null
|
||||||
|
|
||||||
export function useProjectData(projectId, profile, projectAddedEvents) {
|
export function useProjectData(projectId, profile, projectAddedEvents) {
|
||||||
const [projectAge, setAge] = useState(null)
|
const [projectAge, setAge] = useState(null)
|
||||||
const [projectAssets, setAssets] = useState(null)
|
const [projectAssets, setAssets] = useState(null)
|
||||||
const [ipfsReady, setIpfsState] = useState(null)
|
const [ipfsReady, setIpfsState] = useState(null)
|
||||||
|
const [delegateProfiles, setDelegateProfiles] = useState(null)
|
||||||
|
const { account } = useContext(FundingContext)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ipfs.on('ready', () => { setIpfsState(true) })
|
ipfs.on('ready', () => { setIpfsState(true) })
|
||||||
}, [projectId])
|
}, [projectId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchAndAddDelegateProfiles(account, setDelegateProfiles)
|
||||||
|
}, [account])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getProjectAge(projectId, projectAddedEvents, setAge)
|
getProjectAge(projectId, projectAddedEvents, setAge)
|
||||||
}, [projectAddedEvents])
|
}, [projectAddedEvents])
|
||||||
|
@ -62,5 +75,5 @@ export function useProjectData(projectId, profile, projectAddedEvents) {
|
||||||
|
|
||||||
const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets])
|
const manifest = useMemo(() => getProjectManifest(projectAssets), [projectAssets])
|
||||||
|
|
||||||
return { projectAge, projectAssets, manifest }
|
return { projectAge, projectAssets, manifest, delegateProfiles }
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,11 @@ class App extends React.Component {
|
||||||
if (!!isInitialized) {
|
if (!!isInitialized) {
|
||||||
if (environment === 'development') console.log('mock_time:', await LiquidPledging.mock_time.call())
|
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()
|
const lpAllowance = await getLpAllowance()
|
||||||
//TODO add block based sync
|
//TODO add block based sync
|
||||||
const authorizedPayments = await getAuthorizedPayments()
|
const authorizedPayments = await getAuthorizedPayments()
|
||||||
const account = await web3.eth.getCoinbase()
|
|
||||||
this.syncWithRemote()
|
this.syncWithRemote()
|
||||||
this.setState({
|
this.setState({
|
||||||
account,
|
account,
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default appSchema({
|
||||||
name: 'profiles',
|
name: 'profiles',
|
||||||
columns: [
|
columns: [
|
||||||
{ name: 'event_id', type: 'string' },
|
{ name: 'event_id', type: 'string' },
|
||||||
{ name: 'addr', type: 'string' },
|
{ name: 'addr', type: 'string', isIndexed: true },
|
||||||
{ name: 'canceled', type: 'boolean' },
|
{ name: 'canceled', type: 'boolean' },
|
||||||
{ name: 'commit_time', type: 'number' },
|
{ name: 'commit_time', type: 'number' },
|
||||||
{ name: 'type', type: 'string' },
|
{ name: 'type', type: 'string' },
|
||||||
|
|
Loading…
Reference in New Issue