Skip to content

Commit

Permalink
swaps NTP HTTPS upgrades stat for bandwidth saved
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriusA committed May 4, 2020
1 parent bcda739 commit 571a15e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
3 changes: 0 additions & 3 deletions browser/ui/webui/brave_new_tab_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions components/brave_new_tab_ui/api/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
export type Stats = {
adsBlockedStat: number,
javascriptBlockedStat: number,
httpsUpgradesStat: number,
fingerprintingBlockedStat: number
fingerprintingBlockedStat: number,
bandwidthSavedStat: number
}

type StatsUpdatedHandler = (statsData: Stats) => void
Expand Down
46 changes: 39 additions & 7 deletions components/brave_new_tab_ui/containers/newTab/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -59,19 +88,22 @@ 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>
<StatsItem
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)}
Expand Down
2 changes: 1 addition & 1 deletion components/brave_new_tab_ui/storage/new_tab_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const defaultState: NewTab.State = {
stats: {
adsBlockedStat: 0,
javascriptBlockedStat: 0,
httpsUpgradesStat: 0,
bandwidthSavedStat: 0,
fingerprintingBlockedStat: 0
},
rewardsState: {
Expand Down
2 changes: 1 addition & 1 deletion components/definitions/newTab.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ declare namespace NewTab {
export interface Stats {
adsBlockedStat: number
javascriptBlockedStat: number
httpsUpgradesStat: number
bandwidthSavedStat: number
fingerprintingBlockedStat: number
}

Expand Down
2 changes: 1 addition & 1 deletion components/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const newTabInitialState: NewTab.ApplicationState = {
stats: {
adsBlockedStat: 0,
javascriptBlockedStat: 0,
httpsUpgradesStat: 0,
bandwidthSavedStat: 0,
fingerprintingBlockedStat: 0
}
}
Expand Down

0 comments on commit 571a15e

Please sign in to comment.