Merge pull request #1015 from embark-framework/bug_fix/gas-estimator

Add a warning when there is no blocks for the estimator
This commit is contained in:
Eric Mastro 2018-10-31 10:37:26 +01:00 committed by GitHub
commit 63847b7842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -4,7 +4,7 @@ import React from "react";
import Loading from '../components/Loading'; import Loading from '../components/Loading';
import Error from '../components/Error'; import Error from '../components/Error';
const DataWrapper = ({error, loading, shouldRender, render, ...rest}) => { const DataWrapper = ({error, loading, shouldRender, render, elseRender, ...rest}) => {
if (error) { if (error) {
return <Error error={error} />; return <Error error={error} />;
} }
@ -17,6 +17,10 @@ const DataWrapper = ({error, loading, shouldRender, render, ...rest}) => {
return <Loading />; return <Loading />;
} }
if (elseRender) {
return elseRender(rest);
}
return <React.Fragment />; return <React.Fragment />;
}; };
@ -24,6 +28,7 @@ DataWrapper.propTypes = {
error: PropTypes.string, error: PropTypes.string,
loading: PropTypes.bool, loading: PropTypes.bool,
render: PropTypes.func, render: PropTypes.func,
elseRender: PropTypes.func,
shouldRender: PropTypes.bool shouldRender: PropTypes.bool
}; };

View File

@ -5,6 +5,7 @@ import GasStation from '../components/GasStation';
import {stopGasOracle, listenToGasOracle, gasOracle as ethGasAction, blocks as blocksAction} from "../actions"; import {stopGasOracle, listenToGasOracle, gasOracle as ethGasAction, blocks as blocksAction} from "../actions";
import DataWrapper from "../components/DataWrapper"; import DataWrapper from "../components/DataWrapper";
import {getOracleGasStats, getLastBlock} from "../reducers/selectors"; import {getOracleGasStats, getLastBlock} from "../reducers/selectors";
import {Alert} from 'reactstrap';
class GasStationContainer extends Component { class GasStationContainer extends Component {
componentDidMount() { componentDidMount() {
@ -18,6 +19,9 @@ class GasStationContainer extends Component {
} }
getCurrentGas() { getCurrentGas() {
if (!this.gasStation) {
return 'Unavailable';
}
return this.gasStation.getCurrentGas(); return this.gasStation.getCurrentGas();
} }
@ -25,7 +29,13 @@ class GasStationContainer extends Component {
return <DataWrapper shouldRender={Boolean(this.props.gasOracleStats && Object.keys(this.props.gasOracleStats).length && this.props.lastBlock)} return <DataWrapper shouldRender={Boolean(this.props.gasOracleStats && Object.keys(this.props.gasOracleStats).length && this.props.lastBlock)}
{...this.props} render={({lastBlock, gasOracleStats}) => ( {...this.props} render={({lastBlock, gasOracleStats}) => (
<GasStation gasOracleStats={gasOracleStats} lastBlock={lastBlock} ref={instance => { this.gasStation = instance; }}/> <GasStation gasOracleStats={gasOracleStats} lastBlock={lastBlock} ref={instance => { this.gasStation = instance; }}/>
)}/>; )} elseRender={() => {
let message = 'Currently not enough blocks mined to estimated';
if (Object.keys(this.props.gasOracleStats).length === 0) {
message = 'No blocks detected. If you are connected using an RPC connection, switch to WS to have access to new block events.'
}
return (<Alert color="danger">{message}</Alert>)
}}/>;
} }
} }