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

Adds support for BAT in brave payments #10953

Closed
wants to merge 1 commit 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
16 changes: 8 additions & 8 deletions app/common/lib/ledgerExportUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports.getPublisherVoteData = (transactions, viewingIds) => {
* Generates a contribution breakdown by publisher in an array of CSV rows from an array of transactions
* @example
* txUtil.getTransactionCSVRows(client.state.transactions)
* // [ ['Publisher,Votes,Fraction,BTC,USD'],
* // [ ['Publisher,Votes,Fraction,BAT,USD'],
* // ['chronicle.com,2,0.04081632653061224,0.0000033221,0.20 USD'],
* // ['waitbutwhy.com,3,0.061224489795918366,0.0000049832,0.31 USD'],
* // ['archlinux.org,1,0.02040816326530612,0.0000016611,0.10 USD'],
Expand Down Expand Up @@ -234,13 +234,13 @@ module.exports.getTransactionCSVRows = (transactions, viewingIds, addTotalRow, s

const currency = (publishers.length ? txContribData[publishers[0]].contribution.currency : 'USD')

const headerRow = ['Publisher', 'Votes', 'Fraction', 'BTC', currency].join(',')
const headerRow = ['Publisher', 'Votes', 'Fraction', 'BAT', currency].join(',')

var totalsRow = {
label: 'TOTAL',
votes: 0,
fraction: 0,
btc: 0,
bat: 0,
fiat: 0
}

Expand All @@ -249,10 +249,10 @@ module.exports.getTransactionCSVRows = (transactions, viewingIds, addTotalRow, s
rows = rows.concat(publishers.map(function (pub) {
var pubRow = txContribData[pub]

let rowBTC = pubRow.contribution.satoshis / Math.pow(10, 10)
let rowBAT = pubRow.contribution.satoshis / Math.pow(10, 10)
totalsRow.votes += pubRow.votes
totalsRow.fraction += pubRow.fraction
totalsRow.btc += rowBTC
totalsRow.bat += rowBAT

if (pubRow.contribution.currency === currency) {
totalsRow.fiat += parseFloat(pubRow.contribution.fiat || '0')
Expand All @@ -264,7 +264,7 @@ module.exports.getTransactionCSVRows = (transactions, viewingIds, addTotalRow, s
pub,
pubRow.votes,
pubRow.fraction,
rowBTC,
rowBAT,
pubRow.contribution.fiat.toFixed(2) + ' ' + pubRow.contribution.currency
].join(',')
}))
Expand All @@ -275,7 +275,7 @@ module.exports.getTransactionCSVRows = (transactions, viewingIds, addTotalRow, s
totalsRow.label,
totalsRow.votes,
totalsRow.fraction,
totalsRow.btc,
totalsRow.bat,
totalsRow.fiat.toFixed(2) + ' ' + currency
].join(','))
}
Expand All @@ -287,7 +287,7 @@ module.exports.getTransactionCSVRows = (transactions, viewingIds, addTotalRow, s
* Generates a contribution breakdown by publisher in an array of CSV rows from an array of transactions
* @example
* txUtil.getTransactionCSVText(state.transactions)
* // 'Publisher,Votes,Fraction,BTC,USD\nchronicle.com,2,0.04081632653061224,0.0000033221,0.20 USD\nwaitbutwhy.com,3,0.061224489795918366,0.0000049832,0.31 USD\narchlinux.org,1,0.02040816326530612,0.0000016611,0.10 USD /.../'
* // 'Publisher,Votes,Fraction,BAT,USD\nchronicle.com,2,0.04081632653061224,0.0000033221,0.20 USD\nwaitbutwhy.com,3,0.061224489795918366,0.0000049832,0.31 USD\narchlinux.org,1,0.02040816326530612,0.0000016611,0.10 USD /.../'
*
* @param {Object[]} transactions - array of transactions
* @param {string[]=} viewingIds - OPTIONAL array/string with one or more viewingIds to filter transactions by (if empty, uses all tx)
Expand Down
19 changes: 11 additions & 8 deletions app/common/lib/ledgerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ module.exports.shouldTrackView = (view, responseList) => {
return false
}

module.exports.btcToCurrencyString = (btc, ledgerData) => {
const balance = Number(btc || 0)
module.exports.batToCurrencyString = (bat, ledgerData) => {
const balance = Number(bat || 0)
const currency = ledgerData.get('currency') || 'USD'

if (balance === 0) {
return `0 ${currency}`
}

if (ledgerData.get('btc') && typeof ledgerData.get('amount') === 'number') {
const btcValue = ledgerData.get('btc') / ledgerData.get('amount')
const fiatValue = (balance / btcValue).toFixed(2)
const ledgerBat = ledgerData.get('bat')
const amount = ledgerData.get('amount')

if (ledgerBat && typeof amount === 'number') {
const batValue = ledgerBat / amount
const fiatValue = (balance / batValue).toFixed(2)
let roundedValue = Math.floor(fiatValue)
const diff = fiatValue - roundedValue

Expand All @@ -66,7 +69,7 @@ module.exports.btcToCurrencyString = (btc, ledgerData) => {
return `${roundedValue.toFixed(2)} ${currency}`
}

return `${balance} BTC`
return `${balance} BAT`
}

module.exports.formattedTimeFromNow = (timestamp) => {
Expand All @@ -89,11 +92,11 @@ module.exports.walletStatus = (ledgerData) => {
const pendingFunds = Number(ledgerData.get('unconfirmed') || 0)

if (pendingFunds + Number(ledgerData.get('balance') || 0) <
0.9 * Number(ledgerData.get('btc') || 0)) {
0.9 * Number(ledgerData.get('bat') || 0)) {
status.id = 'insufficientFundsStatus'
} else if (pendingFunds > 0) {
status.id = 'pendingFundsStatus'
status.args = {funds: module.exports.btcToCurrencyString(pendingFunds, ledgerData)}
status.args = {funds: module.exports.batToCurrencyString(pendingFunds, ledgerData)}
} else if (transactions && transactions.size > 0) {
status.id = 'defaultWalletStatus'
} else {
Expand Down
16 changes: 6 additions & 10 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ backupLedger=Backup your wallet
balanceRecovered={{balance}} was recovered and transferred to your Brave wallet.
beta=beta
bitcoin=Bitcoin
bitcoinAdd=Use your existing Bitcoin wallet/account
bitcoinAddDescription=Use any BTC wallet that can transfer Bitcoin to your Brave wallet.
bitcoinAdd=Use your existing Ethereum wallet/account
bitcoinAddDescription=Use ETH wallet that can transfer BAT to your Brave wallet.
bitcoinBalance=Please transfer:&nbsp;
bitcoinBuy=Buy Bitcoin
bitcoinCopyAddress=Copy Bitcoin address to clipboard
Expand Down Expand Up @@ -60,8 +60,7 @@ cancel=Cancel
checkDefaultOnStartup=Always check on startup
clearAll=Clear all
clearBrowsingDataNow=Clear Browsing Data Now…
coinbaseMessage=debit/credit funding powered by coinbase
coinbaseNotAvailable=Sorry! Adding funds with a credit/debit card is available only for contributions of $5/month at the moment.
upholdMessage=debit/credit funding powered by Uphold
comingSoon=Coming soon!
compactBraveryPanel=Use compact panel
contentSettings=Content Settings
Expand Down Expand Up @@ -132,9 +131,6 @@ flashTroubleshooting=Flash not working? Try the troubleshooting tips on our
fr-FR=French (France)
fullscreenContent=Full Screen Content
fullscreenPermission=Fullscreen access
fundingDisabled1=Card funding is temporarily unavailable.
fundingDisabled2=We apologize for the inconvenience.
fundingDisabled3=Learn more...
general=General
generalSettings=General Settings
geolocationPermission=Location access
Expand Down Expand Up @@ -186,7 +182,7 @@ minimumVisitsLow=1 visit
minimumVisitsMedium=5 visits
minimumVisitsSetting=Minimum visits for publisher relevancy
moneyAdd=Use your debit/credit card
moneyAddSubTitle=No Bitcoin needed!
moneyAddSubTitle=No BAT needed!
monthlyBudget=monthly budget
ms-MY=Malay (Malaysia)
multipleHomePages.title=Multiple home pages
Expand Down Expand Up @@ -302,7 +298,7 @@ site=Site
sitePermissions=Saved Site Permissions
sitePermissionsExceptions=Saved Site Exceptions
sl=Slovenian
smartphoneTitle=Use your smartphone app to transfer Bitcoin
smartphoneTitle=Use your smartphone app to transfer BAT
startsWith=Brave starts with
startsWithOptionHomePage=Home page
startsWithOptionLastTime=My windows / tabs from last time
Expand Down Expand Up @@ -385,4 +381,4 @@ visits=Visits
wideURLbar=Use wide URL bar
widevine=Run Google Widevine
widevineSection=Google Widevine Support
zh-CN=Chinese
zh-CN=Chinese
Loading