Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounting for AC in NTP widget contrib totals #3868

Merged
merged 1 commit into from
Nov 7, 2019
Merged
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
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)
}