chore(zcashd-params): fix params download on windows

This commit is contained in:
georgelima 2019-02-04 22:32:53 -02:00
parent d0191ca7d6
commit fcc500e379
4 changed files with 51 additions and 18 deletions

View File

@ -2,6 +2,8 @@
import React, { PureComponent } from 'react';
import styled from 'styled-components';
import { Transition, animated } from 'react-spring';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ipcRenderer } from 'electron';
import CircleProgressComponent from 'react-circle';
import { TextComponent } from './text';
@ -42,21 +44,30 @@ type Props = {
type State = {
start: boolean,
message: string,
};
const TIME_DELAY_ANIM = 100;
export class LoadingScreen extends PureComponent<Props, State> {
state = { start: false };
state = { start: false, message: 'ZEC Wallet Starting' };
componentDidMount() {
setTimeout(() => {
this.setState(() => ({ start: true }));
}, TIME_DELAY_ANIM);
ipcRenderer.on('zcashd-params-download', (event, message) => {
this.setState(() => ({ message }));
});
}
componentWillUnmount() {
ipcRenderer.removeAllListeners('zcashd-log');
}
render() {
const { start } = this.state;
const { start, message } = this.state;
const { progress } = this.props;
return (
@ -74,18 +85,28 @@ export class LoadingScreen extends PureComponent<Props, State> {
}}
>
{() => props => (
<animated.div style={props} id='loading-screen'>
<animated.div
style={{
...props,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
}}
id='loading-screen'
>
<CircleWrapper>
<Logo src={zcashLogo} alt='Zcash logo' />
<CircleProgressComponent
progress={progress}
s
responsive
showPercentage={false}
progressColor={theme.colors.activeItem}
bgColor={theme.colors.inactiveItem}
/>
</CircleWrapper>
<TextComponent value='ZEC Wallet Starting' />
<TextComponent value={message} />
</animated.div>
)}
</Transition>

View File

@ -13,11 +13,11 @@ import got from 'got';
import Queue from 'p-queue';
// eslint-disable-next-line
import { app } from '../electron';
import { app, mainWindow } from '../electron';
import getBinariesPath from './get-binaries-path';
import log from './logger';
const queue = new Queue({ concurrency: 1, autoStart: false });
const queue = new Queue({ concurrency: 2, autoStart: false });
const httpClient = got.extend({
baseUrl: 'https://z.cash/downloads/',
@ -61,19 +61,22 @@ const checkSha256 = (pathToFile: string, expectedHash: string) => new Promise((r
// eslint-disable-next-line max-len
const downloadFile = ({ file, pathToSave }): Promise<*> => new Promise((resolve, reject) => {
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', `Downloading ${file.name}...`);
log(`Downloading ${file.name}...`);
httpClient
.stream(file.name)
.on('end', () => {
checkSha256(pathToSave, file.hash).then((isValid) => {
if (isValid) {
log(`SHA256 validation for file ${file.name} succeeded!`);
resolve(file.name);
} else {
reject(new Error(`SHA256 validation failed for file: ${file.name}`));
}
});
checkSha256(pathToSave, file.hash)
.then((isValid) => {
if (isValid) {
log(`SHA256 validation for file ${file.name} succeeded!`);
resolve(file.name);
} else {
reject(new Error(`SHA256 validation failed for file: ${file.name}`));
}
})
.catch(resolve);
})
.on('error', err => reject(new Error(err)))
.pipe(fs.createWriteStream(pathToSave));
@ -118,7 +121,16 @@ export default (): Promise<*> => new Promise((resolve, reject) => {
if (!missingDownloadParam) return resolve();
queue.onEmpty(resolve);
/*
Manual approach to check the end of the queue
onIdle/onEmpty was not working
*/
const interval = setInterval(() => {
if (queue.size === 0 && queue.pending === 0) {
clearInterval(interval);
resolve();
}
}, 500);
queue.start();
});
});

View File

@ -13,6 +13,5 @@ export const locateZcashConf = () => {
return path.join(app.getPath('home'), '.zcash', 'zcash.conf');
}
// TODO: Need to test on windows
return path.join(app.getPath('appData'), 'Zcash', 'zcash.conf');
};

View File

@ -42,8 +42,6 @@ const getDaemonOptions = ({ username, password, optionsFromZcashConf }) => {
...optionsFromZcashConf,
];
log(defaultOptions);
return isDev ? defaultOptions.concat(['-testnet', '-addnode=testnet.z.cash']) : defaultOptions;
};
@ -53,6 +51,8 @@ let resolved = false;
const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve, reject) => {
const processName = path.join(getBinariesPath(), getOsFolder(), getDaemonName());
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', 'Fetching params...');
const [err] = await eres(fetchParams());
if (err) {
@ -60,6 +60,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
return reject(new Error(err));
}
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', 'ZEC Wallet Starting');
log('Fetch Params finished!');
const [, isRunning] = await eres(processExists(processName));