2018-12-11 04:13:45 -08:00
|
|
|
// @flow
|
|
|
|
import React, { type ComponentType, Component } from 'react';
|
|
|
|
|
2018-12-19 07:59:31 -08:00
|
|
|
import { LoadingScreen } from './loading-screen';
|
|
|
|
|
2018-12-11 04:13:45 -08:00
|
|
|
import rpc from '../../services/api';
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
isRunning: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
type Props = {};
|
|
|
|
|
2018-12-15 07:10:39 -08:00
|
|
|
/* eslint-disable max-len */
|
2018-12-11 04:13:45 -08:00
|
|
|
export const withDaemonStatusCheck = <PassedProps: {}>(
|
|
|
|
WrappedComponent: ComponentType<PassedProps>,
|
|
|
|
): ComponentType<$Diff<PassedProps, Props>> => class extends Component<PassedProps, State> {
|
|
|
|
timer: ?IntervalID = null;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
isRunning: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.runTest();
|
|
|
|
|
2018-12-11 14:28:05 -08:00
|
|
|
this.timer = setInterval(this.runTest, 2000);
|
2018-12-11 04:13:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.timer) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
this.timer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 14:28:05 -08:00
|
|
|
runTest = () => {
|
2018-12-11 04:13:45 -08:00
|
|
|
rpc.getinfo().then((response) => {
|
2018-12-11 14:28:05 -08:00
|
|
|
if (response) {
|
|
|
|
this.setState(() => ({ isRunning: true }));
|
|
|
|
if (this.timer) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
this.timer = null;
|
|
|
|
}
|
|
|
|
}
|
2018-12-11 04:13:45 -08:00
|
|
|
});
|
2018-12-11 14:28:05 -08:00
|
|
|
};
|
2018-12-11 04:13:45 -08:00
|
|
|
|
|
|
|
render() {
|
2018-12-12 10:59:13 -08:00
|
|
|
const { isRunning } = this.state;
|
|
|
|
|
|
|
|
if (isRunning) {
|
2018-12-11 04:13:45 -08:00
|
|
|
return <WrappedComponent {...this.props} {...this.state} />;
|
|
|
|
}
|
|
|
|
|
2018-12-19 07:59:31 -08:00
|
|
|
return <LoadingScreen />;
|
2018-12-11 04:13:45 -08:00
|
|
|
}
|
|
|
|
};
|