-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
808 additions
and
431 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.