Newer
Older
// 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';
Luke Schoen
committed
import { chainName$, withoutLoading } from '@parity/light.js';
import light from '@parity/light.js-react';
import { Modal } from 'fether-ui';
import withHealth from '../../utils/withHealth';
import loading from '../../assets/img/icons/loading.svg';
}) => syncing,
// Only call light.js chainName$ if we're syncing
light({
chainName: () => chainName$().pipe(withoutLoading())
})
)
class HealthModal extends Component {
static propTypes = {
Luke Schoen
committed
chainName: PropTypes.string,
children: PropTypes.node,
health: PropTypes.object,
visible: PropTypes.bool
};
render () {
const { children, fullscreen, visible } = this.props;
return (
<Modal
description={this.renderDescription()}
loading={loading}
title={this.renderTitle()}
visible={visible}
>
{children}
</Modal>
);
}
renderTitle = () => {
const {
health: { status }
} = this.props;
if (status.downloading) {
return 'Downloading Parity Ethereum...';
} else if (status.launching) {
return 'Launching the node...';
} else if (!status.nodeConnected && !status.internet) {
return 'No internet. No node connected';
Luke Schoen
committed
} else if (!status.nodeConnected && status.internet) {
return 'Connecting to node...';
} else if (status.nodeConnected && !status.internet) {
return 'No internet. Connected to node';
} else if (!status.clockSync) {
return 'Clock of host not in sync';
} else if (!status.peers) {
Luke Schoen
committed
return 'Connecting to peers...';
} else if (status.syncing) {
return `Syncing...`;
} else {
return '';
}
};
renderDescription = () => {
const {
chainName,
health: { payload, status }
} = this.props;
if (!status.internet) {
return 'Please connect to the Internet';
Luke Schoen
committed
} else if (status.downloading) {
return `Downloading Parity Ethereum... (${
payload.downloading.syncPercentage
}%)`;
} else if (!status.clockSync) {
return `Mac: System Preferences -> Date & Time -> Uncheck and recheck "Set date and time automatically"
Windows: Control Panel -> "Clock, Language, and Region" -> "Date and Time" -> Uncheck and recheck "Set date and time automatically"`;
} else if (!status.peers) {
return 'Searching for peers';
} else if (status.syncing) {
return `Syncing...${
Luke Schoen
committed
payload &&
Luke Schoen
committed
payload.syncing &&
payload.syncing.syncPercentage &&
payload.syncing.syncPercentage.gt(0)
? ` (${payload.syncing.syncPercentage.toFixed(0)}%)`
: ''
Luke Schoen
committed
} ${chainName}`;
} else {
return '';
}
};
}
export { HealthModal };