add check for ethereum provider and enable if not yet connected
This commit is contained in:
parent
0aeaae5935
commit
27cc5dae9f
|
@ -34,7 +34,7 @@ const addProjectSucessMsg = response => {
|
||||||
}
|
}
|
||||||
const formatPercent = number => Number(number).toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2})
|
const formatPercent = number => Number(number).toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2})
|
||||||
const SubmissionSection = ({ classes, projectData, projectId, commitTime, profileData, startPolling }) => {
|
const SubmissionSection = ({ classes, projectData, projectId, commitTime, profileData, startPolling }) => {
|
||||||
const { account, openSnackBar, prices } = useContext(FundingContext)
|
const { account, enableEthereum, openSnackBar, prices } = useContext(FundingContext)
|
||||||
const { projectAge, projectAssets, manifest } = projectData
|
const { projectAge, projectAssets, manifest } = projectData
|
||||||
const { pledgesInfos } = profileData
|
const { pledgesInfos } = profileData
|
||||||
const pledgesInfo = pledgesInfos[0]
|
const pledgesInfo = pledgesInfos[0]
|
||||||
|
@ -45,6 +45,7 @@ const SubmissionSection = ({ classes, projectData, projectId, commitTime, profil
|
||||||
const createdDate = getDateCreated(projectAge)
|
const createdDate = getDateCreated(projectAge)
|
||||||
const percentToGoal = manifest ? formatPercent(Number(totalPledged) / Number(manifest.goal)) : formatPercent(0)
|
const percentToGoal = manifest ? formatPercent(Number(totalPledged) / Number(manifest.goal)) : formatPercent(0)
|
||||||
const isCreator = projectData.creator === account
|
const isCreator = projectData.creator === account
|
||||||
|
const buttonText = account ? 'Fund' : 'Connect & Fund'
|
||||||
return (
|
return (
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{
|
initialValues={{
|
||||||
|
@ -54,7 +55,8 @@ const SubmissionSection = ({ classes, projectData, projectId, commitTime, profil
|
||||||
const { amount } = values
|
const { amount } = values
|
||||||
const { goalToken } = manifest
|
const { goalToken } = manifest
|
||||||
const { chainReadibleFn } = getTokenByAddress(goalToken)
|
const { chainReadibleFn } = getTokenByAddress(goalToken)
|
||||||
const args = [projectId, account, goalToken, chainReadibleFn(amount)]
|
const userAccount = account ? account : await enableEthereum()
|
||||||
|
const args = [projectId, userAccount, goalToken, chainReadibleFn(amount)]
|
||||||
const toSend = addGiverAndDonate(...args)
|
const toSend = addGiverAndDonate(...args)
|
||||||
const estimatedGas = await toSend.estimateGas()
|
const estimatedGas = await toSend.estimateGas()
|
||||||
|
|
||||||
|
@ -162,7 +164,7 @@ const SubmissionSection = ({ classes, projectData, projectId, commitTime, profil
|
||||||
/>
|
/>
|
||||||
<div className={classes.amountText}>{getTokenLabel(manifest.goalToken)}</div>
|
<div className={classes.amountText}>{getTokenLabel(manifest.goalToken)}</div>
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit" color="primary" variant="contained" className={classnames(classes.formButton)}>{isSubmitting ? 'Ethereum Submission In Progress' : 'Fund'}</Button>
|
<Button type="submit" color="primary" variant="contained" className={classnames(classes.formButton)}>{isSubmitting ? 'Ethereum Submission In Progress' : buttonText}</Button>
|
||||||
</div>}
|
</div>}
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,6 +36,10 @@ class App extends React.Component {
|
||||||
this.setGraphClient(network)
|
this.setGraphClient(network)
|
||||||
this.getAndSetPrices()
|
this.getAndSetPrices()
|
||||||
|
|
||||||
|
if (window.ethereum) {
|
||||||
|
const { selectedAddress: account } = window.ethereum
|
||||||
|
if (account) this.setState({ account })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +71,7 @@ class App extends React.Component {
|
||||||
const account = await web3.eth.getCoinbase()
|
const account = await web3.eth.getCoinbase()
|
||||||
this.setState({ account })
|
this.setState({ account })
|
||||||
this.web3Init()
|
this.web3Init()
|
||||||
|
return account
|
||||||
}
|
}
|
||||||
|
|
||||||
getAndSetPrices = async () => {
|
getAndSetPrices = async () => {
|
||||||
|
@ -125,6 +130,7 @@ class App extends React.Component {
|
||||||
appendPledges,
|
appendPledges,
|
||||||
appendFundProfile,
|
appendFundProfile,
|
||||||
account,
|
account,
|
||||||
|
enableEthereum,
|
||||||
transferPledgeAmounts,
|
transferPledgeAmounts,
|
||||||
authorizedPayments,
|
authorizedPayments,
|
||||||
needsInit,
|
needsInit,
|
||||||
|
|
Loading…
Reference in New Issue