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

Payment history CSV receipt links #3477 (WIP) #4312

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 13 additions & 0 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ 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 @@ -286,6 +287,18 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately there seems to be no way to specify the filename so it defaults to download.csv. but i'm fine with merging this as-is and fixing the filename in a later issue. thanks!

}
}
})
}

/*
Expand Down
4 changes: 4 additions & 0 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ const AboutActions = {
ipc.send(messages.LEDGER_CREATE_WALLET)
},

receiptLinkClick: function (viewingId, receiptFileName) {
ipc.send(messages.OPEN_LEDGER_TRANSACTION_CSV, viewingId, receiptFileName)
},

setLedgerEnabled: function (enabled) {
ipc.send(messages.LEDGER_ENABLE, enabled)
},
Expand Down
18 changes: 16 additions & 2 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ class PaymentHistory extends ImmutableComponent {
<tr>
<th className='sort-header' data-l10n-id='date' />
<th className='sort-header' data-l10n-id='totalAmount' />
<th className='sort-header' data-l10n-id='receiptLink' />
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -520,13 +521,26 @@ class PaymentHistoryRow extends ImmutableComponent {
return (fiatAmount && typeof fiatAmount === 'number' ? fiatAmount.toFixed(2) : '0.00')
}

get viewingId () {
return this.transaction.get('viewingId')
}

get receiptFileName () {
return `brave_ledger${this.numericDateStr}.csv`
}

onReceiptLinkClick () {
aboutActions.receiptLinkClick(this.viewingId, this.receiptFileName)
}

render () {
var date = this.formattedDate
var totalAmountStr = `${this.totalAmount} ${this.currency}`

return <tr>
<td data-sort={this.timestamp}>{date}</td>
<td data-sort={this.satoshis}>{totalAmountStr}</td>
<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>
</tr>
}
}
Expand Down
1 change: 1 addition & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const messages = {
LEDGER_PUBLISHER: _,
LEDGER_UPDATED: _,
LEDGER_CREATE_WALLET: _,
OPEN_LEDGER_TRANSACTION_CSV: _,
CHECK_BITCOIN_HANDLER: _,
ADD_FUNDS_CLOSED: _
}
Expand Down
3 changes: 1 addition & 2 deletions less/about/preferences.less
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ div.nextPaymentSubmission {

.modal .dialog.paymentHistory {
padding: 0px;
width: 450px;

.dialog-header {
background-color: #EEE;
Expand Down Expand Up @@ -684,7 +683,7 @@ div.nextPaymentSubmission {
font-weight: 500;
border-bottom: 2px solid @lightGray;
text-align: left;
width: 25%;
width: 18%;
}
td {
text-align: left;
Expand Down