Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1043 from lbryio/export-csv
Feature: export wallet transactions
- Loading branch information
Showing
17 changed files
with
191 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Link from 'component/link'; | ||
import parseData from 'util/parseData'; | ||
import * as icons from 'constants/icons'; | ||
const { remote } = require('electron'); | ||
|
||
class FileExporter extends React.PureComponent { | ||
static propTypes = { | ||
data: PropTypes.array, | ||
title: PropTypes.string, | ||
label: PropTypes.string, | ||
defaultPath: PropTypes.string, | ||
onFileCreated: PropTypes.func, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
handleFileCreation(filename, data) { | ||
const { onFileCreated } = this.props; | ||
fs.writeFile(filename, data, err => { | ||
if (err) throw err; | ||
// Do something after creation | ||
onFileCreated && onFileCreated(filename); | ||
}); | ||
} | ||
|
||
handleButtonClick() { | ||
const { title, defaultPath, data } = this.props; | ||
|
||
const options = { | ||
title, | ||
defaultPath, | ||
filters: [{ name: 'JSON', extensions: ['json'] }, { name: 'CSV', extensions: ['csv'] }], | ||
}; | ||
|
||
remote.dialog.showSaveDialog(options, filename => { | ||
// User hit cancel so do nothing: | ||
if (!filename) return; | ||
// Get extension and remove initial dot | ||
const format = path.extname(filename).replace(/\./g, ''); | ||
// Parse data to string with the chosen format | ||
const parsed = parseData(data, format); | ||
// Write file | ||
parsed && this.handleFileCreation(filename, parsed); | ||
}); | ||
} | ||
|
||
render() { | ||
const { title, label } = this.props; | ||
return ( | ||
<Link | ||
button="primary" | ||
icon={icons.DOWNLOAD} | ||
title={title || __('Export')} | ||
label={label || __('Export')} | ||
onClick={() => this.handleButtonClick()} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default FileExporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.