From fecad8d665e8f3fc598bbcb452375db1eac69ce9 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Thu, 2 Aug 2018 18:06:51 +0200 Subject: [PATCH 1/5] Remove nodeHealth$, use peerCount$ --- packages/fether-react/src/Health/Health.js | 4 +- packages/fether-react/src/Overlay/Overlay.js | 6 +- .../assets/sass/components/_alert-screen.scss | 1 + .../fether-react/src/stores/healthStore.js | 73 ++++--------------- 4 files changed, 20 insertions(+), 64 deletions(-) diff --git a/packages/fether-react/src/Health/Health.js b/packages/fether-react/src/Health/Health.js index 02d6c6d8..fc2f584e 100644 --- a/packages/fether-react/src/Health/Health.js +++ b/packages/fether-react/src/Health/Health.js @@ -60,8 +60,8 @@ class Health extends Component { return `Downloading... (${payload.percentage}%)`; case STATUS.GOOD: return 'Synced'; - case STATUS.NOINTERNET: - return 'No internet'; + case STATUS.NOPEERS: + return 'Not connected to any peers'; case STATUS.RUNNING: return 'Running...'; case STATUS.SYNCING: diff --git a/packages/fether-react/src/Overlay/Overlay.js b/packages/fether-react/src/Overlay/Overlay.js index 93f9ee50..bc8407a6 100644 --- a/packages/fether-react/src/Overlay/Overlay.js +++ b/packages/fether-react/src/Overlay/Overlay.js @@ -74,7 +74,7 @@ class Overlays extends Component { switch (status) { case STATUS.CLOCKNOTSYNC: - return `Mac: System Preferences -> Date & Time -> Uncheck and recheck + 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"`; @@ -83,7 +83,7 @@ class Overlays extends Component { return payload && payload.percentage && payload.percentage.gt(0) ? `${payload.percentage.toFixed(0)}%` : ''; - case STATUS.NOINTERNET: + case STATUS.NOPEERS: return 'Getting some more peers...'; default: return ''; @@ -102,7 +102,7 @@ class Overlays extends Component { return 'Your clock is not sync'; case STATUS.DOWNLOADING: return 'Downloading Parity...'; - case STATUS.NOINTERNET: + case STATUS.NOPEERS: return 'Bad connectivity'; case STATUS.RUNNING: return 'Connecting to the node...'; diff --git a/packages/fether-react/src/assets/sass/components/_alert-screen.scss b/packages/fether-react/src/assets/sass/components/_alert-screen.scss index b4953dc9..737a136e 100644 --- a/packages/fether-react/src/assets/sass/components/_alert-screen.scss +++ b/packages/fether-react/src/assets/sass/components/_alert-screen.scss @@ -22,6 +22,7 @@ .alert-screen_text { margin-top: 1rem; text-align: center; + white-space: pre-line; h1, h2, big, diff --git a/packages/fether-react/src/stores/healthStore.js b/packages/fether-react/src/stores/healthStore.js index 435b8ffe..ea51f499 100644 --- a/packages/fether-react/src/stores/healthStore.js +++ b/packages/fether-react/src/stores/healthStore.js @@ -7,7 +7,7 @@ import { action, computed, observable } from 'mobx'; import BigNumber from 'bignumber.js'; import isElectron from 'is-electron'; -import { nodeHealth$, syncing$ } from '@parity/light.js'; +import { peerCount$, syncing$ } from '@parity/light.js'; import Debug from '../utils/debug'; import parityStore from './parityStore'; @@ -22,19 +22,18 @@ export const STATUS = { CLOCKNOTSYNC: 'CLOCKNOTSYNC', // Local clock is not sync DOWNLOADING: 'DOWNLOADING', // Currently downloading Parity GOOD: 'GOOD', // Everything's fine - NOINTERNET: 'NOINTERNET', // No network connection - OTHER: 'OTHER', // Unknown state, might have a payload + NOPEERS: 'NOPEERS', // Not connected to any peers RUNNING: 'RUNNING', // Parity is running (only checked at startup) SYNCING: 'SYNCING' // Obvious }; export class HealthStore { - @observable nodeHealth; + @observable peerCount; @observable syncing; @observable clockSync; constructor () { - nodeHealth$().subscribe(this.setNodeHealth); + peerCount$(({withoutLoading: true})).subscribe(this.setPeerCount); syncing$().subscribe(this.setSyncing); if (!electron) { @@ -80,9 +79,7 @@ export class HealthStore { // Check if we get responses from the WS server if ( - !parityStore.isApiConnected || - !this.nodeHealth || - !Object.keys(this.nodeHealth).length + !parityStore.isApiConnected ) { return { status: STATUS.CANTCONNECT @@ -105,64 +102,22 @@ export class HealthStore { }; } - // Find out if there are bad statuses - const bad = Object.values(this.nodeHealth) - .filter(x => x) - .map(({ status }) => status) - .find(s => s === 'bad'); - // Find out if there are needsAttention statuses - const needsAttention = Object.keys(this.nodeHealth) - .filter(key => key !== 'time') - .map(key => this.nodeHealth[key]) - .filter(x => x) - .map(({ status }) => status) - .find(s => s === 'needsattention'); - - if (!bad && !needsAttention) { - return { - status: STATUS.GOOD - }; + if (this.clockSync && !this.clockSync.isClockSync) { + return { status: STATUS.CLOCKNOTSYNC }; } - // Now we have a bad or a needsattention message - - // Get all non-empty messages from all statuses - const details = Object.values(this.nodeHealth) - .map(({ message }) => message) - .filter(x => x); - - // If status is bad or needsattention, there should be an associated - // message. Just in case, we do an additional test. - if (!details || !details.length) { - return { status: STATUS.OTHER }; + if (this.peerCount.eq(0)) { + return { status: STATUS.NOPEERS }; } - const message = details[0]; - - if ( - message === - "Your node is still syncing, the values you see might be outdated. Wait until it's fully synced." - ) { - return { status: STATUS.SYNCING }; - } - - if ( - message === - 'You are not connected to any peers. There is most likely some network issue. Fix connectivity.' - ) { - return { status: STATUS.NOINTERNET, payload: message }; - } - - if (this.clockSync && this.clockSync.isClockSync) { - return { status: STATUS.CLOCKNOTSYNC, payload: message }; - } - - return { status: STATUS.OTHER, payload: message }; + return { + status: STATUS.GOOD + }; } @action - setNodeHealth = nodeHealth => { - this.nodeHealth = nodeHealth; + setPeerCount = peerCount => { + this.peerCount = peerCount; }; @action -- GitLab From c3da800a26336ef5bf4b1e78e57c66bd07fd89c4 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 6 Aug 2018 15:53:32 +0200 Subject: [PATCH 2/5] Update `@parity/light.js` dependency --- packages/fether-react/package.json | 2 +- packages/light-hoc/package.json | 2 +- yarn.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/fether-react/package.json b/packages/fether-react/package.json index d4709fd5..0e8858d8 100644 --- a/packages/fether-react/package.json +++ b/packages/fether-react/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "@parity/api": "^2.1.22", - "@parity/light.js": "https://github.com/parity-js/light.js#458d9318ef16bc583375d7a5cd414e2939d6ecfd", + "@parity/light.js": "https://github.com/parity-js/light.js#f2e4648db57a97380ad374d7cd15342f44a5ade1", "@parity/shared": "^3.0.2", "bignumber.js": "^4.1.0", "debounce-promise": "^3.1.0", diff --git a/packages/light-hoc/package.json b/packages/light-hoc/package.json index 23fd9094..dbdf9776 100644 --- a/packages/light-hoc/package.json +++ b/packages/light-hoc/package.json @@ -31,7 +31,7 @@ "start": "yarn build --watch" }, "peerDependencies": { - "@parity/light.js": "https://github.com/parity-js/light.js#458d9318ef16bc583375d7a5cd414e2939d6ecfd", + "@parity/light.js": "https://github.com/parity-js/light.js#f2e4648db57a97380ad374d7cd15342f44a5ade1", "react": "^16.4.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 5d2abf81..29cd7fb3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -977,9 +977,9 @@ u2f-api "0.0.9" u2f-api-polyfill "0.4.3" -"@parity/light.js@https://github.com/parity-js/light.js#458d9318ef16bc583375d7a5cd414e2939d6ecfd": +"@parity/light.js@https://github.com/parity-js/light.js#f2e4648db57a97380ad374d7cd15342f44a5ade1": version "1.0.0" - resolved "https://github.com/parity-js/light.js#458d9318ef16bc583375d7a5cd414e2939d6ecfd" + resolved "https://github.com/parity-js/light.js#f2e4648db57a97380ad374d7cd15342f44a5ade1" dependencies: "@parity/api" "^2.1.23" json-prune "^1.1.0" -- GitLab From 4502d3ab04febefc01534524dadc70b2aef2b682 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 6 Aug 2018 15:54:36 +0200 Subject: [PATCH 3/5] Lint --- packages/fether-react/src/stores/healthStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fether-react/src/stores/healthStore.js b/packages/fether-react/src/stores/healthStore.js index ea51f499..a1bdc38f 100644 --- a/packages/fether-react/src/stores/healthStore.js +++ b/packages/fether-react/src/stores/healthStore.js @@ -111,7 +111,7 @@ export class HealthStore { } return { - status: STATUS.GOOD + status: STATUS.GOOD }; } -- GitLab From 920b1c14271cee8406f4fb1662a2624bf8d19a9c Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 6 Aug 2018 16:10:40 +0200 Subject: [PATCH 4/5] Verify if peerCount is not set --- packages/fether-react/src/stores/healthStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fether-react/src/stores/healthStore.js b/packages/fether-react/src/stores/healthStore.js index a1bdc38f..cf0df138 100644 --- a/packages/fether-react/src/stores/healthStore.js +++ b/packages/fether-react/src/stores/healthStore.js @@ -106,7 +106,7 @@ export class HealthStore { return { status: STATUS.CLOCKNOTSYNC }; } - if (this.peerCount.eq(0)) { + if (this.peerCount && this.peerCount.eq(0)) { return { status: STATUS.NOPEERS }; } -- GitLab From 5fd50c0b5c1fb7165ad9e890adf9414606587bc2 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 6 Aug 2018 16:28:57 +0200 Subject: [PATCH 5/5] Use symbols --- packages/fether-react/src/stores/healthStore.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/fether-react/src/stores/healthStore.js b/packages/fether-react/src/stores/healthStore.js index cf0df138..55206bb5 100644 --- a/packages/fether-react/src/stores/healthStore.js +++ b/packages/fether-react/src/stores/healthStore.js @@ -18,13 +18,13 @@ const electron = isElectron() ? window.require('electron') : null; // List here all possible states of our health store. Each state can have a // payload. export const STATUS = { - CANTCONNECT: 'CANTCONNECT', // Can't connect to Parity's api - CLOCKNOTSYNC: 'CLOCKNOTSYNC', // Local clock is not sync - DOWNLOADING: 'DOWNLOADING', // Currently downloading Parity - GOOD: 'GOOD', // Everything's fine - NOPEERS: 'NOPEERS', // Not connected to any peers - RUNNING: 'RUNNING', // Parity is running (only checked at startup) - SYNCING: 'SYNCING' // Obvious + CANTCONNECT: Symbol('CANTCONNECT'), // Can't connect to Parity's api + CLOCKNOTSYNC: Symbol('CLOCKNOTSYNC'), // Local clock is not sync + DOWNLOADING: Symbol('DOWNLOADING'), // Currently downloading Parity + GOOD: Symbol('GOOD'), // Everything's fine + NOPEERS: Symbol('NOPEERS'), // Not connected to any peers + RUNNING: Symbol('RUNNING'), // Parity is running (only checked at startup) + SYNCING: Symbol('SYNCING') // Obvious }; export class HealthStore { -- GitLab