Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
v0.7.2 (#140)
Browse files Browse the repository at this point in the history
v0.7.2
  • Loading branch information
andrerfneves authored May 31, 2019
2 parents 6229a35 + 62e215b commit fc19baa
Show file tree
Hide file tree
Showing 25 changed files with 410 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"browser": true,
"node": true,
"mocha": true,
"jest/globals": true
"jest": true
},
"plugins": ["flowtype", "jest"],
"settings": {
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ List of the main open source libraries and technologies used in building **Zepio
- [zcashd](https://github.com/zcash/zcash): Zcash node daemon
- [Electron](https://github.com/electron/electron): Desktop application builder
- [React](https://facebook.github.io/react/): User interface view layer
- [Redux](http://redux.js.org/): Predictable application state container
- [Redux](https://redux.js.org/): Predictable application state container
- [Styled Components](https://www.styled-components.com/): Visual primitives for theming and styling applications
- [webpack](http://webpack.github.io/): Application module bundler (and more)
- [Babel](http://babeljs.io/): ES7/JSX transpilling
- [ESLint](http://eslint.org/): Code linting rules
- [webpack](https://webpack.github.io/): Application module bundler (and more)
- [Babel](https://babeljs.io/): ES7/JSX transpilling
- [ESLint](https://eslint.org/): Code linting rules
- [Flow](https://flow.org): JavaScript static type checker
- [Docz](https://docz.site): Documentation builder
- [BigNumber.js](https://github.com/MikeMcl/bignumber.js#readme): Arbitrary-precision decimal and non-decimal arithmetic with safety

## Installing and Running From Source

Expand Down
2 changes: 1 addition & 1 deletion __mocks__/electron-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = class {
}

get() {
return 'test value';
return 'TESTNET';
}
};
1 change: 1 addition & 0 deletions __tests__/components/transaction-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ beforeAll(() => {
});
afterAll(() => {
global.Date = originalDate;
// $FlowFixMe
dateFns.format.mockRestore();
cleanup();
});
Expand Down
1 change: 1 addition & 0 deletions __tests__/components/transactions-daily.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ beforeAll(() => {
});
afterAll(() => {
global.Date = originalDate;
// $FlowFixMe
dateFns.format.mockRestore();
cleanup();
});
Expand Down
18 changes: 11 additions & 7 deletions __tests__/e2e/startup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ describe('Startup', () => {
expect(app.client.getTitle()).resolves.toEqual('Zepio');
});

test('should show the text "Zepio Starting" in loading screen', async () => expect(app.client.element('#loading-screen:first-child p').getHTML()).resolves.toEqual(
expect.stringContaining('Zepio Starting'),
));
test('should show the text "Zepio Starting" in loading screen', async () => {
expect(
app.client.element('div[data-testid~="LoadingScreen"]:first-child p').getHTML(),
).resolves.toEqual(expect.stringContaining('Zepio Starting'));
});

test('should show the zcash logo in loading screen', () => expect(app.client.getAttribute('#loading-screen:first-child img', 'src')).resolves.toEqual(
expect.stringContaining('/assets/zcash-simple-icon.svg'),
));
test('should show the zcash logo in loading screen', () => expect(
app.client.getAttribute('div[data-testid~="LoadingScreen"]:first-child img', 'src'),
).resolves.toEqual(expect.stringContaining('/assets/zcash-simple-icon.svg')));

test('should show the loading circle in loading screen', () => {
expect(app.client.element('#loading-screen svg').isExisting()).resolves.toEqual(true);
expect(
app.client.element('div[data-testid~="LoadingScreen"] svg').isExisting(),
).resolves.toEqual(true);
});
});
4 changes: 2 additions & 2 deletions __tests__/e2e/status-pill.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ afterAll(() => app.stop());

describe('Status Pill', () => {
test('should show status pill in the header', async () => expect(
app.client.waitUntilTextExists('#status-pill', 'ready').getText('#status-pill'),
).resolves.toEqual(expect.stringContaining('ready')));
app.client.waitUntilTextExists('#status-pill', 'READY', 30000).getText('#status-pill'),
).resolves.toEqual(expect.stringContaining('READY')));
});
6 changes: 4 additions & 2 deletions __tests__/setup/mockAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const handler = (server) => {

switch (method) {
case 'getinfo':
sleep(1500).then(() => res.send({ result: { version: 1.0 } }));
sleep(500).then(() => res.send({ result: { version: 1.0 } }));
break;
case 'getblockchaininfo':
return res.send({ result: { verificationprogress: 1 } });
Expand All @@ -43,7 +43,7 @@ const handler = (server) => {
});
case 'z_sendmany':
// eslint-disable-next-line
sleep(2000).then(() => {
sleep(1000).then(() => {
const [, [obj], amount, fee] = req.body.params;

if ((obj.address[0] === 'z' || obj.address[0] === 't') && amount > 0) {
Expand Down Expand Up @@ -109,6 +109,8 @@ const handler = (server) => {
return res.send({
result: 10,
});
case 'ping':
return res.send(null);
default:
return null;
}
Expand Down
31 changes: 24 additions & 7 deletions app/components/status-pill.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ type State = {
showTooltip: boolean,
};

const MINUTE_IN_MILI = 60000;
const INTERVAL_AFTER_READY = 60000;
const INTERVAL_BEFORE_READY = 10000;

class Component extends PureComponent<Props, State> {
timer: ?IntervalID = null;

constructor(props) {
requestOnTheFly: boolean = false;

constructor(props: Props) {
super(props);

this.state = {
Expand All @@ -113,27 +116,41 @@ class Component extends PureComponent<Props, State> {
}

componentDidMount() {
const { getBlockchainStatus } = this.props;

this.timer = setInterval(() => getBlockchainStatus(), 2000);
this.timer = setInterval(() => this.updateStatus(), INTERVAL_BEFORE_READY);
}

componentDidUpdate(prevProps: Props) {
const { getBlockchainStatus, nodeSyncType } = this.props;
const { nodeSyncType } = this.props;
if (
prevProps.nodeSyncType === NODE_SYNC_TYPES.SYNCING
&& nodeSyncType === NODE_SYNC_TYPES.READY
) {
// if the status is "ready", we can increase the interval to avoid useless rpc calls
this.cleanUpdateInterval();
this.timer = setInterval(() => getBlockchainStatus(), MINUTE_IN_MILI);
this.timer = setInterval(() => this.updateStatus(), INTERVAL_AFTER_READY);
}
}

componentWillUnmount() {
this.cleanUpdateInterval();
}

updateStatus = () => {
if (this.requestOnTheFly) return;

this.requestOnTheFly = true;

const { getBlockchainStatus } = this.props;

getBlockchainStatus()
.then(() => {
this.requestOnTheFly = false;
})
.catch(() => {
this.requestOnTheFly = false;
});
};

cleanUpdateInterval = () => {
if (this.timer) {
clearInterval(this.timer);
Expand Down
70 changes: 40 additions & 30 deletions app/components/with-daemon-status-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import electron from 'electron'; // eslint-disable-line
import React, { type ComponentType, Component } from 'react';

import store from '../../config/electron-store';

import { LoadingScreen } from './loading-screen';

import rpc from '../../services/api';
Expand All @@ -20,7 +22,7 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
): ComponentType<$Diff<PassedProps, Props>> => class extends Component<PassedProps, State> {
timer: ?IntervalID = null;

hasDaemonError: boolean = false;
requestOnTheFly: boolean = false;

state = {
isRunning: false,
Expand All @@ -32,18 +34,25 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
this.runTest();
this.timer = setInterval(this.runTest, 3000);

electron.ipcRenderer.on('zcash-daemon-status', (event: empty, message: Object) => {
this.hasDaemonError = message.error;

if (message.error) {
clearInterval(this.timer);
}
electron.ipcRenderer.on(
'zcash-daemon-status',
(
event: empty,
message: {
error: boolean,
status: string,
},
) => {
if (message.error) {
clearInterval(this.timer);
}

this.setState({
message: message.status,
...(message.error ? { progress: 0, isRunning: false } : {}),
});
});
this.setState({
message: message.status,
...(message.error ? { progress: 0, isRunning: false } : {}),
});
},
);
}

componentWillUnmount() {
Expand All @@ -54,30 +63,31 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
}

runTest = () => {
if (this.hasDaemonError) return;
const daemonPID: number = store.get('DAEMON_PROCESS_PID');

if (this.requestOnTheFly || !daemonPID) return;

this.requestOnTheFly = true;

rpc
.getinfo()
.then((response) => {
if (this.hasDaemonError) return;

if (response) {
setTimeout(() => {
this.setState(() => ({ isRunning: true }));
}, 500);
this.setState(() => ({ progress: 100 }));

if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
.ping()
.then(() => {
this.requestOnTheFly = false;

setTimeout(() => {
this.setState(() => ({ isRunning: true }));
}, 500);
this.setState(() => ({ progress: 100 }));

if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
})
.catch((error) => {
if (this.hasDaemonError) return;

const statusMessage = error.message === 'Something went wrong' ? 'Zepio Starting' : error.message;
this.requestOnTheFly = false;

const statusMessage: string = error.message === 'Something went wrong' ? 'Zepio Starting' : error.message;
const isRpcOff = Math.trunc(error.statusCode / 100) === 5;

this.setState({
Expand Down
2 changes: 1 addition & 1 deletion app/theme/docz.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ThemeProvider } from 'styled-components';
import { appTheme } from './theme';
import { GlobalStyle } from './global';

export const DoczWrapper = ({ children }: { children: () => Node<*> }) => (
export const DoczWrapper = ({ children }: { children: () => Node }) => (
<ThemeProvider theme={appTheme}>
<Fragment>
<GlobalStyle />
Expand Down
2 changes: 1 addition & 1 deletion app/types/redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { AppState } from './app-state';

export type Action = { type: $Subtype<string>, payload: Object };
export type Action = { type: string, payload: Object };
export type GetState = () => AppState;
export type Dispatch = (action: Action) => void;
export type Middleware = ({ dispatch: Dispatch, getState: GetState }) => (
Expand Down
7 changes: 6 additions & 1 deletion app/utils/get-coin-name.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// @flow
import electron from 'electron'; // eslint-disable-line
import { isTestnet } from '../../config/is-testnet';

export const getCoinName = () => (isTestnet() ? 'TAZ' : 'ZEC');
export const getCoinName = () => {
if (electron.remote.process.env.NODE_ENV === 'test' || isTestnet()) return 'TAZ';

return 'ZEC';
};
Binary file modified bin/linux/zcashd
Binary file not shown.
Binary file modified bin/mac/zcashd
Binary file not shown.
Binary file modified bin/win/zcashd.exe
Binary file not shown.
19 changes: 19 additions & 0 deletions config/daemon/check-lock-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
import fs from 'fs';
import path from 'path';
import { promisify } from 'util';
import eres from 'eres';

import { getZcashFolder } from './get-zcash-folder';

const ZCASH_LOCK_FILE = '.lock';

export const checkLockFile = async (zcashPath?: string) => {
try {
const myPath = zcashPath || getZcashFolder();
const [cannotAccess] = await eres(promisify(fs.access)(path.join(myPath, ZCASH_LOCK_FILE)));
return !cannotAccess;
} catch (err) {
return false;
}
};
17 changes: 17 additions & 0 deletions config/daemon/get-daemon-process-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @flow
import fs from 'fs';
import path from 'path';
import { getZcashFolder } from './get-zcash-folder';

const ZCASH_PID_FILE = 'zcashd.pid';

export const getDaemonProcessId = (zcashPath?: string) => {
try {
const myPath = zcashPath || getZcashFolder();
const buffer = fs.readFileSync(path.join(myPath, ZCASH_PID_FILE));
const pid = Number(buffer.toString().trim());
return pid;
} catch (err) {
return null;
}
};
18 changes: 18 additions & 0 deletions config/daemon/get-zcash-folder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow
import os from 'os';
import path from 'path';
import electron from 'electron'; // eslint-disable-line

export const getZcashFolder = () => {
const { app } = electron;

if (os.platform() === 'darwin') {
return path.join(app.getPath('appData'), 'Zcash');
}

if (os.platform() === 'linux') {
return path.join(app.getPath('home'), '.zcash');
}

return path.join(app.getPath('appData'), 'Zcash');
};
Loading

0 comments on commit fc19baa

Please sign in to comment.