Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2866 from ethcore/ng-accounts-backup
Browse files Browse the repository at this point in the history
Export accounts as JSON or CSV
  • Loading branch information
gavofyork authored Nov 16, 2016
2 parents a5c6cc3 + b9f3c4b commit b9e9544
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
14 changes: 7 additions & 7 deletions js/src/ui/Actionbar/Export/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';

import FileSaver from 'file-saver';
import FileDownloadIcon from 'material-ui/svg-icons/file/file-download';

Expand All @@ -38,19 +39,18 @@ class ActionbarExport extends Component {
className={ className }
icon={ <FileDownloadIcon /> }
label='export'
onClick={ this.onDownloadBackup } />
onClick={ this.handleExport }
/>
);
}

onDownloadBackup = () => {
handleExport = () => {
const { filename, content } = this.props;

const text = (typeof content === 'string')
? content
: JSON.stringify(content, null, 4);
const text = JSON.stringify(content, null, 4);

const blob = new Blob([ text ], { type: 'text/plain;charset=utf-8' });
FileSaver.saveAs(blob, filename);
const blob = new Blob([ text ], { type: 'application/json' });
FileSaver.saveAs(blob, `${filename}.json`);
}
}

Expand Down
9 changes: 8 additions & 1 deletion js/src/views/Accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { uniq } from 'lodash';

import List from './List';
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';

Expand Down Expand Up @@ -97,13 +97,20 @@ class Accounts extends Component {
}

renderActionbar () {
const { accounts } = this.props;

const buttons = [
<Button
key='newAccount'
icon={ <ContentAdd /> }
label='new account'
onClick={ this.onNewAccountClick } />,

<ActionbarExport
key='exportAccounts'
content={ accounts }
filename='accounts' />,

this.renderSearchButton(),
this.renderSortButton()
];
Expand Down
2 changes: 1 addition & 1 deletion js/src/views/Addresses/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Addresses extends Component {
<ActionbarExport
key='exportAddressbook'
content={ contacts }
filename='addressbook.json' />,
filename='addressbook' />,

<ActionbarImport
key='importAddressbook'
Expand Down

0 comments on commit b9e9544

Please sign in to comment.