// Copyright 2015-2018 Parity Technologies (UK) Ltd. // This file is part of Parity. // // SPDX-License-Identifier: BSD-3-Clause import React, { Component } from 'react'; import PropTypes from 'prop-types'; import withHealth, { STATUS } from '../utils/withHealth'; import loading from '../assets/img/icons/loading.svg'; function statusMatches (status, require) { switch (require) { case 'connected': return ( status !== STATUS.NOINTERNET && status !== STATUS.DOWNLOADING && status !== STATUS.LAUNCHING ); case 'sync': return status === STATUS.GOOD; default: throw new Error(`Status '${status}' must be one of 'connected|sync'.`); } } @withHealth class RequireHealthOverlay extends Component { static propTypes = { require: PropTypes.oneOf(['connected', 'sync']), fullscreen: PropTypes.bool }; state = { visible: false }; componentDidMount () { this.updateVisibility(); } componentDidUpdate () { this.updateVisibility(); } updateVisibility = () => { if (statusMatches(this.props.health.status, this.props.require)) { if (this.state.visible !== false) { this.setState({ visible: false }); } } else { if (this.state.visible === false) { this.setState({ visible: true }); } } } render () { const { visible } = this.state; const { fullscreen } = this.props; return visible === true ? (
{this.renderDescription()}