From ccdab1bb90cfd65273dd4e2c3bf87039014a9719 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 31 Aug 2018 16:37:06 -0400 Subject: [PATCH] add gas station container --- embark-ui/src/components/GasStation.js | 32 ++---------- .../containers/ContractDeploymentContainer.js | 16 +++--- .../containers/ContractFunctionsContainer.js | 21 +++----- .../src/containers/GasStationContainer.js | 51 +++++++++++++++++++ 4 files changed, 70 insertions(+), 50 deletions(-) create mode 100644 embark-ui/src/containers/GasStationContainer.js diff --git a/embark-ui/src/components/GasStation.js b/embark-ui/src/components/GasStation.js index da4caab7..786c48c6 100644 --- a/embark-ui/src/components/GasStation.js +++ b/embark-ui/src/components/GasStation.js @@ -1,11 +1,7 @@ import PropTypes from "prop-types"; 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 {CopyToClipboard} from 'react-copy-to-clipboard'; -import {listenToGasOracle, gasOracle as ethGasAction} from "../actions"; -import {getOracleGasStats, getLastBlock} from "../reducers/selectors"; const COLORS = { good: 'green', @@ -25,13 +21,6 @@ class GasStation extends Component { }; } - componentDidMount() { - this.props.fetchEthGas(); - if (!this.props.gasOracleStats.length) { - this.props.listenToGasOracle(); - } - } - getGasOracleFormatted() { let totalWait = 0; let totalTxs = 0; @@ -164,23 +153,8 @@ class GasStation extends Component { } GasStation.propTypes = { - gasOracleStats: PropTypes.object, - lastBlock: PropTypes.object, - listenToGasOracle: PropTypes.func, - fetchEthGas: PropTypes.func + gasOracleStats: PropTypes.object.isRequired, + lastBlock: PropTypes.object.isRequired }; -function mapStateToProps(state, _props) { - return { - gasOracleStats: getOracleGasStats(state), - lastBlock: getLastBlock(state) - }; -} - -export default withRouter(connect( - mapStateToProps, - { - listenToGasOracle: listenToGasOracle, - fetchEthGas: ethGasAction.request - } -)(GasStation)); +export default GasStation; diff --git a/embark-ui/src/containers/ContractDeploymentContainer.js b/embark-ui/src/containers/ContractDeploymentContainer.js index 5cba6e0c..f6c264e5 100644 --- a/embark-ui/src/containers/ContractDeploymentContainer.js +++ b/embark-ui/src/containers/ContractDeploymentContainer.js @@ -6,7 +6,7 @@ import {withRouter} from 'react-router-dom'; import {contractProfile as contractProfileAction, contractDeploy as contractDeployAction} from '../actions'; import ContractFunctions from '../components/ContractFunctions'; import DataWrapper from "../components/DataWrapper"; -import GasStation from "../components/GasStation"; +import GasStationContainer from "../containers/GasStationContainer"; import {getContractProfile, getContractDeploys} from "../reducers/selectors"; class ContractDeploymentContainer extends Component { @@ -16,17 +16,17 @@ class ContractDeploymentContainer extends Component { render() { return ( - - ( + ( + - )}/> - - + + + )}/> ); } } diff --git a/embark-ui/src/containers/ContractFunctionsContainer.js b/embark-ui/src/containers/ContractFunctionsContainer.js index 4fc871f2..025e9ace 100644 --- a/embark-ui/src/containers/ContractFunctionsContainer.js +++ b/embark-ui/src/containers/ContractFunctionsContainer.js @@ -6,7 +6,7 @@ import {withRouter} from 'react-router-dom'; import {contractProfile as contractProfileAction, contractFunction as contractFunctionAction} from '../actions'; import ContractFunctions from '../components/ContractFunctions'; import DataWrapper from "../components/DataWrapper"; -import GasStation from "../components/GasStation"; +import GasStationContainer from "../containers/GasStationContainer"; import {getContractProfile, getContractFunctions} from "../reducers/selectors"; class ContractFunctionsContainer extends Component { @@ -16,21 +16,17 @@ class ContractFunctionsContainer extends Component { render() { return ( - - ( + ( + - )}/> - ( - - )}/> - + + + )}/> ); } } @@ -50,7 +46,6 @@ ContractFunctionsContainer.propTypes = { contractFunctions: PropTypes.arrayOf(PropTypes.object), postContractFunction: PropTypes.func, fetchContractProfile: PropTypes.func, - fetchEthGas: PropTypes.func, error: PropTypes.string }; diff --git a/embark-ui/src/containers/GasStationContainer.js b/embark-ui/src/containers/GasStationContainer.js new file mode 100644 index 00000000..0c2518b1 --- /dev/null +++ b/embark-ui/src/containers/GasStationContainer.js @@ -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 ( + + )}/>; + + } +} + +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));