From 26f7c2bda60059be50e38a4bccf19aade4cf8999 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 23 May 2019 17:50:22 -0400 Subject: [PATCH] attempt sync after update use pledgeTypes map --- src/components/projects/ProjectPledges.jsx | 13 +++++++------ src/components/projects/hooks.js | 5 +++-- src/dapp.js | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/components/projects/ProjectPledges.jsx b/src/components/projects/ProjectPledges.jsx index f306f20..0bcf352 100644 --- a/src/components/projects/ProjectPledges.jsx +++ b/src/components/projects/ProjectPledges.jsx @@ -160,14 +160,14 @@ const Title = ({ className, manifest }) => ( ) const getSendFn = (pledgeType, filteredPledges) => { - if (pledgeType === PLEDGED) { + if (pledgeTypes[pledgeType] === PLEDGED) { return filteredPledges.length > 1 ? mWithdraw : withdraw } return confirmPayment } const getArgs = (pledgeType, filteredPledges) => { - if (pledgeType === PLEDGED) { + if (pledgeTypes[pledgeType] === PLEDGED) { const formattedPledges = filteredPledges.map(pledge => ({ amount: pledge.amount, id: pledge.idPledge })) const encodedPledges = encodePledges(formattedPledges) const withdrawArgs = [filteredPledges[0].id, filteredPledges[0].amount] @@ -176,10 +176,10 @@ const getArgs = (pledgeType, filteredPledges) => { const { idPayment } = filteredPledges[0].authorization.returnValues return [idPayment] } -const SubmissionSection = ({ classes, openSnackBar, pledges, pledgeType }) => { +const SubmissionSection = ({ classes, openSnackBar, syncWithRemote, pledges, pledgeType }) => { return ( { + onSubmit={async(values) => { const { pledge } = values const filteredPledges = Object.keys(pledge) .filter(p => !!pledge[p]) @@ -199,7 +199,7 @@ const SubmissionSection = ({ classes, openSnackBar, pledges, pledgeType }) => { }) .finally(() => { openSnackBar('success', 'Withdraws initiated') - resetForm() + syncWithRemote() }) }} > @@ -259,7 +259,7 @@ function CenteredTabs({ pledged, paying, paid, pledgeType, setPledgeType }) { function ProjectPledges({classes, match, projectAddedEvents, pledges, authorizedPayments}) { const [pledgeType, setPledgeType] = useState(0) const projectId = match.params.id - const { manifest, delegateProfiles, openSnackBar } = useProjectData(projectId, projectAddedEvents) + const { manifest, delegateProfiles, openSnackBar, syncWithRemote } = useProjectData(projectId, projectAddedEvents) const delegatePledges = useProfileData(delegateProfiles) const enrichedPledges = usePledgesAuthorizations(pledges, authorizedPayments).filter(p => Number(p.amount) > 0) const pledged = enrichedPledges.filter(p => p.pledgeState === 0) @@ -286,6 +286,7 @@ function ProjectPledges({classes, match, projectAddedEvents, pledges, authorized delegatePledges={delegatePledges} projectId={projectId} openSnackBar={openSnackBar} + syncWithRemote={syncWithRemote} pledges={selectedPledges[pledgeType]} pledgeType={pledgeType} /> diff --git a/src/components/projects/hooks.js b/src/components/projects/hooks.js index 8d88755..824ba9a 100644 --- a/src/components/projects/hooks.js +++ b/src/components/projects/hooks.js @@ -105,7 +105,7 @@ export function useProjectData(projectId, projectAddedEvents) { const [projectAssets, setAssets] = useState(null) const [ipfsReady, setIpfsState] = useState(null) const [delegateProfiles, setDelegateProfiles] = useState(null) - const { account, openSnackBar } = useContext(FundingContext) + const { account, openSnackBar, syncWithRemote } = useContext(FundingContext) useEffect(() => { ipfs.on('ready', () => { setIpfsState(true) }) @@ -130,7 +130,8 @@ export function useProjectData(projectId, projectAddedEvents) { projectAssets, manifest, delegateProfiles, - openSnackBar + openSnackBar, + syncWithRemote } } diff --git a/src/dapp.js b/src/dapp.js index b1d5989..7cf960c 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -54,7 +54,8 @@ class App extends React.Component { }) } - async syncWithRemote() { + syncWithRemote = async () => { + this.setState({ loading: true }) // not running in parallel due to possible metamask / infura limitation await getAndAddLpEvents() await getAndAddVaultEvents() @@ -82,8 +83,20 @@ class App extends React.Component { render() { const { account, needsInit, lpAllowance: _lpAllowance, loading, authorizedPayments, snackbar } = this.state - const { appendFundProfile, appendPledges, transferPledgeAmounts, openSnackBar, closeSnackBar } = this - const fundingContext = { appendPledges, appendFundProfile, account, transferPledgeAmounts, authorizedPayments, needsInit, initVaultAndLP, standardTokenApproval, openSnackBar, closeSnackBar } + const { appendFundProfile, appendPledges, transferPledgeAmounts, openSnackBar, closeSnackBar, syncWithRemote } = this + const fundingContext = { + appendPledges, + appendFundProfile, + account, + transferPledgeAmounts, + authorizedPayments, + needsInit, + initVaultAndLP, + standardTokenApproval, + openSnackBar, + closeSnackBar, + syncWithRemote + } return (