From f67bbeba152aa4f7a095c4567a7035c0596f0c81 Mon Sep 17 00:00:00 2001 From: George Lima Date: Mon, 18 Feb 2019 23:20:25 -0300 Subject: [PATCH] fix(settings): add getWalletFolderPath for all platforms --- app/views/settings.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/views/settings.js b/app/views/settings.js index 2cf19d0..8d3d516 100644 --- a/app/views/settings.js +++ b/app/views/settings.js @@ -2,6 +2,8 @@ /* eslint-disable import/no-extraneous-dependencies */ import fs from 'fs'; +import os from 'os'; +import path from 'path'; import { promisify } from 'util'; import React, { PureComponent } from 'react'; import styled from 'styled-components'; @@ -24,8 +26,6 @@ import { DARK, LIGHT } from '../constants/themes'; import electronStore from '../../config/electron-store'; import type { MapDispatchToProps, MapStateToProps } from '../containers/settings'; -const HOME_DIR = electron.remote.app.getPath('home'); - const Wrapper = styled.div` margin-top: ${props => props.theme.layoutContentPaddingTop}; `; @@ -111,6 +111,20 @@ export class SettingsView extends PureComponent { loadAddresses(); } + getWalletFolderPath = () => { + const { app } = electron.remote; + + 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'); + }; + exportViewKeys = () => { const { addresses } = this.props; @@ -189,15 +203,17 @@ export class SettingsView extends PureComponent { async (pathToSave: string) => { if (!pathToSave) return; - const zcashDir = isDev ? `${HOME_DIR}/.zcash/testnet3` : HOME_DIR; + const WALLET_DIR = this.getWalletFolderPath(); + + const zcashDir = isDev ? path.join(WALLET_DIR, 'testnet3') : WALLET_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."); + return; } const [error] = await eres(promisify(fs.copyFile)(walletDatPath, pathToSave));