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

Export accounts as JSON or CSV #2866

Merged
merged 6 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,13 +96,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 @@ -105,7 +105,7 @@ class Addresses extends Component {
<ActionbarExport
key='exportAddressbook'
content={ contacts }
filename='addressbook.json' />,
filename='addressbook' />,

this.renderSearchButton(),
this.renderSortButton()
Expand Down