2018-10-09 15:03:20 +00:00
|
|
|
import React from 'react';
|
2018-07-06 22:12:09 +00:00
|
|
|
import 'typeface-roboto'
|
2018-06-12 19:56:41 +00:00
|
|
|
import Toggle from 'react-toggle';
|
2018-05-13 04:31:01 +00:00
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
2018-06-12 22:17:04 +00:00
|
|
|
import TestToken from 'Embark/contracts/TestToken';
|
2018-10-24 15:25:30 +00:00
|
|
|
import { startCase } from 'lodash';
|
2018-09-04 21:49:39 +00:00
|
|
|
import UsernameRegistrar from 'Embark/contracts/UsernameRegistrar';
|
2018-06-05 00:34:56 +00:00
|
|
|
import NameLookup from './components/ens/nameLookup';
|
2018-06-12 22:17:04 +00:00
|
|
|
import AdminMode from './components/AdminMode';
|
2018-06-13 16:58:19 +00:00
|
|
|
import TokenPermissions from './components/standard/TokenPermissionConnect';
|
2018-06-19 19:05:42 +00:00
|
|
|
import web3 from "Embark/web3";
|
2018-07-06 22:12:09 +00:00
|
|
|
import Welcome from './components/ens/welcome';
|
2018-07-11 17:31:33 +00:00
|
|
|
import Hidden from '@material-ui/core/Hidden';
|
2018-08-24 18:13:06 +00:00
|
|
|
import Web3Render from './components/standard/Web3Render';
|
2018-09-04 16:29:05 +00:00
|
|
|
import StatusOptimized from './components/standard/StatusOptimized';
|
2018-10-09 15:03:20 +00:00
|
|
|
import { HashRouter, Route } from "react-router-dom";
|
2018-05-13 04:31:01 +00:00
|
|
|
import './dapp.css';
|
|
|
|
|
2018-06-19 19:05:42 +00:00
|
|
|
const { getNetworkType } = web3.eth.net;
|
|
|
|
const symbols = {
|
|
|
|
'ropsten': 'STT',
|
|
|
|
'private': 'SNT',
|
|
|
|
'main': 'SNT'
|
|
|
|
}
|
|
|
|
|
2018-10-24 15:25:30 +00:00
|
|
|
const isReady = (network, environment) => {
|
|
|
|
if (!network || !environment) return;
|
|
|
|
const formattedNetwork = network.toLowerCase();
|
|
|
|
if (formattedNetwork.includes('main') || formattedNetwork.includes('live')) {
|
|
|
|
if (environment === 'livenet') return true
|
2018-12-07 14:52:30 +00:00
|
|
|
} else if(formattedNetwork.includes('ropsten')) {
|
|
|
|
if (environment === 'testnet') return true
|
2018-10-24 15:25:30 +00:00
|
|
|
}
|
2018-10-27 14:28:29 +00:00
|
|
|
return formattedNetwork.includes(environment.toLowerCase());
|
2018-10-24 15:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Web3RenderContent = ({ network, history, match, environment }) => (
|
|
|
|
<Web3Render ready={isReady(network, environment)} network={startCase(environment)}>
|
2018-10-09 15:03:20 +00:00
|
|
|
<div>
|
|
|
|
<NameLookup {...{history, match}}/>
|
|
|
|
<Hidden mdDown>
|
|
|
|
<div style={{textAlign: 'center', margin: '0px 40px'}}>
|
|
|
|
<TokenPermissions
|
|
|
|
symbol={symbols[network] || 'SNT'}
|
|
|
|
spender={UsernameRegistrar._address}
|
|
|
|
methods={TestToken.methods}/>
|
|
|
|
<hr/>
|
|
|
|
<Toggle onChange={() => {
|
|
|
|
this.setState({admin: !admin})
|
|
|
|
}}/>
|
|
|
|
<br/>
|
|
|
|
<span>Admin Mode</span>
|
|
|
|
</div>
|
|
|
|
</Hidden>
|
|
|
|
</div>
|
|
|
|
</Web3Render>
|
|
|
|
);
|
|
|
|
|
2018-05-13 04:31:01 +00:00
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
2018-06-12 19:56:41 +00:00
|
|
|
super(props)
|
2018-05-13 04:31:01 +00:00
|
|
|
}
|
2018-10-09 15:03:20 +00:00
|
|
|
state = { admin: false };
|
2018-05-13 04:31:01 +00:00
|
|
|
|
2018-05-22 14:31:27 +00:00
|
|
|
componentDidMount(){
|
2018-09-28 19:12:52 +00:00
|
|
|
EmbarkJS.onReady((err) => {
|
2018-10-24 15:25:30 +00:00
|
|
|
getNetworkType().then(network => {
|
|
|
|
const { environment } = EmbarkJS
|
|
|
|
this.setState({ network, environment })
|
|
|
|
});
|
2018-05-13 04:31:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-12 19:56:41 +00:00
|
|
|
render() {
|
2018-10-24 15:25:30 +00:00
|
|
|
const { admin, network, environment } = this.state;
|
2018-10-09 15:03:20 +00:00
|
|
|
|
2018-05-23 19:57:38 +00:00
|
|
|
return (
|
2018-10-09 16:39:37 +00:00
|
|
|
<HashRouter hashType="noslash">
|
2018-10-09 15:03:20 +00:00
|
|
|
<div>
|
|
|
|
<Hidden mdDown>
|
|
|
|
<StatusOptimized/>
|
|
|
|
</Hidden>
|
|
|
|
<div style={{display: admin ? 'block' : 'none'}}>
|
|
|
|
<AdminMode style={{display: admin ? 'block' : 'none'}}/>
|
2018-07-09 19:07:55 +00:00
|
|
|
</div>
|
2018-10-09 15:03:20 +00:00
|
|
|
|
|
|
|
<Route exact path="/" component={Welcome}/>
|
|
|
|
<Route path="/search" render={({history, match}) => (
|
2018-10-24 15:25:30 +00:00
|
|
|
<Web3RenderContent {...{history, match, network, environment}} />
|
2018-10-09 15:03:20 +00:00
|
|
|
)}/>
|
|
|
|
</div>
|
|
|
|
</HashRouter>
|
2018-06-12 19:56:41 +00:00
|
|
|
);
|
2018-05-13 04:31:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 14:25:59 +00:00
|
|
|
export default App;
|