diff --git a/app/views/console.js b/app/views/console.js
index 0ccf78a..6193d0d 100644
--- a/app/views/console.js
+++ b/app/views/console.js
@@ -1,16 +1,18 @@
// @flow
import React, { PureComponent, Fragment } from 'react';
-// eslint-disable-next-line import/no-extraneous-dependencies
-import { ipcRenderer } from 'electron';
import styled, { withTheme } from 'styled-components';
import uuid from 'uuid/v4';
+import eres from 'eres';
+import humanizeDuration from 'humanize-duration';
import { TextComponent } from '../components/text';
import ConsoleSymbolDark from '../assets/images/console_zcash_dark.png';
import ConsoleSymbolLight from '../assets/images/console_zcash_light.png';
import { DARK } from '../constants/themes';
+import rpc from '../../services/api';
+import store from '../../config/electron-store';
const Wrapper = styled.div`
max-height: 100%;
@@ -31,30 +33,6 @@ const ConsoleImg = styled.img`
width: auto;
`;
-const initialLog = `
- Thank you for running a Zcash node!
- You're helping to strengthen the network and contributing to a social good :)
-
- In order to ensure you are adequately protecting your privacy when using Zcash, please see .
-`;
-
-const defaultState = `
- Thank you for running a Zcash node!
- You're helping to strengthen the network and contributing to a social good :)
- In order to ensure you are adequately protecting your privacy when using Zcash, please see .
-
- Block height | 0
- Connections | 0
- Network solution rate | 0 Sol/s
- You are currently not mining.
- To enable mining, add 'gen=1' to your zcash.conf and restart.
-
- Since starting this node 0 minutes, 0 seconds ago:
-- You have validated 0 transactions!
-\n
-------------------------------------------
-`;
-
const breakpoints = [1, 4, 7, 10, 13];
type Props = {
@@ -62,26 +40,68 @@ type Props = {
};
type State = {
- log: string,
+ blockHeight: number,
+ connections: number,
+ networkSolutionsRate: number,
};
class Component extends PureComponent {
+ interval: ?IntervalID = null;
+
+ requestOnTheFly: boolean = false;
+
state = {
- log: defaultState,
+ blockHeight: 0,
+ connections: 0,
+ networkSolutionsRate: 0,
};
componentDidMount() {
- ipcRenderer.on('zcashd-log', (event: empty, message: string) => {
- this.setState(() => ({ log: initialLog + message }));
- });
+ this.interval = setInterval(() => this.update(), 3000);
}
componentWillUnmount() {
- ipcRenderer.removeAllListeners('zcashd-log');
+ clearInterval(this.interval);
}
+ update = async () => {
+ if (this.requestOnTheFly) return;
+
+ this.requestOnTheFly = true;
+
+ const [err, result] = await eres(Promise.all([rpc.getinfo(), rpc.getmininginfo()]));
+
+ if (err) return;
+
+ this.setState(
+ {
+ blockHeight: result[0].blocks,
+ connections: result[0].connections,
+ networkSolutionsRate: result[1].networksolps,
+ },
+ () => {
+ this.requestOnTheFly = false;
+ },
+ );
+ };
+
+ getLog = (state: State) => `
+ Thank you for running a Zcash node!
+ You're helping to strengthen the network and contributing to a social good :)
+ In order to ensure you are adequately protecting your privacy when using Zcash, please see .
+
+ Block height | ${state.blockHeight}
+ Connections | ${state.connections}
+ Network solution rate | ${state.networkSolutionsRate} Sol/s
+
+ Started ${humanizeDuration(new Date() - new Date(store.get('DAEMON_START_TIME')), {
+ round: true,
+ })} ago
+ \n
+ ------------------------------------------
+ `;
+
render() {
- const { log } = this.state;
const { theme } = this.props;
const ConsoleSymbol = theme.mode === DARK ? ConsoleSymbolDark : ConsoleSymbolLight;
@@ -90,12 +110,14 @@ class Component extends PureComponent {
- {log.split('\n').map((item, idx) => (
-
-
- {breakpoints.includes(idx) ?
: null}
-
- ))}
+ {this.getLog(this.state)
+ .split('\n')
+ .map((item, idx) => (
+
+
+ {breakpoints.includes(idx) ?
: null}
+
+ ))}
);
diff --git a/flow-custom-typedefs/humanize-duration.js b/flow-custom-typedefs/humanize-duration.js
new file mode 100644
index 0000000..cbe8ed5
--- /dev/null
+++ b/flow-custom-typedefs/humanize-duration.js
@@ -0,0 +1,22 @@
+declare module 'humanize-duration' {
+ declare type options = {
+ language?: string,
+ fallbacks?: string[],
+ delimiter?: string,
+ spacer?: string,
+ largest?: number,
+ units?: string[],
+ round?: boolean,
+ decimal?: string,
+ conjunction?: string,
+ maxDecimalPoints?: number,
+ unitMeasures?: {
+ y?: number,
+ mo?: number,
+ w?: number,
+ d?: number,
+ },
+ };
+
+ declare module.exports: (milli: number, opt?: options) => string;
+}
diff --git a/package.json b/package.json
index e5749e4..0294d79 100644
--- a/package.json
+++ b/package.json
@@ -230,6 +230,7 @@
"find-process": "^1.2.1",
"got": "^9.6.0",
"history": "^4.7.2",
+ "humanize-duration": "^3.18.0",
"lodash.flow": "^3.5.0",
"lodash.groupby": "^4.6.0",
"lodash.uniqby": "^4.7.0",
diff --git a/yarn.lock b/yarn.lock
index b90c500..4eaec26 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7887,6 +7887,11 @@ humanize-duration@^3.15.3:
version "3.16.0"
resolved "https://registry.yarnpkg.com/humanize-duration/-/humanize-duration-3.16.0.tgz#c7ec3b898305f007c63893f891870b2b5a2e0a7d"
+humanize-duration@^3.18.0:
+ version "3.18.0"
+ resolved "https://registry.yarnpkg.com/humanize-duration/-/humanize-duration-3.18.0.tgz#ba07a945d6d4358b9751fecabe27864bf965afbc"
+ integrity sha512-reYy4EJMqlhX13TDlgSqLYfVGKOoixoEzsSL6DBlp22dScWN8Q2eMgDF4L0q28mzbgO40rnBy3WyEUQEhfYALw==
+
humanize-string@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/humanize-string/-/humanize-string-1.0.2.tgz#fef0a8bc9b1b857ca4013bbfaea75071736988f6"