fix(parse-zcash-conf): remove side-effects from zcashParse method
This commit is contained in:
parent
5fc34f611b
commit
c22fbb4eb3
|
@ -4,7 +4,6 @@ import fs from 'fs';
|
||||||
|
|
||||||
import { locateZcashConf } from './locate-zcash-conf';
|
import { locateZcashConf } from './locate-zcash-conf';
|
||||||
import { filterObjectNullKeys } from '../../app/utils/filter-object-null-keys';
|
import { filterObjectNullKeys } from '../../app/utils/filter-object-null-keys';
|
||||||
import store from '../electron-store';
|
|
||||||
|
|
||||||
type ZcashConfFile = {
|
type ZcashConfFile = {
|
||||||
testnet: ?string,
|
testnet: ?string,
|
||||||
|
@ -32,14 +31,15 @@ type ZcashConfFile = {
|
||||||
paytxfee: ?string,
|
paytxfee: ?string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseZcashConf = (): Promise<Array<string>> => new Promise((resolve, reject) => {
|
export const parseZcashConf = (): Promise<ZcashConfFile> => new Promise((resolve, reject) => {
|
||||||
fs.readFile(locateZcashConf(), (err, file) => {
|
fs.readFile(locateZcashConf(), (err, file) => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
|
|
||||||
const fileString = file.toString();
|
const fileString = file.toString();
|
||||||
|
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
const { rpcuser, rpcpassword, ...payload }: ZcashConfFile = filterObjectNullKeys(
|
const payload: ZcashConfFile = filterObjectNullKeys(
|
||||||
fileString.split('\n').reduce((acc, cur) => {
|
fileString.split('\n').reduce((acc, cur) => {
|
||||||
if (!cur) return acc;
|
if (!cur) return acc;
|
||||||
|
|
||||||
|
@ -52,14 +52,18 @@ export const parseZcashConf = (): Promise<Array<string>> => new Promise((resolve
|
||||||
}, {}),
|
}, {}),
|
||||||
);
|
);
|
||||||
|
|
||||||
store.set('rpcuser', rpcuser || '');
|
resolve(payload);
|
||||||
store.set('rpcpassword', rpcpassword || '');
|
|
||||||
|
|
||||||
// $FlowFixMe
|
|
||||||
resolve(Object.keys(payload).reduce((acc, key) => acc.concat(`-${key}=${payload[key]}`), []));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* eslint-disable-next-line max-len */
|
||||||
|
export const generateArgsFromConf = (obj: ZcashConfFile): Array<string> => Object.keys(obj).reduce((acc, key) => {
|
||||||
|
// We can omit the credentials for the command line
|
||||||
|
if (key === 'rpcuser' || key === 'rpcpassword') return acc;
|
||||||
|
|
||||||
|
return acc.concat(`-${key}=${String(obj[key])}`);
|
||||||
|
}, []);
|
||||||
|
|
||||||
export const parseCmdArgs = (cmd: string): { user: string, password: string } => {
|
export const parseCmdArgs = (cmd: string): { user: string, password: string } => {
|
||||||
const rpcUserInArgs = cmd.split(' ').find(x => x.startsWith('-rpcuser'));
|
const rpcUserInArgs = cmd.split(' ').find(x => x.startsWith('-rpcuser'));
|
||||||
const rpcPasswordInArgs = cmd.split(' ').find(x => x.startsWith('-rpcpassword'));
|
const rpcPasswordInArgs = cmd.split(' ').find(x => x.startsWith('-rpcpassword'));
|
||||||
|
|
Loading…
Reference in New Issue