fix(settings): check for null pathToSave before to backup wallet

This commit is contained in:
George Lima 2019-01-13 00:06:05 -03:00
parent e966a80129
commit d5a658e4c6
1 changed files with 15 additions and 12 deletions

View File

@ -145,26 +145,29 @@ export class SettingsView extends PureComponent<Props, State> {
};
backupWalletDat = async () => {
const zcashDir = isDev ? `${HOME_DIR}/.zcash/testnet3` : HOME_DIR;
const walletDatPath = `${zcashDir}/wallet.dat`;
const backupFileName = `zcash-wallet-backup-${dateFns.format(
new Date(),
'YYYY-MM-DD-mm-ss',
)}.dat`;
const [cannotAccess] = await eres(promisify(fs.access)(walletDatPath));
/* eslint-disable no-alert */
if (cannotAccess) {
alert(
"Couldn't backup the wallet.dat file. You need to back it up manually.",
);
}
electron.remote.dialog.showSaveDialog(
{ defaultPath: backupFileName },
async (pathToSave) => {
if (!pathToSave) return;
const zcashDir = isDev ? `${HOME_DIR}/.zcash/testnet3` : HOME_DIR;
const walletDatPath = `${zcashDir}/wallet.dat`;
const [cannotAccess] = await eres(promisify(fs.access)(walletDatPath));
/* eslint-disable no-alert */
if (cannotAccess) {
alert(
"Couldn't backup the wallet.dat file. You need to back it up manually.",
);
}
const [error] = await eres(
promisify(fs.copyFile)(walletDatPath, pathToSave),
);