From 3949154eb5c3632f91ddd2ad69e36807d8709f8f Mon Sep 17 00:00:00 2001 From: ryanml Date: Sun, 3 Nov 2019 23:48:36 -0700 Subject: [PATCH] Accounting for AC in NTP widget contrib totals Fixes brave/brave-browser#6740 --- components/brave_new_tab_ui/rewards-utils.ts | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/components/brave_new_tab_ui/rewards-utils.ts b/components/brave_new_tab_ui/rewards-utils.ts index 109e57323c36..925d3abc28f8 100644 --- a/components/brave_new_tab_ui/rewards-utils.ts +++ b/components/brave_new_tab_ui/rewards-utils.ts @@ -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) => { +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) => { + 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) }