feature(settings): add backup wallet.dat button
This commit is contained in:
parent
fa6fbb16cd
commit
e966a80129
|
@ -1,6 +1,13 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
|
import fs from 'fs';
|
||||||
|
import { promisify } from 'util';
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import electron from 'electron';
|
||||||
|
import isDev from 'electron-is-dev';
|
||||||
|
import dateFns from 'date-fns';
|
||||||
|
import eres from 'eres';
|
||||||
|
|
||||||
import { Button } from '../components/button';
|
import { Button } from '../components/button';
|
||||||
import { ConfirmDialogComponent } from '../components/confirm-dialog';
|
import { ConfirmDialogComponent } from '../components/confirm-dialog';
|
||||||
|
@ -12,6 +19,8 @@ import { Clipboard } from '../components/clipboard';
|
||||||
|
|
||||||
import rpc from '../../services/api';
|
import rpc from '../../services/api';
|
||||||
|
|
||||||
|
const HOME_DIR = electron.remote.app.getPath('home');
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
margin-top: ${props => props.theme.layoutContentPaddingTop};
|
margin-top: ${props => props.theme.layoutContentPaddingTop};
|
||||||
`;
|
`;
|
||||||
|
@ -135,6 +144,40 @@ 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) => {
|
||||||
|
const [error] = await eres(
|
||||||
|
promisify(fs.copyFile)(walletDatPath, pathToSave),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
alert(
|
||||||
|
"Couldn't backup the wallet.dat file. You need to back it up manually.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
const {
|
const {
|
||||||
viewKeys,
|
viewKeys,
|
||||||
|
@ -238,6 +281,8 @@ export class SettingsView extends PureComponent<Props, State> {
|
||||||
{error && <TextComponent value={error} align='center' />}
|
{error && <TextComponent value={error} align='center' />}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</ConfirmDialogComponent>
|
</ConfirmDialogComponent>
|
||||||
|
|
||||||
|
<Btn label='Backup wallet.dat' onClick={this.backupWalletDat} />
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue