From 33193494cc2ceaa3286b8251cc603f32985d8801 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 19 Mar 2018 16:09:12 +0100 Subject: [PATCH 1/2] Require parity >=1.10 before launching UI --- package-lock.json | 7 ---- package.json | 1 + src/Connection/connection.js | 74 +++++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 448808d..1401e5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -525,13 +525,6 @@ "@parity/jsonrpc": "2.1.5", "@parity/ledger": "2.1.2", "@parity/shared": "2.2.25" - }, - "dependencies": { - "@parity/jsonrpc": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@parity/jsonrpc/-/jsonrpc-2.1.5.tgz", - "integrity": "sha512-M6aLgssTfqloNgVFuzxSQ3J5RJ5T9g4a4wka1QVumaud7e4ubFjuJgR0F+0aQ/H1zdiTSMDHSmoaeAp8UoE4fA==" - } } }, "@parity/plugin-signer-account": { diff --git a/package.json b/package.json index 3cdc46e..bd3a288 100644 --- a/package.json +++ b/package.json @@ -149,6 +149,7 @@ }, "dependencies": { "@parity/api": "2.1.20", + "@parity/mobx": "1.1.2", "@parity/plugin-signer-account": "github:parity-js/plugin-signer-account#3acd84ba1965f9ee419edd04d84e13e097e6d661", "@parity/plugin-signer-default": "github:parity-js/plugin-signer-default#dcf8cf23bb050070b6a691413b974b5c2d7d1ce6", "@parity/plugin-signer-hardware": "github:parity-js/plugin-signer-hardware#e8b8a4e67adc37870e370d22805632d08012b9ee", diff --git a/src/Connection/connection.js b/src/Connection/connection.js index 2cc2073..c035ceb 100644 --- a/src/Connection/connection.js +++ b/src/Connection/connection.js @@ -18,7 +18,9 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { FormattedMessage } from 'react-intl'; import isElectron from 'is-electron'; +import { observer } from 'mobx-react'; import PropTypes from 'prop-types'; +import stores from '@parity/mobx'; import GradientBg from '@parity/ui/lib/GradientBg'; import Icon from 'semantic-ui-react/dist/commonjs/elements/Icon'; @@ -33,6 +35,7 @@ if (isElectron()) { electron = window.require('electron'); } +@observer class Connection extends Component { static contextTypes = { api: PropTypes.object.isRequired @@ -51,6 +54,8 @@ class Connection extends Component { validToken: false } + versionInfoStore = stores.parity.versionInfo().get(this.context.api) + componentDidMount () { if (isElectron()) { const { ipcRenderer, remote } = electron; @@ -75,6 +80,18 @@ class Connection extends Component { } } + /** + * Electron UI requires parity version >=1.10.0 + */ + isVersionCorrect = () => { + const { versionInfo } = this.versionInfoStore; + + if (!versionInfo) { return true; } // Simpler to return true when pinging for parity_versionInfo + const { version: { major, minor } } = versionInfo; + + return major > 1 || (major === 1 && minor >= 10); + } + handleOpenWebsite = () => { const { shell } = electron; @@ -82,10 +99,9 @@ class Connection extends Component { } render () { - const { isConnecting, isConnected, needsToken } = this.props; - const { parityInstallLocation } = this.state; + const { isConnecting, isConnected } = this.props; - if (!isConnecting && isConnected) { + if (!isConnecting && isConnected && this.isVersionCorrect()) { return null; } @@ -102,28 +118,35 @@ class Connection extends Component {
- { - needsToken - ? - : parityInstallLocation - ? - : - } + {this.renderIcon()}
- { - needsToken - ? this.renderSigner() - : parityInstallLocation - ? this.renderPing() - : this.renderParityNotInstalled() - } + {this.renderText()} ); } + renderIcon = () => { + const { isConnected, needsToken } = this.props; + const { parityInstallLocation } = this.state; + + if (needsToken) { return ; } + if (!parityInstallLocation || (isConnected && !this.isVersionCorrect())) { return ; } + return ; + } + + renderText = () => { + const { isConnected, needsToken } = this.props; + const { parityInstallLocation } = this.state; + + if (needsToken) { return this.renderSigner(); } + if (!parityInstallLocation) { return this.renderParityNotInstalled(); } + if (isConnected && !this.isVersionCorrect()) { return this.renderIncorrectVersion(); } + return this.renderPing(); + } + renderSigner () { const { loading, token, validToken } = this.state; const { isConnecting, needsToken } = this.props; @@ -202,6 +225,23 @@ class Connection extends Component { ); } + renderIncorrectVersion () { + const { versionInfo: { version: { major, minor, patch } } } = this.versionInfoStore; + + return ( +
+ https://parity.io, + version: `${major}.${minor}.${patch}` + } } + /> +
+ ); + } + validateToken = (_token) => { const token = _token.trim(); const validToken = /^[a-zA-Z0-9]{4}(-)?[a-zA-Z0-9]{4}(-)?[a-zA-Z0-9]{4}(-)?[a-zA-Z0-9]{4}$/.test(token); -- GitLab From 0596346ce131766be540e4c0c809258798b4fc09 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 19 Mar 2018 16:16:14 +0100 Subject: [PATCH 2/2] Remove uesless code --- src/Connection/connection.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Connection/connection.js b/src/Connection/connection.js index c035ceb..934256f 100644 --- a/src/Connection/connection.js +++ b/src/Connection/connection.js @@ -129,21 +129,21 @@ class Connection extends Component { } renderIcon = () => { - const { isConnected, needsToken } = this.props; + const { needsToken } = this.props; const { parityInstallLocation } = this.state; if (needsToken) { return ; } - if (!parityInstallLocation || (isConnected && !this.isVersionCorrect())) { return ; } + if (!parityInstallLocation || !this.isVersionCorrect()) { return ; } return ; } renderText = () => { - const { isConnected, needsToken } = this.props; + const { needsToken } = this.props; const { parityInstallLocation } = this.state; if (needsToken) { return this.renderSigner(); } if (!parityInstallLocation) { return this.renderParityNotInstalled(); } - if (isConnected && !this.isVersionCorrect()) { return this.renderIncorrectVersion(); } + if (!this.isVersionCorrect()) { return this.renderIncorrectVersion(); } return this.renderPing(); } -- GitLab