add check for web3Provider
This commit is contained in:
parent
815ebfde29
commit
44bbf31aa3
|
@ -0,0 +1,15 @@
|
||||||
|
import React, { Fragment } from 'react';
|
||||||
|
|
||||||
|
const NoWeb3 = () => (
|
||||||
|
<div>
|
||||||
|
NO WEB3 Provider detected
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
const Web3Render = ({ ready, children }) => (
|
||||||
|
<Fragment>
|
||||||
|
{ready ? <Fragment>{children}</Fragment> : <NoWeb3 />}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Web3Render;
|
14
app/dapp.js
14
app/dapp.js
|
@ -7,6 +7,7 @@ import AdminView from './components/AdminView';
|
||||||
import Voting from './components/Voting';
|
import Voting from './components/Voting';
|
||||||
import SNT from 'Embark/contracts/SNT';
|
import SNT from 'Embark/contracts/SNT';
|
||||||
import { VotingContext } from './context';
|
import { VotingContext } from './context';
|
||||||
|
import Web3Render from './components/standard/Web3Render'
|
||||||
window['SNT'] = SNT;
|
window['SNT'] = SNT;
|
||||||
|
|
||||||
import './dapp.css';
|
import './dapp.css';
|
||||||
|
@ -25,13 +26,16 @@ class App extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
state = { admin: false, pollOrder: 'NEWEST_ADDED' };
|
state = { admin: false, pollOrder: 'NEWEST_ADDED', web3Provider: true };
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
__embarkContext.execWhenReady(() => {
|
EmbarkJS.onReady((err) => {
|
||||||
|
if (err) this.setState({ web3Provider: false });
|
||||||
|
else {
|
||||||
this._getPolls();
|
this._getPolls();
|
||||||
this._setAccounts();
|
this._setAccounts();
|
||||||
});
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setAccount(_account){
|
setAccount(_account){
|
||||||
|
@ -80,11 +84,12 @@ class App extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
const { admin } = this.state;
|
const { admin, web3Provider } = this.state;
|
||||||
const { _getPolls, updatePoll, setPollOrder, appendToPoll } = this;
|
const { _getPolls, updatePoll, setPollOrder, appendToPoll } = this;
|
||||||
const toggleAdmin = () => this.setState({ admin: true });
|
const toggleAdmin = () => this.setState({ admin: true });
|
||||||
const votingContext = { getPolls: _getPolls, toggleAdmin, updatePoll, appendToPoll, setPollOrder, ...this.state };
|
const votingContext = { getPolls: _getPolls, toggleAdmin, updatePoll, appendToPoll, setPollOrder, ...this.state };
|
||||||
return (
|
return (
|
||||||
|
<Web3Render ready={web3Provider}>
|
||||||
<VotingContext.Provider value={votingContext}>
|
<VotingContext.Provider value={votingContext}>
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{admin ?
|
{admin ?
|
||||||
|
@ -92,6 +97,7 @@ class App extends React.Component {
|
||||||
<Voting />}
|
<Voting />}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
</VotingContext.Provider>
|
</VotingContext.Provider>
|
||||||
|
</Web3Render>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue