swaps NTP HTTPS upgrades stat for bandwidth saved

This commit is contained in:
AndriusA
2020-05-12 11:44:20 +01:00
parent 5b8545df55
commit ba063e1e5a
6 changed files with 44 additions and 15 deletions
@@ -52,9 +52,6 @@ base::DictionaryValue GetStatsDictionary(PrefService* prefs) {
stats_data.SetInteger(
"javascriptBlockedStat",
prefs->GetUint64(kJavascriptBlocked));
stats_data.SetInteger(
"httpsUpgradesStat",
prefs->GetUint64(kHttpsUpgrades));
stats_data.SetInteger(
"fingerprintingBlockedStat",
prefs->GetUint64(kFingerprintingBlocked));
+2 -2
View File
@@ -13,8 +13,8 @@
export type Stats = {
adsBlockedStat: number,
javascriptBlockedStat: number,
httpsUpgradesStat: number,
fingerprintingBlockedStat: number
fingerprintingBlockedStat: number,
bandwidthSavedStat: number
}
type StatsUpdatedHandler = (statsData: Stats) => void
@@ -21,8 +21,37 @@ class Stats extends React.Component<Props, {}> {
return this.props.stats.adsBlockedStat || 0
}
get httpsUpgradedCount () {
return this.props.stats.httpsUpgradesStat || 0
get estimatedBandwidthSaved () {
const estimatedBWSaved = this.props.stats.bandwidthSavedStat
if (estimatedBWSaved) {
const bytes = estimatedBWSaved < 1024
const kilobytes = estimatedBWSaved < 1024 * 1024
const megabytes = estimatedBWSaved < 1024 * 1024 * 1024
let counter
let id
if (bytes) {
counter = estimatedBWSaved
id = 'B'
} else if (kilobytes) {
counter = (estimatedBWSaved / 1024).toFixed(0)
id = 'KB'
} else if (megabytes) {
counter = (estimatedBWSaved / 1024 / 1024).toFixed(1)
id = 'MB'
} else {
counter = (estimatedBWSaved / 1024 / 1024 / 1024).toFixed(2)
id = 'GB'
}
return {
id,
value: counter,
args: JSON.stringify({ value: counter })
}
} else {
return false
}
}
get estimatedTimeSaved () {
@@ -59,8 +88,8 @@ class Stats extends React.Component<Props, {}> {
render () {
const trackedBlockersCount = this.adblockCount.toLocaleString()
const httpsUpgradedCount = this.httpsUpgradedCount.toLocaleString()
const timeSaved = this.estimatedTimeSaved
const bandwidthSaved = this.estimatedBandwidthSaved
return (
<StatsContainer>
@@ -68,10 +97,13 @@ class Stats extends React.Component<Props, {}> {
description={getLocale('adsTrackersBlocked')}
counter={trackedBlockersCount}
/>
<StatsItem
description={getLocale('httpsUpgraded')}
counter={httpsUpgradedCount}
/>
{bandwidthSaved &&
<StatsItem
counter={bandwidthSaved.value}
text={getLocale(bandwidthSaved.id)}
description={getLocale('estimatedBandwidthSaved')}
/>
}
<StatsItem
counter={timeSaved.value}
text={getLocale(timeSaved.id)}
@@ -28,7 +28,7 @@ export const defaultState: NewTab.State = {
stats: {
adsBlockedStat: 0,
javascriptBlockedStat: 0,
httpsUpgradesStat: 0,
bandwidthSavedStat: 0,
fingerprintingBlockedStat: 0
},
rewardsState: {
+1 -1
View File
@@ -58,7 +58,7 @@ declare namespace NewTab {
export interface Stats {
adsBlockedStat: number
javascriptBlockedStat: number
httpsUpgradesStat: number
bandwidthSavedStat: number
fingerprintingBlockedStat: number
}
+1 -1
View File
@@ -54,7 +54,7 @@ export const newTabInitialState: NewTab.ApplicationState = {
stats: {
adsBlockedStat: 0,
javascriptBlockedStat: 0,
httpsUpgradesStat: 0,
bandwidthSavedStat: 0,
fingerprintingBlockedStat: 0
}
}