Merge pull request #105 from andrerfneves/bugfix/daemon-mode-startup

Bugfix/daemon mode startup
This commit is contained in:
André Neves 2019-04-16 23:30:30 -04:00 committed by GitHub
commit 0ba7968892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 46 deletions

View File

@ -1,10 +1,12 @@
# Zepio | ZEC Wallet # Zepio | ZEC Wallet
Zepio is a modern cross-platform full-node desktop wallet for the Zcash Network. Zepio is a Sapling-enabled shielded-address first Zcash wallet, featuring cross-platform applications (macOS, Windows and Linux), built-in full node with support for `mainnet` and `testnet`, as well as `dark` and `light` themes.
[![Build Status](https://app.bitrise.io/app/e3e2de9d817688f9/status.svg?token=JsSLjbxa6yt6-oy5MgU9uQ)](https://app.bitrise.io/app/e3e2de9d817688f9)
![Flow Coverage](./public/flow-coverage-badge.svg) ![Flow Coverage](./public/flow-coverage-badge.svg)
### [Latest Documentation at https://zepiowallet.com](https://zepiowallet.com)
## Stack Information ## Stack Information
- [Electron](https://github.com/electron/electron): desktop application builder - [Electron](https://github.com/electron/electron): desktop application builder

View File

@ -181,11 +181,11 @@ class Component extends PureComponent<Props, State> {
switch (nodeSyncType) { switch (nodeSyncType) {
case 'syncing': case 'syncing':
return "Syncing blockchain data. You may not send funds or see latest transactions until it's synced 100%"; return 'Syncing blockchain data. You may not send funds or see latest transactions until it\'s synced.';
case 'ready': case 'ready':
return 'Your chain data is up to date'; return 'Your node is synced.';
case 'error': case 'error':
return 'There was an error. Try restarting Zepio'; return 'There was an error. Try restarting Zepio.';
default: default:
return ''; return '';
} }

View File

@ -1,7 +1,7 @@
// @flow // @flow
import isDev from 'electron-is-dev'; import { isTestnet } from '../../config/is-testnet';
export const ZCASH_EXPLORER_BASE_URL = isDev export const ZCASH_EXPLORER_BASE_URL = isTestnet()
? 'https://chain.so/tx/ZECTEST/' ? 'https://chain.so/tx/ZECTEST/'
: 'https://zcha.in/transactions/'; : 'https://zcha.in/transactions/';

View File

@ -72,9 +72,7 @@ class Component extends PureComponent<Props, State> {
componentDidMount() { componentDidMount() {
ipcRenderer.on('zcashd-log', (event: empty, message: string) => { ipcRenderer.on('zcashd-log', (event: empty, message: string) => {
if (message.indexOf('Downloading') !== -1) { this.setState(() => ({ log: initialLog + message }));
this.setState(() => ({ log: initialLog + message }));
}
}); });
} }

View File

@ -1,6 +1,7 @@
// @flow // @flow
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
import fs from 'fs'; import fs from 'fs';
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
@ -248,7 +249,7 @@ export class SettingsView extends PureComponent<Props, State> {
const zAddresses = addresses.filter(({ address }) => address.startsWith('z')); const zAddresses = addresses.filter(({ address }) => address.startsWith('z'));
this.setState({ isLoading: true }); this.setState(() => ({ isLoading: true }));
Promise.all( Promise.all(
zAddresses.map(async ({ address }) => { zAddresses.map(async ({ address }) => {
@ -256,18 +257,18 @@ export class SettingsView extends PureComponent<Props, State> {
return { zAddress: address, key: viewKey }; return { zAddress: address, key: viewKey };
}), }),
).then((viewKeys) => { ).then((viewKeys) => {
this.setState({ this.setState(() => ({
viewKeys, viewKeys,
successExportViewKeys: true, successExportViewKeys: true,
isLoading: false, isLoading: false,
}); }));
}); });
}; };
exportPrivateKeys = () => { exportPrivateKeys = () => {
const { addresses } = this.props; const { addresses } = this.props;
this.setState({ isLoading: true }); this.setState(() => ({ isLoading: true }));
Promise.all( Promise.all(
addresses.map(async ({ address }) => { addresses.map(async ({ address }) => {
@ -278,13 +279,16 @@ export class SettingsView extends PureComponent<Props, State> {
}), }),
) )
.then((privateKeys) => { .then((privateKeys) => {
this.setState({ this.setState(() => ({
privateKeys, privateKeys,
successExportPrivateKeys: true, successExportPrivateKeys: true,
isLoading: false, isLoading: false,
}); }));
}) })
.catch(error => this.setState({ isLoading: false, error: error.message })); .catch((error) => {
console.log({ error });
this.setState(() => ({ isLoading: false, error: error.message }));
});
}; };
importPrivateKeys = () => { importPrivateKeys = () => {

View File

@ -10,7 +10,7 @@ export default (processName: string): Promise<void> => new Promise((resolve) =>
if (!isRunning) { if (!isRunning) {
clearInterval(interval); clearInterval(interval);
resolve(); setTimeout(resolve, 1000);
} }
}, 500); }, 500);
}); });

View File

@ -46,7 +46,6 @@ const getDaemonOptions = ({
const defaultOptions = [ const defaultOptions = [
'-server=1', '-server=1',
'-rest=1',
'-showmetrics', '-showmetrics',
'--metricsui=0', '--metricsui=0',
'-metricsrefreshtime=1', '-metricsrefreshtime=1',
@ -69,6 +68,7 @@ const ZCASHD_PROCESS_NAME = getDaemonName();
// eslint-disable-next-line // eslint-disable-next-line
const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve, reject) => { const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve, reject) => {
const processName = path.join(getBinariesPath(), getOsFolder(), ZCASHD_PROCESS_NAME); const processName = path.join(getBinariesPath(), getOsFolder(), ZCASHD_PROCESS_NAME);
const isRelaunch = Boolean(process.argv.find(arg => arg === '--relaunch'));
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', 'Fetching params...'); if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', 'Fetching params...');
@ -86,7 +86,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
// In case of --relaunch on argv, we need wait to close the old zcash daemon // In case of --relaunch on argv, we need wait to close the old zcash daemon
// a workaround is use a interval to check if there is a old process running // a workaround is use a interval to check if there is a old process running
if (process.argv.find(arg => arg === '--relaunch')) { if (isRelaunch) {
await waitForDaemonClose(ZCASHD_PROCESS_NAME); await waitForDaemonClose(ZCASHD_PROCESS_NAME);
} }
@ -137,7 +137,9 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
store.set(EMBEDDED_DAEMON, true); store.set(EMBEDDED_DAEMON, true);
store.set(ZCASH_NETWORK, optionsFromZcashConf.testnet === '1' ? TESTNET : MAINNET); if (!isRelaunch) {
store.set(ZCASH_NETWORK, optionsFromZcashConf.testnet === '1' ? TESTNET : MAINNET);
}
if (!optionsFromZcashConf.rpcuser) store.set('rpcuser', uuid()); if (!optionsFromZcashConf.rpcuser) store.set('rpcuser', uuid());
if (!optionsFromZcashConf.rpcpassword) store.set('rpcpassword', uuid()); if (!optionsFromZcashConf.rpcpassword) store.set('rpcpassword', uuid());

View File

@ -1,9 +1,9 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable */
import { css } from 'docz-plugin-css'; import { css } from 'docz-plugin-css';
export default { export default {
title: 'Zcash Foundation', title: 'Zepio',
description: 'Zcash Foundation User Interface Styleguide', description: 'Zepio Component Styleguide',
plugins: [css()], plugins: [css()],
htmlContext: { htmlContext: {
head: { head: {

View File

@ -6,17 +6,11 @@ import { METHODS, type APIMethods } from './utils';
import store from '../config/electron-store'; import store from '../config/electron-store';
import { isTestnet } from '../config/is-testnet'; import { isTestnet } from '../config/is-testnet';
const RPC = { const getRPCConfig = () => ({
host: '127.0.0.1', host: '127.0.0.1',
port: isTestnet() ? 18232 : 8232, port: isTestnet() ? 18232 : 8232,
user: store.get('rpcuser'), user: store.get('rpcuser'),
password: store.get('rpcpassword'), password: store.get('rpcpassword'),
};
const client = got.extend({
method: 'POST',
json: true,
auth: `${RPC.user}:${RPC.password}`,
}); });
const getMessage = (statusCode) => { const getMessage = (statusCode) => {
@ -31,21 +25,29 @@ const getMessage = (statusCode) => {
const api: APIMethods = METHODS.reduce( const api: APIMethods = METHODS.reduce(
(obj, method) => ({ (obj, method) => ({
...obj, ...obj,
[method]: (...args) => client [method]: (...args) => {
.post(`http://${RPC.host}:${RPC.port}`, { const RPC = getRPCConfig();
body: { return (
method, got
jsonrpc: '2.0', .post(`http://${RPC.host}:${RPC.port}`, {
id: Date.now(), method: 'POST',
params: args, json: true,
}, auth: `${RPC.user}:${RPC.password}`,
}) body: {
.then(data => Promise.resolve(data.body && data.body.result)) method,
// eslint-disable-next-line jsonrpc: '2.0',
.catch(payload => Promise.reject({ id: Date.now(),
message: payload.body?.error?.message || getMessage(payload.statusCode), params: args,
statusCode: payload.statusCode, },
})), })
.then(data => Promise.resolve(data.body && data.body.result))
// eslint-disable-next-line
.catch(payload => Promise.reject({
message: payload.body?.error?.message || getMessage(payload.statusCode),
statusCode: payload.statusCode,
}))
);
},
}), }),
{}, {},
); );