2018-04-23 20:42:52 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2019-08-23 15:51:03 +00:00
|
|
|
import {TabContent, TabPane, Nav, NavItem, NavLink} from 'reactstrap';
|
|
|
|
import classnames from 'classnames';
|
2016-08-18 11:45:08 +00:00
|
|
|
|
2018-01-03 17:42:48 +00:00
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
2018-04-23 20:42:52 +00:00
|
|
|
import Blockchain from './components/blockchain';
|
|
|
|
import Whisper from './components/whisper';
|
2018-04-24 20:21:33 +00:00
|
|
|
import Storage from './components/storage';
|
2018-07-11 17:11:55 +00:00
|
|
|
import ENS from './components/ens';
|
2018-01-03 17:42:48 +00:00
|
|
|
|
2019-08-23 15:51:03 +00:00
|
|
|
import 'bootstrap/dist/css/bootstrap.css';
|
2018-01-12 21:33:16 +00:00
|
|
|
import './dapp.css';
|
|
|
|
|
2018-04-23 20:42:52 +00:00
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2015-05-24 13:07:19 +00:00
|
|
|
|
2018-04-23 20:42:52 +00:00
|
|
|
this.state = {
|
2018-08-24 14:05:48 +00:00
|
|
|
error: null,
|
2019-08-23 15:51:03 +00:00
|
|
|
activeKey: '1',
|
2018-04-24 20:21:33 +00:00
|
|
|
whisperEnabled: false,
|
2018-09-11 08:11:22 +00:00
|
|
|
storageEnabled: false,
|
2018-10-23 15:39:14 +00:00
|
|
|
blockchainEnabled: false
|
2018-07-11 17:11:55 +00:00
|
|
|
};
|
2018-04-23 20:42:52 +00:00
|
|
|
}
|
2017-10-25 10:19:24 +00:00
|
|
|
|
2018-07-11 17:11:55 +00:00
|
|
|
componentDidMount() {
|
2019-02-22 19:10:53 +00:00
|
|
|
EmbarkJS.onReady((err) => {
|
2018-08-23 20:09:47 +00:00
|
|
|
if (err) {
|
|
|
|
// If err is not null then it means something went wrong connecting to ethereum
|
|
|
|
// you can use this to ask the user to enable metamask for e.g
|
2018-09-11 21:10:36 +00:00
|
|
|
return this.setState({error: err.message || err});
|
2018-08-23 20:09:47 +00:00
|
|
|
}
|
2018-09-14 22:39:47 +00:00
|
|
|
|
2019-12-05 15:44:44 +00:00
|
|
|
EmbarkJS.Blockchain.isAvailable().then(result => {
|
|
|
|
this.setState({blockchainEnabled: result});
|
|
|
|
});
|
|
|
|
|
2019-06-28 10:57:23 +00:00
|
|
|
EmbarkJS.Messages.isAvailable().then(result => {
|
|
|
|
this.setState({whisperEnabled: result});
|
2018-09-14 22:39:47 +00:00
|
|
|
});
|
2018-08-22 09:11:57 +00:00
|
|
|
|
|
|
|
EmbarkJS.Storage.isAvailable().then((result) => {
|
|
|
|
this.setState({storageEnabled: result});
|
|
|
|
}).catch(() => {
|
|
|
|
this.setState({storageEnabled: false});
|
|
|
|
});
|
2017-01-26 11:29:17 +00:00
|
|
|
});
|
2018-04-23 20:42:52 +00:00
|
|
|
}
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2018-07-11 17:11:55 +00:00
|
|
|
_renderStatus(title, available) {
|
2018-04-23 20:42:52 +00:00
|
|
|
let className = available ? 'pull-right status-online' : 'pull-right status-offline';
|
|
|
|
return <React.Fragment>
|
2018-07-11 17:11:55 +00:00
|
|
|
{title}
|
2019-08-26 15:12:42 +00:00
|
|
|
<span className={className}/>
|
2018-04-23 20:42:52 +00:00
|
|
|
</React.Fragment>;
|
2017-10-25 10:19:24 +00:00
|
|
|
}
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2018-07-30 11:49:03 +00:00
|
|
|
handleSelect(key) {
|
2019-08-23 15:51:03 +00:00
|
|
|
this.setState({activeKey: key});
|
2018-07-30 11:49:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 17:11:55 +00:00
|
|
|
render() {
|
2018-08-29 09:22:43 +00:00
|
|
|
const ensEnabled = EmbarkJS.Names.currentNameSystems && EmbarkJS.Names.isAvailable();
|
2018-08-23 20:09:47 +00:00
|
|
|
if (this.state.error) {
|
|
|
|
return (<div>
|
2019-08-23 15:51:03 +00:00
|
|
|
<div>Something went wrong connecting to ethereum. Please make sure you have a node running or are using metamask
|
|
|
|
to connect to the ethereum network:
|
|
|
|
</div>
|
2018-08-23 20:09:47 +00:00
|
|
|
<div>{this.state.error}</div>
|
|
|
|
</div>);
|
2018-08-23 20:23:00 +00:00
|
|
|
}
|
2018-08-23 20:09:47 +00:00
|
|
|
return (<div>
|
|
|
|
<h3>Embark - Usage Example</h3>
|
2019-08-23 15:51:03 +00:00
|
|
|
<Nav tabs>
|
|
|
|
<NavItem>
|
|
|
|
<NavLink onClick={() => this.handleSelect('1')} className={classnames({ active: this.state.activeKey === '1' })}>
|
|
|
|
{this._renderStatus('Blockchain', this.state.blockchainEnabled)}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
|
|
|
<NavItem>
|
|
|
|
<NavLink onClick={() => this.handleSelect('2')} className={classnames({ active: this.state.activeKey === '2' })}>
|
|
|
|
{this._renderStatus('Decentralized Storage', this.state.storageEnabled)}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
|
|
|
<NavItem>
|
|
|
|
<NavLink onClick={() => this.handleSelect('3')} className={classnames({ active: this.state.activeKey === '3' })}>
|
|
|
|
{this._renderStatus('P2P communication (Whisper)', this.state.whisperEnabled)}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
|
|
|
<NavItem>
|
|
|
|
<NavLink onClick={() => this.handleSelect('4')} className={classnames({ active: this.state.activeKey === '4' })}>
|
|
|
|
{this._renderStatus('Naming (ENS)', ensEnabled)}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
|
|
|
</Nav>
|
|
|
|
<TabContent activeTab={this.state.activeKey}>
|
|
|
|
<TabPane tabId="1">
|
2018-07-11 17:11:55 +00:00
|
|
|
<Blockchain/>
|
2019-08-23 15:51:03 +00:00
|
|
|
</TabPane>
|
|
|
|
<TabPane tabId="2">
|
2018-07-11 17:11:55 +00:00
|
|
|
<Storage enabled={this.state.storageEnabled}/>
|
2019-08-23 15:51:03 +00:00
|
|
|
</TabPane>
|
|
|
|
<TabPane tabId="3">
|
2018-07-11 17:11:55 +00:00
|
|
|
<Whisper enabled={this.state.whisperEnabled}/>
|
2019-08-23 15:51:03 +00:00
|
|
|
</TabPane>
|
|
|
|
<TabPane tabId="4">
|
2018-08-29 09:22:43 +00:00
|
|
|
<ENS enabled={ensEnabled}/>
|
2019-08-23 15:51:03 +00:00
|
|
|
</TabPane>
|
|
|
|
</TabContent>
|
2018-04-23 20:42:52 +00:00
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2019-08-23 15:51:03 +00:00
|
|
|
ReactDOM.render(<App/>, document.getElementById('app'));
|