mirror of
https://github.com/status-im/meritocracy.git
synced 2025-01-09 13:26:11 +00:00
Merge pull request #9 from jrainville/feat/restructure
Restructure the files so that App only contains the router
This commit is contained in:
commit
a7bc5d6682
62
app/js/App.js
Normal file
62
app/js/App.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*global web3*/
|
||||||
|
import React from 'react';
|
||||||
|
import {HashRouter, Route, Redirect, Switch} from "react-router-dom";
|
||||||
|
|
||||||
|
import EmbarkJS from 'Embark/EmbarkJS';
|
||||||
|
|
||||||
|
import Home from './components/Home';
|
||||||
|
|
||||||
|
const MAINNET = 1;
|
||||||
|
const TESTNET = 3;
|
||||||
|
|
||||||
|
class App extends React.Component {
|
||||||
|
|
||||||
|
state = {
|
||||||
|
error: null,
|
||||||
|
loading: true
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
EmbarkJS.onReady(async (err) => {
|
||||||
|
if (err) {
|
||||||
|
return this.setState({error: err.message || err});
|
||||||
|
}
|
||||||
|
|
||||||
|
const netId = await web3.eth.net.getId();
|
||||||
|
if (EmbarkJS.environment === 'testnet' && netId !== TESTNET) {
|
||||||
|
return this.setState({error: 'Please connect to Ropsten'});
|
||||||
|
}
|
||||||
|
if (EmbarkJS.environment === 'livenet' && netId !== MAINNET) {
|
||||||
|
return this.setState({error: 'Please connect to Mainnet'});
|
||||||
|
}
|
||||||
|
this.setState({loading: false})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {error, loading} = this.state;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (<div>
|
||||||
|
<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>
|
||||||
|
<div>{error}</div>
|
||||||
|
</div>);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <p>Loading, please wait</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (<HashRouter>
|
||||||
|
<Switch>
|
||||||
|
<Route exact path="/" component={Home}/>
|
||||||
|
|
||||||
|
<Redirect to="/404"/>
|
||||||
|
</Switch>
|
||||||
|
</HashRouter>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
@ -1,12 +1,9 @@
|
|||||||
/*global web3*/
|
/*global web3*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Button, Grid, Row, Col, Alert } from 'react-bootstrap';
|
import {Button, Grid, Row, Col, Alert } from 'react-bootstrap';
|
||||||
import * as NumericInput from 'react-numeric-input';
|
import * as NumericInput from 'react-numeric-input';
|
||||||
import Select from 'react-select';
|
import Select from 'react-select';
|
||||||
|
|
||||||
import EmbarkJS from 'Embark/EmbarkJS';
|
|
||||||
|
|
||||||
import Meritocracy from 'Embark/contracts/Meritocracy';
|
import Meritocracy from 'Embark/contracts/Meritocracy';
|
||||||
|
|
||||||
// import './css/dapp.css';
|
// import './css/dapp.css';
|
||||||
@ -17,19 +14,15 @@ TODO:
|
|||||||
- listen to events to update UI, (initially on page load but within function calls)
|
- listen to events to update UI, (initially on page load but within function calls)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const MAINNET = 1;
|
|
||||||
const TESTNET = 3;
|
|
||||||
|
|
||||||
// Todo Resolve ENS entries
|
// Todo Resolve ENS entries
|
||||||
import contributors from "./contributors";
|
import contributors from "../contributors";
|
||||||
let options = contributors;
|
let options = contributors;
|
||||||
|
|
||||||
class App extends React.Component {
|
class Home extends React.Component {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
error: null,
|
|
||||||
errorMsg: null,
|
errorMsg: null,
|
||||||
busy: true,
|
busy: false,
|
||||||
selectedContributors: [],
|
selectedContributors: [],
|
||||||
contributorList: [],
|
contributorList: [],
|
||||||
currentContributor: {
|
currentContributor: {
|
||||||
@ -40,9 +33,8 @@ class App extends React.Component {
|
|||||||
status: []
|
status: []
|
||||||
},
|
},
|
||||||
award: 0,
|
award: 0,
|
||||||
praise: '',
|
praise: ''
|
||||||
networkName: ''
|
};
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -54,29 +46,12 @@ class App extends React.Component {
|
|||||||
this.withdrawTokens = this.withdrawTokens.bind(this);
|
this.withdrawTokens = this.withdrawTokens.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
async componentDidMount() {
|
||||||
EmbarkJS.onReady(async (err) => {
|
options = options.map(prepareOptions);
|
||||||
if (err) {
|
|
||||||
return this.setState({error: err.message || err});
|
|
||||||
}
|
|
||||||
|
|
||||||
const netId = await web3.eth.net.getId();
|
await this.getContributors();
|
||||||
if (EmbarkJS.environment === 'testnet' && netId !== TESTNET) {
|
|
||||||
this.setState({ error: 'Please connect to Ropsten' });
|
|
||||||
return;
|
|
||||||
} else if (EmbarkJS.environment === 'livenet' && netId !== MAINNET) {
|
|
||||||
this.setState({ error: 'Please connect to Mainnet' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({busy: false});
|
this.getCurrentContributorData();
|
||||||
|
|
||||||
options = options.map(prepareOptions);
|
|
||||||
|
|
||||||
await this.getContributors();
|
|
||||||
|
|
||||||
this.getCurrentContributorData();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleContributorSelection(_selectedContributors) {
|
handleContributorSelection(_selectedContributors) {
|
||||||
@ -99,7 +74,6 @@ class App extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
praise: '',
|
praise: '',
|
||||||
selectedContributors: [],
|
selectedContributors: [],
|
||||||
error: '',
|
|
||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
award: 0
|
award: 0
|
||||||
});
|
});
|
||||||
@ -132,7 +106,7 @@ class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getContributors() {
|
async getContributors() {
|
||||||
const registry = await Meritocracy.methods.getRegistry().call();
|
const registry = await Meritocracy.methods.getRegistry().call({from: web3.eth.defaultAccount});
|
||||||
const contributorList = options.filter(x => registry.includes(x.value) && x.value !== web3.eth.defaultAccount);
|
const contributorList = options.filter(x => registry.includes(x.value) && x.value !== web3.eth.defaultAccount);
|
||||||
this.setState({contributorList});
|
this.setState({contributorList});
|
||||||
}
|
}
|
||||||
@ -182,7 +156,7 @@ class App extends React.Component {
|
|||||||
async withdrawTokens(e) {
|
async withdrawTokens(e) {
|
||||||
const {currentContributor} = this.state;
|
const {currentContributor} = this.state;
|
||||||
|
|
||||||
if (currentContributor.received == 0) {
|
if (currentContributor.received === 0) {
|
||||||
this.setState({errorMsg: 'can only call withdraw when you have tokens'});
|
this.setState({errorMsg: 'can only call withdraw when you have tokens'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -210,14 +184,7 @@ class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectedContributors, contributorList, award, currentContributor, praise, busy, error, errorMsg } = this.state;
|
const { selectedContributors, contributorList, award, currentContributor, praise, busy, errorMsg } = this.state;
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return (<div>
|
|
||||||
<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>
|
|
||||||
<div>{error}</div>
|
|
||||||
</div>);
|
|
||||||
}
|
|
||||||
|
|
||||||
const maxAllocation = selectedContributors.length ? currentContributor.allocation / selectedContributors.length : 0;
|
const maxAllocation = selectedContributors.length ? currentContributor.allocation / selectedContributors.length : 0;
|
||||||
|
|
||||||
@ -278,6 +245,6 @@ const prepareOptions = option => {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
return option;
|
return option;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default App;
|
export default Home;
|
@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import App from './app';
|
import App from './App';
|
||||||
|
|
||||||
ReactDOM.render(<App />, document.getElementById('app'));
|
ReactDOM.render(
|
||||||
|
<App/>,
|
||||||
|
document.getElementById('app')
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user