From 27cc5dae9f8314932679c0d1b1f1eb50b62ef350 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Tue, 20 Aug 2019 11:10:36 -0400 Subject: [PATCH] add check for ethereum provider and enable if not yet connected --- src/components/projects/FundProject.jsx | 8 +++++--- src/dapp.js | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/projects/FundProject.jsx b/src/components/projects/FundProject.jsx index 6421400..5903fd3 100644 --- a/src/components/projects/FundProject.jsx +++ b/src/components/projects/FundProject.jsx @@ -34,7 +34,7 @@ const addProjectSucessMsg = response => { } const formatPercent = number => Number(number).toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}) 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 { pledgesInfos } = profileData const pledgesInfo = pledgesInfos[0] @@ -45,6 +45,7 @@ const SubmissionSection = ({ classes, projectData, projectId, commitTime, profil const createdDate = getDateCreated(projectAge) const percentToGoal = manifest ? formatPercent(Number(totalPledged) / Number(manifest.goal)) : formatPercent(0) const isCreator = projectData.creator === account + const buttonText = account ? 'Fund' : 'Connect & Fund' return (
{getTokenLabel(manifest.goalToken)}
- + } ) diff --git a/src/dapp.js b/src/dapp.js index ed3f99b..60a1e4c 100644 --- a/src/dapp.js +++ b/src/dapp.js @@ -36,6 +36,10 @@ class App extends React.Component { this.setGraphClient(network) 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() this.setState({ account }) this.web3Init() + return account } getAndSetPrices = async () => { @@ -125,6 +130,7 @@ class App extends React.Component { appendPledges, appendFundProfile, account, + enableEthereum, transferPledgeAmounts, authorizedPayments, needsInit,