Unverified Commit 7cdce3b5 authored by Amaury Martiny's avatar Amaury Martiny Committed by GitHub
Browse files

feat: Try relaunching parity-ethereum node if it's not connecting after 15s (#543)

* Clean some code

* Restart node after 15s

* Remove console.lgo

* Update comment

* Remove useless arg

* remove hasCalledInitParityEthereum
parent 6667c2f9
Pipeline #50784 passed with stages
in 16 minutes and 24 seconds
......@@ -4,7 +4,9 @@
// SPDX-License-Identifier: BSD-3-Clause
import cli from 'commander';
import { DEFAULT_CHAIN, DEFAULT_WS_PORT } from '../constants';
const { productName } = require('../../../../electron-builder.json');
const { version } = require('../../../../package.json');
......
......@@ -99,7 +99,7 @@ class FetherApp extends EventEmitter {
setupGlobals = () => setupGlobals();
setupLogger = () => setupLogger();
setupMenu = () => setupMenu(this);
setupParityEthereum = () => setupParityEthereum(this);
setupParityEthereum = () => setupParityEthereum();
setupRequestListeners = () => setupRequestListeners(this);
setupSecurity = () => setupSecurity(this);
setupWinListeners = () => setupWinListeners(this);
......
......@@ -9,6 +9,7 @@ import settings from 'electron-settings';
import { bundledParityPath } from '../utils/paths';
import cli from '../cli';
import Pino from '../utils/pino';
import setupParityEthereum from '../methods/setupParityEthereum';
import { TRUSTED_LOOPBACK } from '../constants';
const pino = Pino();
......@@ -45,6 +46,11 @@ export default async (fetherApp, event, data) => {
break;
}
case 'RESTART_NODE_REQUEST': {
setupParityEthereum();
break;
}
case 'SET_LANGUAGE_REQUEST': {
event.sender.send('send-to-renderer', {
action: 'SET_LANGUAGE_RESPONSE',
......
......@@ -5,9 +5,9 @@
import ParityEthereum from '../parityEthereum';
function setupParityEthereum (fetherApp) {
function setupParityEthereum () {
// Run Parity Ethereum if not running and requested
return new ParityEthereum(fetherApp.win);
return new ParityEthereum();
}
export default setupParityEthereum;
......@@ -13,14 +13,8 @@ import Pino from '../utils/pino';
const pino = Pino();
let hasCalledInitParityEthereum = false;
class ParityEthereum {
constructor () {
if (hasCalledInitParityEthereum) {
throw new Error('Unable to initialise Parity Ethereum more than once');
}
/*
* - If an instance of Parity Ethereum is already running, we connect to it
* and then check in fether-react if the parity_versionInfo RPC returns
......
......@@ -10,7 +10,6 @@ import { inject, observer } from 'mobx-react';
import light from '@parity/light.js-react';
import i18n, { packageNS } from '../../i18n';
import RequireHealthOverlay from '../../RequireHealthOverlay';
import Health from '../../Health';
import withAccountsInfo from '../../utils/withAccountsInfo';
import Feedback from './Feedback';
......@@ -48,7 +47,7 @@ class AccountsList extends Component {
const accountsListLength = accountsList && accountsList.length;
return (
<RequireHealthOverlay require='node'>
<div>
<div className='accounts-list'>
<Header
right={
......@@ -105,7 +104,7 @@ class AccountsList extends Component {
</div>
</nav>
</div>
</RequireHealthOverlay>
</div>
);
}
}
......
......@@ -8,7 +8,6 @@ import { AccountCard } from 'fether-ui';
import { inject, observer } from 'mobx-react';
import i18n, { packageNS } from '../../../i18n';
import RequireHealthOverlay from '../../../RequireHealthOverlay';
@inject('createAccountStore')
@observer
......@@ -33,49 +32,47 @@ class AccountCopyPhrase extends Component {
const currentStep = pathname.slice(-1);
return (
<RequireHealthOverlay require='node'>
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' onSubmit={this.handleSubmit}>
<div className='text'>
<p>{i18n.t(`${packageNS}:account.create.copy_phrase.msg1`)}</p>
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' onSubmit={this.handleSubmit}>
<div className='text'>
<p>{i18n.t(`${packageNS}:account.create.copy_phrase.msg1`)}</p>
</div>
<div className='text -code'>{bip39Phrase}</div>
<div className='text'>
<div className='text -tiny'>
{i18n.t(`${packageNS}:account.create.copy_phrase.msg2`)}
<ul className='-bulleted'>
<li>
{i18n.t(`${packageNS}:account.create.copy_phrase.msg3`)}
</li>
<li>
{i18n.t(`${packageNS}:account.create.copy_phrase.msg4`)}
</li>
</ul>
</div>
<div className='text -code'>{bip39Phrase}</div>
<div className='text'>
<div className='text -tiny'>
{i18n.t(`${packageNS}:account.create.copy_phrase.msg2`)}
<ul className='-bulleted'>
<li>
{i18n.t(`${packageNS}:account.create.copy_phrase.msg3`)}
</li>
<li>
{i18n.t(`${packageNS}:account.create.copy_phrase.msg4`)}
</li>
</ul>
</div>
</div>
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button
className='button -back'
onClick={history.goBack}
type='button'
>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
)}
<button autoFocus className='button'>
{i18n.t(`${packageNS}:navigation.next`)}
</div>
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button
className='button -back'
onClick={history.goBack}
type='button'
>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
</nav>
</form>
]}
i18n={i18n}
packageNS={packageNS}
/>
</RequireHealthOverlay>
)}
<button autoFocus className='button'>
{i18n.t(`${packageNS}:navigation.next`)}
</button>
</nav>
</form>
]}
i18n={i18n}
packageNS={packageNS}
/>
);
}
}
......
......@@ -9,7 +9,6 @@ import light from '@parity/light.js-react';
import { inject, observer } from 'mobx-react';
import { addressShort, Card, Form as FetherForm } from 'fether-ui';
import RequireHealthOverlay from '../../../RequireHealthOverlay';
import Scanner from '../../../Scanner';
import withAccountsInfo from '../../../utils/withAccountsInfo';
import withHealth from '../../../utils/withHealth';
......@@ -279,23 +278,21 @@ class AccountImportOptions extends Component {
const spacer = <div style={{ height: '0.5rem' }} />;
return (
<RequireHealthOverlay require='node'>
<div className='center-md'>
{!importingFromSigner && jsonCard}
{spacer}
{signerCard}
{spacer}
{!importingFromSigner && phraseCard}
<p className='error-import-account'>{error}</p>
{currentStep > 1 && (
<nav className='form-nav -space-around'>
<button className='button -back' onClick={history.goBack}>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
</nav>
)}
</div>
</RequireHealthOverlay>
<div className='center-md'>
{!importingFromSigner && jsonCard}
{spacer}
{signerCard}
{spacer}
{!importingFromSigner && phraseCard}
<p className='error-import-account'>{error}</p>
{currentStep > 1 && (
<nav className='form-nav -space-around'>
<button className='button -back' onClick={history.goBack}>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
</nav>
)}
</div>
);
}
......
......@@ -9,7 +9,6 @@ import Blockies from 'react-blockies';
import { inject, observer } from 'mobx-react';
import i18n, { packageNS } from '../../../i18n';
import RequireHealthOverlay from '../../../RequireHealthOverlay';
import loading from '../../../assets/img/icons/loading.svg';
@inject('createAccountStore')
......@@ -62,11 +61,7 @@ class AccountName extends Component {
createAccountStore: { isImport }
} = this.props;
return (
<RequireHealthOverlay require='node'>
{isImport ? this.renderCardWhenImported() : this.renderCardWhenNew()}
</RequireHealthOverlay>
);
return isImport ? this.renderCardWhenImported() : this.renderCardWhenNew();
}
renderCardWhenImported = () => {
......
......@@ -8,7 +8,6 @@ import { AccountCard, Form as FetherForm } from 'fether-ui';
import { inject, observer } from 'mobx-react';
import i18n, { packageNS } from '../../../i18n';
import RequireHealthOverlay from '../../../RequireHealthOverlay';
@inject('createAccountStore')
@observer
......@@ -72,96 +71,91 @@ class AccountPassword extends Component {
const currentStep = pathname.slice(-1);
return (
<RequireHealthOverlay require='node'>
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' noValidate onSubmit={this.handleSubmit}>
<div className='text'>
<p>
{' '}
{jsonString
? i18n.t(
`${packageNS}:account.password.import.label_msg_unlock_json`
)
: i18n.t(
`${packageNS}:account.password.create.label_msg_password`
)}
</p>
</div>
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' noValidate onSubmit={this.handleSubmit}>
<div className='text'>
<p>
{' '}
{jsonString
? i18n.t(
`${packageNS}:account.password.import.label_msg_unlock_json`
)
: i18n.t(
`${packageNS}:account.password.create.label_msg_password`
)}
</p>
</div>
<FetherForm.Field
autoFocus
label={i18n.t(
`${packageNS}:account.password.common.label_password`
)}
onChange={this.handlePasswordChange}
required
type='password'
value={password}
/>
{!jsonString && (
<FetherForm.Field
autoFocus
label={i18n.t(
`${packageNS}:account.password.common.label_password`
`${packageNS}:account.password.common.label_password_confirm`
)}
onChange={this.handlePasswordChange}
onChange={this.handleConfirmChange}
required
type='password'
value={password}
value={confirm}
/>
{!jsonString && (
<FetherForm.Field
label={i18n.t(
`${packageNS}:account.password.common.label_password_confirm`
)}
<p>
{error &&
error +
' ' +
i18n.t(
`${packageNS}:account.password.common.error_msg_password_incorrect`
)}
onChange={this.handleConfirmChange}
required
type='password'
value={confirm}
/>
)}
</p>
<p>
{error &&
error +
' ' +
i18n.t(
`${packageNS}:account.password.common.error_msg_password_incorrect`
)}
</p>
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button
className='button -back'
onClick={history.goBack}
type='button'
>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
)}
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button
autoFocus
className='button'
disabled={
!password ||
(!jsonString && confirm !== password) ||
isLoading
}
className='button -back'
onClick={history.goBack}
type='button'
>
{i18n.t(
`${packageNS}:account.password.common.button_confirm`,
{
postfix: isImport
? i18n.t(
`${packageNS}:account.password.common.button_confirm_opt1`
)
: i18n.t(
`${packageNS}:account.password.common.button_confirm_opt2`
)
}
)}
{i18n.t(`${packageNS}:navigation.back`)}
</button>
</nav>
</form>
]}
i18n={i18n}
packageNS={packageNS}
/>
</RequireHealthOverlay>
)}
<button
autoFocus
className='button'
disabled={
!password ||
(!jsonString && confirm !== password) ||
isLoading
}
>
{i18n.t(`${packageNS}:account.password.common.button_confirm`, {
postfix: isImport
? i18n.t(
`${packageNS}:account.password.common.button_confirm_opt1`
)
: i18n.t(
`${packageNS}:account.password.common.button_confirm_opt2`
)
})}
</button>
</nav>
</form>
]}
i18n={i18n}
packageNS={packageNS}
/>
);
}
}
......
......@@ -8,7 +8,6 @@ import { AccountCard, Card, Form as FetherForm } from 'fether-ui';
import { inject, observer } from 'mobx-react';
import i18n, { packageNS } from '../../../i18n';
import RequireHealthOverlay from '../../../RequireHealthOverlay';
import AccountImportOptions from '../AccountImportOptions';
@inject('createAccountStore')
......@@ -89,24 +88,20 @@ class AccountRewritePhrase extends Component {
</form>
];
return (
<RequireHealthOverlay require='node'>
{isImport ? (
<Card>{body}</Card>
) : (
<AccountCard
address={address}
name={
address && !name
? i18n.t(`${packageNS}:account.existing.no_name`)
: name
}
drawers={body}
i18n={i18n}
packageNS={packageNS}
/>
)}
</RequireHealthOverlay>
return isImport ? (
<Card>{body}</Card>
) : (
<AccountCard
address={address}
name={
address && !name
? i18n.t(`${packageNS}:account.existing.no_name`)
: name
}
drawers={body}
i18n={i18n}
packageNS={packageNS}
/>
);
}
......
......@@ -149,51 +149,53 @@ class App extends Component {
}
return (
<div className='content'>
<div className='window'>
<RequireParityVersion>
<Modal
title={i18n.t(`${packageNS}:releases.new_release_title`)}
description={
newRelease
? i18n.t(`${packageNS}:releases.new_release_description`, {
release_name: newRelease.name
})
: ''
}
visible={newRelease && !newRelease.ignore}
buttons={this.renderModalLinks()}
>
<Router>
<Switch>
{/* The next line is the homepage */}
<Redirect exact from='/' to='/accounts' />
<Route path='/accounts' component={Accounts} />
<Route path='/onboarding' component={Onboarding} />
<Route path='/tokens/:accountAddress' component={Tokens} />
<Route
path='/whitelist/:accountAddress'
component={Whitelist}
/>
<Route
path='/backup/:accountAddress'
component={BackupAccount}
/>
<Route
path='/delete/:accountAddress'
component={DeleteAccount}
/>
<Route
path='/send/:tokenAddress/from/:accountAddress'
component={Send}
/>
<Redirect from='*' to='/' />
</Switch>
</Router>
</Modal>
</RequireParityVersion>
<RequireHealthOverlay fullscreen require='node'>
<div className='content'>
<div className='window'>
<RequireParityVersion>
<Modal
title={i18n.t(`${packageNS}:releases.new_release_title`)}
description={
newRelease
? i18n.t(`${packageNS}:releases.new_release_description`, {
release_name: newRelease.name
})
: ''
}
visible={newRelease && !newRelease.ignore}
buttons={this.renderModalLinks()}
>
<Router>
<Switch>
{/* The next line is the homepage */}
<Redirect exact from='/' to='/accounts' />
<Route path='/accounts' component={Accounts} />
<Route path='/onboarding' component={Onboarding} />
<Route path='/tokens/:accountAddress' component={Tokens} />
<Route
path='/whitelist/:accountAddress'
component={Whitelist}
/>
<Route
path='/backup/:accountAddress'
component={BackupAccount}
/>
<Route