2018-04-23 20:42:52 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-07-11 17:11:55 +00:00
|
|
|
import {Tabs, Tab} from 'react-bootstrap';
|
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
|
|
|
|
2018-01-12 21:33:16 +00:00
|
|
|
import './dapp.css';
|
|
|
|
|
2018-04-23 20:42:52 +00:00
|
|
|
class App extends React.Component {
|
2016-08-18 11:45:08 +00:00
|
|
|
|
2018-04-23 20:42:52 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2015-05-24 13:07:19 +00:00
|
|
|
|
2018-04-23 20:42:52 +00:00
|
|
|
this.state = {
|
2018-04-24 20:21:33 +00:00
|
|
|
whisperEnabled: false,
|
2018-07-11 17:11:55 +00:00
|
|
|
storageEnabled: false,
|
|
|
|
ensEnabled: false
|
|
|
|
};
|
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() {
|
2018-05-11 16:27:27 +00:00
|
|
|
EmbarkJS.onReady(() => {
|
2018-04-26 00:11:15 +00:00
|
|
|
if (EmbarkJS.isNewWeb3()) {
|
2018-07-11 17:11:55 +00:00
|
|
|
EmbarkJS.Messages.Providers.whisper.getWhisperVersion((err, _version) => {
|
|
|
|
if (err) {
|
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
this.setState({whisperEnabled: true});
|
2018-04-26 00:11:15 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (EmbarkJS.Messages.providerName === 'whisper') {
|
2018-07-11 17:11:55 +00:00
|
|
|
EmbarkJS.Messages.getWhisperVersion((err, _version) => {
|
|
|
|
if (err) {
|
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
this.setState({whisperEnabled: true});
|
2018-04-26 00:11:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 15:47:35 +00:00
|
|
|
this.setState({
|
2018-07-11 17:11:55 +00:00
|
|
|
storageEnabled: true,
|
|
|
|
ensEnabled: EmbarkJS.Names.isAvailable()
|
2018-04-27 15:47:35 +00:00
|
|
|
});
|
2017-01-26 11:29:17 +00:00
|
|
|
});
|
2018-04-23 20:42:52 +00:00
|
|
|
}
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2017-01-27 00:18:53 +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}
|
2018-04-23 20:42:52 +00:00
|
|
|
<span className={className}></span>
|
|
|
|
</React.Fragment>;
|
2017-10-25 10:19:24 +00:00
|
|
|
}
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2018-07-11 17:11:55 +00:00
|
|
|
render() {
|
2018-04-23 20:42:52 +00:00
|
|
|
return (<div><h3>Embark - Usage Example</h3>
|
|
|
|
<Tabs defaultActiveKey={1} id="uncontrolled-tab-example">
|
|
|
|
<Tab eventKey={1} title="Blockchain">
|
2018-07-11 17:11:55 +00:00
|
|
|
<Blockchain/>
|
2018-04-23 20:42:52 +00:00
|
|
|
</Tab>
|
2018-04-24 20:21:33 +00:00
|
|
|
<Tab eventKey={2} title={this._renderStatus('Decentralized Storage', this.state.storageEnabled)}>
|
2018-07-11 17:11:55 +00:00
|
|
|
<Storage enabled={this.state.storageEnabled}/>
|
2018-04-23 20:42:52 +00:00
|
|
|
</Tab>
|
2018-07-11 17:11:55 +00:00
|
|
|
<Tab eventKey={3} title={this._renderStatus('P2P communication (Whisper)', this.state.whisperEnabled)}>
|
|
|
|
<Whisper enabled={this.state.whisperEnabled}/>
|
|
|
|
</Tab>
|
|
|
|
<Tab eventKey={4} title={this._renderStatus('Naming (ENS)', this.state.ensEnabled)}>
|
|
|
|
<ENS enabled={this.state.ensEnabled}/>
|
2018-04-23 20:42:52 +00:00
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2018-04-23 20:42:52 +00:00
|
|
|
ReactDOM.render(<App></App>, document.getElementById('app'));
|