Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Payment History CSV export download has correct filename
Browse files Browse the repository at this point in the history
simpler: export is just a data URL link, filename suggested by <a> `download` attribute
depends on brave/ledger-client@d50d59e
fixes #4332
  • Loading branch information
Willy Bruns committed Sep 28, 2016
1 parent 7c44c28 commit 87ad861
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
13 changes: 0 additions & 13 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const appStore = require('../js/stores/appStore')
const eventStore = require('../js/stores/eventStore')
const rulesolver = require('./extensions/brave/content/scripts/pageInformation.js')
const ledgerUtil = require('./common/lib/ledgerUtil')
const base64Encode = require('../js/lib/base64').encode

// TBD: remove these post beta [MTR]
const logPath = 'ledger-log.json'
Expand Down Expand Up @@ -287,18 +286,6 @@ if (ipc) {
if (balanceTimeoutId) clearTimeout(balanceTimeoutId)
balanceTimeoutId = setTimeout(getBalance, 5 * msecs.second)
})

ipc.on(messages.OPEN_LEDGER_TRANSACTION_CSV, (event, viewingIds, csvFilename) => {
if (client) {
let txCsvText = client.getTransactionCSVText(viewingIds)
let txCsvTextDataURI = 'data:text/csv;base64,' + base64Encode(txCsvText)

const win = electron.BrowserWindow.getFocusedWindow()
if (win && win.webContents) {
win.webContents.downloadURL(txCsvTextDataURI)
}
}
})
}

/*
Expand Down
7 changes: 4 additions & 3 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Immutable = require('immutable')
const SwitchControl = require('../components/switchControl')
const ModalOverlay = require('../components/modalOverlay')
const cx = require('../lib/classSet.js')
const transactionsToCSVDataURL = require('../lib/ledgerExportUtil.js').transactionsToCSVDataURL
const { getZoomValuePercentage } = require('../lib/zoom')
const config = require('../constants/config')
const appConfig = require('../constants/appConfig')
Expand Down Expand Up @@ -529,8 +530,8 @@ class PaymentHistoryRow extends ImmutableComponent {
return `brave_ledger${this.numericDateStr}.csv`
}

onReceiptLinkClick () {
aboutActions.receiptLinkClick(this.viewingId, this.receiptFileName)
get dataURL () {
return transactionsToCSVDataURL(this.transaction.toJS())
}

render () {
Expand All @@ -540,7 +541,7 @@ class PaymentHistoryRow extends ImmutableComponent {
return <tr>
<td className='narrow' data-sort={this.timestamp}>{date}</td>
<td className='wide' data-sort={this.satoshis}>{totalAmountStr}</td>
<td className='wide'><a onClick={this.onReceiptLinkClick.bind(this)}>{this.receiptFileName}</a></td>
<td className='wide'><a href={this.dataURL} download={this.receiptFileName}>{this.receiptFileName}</a></td>
</tr>
}
}
Expand Down
13 changes: 13 additions & 0 deletions js/lib/ledgerExportUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const txUtil = require('ledger-client/util')
const base64Encode = require('./base64').encode

let transactionsToCSVDataURL = function (transactions) {
let csvText = txUtil.getTransactionCSVText(transactions)
return 'data:text/csv;base64,' + base64Encode(csvText)
}

module.exports = {
transactionsToCSVRows: txUtil.getTransactionCSVRows,
transactionsToCSVText: txUtil.getTransactionCSVText,
transactionsToCSVDataURL: transactionsToCSVDataURL
}

0 comments on commit 87ad861

Please sign in to comment.