From 44bbf31aa37aa406f540b0e80ce417b8604b8559 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Wed, 4 Jul 2018 14:46:52 -0400 Subject: [PATCH] add check for web3Provider --- app/components/standard/Web3Render.js | 15 +++++++++++++ app/dapp.js | 32 ++++++++++++++++----------- 2 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 app/components/standard/Web3Render.js diff --git a/app/components/standard/Web3Render.js b/app/components/standard/Web3Render.js new file mode 100644 index 0000000..7aa5e78 --- /dev/null +++ b/app/components/standard/Web3Render.js @@ -0,0 +1,15 @@ +import React, { Fragment } from 'react'; + +const NoWeb3 = () => ( +
+ NO WEB3 Provider detected +
+) + +const Web3Render = ({ ready, children }) => ( + + {ready ? {children} : } + +); + +export default Web3Render; diff --git a/app/dapp.js b/app/dapp.js index b0607ad..71b93a5 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -7,6 +7,7 @@ import AdminView from './components/AdminView'; import Voting from './components/Voting'; import SNT from 'Embark/contracts/SNT'; import { VotingContext } from './context'; +import Web3Render from './components/standard/Web3Render' window['SNT'] = SNT; import './dapp.css'; @@ -25,13 +26,16 @@ class App extends React.Component { constructor(props) { super(props); } - state = { admin: false, pollOrder: 'NEWEST_ADDED' }; + state = { admin: false, pollOrder: 'NEWEST_ADDED', web3Provider: true }; componentDidMount(){ - __embarkContext.execWhenReady(() => { - this._getPolls(); - this._setAccounts(); - }); + EmbarkJS.onReady((err) => { + if (err) this.setState({ web3Provider: false }); + else { + this._getPolls(); + this._setAccounts(); + } + }) } setAccount(_account){ @@ -80,18 +84,20 @@ class App extends React.Component { } render(){ - const { admin } = this.state; + const { admin, web3Provider } = this.state; const { _getPolls, updatePoll, setPollOrder, appendToPoll } = this; const toggleAdmin = () => this.setState({ admin: true }); const votingContext = { getPolls: _getPolls, toggleAdmin, updatePoll, appendToPoll, setPollOrder, ...this.state }; return ( - - - {admin ? - : - } - - + + + + {admin ? + : + } + + + ); } }