zepio/app/views/console.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-12-05 08:32:13 -08:00
// @flow
import React, { Component, Fragment } from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
2018-12-05 08:32:13 -08:00
import { ipcRenderer } from 'electron';
import styled from 'styled-components';
import generateRandomString from '../utils/generate-random-string';
import { TextComponent } from '../components/text';
import ConsoleSymbol from '../assets/images/console_zcash.svg';
const Wrapper = styled.div`
max-height: 100%;
overflow-y: auto;
background-color: ${props => props.theme.colors.cardBackgroundColor};
margin-top: ${props => props.theme.layoutContentPaddingTop};
border-radius: ${props => props.theme.boxBorderRadius};
padding: 38px 33.5px;
`;
const ConsoleText = styled(TextComponent)`
font-family: 'Source Code Pro', monospace;
`;
const ConsoleImg = styled.img`
height: 200px;
width: auto;
`;
2018-12-05 08:32:13 -08:00
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 <https://z.cash/support/security/>.
`;
const defaultState = `
\n
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!
`;
const breakpoints = [1, 4, 7, 10, 13];
2018-12-05 08:32:13 -08:00
type Props = {};
type State = {
log: string,
2018-12-05 08:32:13 -08:00
};
export class ConsoleView extends Component<Props, State> {
state = {
log: initialLog + defaultState,
2018-12-05 08:32:13 -08:00
};
componentDidMount() {
ipcRenderer.on('zcashd-log', (event, message) => {
this.setState(() => ({ log: initialLog + message }));
2018-12-05 08:32:13 -08:00
});
}
render() {
const { log } = this.state;
2018-12-05 08:32:13 -08:00
return (
<Wrapper>
<Fragment>
<ConsoleImg src={ConsoleSymbol} alt='Zcashd' />
{log.split('\n').map((item, idx) => (
<Fragment key={generateRandomString()}>
<ConsoleText value={item} />
{breakpoints.includes(idx) ? <br /> : null}
</Fragment>
))}
</Fragment>
</Wrapper>
2018-12-05 08:32:13 -08:00
);
}
}