Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #417 from paritytech/am-fix-fresh-sync
Browse files Browse the repository at this point in the history
fix: Fresh sync shows blank screen
  • Loading branch information
amaury1093 authored Feb 11, 2019
2 parents 0dd96a7 + a9ce9e4 commit 08fa743
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 33 deletions.
26 changes: 18 additions & 8 deletions packages/fether-react/src/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ReactResizeDetector from 'react-resize-detector';
import Accounts from '../Accounts';
import BackupAccount from '../BackupAccount';
import Onboarding from '../Onboarding';
import RequireHealthOverlay from '../RequireHealthOverlay';
import Send from '../Send';
import Tokens from '../Tokens';
import Whitelist from '../Whitelist';
Expand Down Expand Up @@ -48,20 +49,29 @@ class App extends Component {
parityStore: { api }
} = this.props;

if (isFirstRun) {
return (
<div className='window'>
<Onboarding />
</div>
);
}

// The child components make use of light.js and light.js needs to be passed
// an API first, otherwise it will throw an error.
// We set parityStore.api right after we set the API for light.js, so we
// verify here that parityStore.api is defined, and if not we don't render
// the children.
// the children, just a <RequireHealthOverlay />.
if (!api) {
return null;
}

if (isFirstRun) {
return (
<div className='window'>
<Onboarding />
</div>
<ReactResizeDetector handleHeight onResize={this.handleResize}>
<RequireHealthOverlay fullscreen require='node'>
{/* Adding these components to have minimum height on window */}
<div className='content'>
<div className='window' />
</div>
</RequireHealthOverlay>
</ReactResizeDetector>
);
}

Expand Down
30 changes: 19 additions & 11 deletions packages/fether-react/src/Health/Health.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
// SPDX-License-Identifier: BSD-3-Clause

import React, { Component } from 'react';

import { branch } from 'recompose';
import { chainName$, withoutLoading } from '@parity/light.js';
import light from '@parity/light.js-react';
import withHealth from '../utils/withHealth';

@light({
chainName: () => chainName$().pipe(withoutLoading())
})
@withHealth
@branch(
({
health: {
status: { good, syncing }
}
}) => good || syncing,
// Only call light.js chainName$ if we're syncing or good
light({
chainName: () => chainName$().pipe(withoutLoading())
})
)
class Health extends Component {
render () {
return (
Expand Down Expand Up @@ -49,18 +57,18 @@ class Health extends Component {
chainName
} = this.props;

if (!status.nodeConnected && !status.internet) {
if (status.downloading) {
return `Downloading Parity Ethereum (${
payload.downloading.syncPercentage
}%)`;
} else if (status.launching) {
return 'Launching the node...';
} else if (!status.nodeConnected && !status.internet) {
return 'No internet. No node connected';
} 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.downloading) {
return `Downloading Parity Ethereum... (${
payload.downloading.syncPercentage
}%)`;
} else if (status.launching) {
return 'Launching the node...';
} else if (!status.clockSync) {
return 'Clock of host not in sync';
} else if (!status.peers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { branch } from 'recompose';
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';

@light({
chainName: () => chainName$().pipe(withoutLoading())
})
@withHealth
@branch(
({
health: {
status: { syncing }
}
}) => syncing,
// Only call light.js chainName$ if we're syncing
light({
chainName: () => chainName$().pipe(withoutLoading())
})
)
class HealthModal extends Component {
static propTypes = {
chainName: PropTypes.string,
Expand Down Expand Up @@ -46,16 +55,16 @@ class HealthModal extends Component {
health: { status }
} = this.props;

if (!status.nodeConnected && !status.internet) {
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';
} 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.downloading) {
return 'Downloading Parity Ethereum...';
} else if (status.launching) {
return 'Launching the node...';
} else if (!status.clockSync) {
return 'Clock of host not in sync';
} else if (!status.peers) {
Expand Down
11 changes: 5 additions & 6 deletions packages/fether-react/src/utils/withHealth.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,20 @@ export default compose(
]) => {
const isDownloading =
online && downloadProgress > 0 && !isParityRunning;
const isNodeConnected =
!isDownloading && isApiConnected && isParityRunning;
const isNoPeers = peerCount === undefined || peerCount.lte(1);
const isNoPeers =
isApiConnected && (peerCount === undefined || peerCount.lte(1));
const isGood =
isSync && !isNoPeers && isClockSync && isNodeConnected && online;
isSync && !isNoPeers && isClockSync && isApiConnected && online;

// Status - list of all states of health store
const status = {
internet: online, // Internet connection
nodeConnected: isNodeConnected, // Connected to local Parity Ethereum node
nodeConnected: isApiConnected, // Connected to local Parity Ethereum node
clockSync: isClockSync, // Local clock is not synchronised
downloading: isDownloading, // Currently downloading Parity Ethereum
launching: !isApiConnected, // Launching Parity Ethereum only upon startup
peers: !isNoPeers, // Connecion to peer nodes
syncing: !isSync, // Synchronising blocks
syncing: isApiConnected && !isSync, // Synchronising blocks
good: isGood // Synchronised and no issues
};

Expand Down

0 comments on commit 08fa743

Please sign in to comment.