Skip to content

Commit

Permalink
Accounting for AC in NTP widget contrib totals
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml committed Nov 4, 2019
1 parent f9bed3c commit 3949154
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions components/brave_new_tab_ui/rewards-utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import { tipsTotal } from '../brave_rewards/resources/page/utils'

export const getTotalContributions = (reports: Record<string, NewTab.RewardsReport>) => {
import BigNumber from 'bignumber.js'

const getReportIndex = () => {
const currentTime = new Date()
const year = currentTime.getFullYear()
const month = (currentTime.getMonth() + 1)
const report: NewTab.RewardsReport = reports[`${year}_${month}`]

if (!report) {
return `${year}_${month}`
}

export const getTotalContributions = (reports: Record<string, NewTab.RewardsReport>) => {
const reportIndex = getReportIndex()

if (!reports.hasOwnProperty(reportIndex)) {
return '0.0'
}

return tipsTotal(report)
const report = reports[reportIndex]
const tips = new BigNumber(report.tips)
const contribute = new BigNumber(report.contribute)

return new BigNumber(report.donation)
.plus(tips)
.plus(contribute)
.dividedBy('1e18')
.toFixed(1, BigNumber.ROUND_DOWN)
}

0 comments on commit 3949154

Please sign in to comment.