diff --git a/CHANGELOG.md b/CHANGELOG.md index 40af3e98d..dad9cdab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ Web UI version numbers should always match the corresponding version of LBRY App ## [Unreleased] ### Added * Save app state when closing to tray ([#968](https://github.com/lbryio/lbry-app/issues/968)) + * Added ability to export wallet transactions to JSON and CSV format ([#976](https://github.com/lbryio/lbry-app/pull/976)) * Add Rewards FAQ to LBRY app ([#1041](https://github.com/lbryio/lbry-app/pull/1041)) + * ### Changed * diff --git a/src/renderer/analytics.js b/src/renderer/analytics.js index 7d426e4f9..c0fd82f13 100644 --- a/src/renderer/analytics.js +++ b/src/renderer/analytics.js @@ -5,16 +5,16 @@ mixpanel.init('691723e855cabb9d27a7a79002216967'); type Analytics = { track: (string, ?Object) => void, - setUser: (Object) => void, - toggle: (boolean, ?boolean) => void -} + setUser: Object => void, + toggle: (boolean, ?boolean) => void, +}; let analyticsEnabled: boolean = false; const analytics: Analytics = { track: (name: string, payload: ?Object): void => { - if(analyticsEnabled) { - if(payload) { + if (analyticsEnabled) { + if (payload) { mixpanel.track(name, payload); } else { mixpanel.track(name); @@ -22,21 +22,21 @@ const analytics: Analytics = { } }, setUser: (user: Object): void => { - if(user.id) { + if (user.id) { mixpanel.identify(user.id); } - if(user.primary_email) { + if (user.primary_email) { mixpanel.people.set({ - "$email": user.primary_email + $email: user.primary_email, }); } }, toggle: (enabled: boolean, logDisabled: ?boolean): void => { - if(!enabled && logDisabled) { + if (!enabled && logDisabled) { mixpanel.track('DISABLED'); } analyticsEnabled = enabled; - } -} + }, +}; export default analytics; diff --git a/src/renderer/component/file-exporter.js b/src/renderer/component/file-exporter.js new file mode 100644 index 000000000..703d565ab --- /dev/null +++ b/src/renderer/component/file-exporter.js @@ -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 ( + this.handleButtonClick()} + /> + ); + } +} + +export default FileExporter; diff --git a/src/renderer/component/transactionList/view.jsx b/src/renderer/component/transactionList/view.jsx index 0d5de3597..df1be4813 100644 --- a/src/renderer/component/transactionList/view.jsx +++ b/src/renderer/component/transactionList/view.jsx @@ -2,6 +2,7 @@ import React from 'react'; import TransactionListItem from './internal/TransactionListItem'; import FormField from 'component/formField'; import Link from 'component/link'; +import FileExporter from 'component/file-exporter.js'; import * as icons from 'constants/icons'; import * as modals from 'constants/modal_types'; @@ -43,6 +44,13 @@ class TransactionList extends React.PureComponent { return (
- {__( - 'Your LBRY update is ready. Restart LBRY now to use it!' - )} -
+{__('Your LBRY update is ready. Restart LBRY now to use it!')}
{__('Want to know what has changed?')} See the{' '}
.
diff --git a/src/renderer/modal/modalAutoUpdateDownloaded/index.js b/src/renderer/modal/modalAutoUpdateDownloaded/index.js
index 7283489aa..855d556df 100644
--- a/src/renderer/modal/modalAutoUpdateDownloaded/index.js
+++ b/src/renderer/modal/modalAutoUpdateDownloaded/index.js
@@ -1,7 +1,7 @@
-import React from "react";
-import { connect } from "react-redux";
-import { doCloseModal, doAutoUpdateDeclined } from "redux/actions/app";
-import ModalAutoUpdateDownloaded from "./view";
+import React from 'react';
+import { connect } from 'react-redux';
+import { doCloseModal, doAutoUpdateDeclined } from 'redux/actions/app';
+import ModalAutoUpdateDownloaded from './view';
const perform = dispatch => ({
closeModal: () => dispatch(doCloseModal()),
diff --git a/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx b/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx
index fda5ed519..c067c24ba 100644
--- a/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx
+++ b/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx
@@ -1,9 +1,9 @@
-import React from "react";
-import { Modal } from "modal/modal";
-import { Line } from "rc-progress";
-import Link from "component/link/index";
+import React from 'react';
+import { Modal } from 'modal/modal';
+import { Line } from 'rc-progress';
+import Link from 'component/link/index';
-const { ipcRenderer } = require("electron");
+const { ipcRenderer } = require('electron');
class ModalAutoUpdateDownloaded extends React.PureComponent {
render() {
@@ -13,20 +13,20 @@ class ModalAutoUpdateDownloaded extends React.PureComponent {
{__(
'A new version of LBRY has been released, downloaded, and is ready for you to use pending a restart.'
diff --git a/src/renderer/page/settings/view.jsx b/src/renderer/page/settings/view.jsx
index 639d9195e..d2a22db03 100644
--- a/src/renderer/page/settings/view.jsx
+++ b/src/renderer/page/settings/view.jsx
@@ -334,7 +334,7 @@ class SettingsPage extends React.PureComponent {
{__("LBRY Leveled Up")}
+ {__('LBRY Leveled Up')}