Skip to content

Commit

Permalink
tests: add and follow eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
come-maiz committed Apr 20, 2018
1 parent bac84ff commit b99912c
Show file tree
Hide file tree
Showing 37 changed files with 808 additions and 431 deletions.
475 changes: 438 additions & 37 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"babel-preset-airbnb": "^2.4.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.7.0",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-redux": "^5.0.7",
Expand Down
32 changes: 15 additions & 17 deletions src/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import Network from '../network'
import AlertActions from './alerts'
import * as ActionTypes from '../actiontypes'
import Network from '../network';
import AlertActions from './alerts';
import * as ActionTypes from '../actiontypes';

const AccountActions = {

findAccount() {
return async function(dispatch) {
findAccount () {
return async function (dispatch) {
try {
const addresses = await Network.getAccounts()
const mainAddress = addresses[0]
dispatch(AccountActions.receiveAccount(mainAddress))
} catch(error) {
dispatch(AlertActions.showError(error))
const addresses = await Network.getAccounts();
const mainAddress = addresses[0];
dispatch(AccountActions.receiveAccount(mainAddress));
} catch (error) {
dispatch(AlertActions.showError(error));
}
}
};
},

receiveAccount(address) {
return { type: ActionTypes.RECEIVE_ACCOUNT, address }
receiveAccount (address) {
return { type: ActionTypes.RECEIVE_ACCOUNT, address };
},
};

}

export default AccountActions
export default AccountActions;
18 changes: 9 additions & 9 deletions src/actions/alerts.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as ActionTypes from '../actiontypes'
import * as ActionTypes from '../actiontypes';

const AlertActions = {
showError(error, message = null) {
console.error(error)
return { type: ActionTypes.SHOW_ERROR, message: (message || error.message) }
showError (error, message = null) {
console.error(error);
return { type: ActionTypes.SHOW_ERROR, message: (message || error.message) };
},

reset() {
return { type: ActionTypes.RESET_ERROR }
}
}
reset () {
return { type: ActionTypes.RESET_ERROR };
},
};

export default AlertActions
export default AlertActions;
12 changes: 6 additions & 6 deletions src/actions/fetching.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as ActionTypes from '../actiontypes';

const FetchingActions = {
start(message) {
return { type: ActionTypes.START_FETCHING, message }
start (message) {
return { type: ActionTypes.START_FETCHING, message };
},

stop() {
return { type: ActionTypes.STOP_FETCHING }
stop () {
return { type: ActionTypes.STOP_FETCHING };
},
}
};

export default FetchingActions
export default FetchingActions;
31 changes: 15 additions & 16 deletions src/actions/jurisdiction.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import * as ActionTypes from '../actiontypes'
import * as ActionTypes from '../actiontypes';

import { Jurisdiction } from '../contracts'
import { JURISDICTION_ADDRESS } from '../constants'
import { Jurisdiction } from '../contracts';
import { JURISDICTION_ADDRESS } from '../constants';

const JurisdictionActions = {

find() {
return async function(dispatch) {
const jurisdiction = await Jurisdiction.at(JURISDICTION_ADDRESS)
dispatch(JurisdictionActions.receive(jurisdiction))
}
find () {
return async function (dispatch) {
const jurisdiction = await Jurisdiction.at(JURISDICTION_ADDRESS);
dispatch(JurisdictionActions.receive(jurisdiction));
};
},

receive(jurisdiction) {
return async function(dispatch) {
const owner = (await jurisdiction.owner()).toString()
receive (jurisdiction) {
return async function (dispatch) {
const owner = (await jurisdiction.owner()).toString();
dispatch({
type: ActionTypes.RECEIVE_JURISDICTION,
jurisdiction: { owner },
})
}
});
};
},
}
};

export default JurisdictionActions
export default JurisdictionActions;
27 changes: 13 additions & 14 deletions src/actions/network.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import Network from '../network'
import * as ActionTypes from '../actiontypes'
import Network from '../network';
import * as ActionTypes from '../actiontypes';

const NetworkActions = {
checkConnection() {
checkConnection () {
return dispatch => {
Network.web3().isConnected() ?
dispatch(NetworkActions.connectionSucceeded()) :
dispatch(NetworkActions.connectionFailed())
}
Network.web3().isConnected()
? dispatch(NetworkActions.connectionSucceeded())
: dispatch(NetworkActions.connectionFailed());
};
},

connectionSucceeded() {
return { type: ActionTypes.CONNECTION_SUCCEEDED }
connectionSucceeded () {
return { type: ActionTypes.CONNECTION_SUCCEEDED };
},

connectionFailed() {
return { type: ActionTypes.CONNECTION_FAILED }
connectionFailed () {
return { type: ActionTypes.CONNECTION_FAILED };
},
};

}

export default NetworkActions
export default NetworkActions;
11 changes: 5 additions & 6 deletions src/actions/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import { Jurisdiction, DummyValidator } from '../contracts';
import { JURISDICTION_ADDRESS, VALIDATOR_ADDRESS } from '../constants';

const ValidationActions = {

checkValidated(address) {
checkValidated (address) {
return async function (dispatch) {
const jurisdiction = await Jurisdiction.at(JURISDICTION_ADDRESS);
const isValidated = await jurisdiction.hasAttribute(address, "VALID");
const isValidated = await jurisdiction.hasAttribute(address, 'VALID');
dispatch(ValidationActions.update(address, isValidated));
}
};
},

update(address, isValidated) {
update (address, isValidated) {
return { type: ActionTypes.VALIDATION_UPDATED, address, isValidated };
},

validate(address) {
validate (address) {
return async function (dispatch) {
const validator = await DummyValidator.at(VALIDATOR_ADDRESS);
await validator.validate({ from: address });
Expand Down
33 changes: 16 additions & 17 deletions src/actions/validators.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import { Jurisdiction } from '../contracts'
import AlertActions from './alerts'
import * as ActionTypes from '../actiontypes'
import { JURISDICTION_ADDRESS } from '../constants'
import { Jurisdiction } from '../contracts';
import AlertActions from './alerts';
import * as ActionTypes from '../actiontypes';
import { JURISDICTION_ADDRESS } from '../constants';

const ValidatorsActions = {

findAll() {
return async function(dispatch) {
const jurisdiction = await Jurisdiction.at(JURISDICTION_ADDRESS)
findAll () {
return async function (dispatch) {
const jurisdiction = await Jurisdiction.at(JURISDICTION_ADDRESS);
// FIXME this is very slow. We have to add a function to the Jurisdiction
// contract that returns all the validators.
// See https://github.com/TPL-protocol/tpl-contracts/issues/2
// --elopio - 20180704
const events = jurisdiction.ValidatorAdded({}, { fromBlock: 0, toBlock: 'latest' });
// FIXME this is not taking reorgs into account
events.watch(function(error, result) {
if(error) AlertActions.showError(error)
else dispatch(ValidatorsActions.add(result.args.validator))
})
}
events.watch(function (error, result) {
if (error) AlertActions.showError(error);
else dispatch(ValidatorsActions.add(result.args.validator));
});
};
},

add(validator) {
return { type: ActionTypes.ADD_VALIDATOR, validator }
add (validator) {
return { type: ActionTypes.ADD_VALIDATOR, validator };
},
}
};

export default ValidatorsActions
export default ValidatorsActions;
21 changes: 7 additions & 14 deletions src/actions/wallet.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
import * as ActionTypes from '../actiontypes';
import Network from '../network'

import { SampleCrowdsale } from '../contracts';
import { SAMPLE_CROWDSALE_ADDRESS } from '../constants';
import { SAMPLE_TOKEN_ADDRESS } from '../constants';
import { SampleToken, } from '../contracts';

import Network from '../network';

import { SampleCrowdsale, SampleToken } from '../contracts';
import { SAMPLE_CROWDSALE_ADDRESS, SAMPLE_TOKEN_ADDRESS } from '../constants';

const WalletActions = {

getBalance(address) {
getBalance (address) {
return async function (dispatch) {
const sampleToken = await SampleToken.at(SAMPLE_TOKEN_ADDRESS);
const balance = await sampleToken.balanceOf(address);
dispatch(WalletActions.updateBalance(address, balance));
};
},

updateBalance(address, balance) {
updateBalance (address, balance) {
return { type: ActionTypes.BALANCE_UPDATED, address, balance };
},


buy(address) {
buy (address) {
return async function (dispatch) {
const sampleCrowdsale = await SampleCrowdsale.at(SAMPLE_CROWDSALE_ADDRESS);
await sampleCrowdsale.sendTransaction({ from: address, value: Network.web3().toWei(0.1, "ether") });
await sampleCrowdsale.sendTransaction({ from: address, value: Network.web3().toWei(0.1, 'ether') });
dispatch(WalletActions.getBalance(address));
};
},

};

export default WalletActions;
10 changes: 5 additions & 5 deletions src/actiontypes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const SHOW_ERROR = 'SHOW_ERROR';
export const RESET_ERROR = 'RESET_ERROR';

export const START_FETCHING = 'START_FETCHING'
export const STOP_FETCHING = 'STOP_FETCHING'
export const START_FETCHING = 'START_FETCHING';
export const STOP_FETCHING = 'STOP_FETCHING';

export const CONNECTION_FAILED = 'CONNECTION_FAILED'
export const CONNECTION_SUCCEEDED = 'CONNECTION_SUCCEEDED'
export const CONNECTION_FAILED = 'CONNECTION_FAILED';
export const CONNECTION_SUCCEEDED = 'CONNECTION_SUCCEEDED';

export const RECEIVE_JURISDICTION = 'RECEIVE_JURISDICTION'
export const RECEIVE_JURISDICTION = 'RECEIVE_JURISDICTION';

export const ADD_VALIDATOR = 'ADD_VALIDATOR';

Expand Down
16 changes: 7 additions & 9 deletions src/components/Account.react.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';

import AccountActions from "../actions/accounts";
import AccountActions from '../actions/accounts';

class Account extends Component {

componentWillMount() {
componentWillMount () {
this.props.findAccount();
}

render() {
render () {
return (
<div>
<p>My address is { this.props.address }</p>
</div>
);
}

}

function mapStateToProps({ accounts }) {
function mapStateToProps ({ accounts }) {
return { address: accounts.address };
}

function mapDispatchToProps(dispatch) {
return({
function mapDispatchToProps (dispatch) {
return ({
findAccount: () => dispatch(AccountActions.findAccount()),
});
}

export default connect(
mapStateToProps,
mapDispatchToProps
mapDispatchToProps,
)(Account);
25 changes: 12 additions & 13 deletions src/components/Alert.react.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React from 'react'
import { connect } from 'react-redux'
import AlertActions from '../actions/alerts'
import React from 'react';
import { connect } from 'react-redux';
import AlertActions from '../actions/alerts';

class Alert extends React.Component {

render() {
render () {
const alert = this.props.alert;
return !alert ? <div/> :
<div>
<p>{alert.message} <span onClick={this._cleanAlert}>x</span>
</p>
</div>
</div>;
}

_cleanAlert = e => {
Expand All @@ -19,17 +18,17 @@ class Alert extends React.Component {
}
}

function mapStateToProps({ alert }) {
return { alert }
function mapStateToProps ({ alert }) {
return { alert };
}

function mapDispatchToProps(dispatch) {
return({
reset: () => dispatch(AlertActions.reset())
function mapDispatchToProps (dispatch) {
return ({
reset: () => dispatch(AlertActions.reset()),
});
}

export default connect(
mapStateToProps,
mapDispatchToProps
)(Alert)
mapDispatchToProps,
)(Alert);
Loading

0 comments on commit b99912c

Please sign in to comment.