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 3 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
19 changes: 19 additions & 0 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ if (ipc) {
if (balanceTimeoutId) clearTimeout(balanceTimeoutId)
balanceTimeoutId = setTimeout(getBalance, 5 * msecs.second)
})

ipc.on(messages.OPEN_LEDGER_TRANSACTION_CSV, (event, viewingIds, csvFilename) => {
if (client) {
var txCsvText = client._getTransactionCSVText(viewingIds)
Copy link
Member

Choose a reason for hiding this comment

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

i would replace all of the below with win.webContents.downloadURL(url), where url is txCsvText as a Blob object URL or perhaps a data URL. then the CSV file will be automatically written to the default downloads folder, and the user can click on the downloads bar to open it.


csvFilename = csvFilename || 'ledgerCsvExport.csv'

let savePath = pathName(csvFilename)

// create CSV
fs.writeFileSync(savePath, txCsvText)

// navigate to CSV
const win = electron.BrowserWindow.getFocusedWindow()
if (win && win.webContents) {
win.webContents.send(messages.SHORTCUT_NEW_FRAME, ('file://' + savePath), { singleFrame: true })
}
}
})
}

/*
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