add polling

This commit is contained in:
Barry Gitarts 2019-08-19 11:28:03 -04:00 committed by Barry G
parent a0ca52fe07
commit 876daa13f5
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react'
import React, { useContext, useMemo, useEffect } from 'react'
import { Formik } from 'formik'
import classnames from 'classnames'
import { useQuery } from '@apollo/react-hooks'
@ -32,7 +32,7 @@ const addProjectSucessMsg = response => {
const { events: { ProjectAdded: { returnValues: { idProject } } } } = response
return `Project created with ID of ${idProject}, will redirect to your new project page in a few seconds`
}
const SubmissionSection = ({ classes, projectData, projectId, commitTime, profileData }) => {
const SubmissionSection = ({ classes, projectData, projectId, commitTime, profileData, startPolling }) => {
const { account, openSnackBar, prices } = useContext(FundingContext)
const { projectAge, projectAssets, manifest } = projectData
const { pledgesInfos } = profileData
@ -59,6 +59,7 @@ const SubmissionSection = ({ classes, projectData, projectId, commitTime, profil
toSend
.send({gas: estimatedGas + 100})
.on('transactionHash', () => { startPolling(10000) })
.then(async res => {
console.log({res})
openSnackBar('success', 'Successfully funded project')
@ -172,11 +173,15 @@ const SubmissionSection = ({ classes, projectData, projectId, commitTime, profil
function FundProject({ classes, match, history }) {
const projectId = match.params.id
const { loading, error, data } = useQuery(getProfileById, {
const { loading, error, data, stopPolling, startPolling } = useQuery(getProfileById, {
variables: { id: formatProjectId(projectId) }
});
const projectData = useProjectData(projectId, data)
useEffect(() => {
stopPolling()
}, [data.profile])
if (loading) return <Loading />
if (error) return <div>{`Error! ${error.message}`}</div>
if(!data.profile) return <Typography className={classes.noProject}>Project Not Found</Typography>
@ -191,6 +196,7 @@ function FundProject({ classes, match, history }) {
projectId={projectId}
profileData={data.profile}
commitTime={commitTime}
startPolling={startPolling}
/>
</div>
)