Stop gas oracle

This commit is contained in:
Anthony Laibe 2018-10-04 16:33:12 +01:00 committed by Pascal Precht
parent d6b348a869
commit 52a5f5dc71
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
3 changed files with 28 additions and 10 deletions

View File

@ -260,6 +260,7 @@ export const WATCH_NEW_CONTRACT_LOGS = 'WATCH_NEW_CONTRACT_LOGS';
export const INIT_BLOCK_HEADER = 'INIT_BLOCK_HEADER'; export const INIT_BLOCK_HEADER = 'INIT_BLOCK_HEADER';
export const STOP_BLOCK_HEADER = 'STOP_BLOCK_HEADER'; export const STOP_BLOCK_HEADER = 'STOP_BLOCK_HEADER';
export const WATCH_GAS_ORACLE = 'WATCH_GAS_ORACLE'; export const WATCH_GAS_ORACLE = 'WATCH_GAS_ORACLE';
export const STOP_GAS_ORACLE = 'STOP_GAS_ORACLE';
export function listenToProcessLogs(processName) { export function listenToProcessLogs(processName) {
return { return {
@ -292,4 +293,10 @@ export function listenToGasOracle(){
}; };
} }
export function stopGasOracle(){
return {
type: STOP_GAS_ORACLE
};
}

View File

@ -3,19 +3,19 @@ import React, {Component} from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {withRouter} from "react-router-dom"; import {withRouter} from "react-router-dom";
import GasStation from '../components/GasStation'; import GasStation from '../components/GasStation';
import {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";
class GasStationContainer extends Component { class GasStationContainer extends Component {
componentDidMount() { componentDidMount() {
this.props.fetchEthGas(); this.props.fetchEthGas();
if (!this.props.gasOracleStats.length) {
this.props.listenToGasOracle(); this.props.listenToGasOracle();
}
if (!this.props.lastBlock) {
this.props.fetchBlocks(); this.props.fetchBlocks();
} }
componentWillUnmount() {
this.props.stopGasOracle();
} }
render() { render() {
@ -31,6 +31,8 @@ GasStationContainer.propTypes = {
gasOracleStats: PropTypes.object, gasOracleStats: PropTypes.object,
lastBlock: PropTypes.object, lastBlock: PropTypes.object,
listenToGasOracle: PropTypes.func, listenToGasOracle: PropTypes.func,
stopGasOracle: PropTypes.func,
fetchBlocks: PropTypes.func,
fetchEthGas: PropTypes.func fetchEthGas: PropTypes.func
}; };
@ -44,8 +46,9 @@ function mapStateToProps(state, _props) {
export default withRouter(connect( export default withRouter(connect(
mapStateToProps, mapStateToProps,
{ {
listenToGasOracle: listenToGasOracle,
fetchEthGas: ethGasAction.request, fetchEthGas: ethGasAction.request,
fetchBlocks: blocksAction.request fetchBlocks: blocksAction.request,
listenToGasOracle,
stopGasOracle
} }
)(GasStationContainer)); )(GasStationContainer));

View File

@ -259,7 +259,15 @@ export function *listenGasOracle() {
const socket = api.websocketGasOracle(credentials); const socket = api.websocketGasOracle(credentials);
const channel = yield call(createChannel, socket); const channel = yield call(createChannel, socket);
while (true) { while (true) {
const gasOracleStats = yield take(channel); const { cancel, gasOracleStats } = yield race({
gasOracleStats: take(channel),
cancel: take(actions.STOP_GAS_ORACLE)
});
if (cancel) {
channel.close();
return;
}
yield put(actions.gasOracle.success(gasOracleStats)); yield put(actions.gasOracle.success(gasOracleStats));
} }
} }