// @flow import React, { type ComponentType, Component } from 'react'; import rpc from '../../services/api'; type State = { isRunning: boolean, }; type Props = {}; export const withDaemonStatusCheck = ( WrappedComponent: ComponentType, ): ComponentType<$Diff> => class extends Component { timer: ?IntervalID = null; state = { isRunning: false, }; componentDidMount() { this.runTest(); this.timer = setInterval(this.runTest, 2000); } componentWillUnmount() { if (this.timer) { clearInterval(this.timer); this.timer = null; } } runTest = () => { rpc.getinfo().then((response) => { if (response) { this.setState(() => ({ isRunning: true })); if (this.timer) { clearInterval(this.timer); this.timer = null; } } }); }; render() { const { isRunning } = this.state; if (isRunning) { return ; } return 'Daemon is starting...'; } };