Merge pull request #2866 from ethcore/ng-accounts-backup

Export accounts as JSON or CSV
This commit is contained in:
Gav Wood 2016-11-16 11:31:18 +08:00 committed by GitHub
commit b9e9544841
3 changed files with 16 additions and 9 deletions

View File

@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import FileSaver from 'file-saver'; import FileSaver from 'file-saver';
import FileDownloadIcon from 'material-ui/svg-icons/file/file-download'; import FileDownloadIcon from 'material-ui/svg-icons/file/file-download';
@ -38,19 +39,18 @@ class ActionbarExport extends Component {
className={ className } className={ className }
icon={ <FileDownloadIcon /> } icon={ <FileDownloadIcon /> }
label='export' label='export'
onClick={ this.onDownloadBackup } /> onClick={ this.handleExport }
/>
); );
} }
onDownloadBackup = () => { handleExport = () => {
const { filename, content } = this.props; const { filename, content } = this.props;
const text = (typeof content === 'string') const text = JSON.stringify(content, null, 4);
? content
: JSON.stringify(content, null, 4);
const blob = new Blob([ text ], { type: 'text/plain;charset=utf-8' }); const blob = new Blob([ text ], { type: 'application/json' });
FileSaver.saveAs(blob, filename); FileSaver.saveAs(blob, `${filename}.json`);
} }
} }

View File

@ -22,7 +22,7 @@ import { uniq } from 'lodash';
import List from './List'; import List from './List';
import { CreateAccount } from '../../modals'; import { CreateAccount } from '../../modals';
import { Actionbar, ActionbarSearch, ActionbarSort, Button, Page, Tooltip } from '../../ui'; import { Actionbar, ActionbarExport, ActionbarSearch, ActionbarSort, Button, Page, Tooltip } from '../../ui';
import styles from './accounts.css'; import styles from './accounts.css';
@ -97,6 +97,8 @@ class Accounts extends Component {
} }
renderActionbar () { renderActionbar () {
const { accounts } = this.props;
const buttons = [ const buttons = [
<Button <Button
key='newAccount' key='newAccount'
@ -104,6 +106,11 @@ class Accounts extends Component {
label='new account' label='new account'
onClick={ this.onNewAccountClick } />, onClick={ this.onNewAccountClick } />,
<ActionbarExport
key='exportAccounts'
content={ accounts }
filename='accounts' />,
this.renderSearchButton(), this.renderSearchButton(),
this.renderSortButton() this.renderSortButton()
]; ];

View File

@ -107,7 +107,7 @@ class Addresses extends Component {
<ActionbarExport <ActionbarExport
key='exportAddressbook' key='exportAddressbook'
content={ contacts } content={ contacts }
filename='addressbook.json' />, filename='addressbook' />,
<ActionbarImport <ActionbarImport
key='importAddressbook' key='importAddressbook'