improve transaction flow on project submission

This commit is contained in:
Barry Gitarts 2019-12-18 14:00:49 -05:00 committed by Barry G
parent c9baa819c8
commit 0eae93b9fe
1 changed files with 5 additions and 9 deletions

View File

@ -78,15 +78,14 @@ async function stepperProgress(values, projectData, submissionState, currencies)
return IS_APPROVED return IS_APPROVED
} }
async function generateSend(projectId, goalToken, fundToken, amount, account) { function generateSend(projectId, goalToken, fundToken, amount, account) {
if (fundToken === IS_ETH) { if (fundToken === IS_ETH) {
return fundWithETH(projectId, goalToken) return fundWithETH(projectId, goalToken)
.send({from: account, value: amount}) .send({from: account, value: amount})
} }
if (fundToken.toLowerCase() === goalToken.toLowerCase()) { if (fundToken.toLowerCase() === goalToken.toLowerCase()) {
let estimated = await addGiverAndDonate(projectId, goalToken, amount).estimateGas({ from: account })
return addGiverAndDonate(projectId, goalToken, amount) return addGiverAndDonate(projectId, goalToken, amount)
.send({from: account, gas: estimated}) .send({from: account})
} }
return fundWithToken(projectId, fundToken, amount, goalToken) return fundWithToken(projectId, fundToken, amount, goalToken)
.send({from: account}) .send({from: account})
@ -151,7 +150,7 @@ const SubmissionSection = ({ classes, projectData, projectId, profileData, start
return toSend return toSend
.send({ from: account, gas: estimated+100 }) .send({ from: account, gas: estimated+100 })
.on('transactionHash', (hash) => { .on('transactionHash', (hash) => {
setSubmissionState(SUBMITTED) setSubmissionState(AUTHORIZATION_SUBMITTED)
openSnackBar('success', `Submitted approve request to chain. TX Hash: ${hash}`) openSnackBar('success', `Submitted approve request to chain. TX Hash: ${hash}`)
}) })
.then(async res => { .then(async res => {
@ -163,8 +162,7 @@ const SubmissionSection = ({ classes, projectData, projectId, profileData, start
const args = [projectId, goalToken, fundToken, weiAmount, userAccount] const args = [projectId, goalToken, fundToken, weiAmount, userAccount]
console.log({args}) console.log({args})
const send = await generateSend(...args) generateSend(...args)
send
.on('transactionHash', (hash) => { .on('transactionHash', (hash) => {
setSubmissionState(SUBMITTED) setSubmissionState(SUBMITTED)
openSnackBar('success', `Submitted funding request to chain. TX Hash: ${hash}`) openSnackBar('success', `Submitted funding request to chain. TX Hash: ${hash}`)
@ -182,7 +180,6 @@ const SubmissionSection = ({ classes, projectData, projectId, profileData, start
.finally(() => { .finally(() => {
client.resetStore() client.resetStore()
}) })
console.log({amount, getProjectId, addProjectSucessMsg, account, openSnackBar}) console.log({amount, getProjectId, addProjectSucessMsg, account, openSnackBar})
}} }}
> >
@ -199,7 +196,6 @@ const SubmissionSection = ({ classes, projectData, projectId, profileData, start
const usdValue = manifest ? convertTokenAmountUsd(values.fundToken || manifest.goalToken, values.amount, prices, currencies) : 0 const usdValue = manifest ? convertTokenAmountUsd(values.fundToken || manifest.goalToken, values.amount, prices, currencies) : 0
const showSpinner = activeStep === IS_SUBMITTED || submissionState === AUTHORIZATION_SUBMITTED const showSpinner = activeStep === IS_SUBMITTED || submissionState === AUTHORIZATION_SUBMITTED
const disableButton = submissionState === AUTHORIZATION_SUBMITTED || activeStep >= IS_SUBMITTED const disableButton = submissionState === AUTHORIZATION_SUBMITTED || activeStep >= IS_SUBMITTED
console.log({submissionState, activeStep})
return ( return (
<form onSubmit={handleSubmit} className={classes.submissionRoot}> <form onSubmit={handleSubmit} className={classes.submissionRoot}>
@ -290,7 +286,7 @@ const SubmissionSection = ({ classes, projectData, projectId, profileData, start
</div>} </div>}
{activeStep !== IS_CONFIRMED && <StatusButton {activeStep !== IS_CONFIRMED && <StatusButton
disabled={disableButton} disabled={disableButton}
buttonText={buttonText[activeStep]} buttonText={disableButton ? 'Submitted' : buttonText[activeStep]}
confirmed={activeStep === IS_CONFIRMED} confirmed={activeStep === IS_CONFIRMED}
loading={showSpinner} loading={showSpinner}
/>} />}