add gas station container

This commit is contained in:
Jonathan Rainville 2018-08-31 16:37:06 -04:00 committed by Pascal Precht
parent 5593534343
commit ccdab1bb90
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 70 additions and 50 deletions

View File

@ -1,11 +1,7 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import React, {Component} from 'react'; import React, {Component} from 'react';
import {connect} from 'react-redux';
import {withRouter} from "react-router-dom";
import {Card, Form, Grid, StampCard, Stamp} from 'tabler-react'; import {Card, Form, Grid, StampCard, Stamp} from 'tabler-react';
import {CopyToClipboard} from 'react-copy-to-clipboard'; import {CopyToClipboard} from 'react-copy-to-clipboard';
import {listenToGasOracle, gasOracle as ethGasAction} from "../actions";
import {getOracleGasStats, getLastBlock} from "../reducers/selectors";
const COLORS = { const COLORS = {
good: 'green', good: 'green',
@ -25,13 +21,6 @@ class GasStation extends Component {
}; };
} }
componentDidMount() {
this.props.fetchEthGas();
if (!this.props.gasOracleStats.length) {
this.props.listenToGasOracle();
}
}
getGasOracleFormatted() { getGasOracleFormatted() {
let totalWait = 0; let totalWait = 0;
let totalTxs = 0; let totalTxs = 0;
@ -164,23 +153,8 @@ class GasStation extends Component {
} }
GasStation.propTypes = { GasStation.propTypes = {
gasOracleStats: PropTypes.object, gasOracleStats: PropTypes.object.isRequired,
lastBlock: PropTypes.object, lastBlock: PropTypes.object.isRequired
listenToGasOracle: PropTypes.func,
fetchEthGas: PropTypes.func
}; };
function mapStateToProps(state, _props) { export default GasStation;
return {
gasOracleStats: getOracleGasStats(state),
lastBlock: getLastBlock(state)
};
}
export default withRouter(connect(
mapStateToProps,
{
listenToGasOracle: listenToGasOracle,
fetchEthGas: ethGasAction.request
}
)(GasStation));

View File

@ -6,7 +6,7 @@ import {withRouter} from 'react-router-dom';
import {contractProfile as contractProfileAction, contractDeploy as contractDeployAction} from '../actions'; import {contractProfile as contractProfileAction, contractDeploy as contractDeployAction} from '../actions';
import ContractFunctions from '../components/ContractFunctions'; import ContractFunctions from '../components/ContractFunctions';
import DataWrapper from "../components/DataWrapper"; import DataWrapper from "../components/DataWrapper";
import GasStation from "../components/GasStation"; import GasStationContainer from "../containers/GasStationContainer";
import {getContractProfile, getContractDeploys} from "../reducers/selectors"; import {getContractProfile, getContractDeploys} from "../reducers/selectors";
class ContractDeploymentContainer extends Component { class ContractDeploymentContainer extends Component {
@ -16,17 +16,17 @@ class ContractDeploymentContainer extends Component {
render() { render() {
return ( return (
<React.Fragment>
<DataWrapper shouldRender={this.props.contractProfile !== undefined} <DataWrapper shouldRender={this.props.contractProfile !== undefined}
{...this.props} {...this.props}
render={({contractProfile, contractDeploys, postContractDeploy}) => ( render={({contractProfile, contractDeploys, postContractDeploy}) => (
<React.Fragment>
<ContractFunctions contractProfile={contractProfile} <ContractFunctions contractProfile={contractProfile}
contractFunctions={contractDeploys} contractFunctions={contractDeploys}
onlyConstructor onlyConstructor
postContractFunction={postContractDeploy}/> postContractFunction={postContractDeploy}/>
)}/> <GasStationContainer/>
<GasStation/>
</React.Fragment> </React.Fragment>
)}/>
); );
} }
} }

View File

@ -6,7 +6,7 @@ import {withRouter} from 'react-router-dom';
import {contractProfile as contractProfileAction, contractFunction as contractFunctionAction} from '../actions'; import {contractProfile as contractProfileAction, contractFunction as contractFunctionAction} from '../actions';
import ContractFunctions from '../components/ContractFunctions'; import ContractFunctions from '../components/ContractFunctions';
import DataWrapper from "../components/DataWrapper"; import DataWrapper from "../components/DataWrapper";
import GasStation from "../components/GasStation"; import GasStationContainer from "../containers/GasStationContainer";
import {getContractProfile, getContractFunctions} from "../reducers/selectors"; import {getContractProfile, getContractFunctions} from "../reducers/selectors";
class ContractFunctionsContainer extends Component { class ContractFunctionsContainer extends Component {
@ -16,21 +16,17 @@ class ContractFunctionsContainer extends Component {
render() { render() {
return ( return (
<React.Fragment>
<DataWrapper shouldRender={this.props.contractProfile !== undefined} <DataWrapper shouldRender={this.props.contractProfile !== undefined}
{...this.props} {...this.props}
render={({contractProfile, contractFunctions, postContractFunction}) => ( render={({contractProfile, contractFunctions, postContractFunction}) => (
<React.Fragment>
<ContractFunctions contractProfile={contractProfile} <ContractFunctions contractProfile={contractProfile}
contractFunctions={contractFunctions} contractFunctions={contractFunctions}
postContractFunction={postContractFunction}/> postContractFunction={postContractFunction}/>
)}/>
<DataWrapper shouldRender={this.props.gasStats !== undefined} <GasStationContainer/>
{...this.props}
render={() => (
<GasStation/>
)}/>
</React.Fragment> </React.Fragment>
)}/>
); );
} }
} }
@ -50,7 +46,6 @@ ContractFunctionsContainer.propTypes = {
contractFunctions: PropTypes.arrayOf(PropTypes.object), contractFunctions: PropTypes.arrayOf(PropTypes.object),
postContractFunction: PropTypes.func, postContractFunction: PropTypes.func,
fetchContractProfile: PropTypes.func, fetchContractProfile: PropTypes.func,
fetchEthGas: PropTypes.func,
error: PropTypes.string error: PropTypes.string
}; };

View File

@ -0,0 +1,51 @@
import PropTypes from "prop-types";
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {withRouter} from "react-router-dom";
import GasStation from '../components/GasStation';
import {listenToGasOracle, gasOracle as ethGasAction, blocks as blocksAction} from "../actions";
import DataWrapper from "../components/DataWrapper";
import {getOracleGasStats, getLastBlock} from "../reducers/selectors";
class GasStationContainer extends Component {
componentDidMount() {
this.props.fetchEthGas();
if (!this.props.gasOracleStats.length) {
this.props.listenToGasOracle();
}
if (!this.props.lastBlock) {
this.props.fetchBlocks();
}
}
render() {
return <DataWrapper shouldRender={this.props.gasOracleStats && Object.keys(this.props.gasOracleStats).length && this.props.lastBlock}
{...this.props} render={({lastBlock, gasOracleStats}) => (
<GasStation gasOracleStats={gasOracleStats} lastBlock={lastBlock}/>
)}/>;
}
}
GasStationContainer.propTypes = {
gasOracleStats: PropTypes.object,
lastBlock: PropTypes.object,
listenToGasOracle: PropTypes.func,
fetchEthGas: PropTypes.func
};
function mapStateToProps(state, _props) {
return {
gasOracleStats: getOracleGasStats(state),
lastBlock: getLastBlock(state)
};
}
export default withRouter(connect(
mapStateToProps,
{
listenToGasOracle: listenToGasOracle,
fetchEthGas: ethGasAction.request,
fetchBlocks: blocksAction.request
}
)(GasStationContainer));