Skip to content

Commit 68d3e9a

Browse files
committed
Add Rewards settings to brave://settings
1 parent 449351c commit 68d3e9a

File tree

16 files changed

+629
-12
lines changed

16 files changed

+629
-12
lines changed

app/brave_generated_resources.grd

+67
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,73 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
337337
<message name="IDS_SETTINGS_BRAVE_OTHER_SEARCH_ENGINES_DESC" desc="The description for the settings switch controlling the addition of custom search engines">
338338
Automatically indexes websites that follow the OpenSearch spec.
339339
</message>
340+
<!-- Settings / Rewards -->
341+
<message name="IDS_SETTINGS_BRAVE_REWARDS_TITLE" desc="The text label for the Rewards settings page">
342+
Brave Rewards
343+
</message>
344+
<message name="IDS_SETTINGS_BRAVE_REWARDS_DISABLED_LABEL" desc="The text label for the Rewards disabled state">
345+
Brave Rewards are disabled
346+
</message>
347+
<message name="IDS_SETTINGS_BRAVE_REWARDS_DISABLED_SUB_LABEL" desc="The text sublabel for the Rewards disabled state">
348+
Click here to learn more
349+
</message>
350+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_DETECTED_ITEM" desc="The menu item for auto-detected settings">
351+
Auto-detected
352+
</message>
353+
<message name="IDS_SETTINGS_BRAVE_REWARDS_DEFAULT_ITEM" desc="The menu item for default settings">
354+
Default
355+
</message>
356+
<message name="IDS_SETTINGS_BRAVE_REWARDS_DISABLED_ITEM" desc="The menu item for disabled settings">
357+
Disabled
358+
</message>
359+
<message name="IDS_SETTINGS_BRAVE_REWARDS_PRIVATE_ADS_TITLE" desc="The text label for the Rewards Private Ads section">
360+
Brave Private Ads
361+
</message>
362+
<message name="IDS_SETTINGS_BRAVE_REWARDS_PRIVATE_ADS_EARN_TOKENS_LABEL" desc="The text label for the settings switch controlling earning tokens for viewing private ads">
363+
Earn tokens by viewing Brave Ads. Ads presented are based on your interests, as inferred from your browsing behavior. No personal data or browsing history ever leaves your browser.
364+
</message>
365+
<message name="IDS_SETTINGS_BRAVE_REWARDS_MAX_ADS_TO_DISPLAY_LABEL" desc="The text label for the setting controlling the maximum number of ads to display">
366+
Maximum number of ads to display
367+
</message>
368+
<message name="IDS_SETTINGS_BRAVE_REWARDS_STATE_LEVEL_AD_TARGETING_LABEL" desc="The text label for the setting controlling state-level ad targeting">
369+
State-level ad targeting
370+
</message>
371+
<message name="IDS_SETTINGS_BRAVE_REWARDS_STATE_LEVEL_AD_TARGETING_DESC_LABEL" desc="The text label for the description of state-level ad targeting">
372+
This allows Brave to show you ads meant specifically for your state.
373+
</message>
374+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_TITLE" desc="The text label for the Rewards Auto-Contribute section">
375+
Auto-Contribute
376+
</message>
377+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_MONTHLY_LIMIT_LABEL" desc="The text label for the setting controlling the monthly auto-contribution limit">
378+
Monthly auto-contribution limit
379+
</message>
380+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_MIN_VISIT_TIME_LABEL" desc="The text label for the setting controlling the minimum page time before logging a visit">
381+
Minimum page time before logging a visit
382+
</message>
383+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_MIN_VISITS_LABEL" desc="The text label for the setting controlling the minimum page visits for publisher relevancy">
384+
Minimum visits for publisher relevancy
385+
</message>
386+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_SHOW_NON_VERIFIED_SITES_LABEL" desc="The text label for the setting controlling showing non-verified sites in the auto-contribution list">
387+
Show non-verified sites in list
388+
</message>
389+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_ALLOW_VIDEO_CONTRIBUTIONS_LABEL" desc="The text label for the setting controlling allowing contributions for videos">
390+
Allow contributions to videos
391+
</message>
392+
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_DESC_LABEL" desc="The text label for the description of auto-contribute">
393+
By turning on Auto-Contribute, you agree to the
394+
</message>
395+
<message name="IDS_SETTINGS_BRAVE_REWARDS_TIP_BUTTONS_TITLE" desc="The text label for the Rewards Tip Buttons section">
396+
Tip buttons
397+
</message>
398+
<message name="IDS_SETTINGS_BRAVE_REWARDS_INLINE_TIP_REDDIT_LABEL" desc="The text label for the setting switch controlling showing inline tip buttons on Reddit">
399+
Reddit
400+
</message>
401+
<message name="IDS_SETTINGS_BRAVE_REWARDS_INLINE_TIP_TWITTER_LABEL" desc="The text label for the setting switch controlling showing inline tip buttons on Twitter">
402+
Twitter
403+
</message>
404+
<message name="IDS_SETTINGS_BRAVE_REWARDS_INLINE_TIP_GITHUB_LABEL" desc="The text label for the setting switch controlling showing inline tip buttons on Github">
405+
Github
406+
</message>
340407
<!-- New Tab Page -->
341408
<message name="IDS_SETTINGS_NEW_TAB" desc="The text label for the New Tab settings page">
342409
New Tab Page

browser/extensions/api/settings_private/brave_prefs_util.cc

+29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "brave/browser/extensions/api/settings_private/brave_prefs_util.h"
77

8+
#include "bat/ads/pref_names.h"
89
#include "brave/browser/ethereum_remote_client/buildflags/buildflags.h"
910
#include "brave/common/pref_names.h"
1011
#include "brave/components/brave_rewards/common/pref_names.h"
@@ -117,6 +118,34 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
117118
(*s_brave_allowlist)[brave_shields::prefs::kLinkedInEmbedControlType] =
118119
settings_api::PrefType::PREF_TYPE_BOOLEAN;
119120

121+
// Rewards/Ads prefs
122+
(*s_brave_allowlist)[ads::prefs::kEnabled] =
123+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
124+
(*s_brave_allowlist)[ads::prefs::kAdsPerHour] =
125+
settings_api::PrefType::PREF_TYPE_NUMBER;
126+
(*s_brave_allowlist)[ads::prefs::kAdsSubdivisionTargetingCode] =
127+
settings_api::PrefType::PREF_TYPE_STRING;
128+
(*s_brave_allowlist)[brave_rewards::prefs::kEnabled] =
129+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
130+
(*s_brave_allowlist)[brave_rewards::prefs::kAutoContributeEnabled] =
131+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
132+
(*s_brave_allowlist)[brave_rewards::prefs::kAutoContributeAmount] =
133+
settings_api::PrefType::PREF_TYPE_NUMBER;
134+
(*s_brave_allowlist)[brave_rewards::prefs::kMinVisitTime] =
135+
settings_api::PrefType::PREF_TYPE_NUMBER;
136+
(*s_brave_allowlist)[brave_rewards::prefs::kMinVisits] =
137+
settings_api::PrefType::PREF_TYPE_NUMBER;
138+
(*s_brave_allowlist)[brave_rewards::prefs::kAllowNonVerified] =
139+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
140+
(*s_brave_allowlist)[brave_rewards::prefs::kAllowVideoContribution] =
141+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
142+
(*s_brave_allowlist)[brave_rewards::prefs::kInlineTipRedditEnabled] =
143+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
144+
(*s_brave_allowlist)[brave_rewards::prefs::kInlineTipTwitterEnabled] =
145+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
146+
(*s_brave_allowlist)[brave_rewards::prefs::kInlineTipGithubEnabled] =
147+
settings_api::PrefType::PREF_TYPE_BOOLEAN;
148+
120149
// Search engine prefs
121150
(*s_brave_allowlist)[prefs::kAddOpenSearchEngines] =
122151
settings_api::PrefType::PREF_TYPE_BOOLEAN;

browser/resources/settings/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ preprocess_if_expr("preprocess_generated") {
161161
"brave_new_tab_page/brave_new_tab_page.m.js",
162162
"brave_privacy_page/brave_personalization_options.m.js",
163163
"brave_privacy_page/brave_privacy_page_browser_proxy.m.js",
164+
"brave_rewards_page/brave_rewards_browser_proxy.m.js",
165+
"brave_rewards_page/brave_rewards_page.m.js",
164166
"brave_search_engines_page/brave_search_engines_page.m.js",
165167
"brave_sync_page/brave_sync_code_dialog.js",
166168
"brave_sync_page/brave_sync_configure.js",
@@ -280,6 +282,7 @@ group("web_modules") {
280282
"brave_ipfs_page:web_modules",
281283
"brave_new_tab_page:web_modules",
282284
"brave_privacy_page:web_modules",
285+
"brave_rewards_page:web_modules",
283286
"brave_search_engines_page:web_modules",
284287
"brave_sync_page:web_modules",
285288
"brave_wallet_page:web_modules",

browser/resources/settings/brave_icons.html

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<path
3232
d="M11.188 1.361l-7 3.111A1.999 1.999 0 0 0 3 6.3V11c0 7.83 6.439 11.486 9 12 2.561-.514 9-4.17 9-12V6.3a2 2 0 0 0-1.188-1.828l-7-3.111a1.997 1.997 0 0 0-1.624 0zm-.895 14.346l-2.77-2.77a1 1 0 0 1 1.414-1.414L11 13.586l5.085-5.085a1 1 0 0 1 1.414 1.414l-5.792 5.792a1 1 0 0 1-1.414 0z" />
3333
</g>
34+
<g id="rewards" viewBox="0 0 24 24">
35+
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.03697 20.985L7.4778 17.2013L11.9181 9.41949V1.91658C11.801 1.91658 11.6839 1.99467 11.595 2.14999L6.33531 11.3679L1.07601 20.5858C0.987365 20.7413 0.978953 20.8824 1.03697 20.985"/>
36+
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9182 1.91658V9.41949L16.3583 17.2013L22.7991 20.985C22.8574 20.8824 22.8489 20.7413 22.7603 20.5858L17.5008 11.3679L12.2411 2.14999C12.1522 1.99445 12.0351 1.91658 11.9182 1.91658"/>
37+
<path fill-rule="evenodd" clip-rule="evenodd" d="M22.7992 20.985L16.3584 17.2013H7.4779L1.03708 20.985C1.0951 21.088 1.21998 21.1519 1.39771 21.1519H22.4383C22.6161 21.1519 22.7409 21.088 22.7992 20.985"/>
38+
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.47787 17.2013H16.3583L11.9182 9.41951L7.47787 17.2013Z" fill="white"/>
39+
</g>
3440
<g id="social-permissions" viewBox="0 0 24 24">
3541
<path
3642
d="M2.75 3c-.414 0-.75.42-.75.938v9.374c0 .518.336.938.75.938h1.5c.414 0 .75-.42.75-.938V3.938C5 3.42 4.664 3 4.25 3h-1.5zm6.125 0A1.866 1.866 0 0 0 7 4.857v9.278c0 .492.197.963.547 1.31l5.185 5.146a1.417 1.417 0 0 0 1.67.239c.548-.297.834-.916.7-1.52l-.932-4.24h5.955A1.866 1.866 0 0 0 22 13.215v-1.855c0-.253-.051-.502-.152-.734l-2.82-6.5A1.876 1.876 0 0 0 17.305 3h-8.43z" />

browser/resources/settings/brave_overrides/basic_page.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import '../brave_default_extensions_page/brave_default_extensions_page.m.js'
1010
import '../brave_help_tips_page/brave_help_tips_page.m.js'
1111
import '../brave_ipfs_page/brave_ipfs_page.m.js'
1212
import '../brave_new_tab_page/brave_new_tab_page.m.js'
13+
import '../brave_rewards_page/brave_rewards_page.m.js'
1314
import '../brave_search_engines_page/brave_search_engines_page.m.js'
1415
import '../brave_sync_page/brave_sync_page.js'
1516
import '../brave_wallet_page/brave_wallet_page.m.js'
@@ -136,7 +137,6 @@ RegisterPolymerTemplateModifications({
136137
'settings-brave-sync-page',
137138
{}
138139
))
139-
140140
const sectionShields = document.createElement('template')
141141
sectionShields.setAttribute('is', 'dom-if')
142142
sectionShields.setAttribute('restamp', true)
@@ -149,6 +149,18 @@ RegisterPolymerTemplateModifications({
149149
prefs: '{{prefs}}'
150150
}
151151
))
152+
const sectionRewards = document.createElement('template')
153+
sectionRewards.setAttribute('is', 'dom-if')
154+
sectionRewards.setAttribute('restamp', true)
155+
sectionRewards.setAttribute('if', '[[showPage_(pageVisibility.rewards)]]')
156+
sectionRewards.content.appendChild(createSectionElement(
157+
'rewards',
158+
'braveRewards',
159+
'settings-brave-rewards-page',
160+
{
161+
prefs: '{{prefs}}'
162+
}
163+
))
152164
const sectionSocialBlocking = document.createElement('template')
153165
sectionSocialBlocking.setAttribute('is', 'dom-if')
154166
sectionSocialBlocking.setAttribute('restamp', true)
@@ -194,8 +206,10 @@ RegisterPolymerTemplateModifications({
194206
sectionAppearance.insertAdjacentElement('afterend', sectionNewTab)
195207
// Insert shields
196208
sectionNewTab.insertAdjacentElement('afterend', sectionShields)
209+
// Insert Rewards
210+
sectionShields.insertAdjacentElement('afterend', sectionRewards)
197211
// Insert Social Blocking
198-
sectionShields.insertAdjacentElement('afterend', sectionSocialBlocking)
212+
sectionRewards.insertAdjacentElement('afterend', sectionSocialBlocking)
199213
// Move privacy section to after social blocking
200214
const sectionPrivacy = getSectionElement(actualTemplate.content, 'privacy')
201215
sectionSocialBlocking.insertAdjacentElement('afterend', sectionPrivacy)

browser/resources/settings/brave_overrides/settings_menu.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,22 @@ RegisterPolymerTemplateModifications({
221221
'shields',
222222
)
223223
newTabEl.insertAdjacentElement('afterend', shieldsEl)
224+
// Add Rewards item
225+
const rewardsEl = createMenuElement(
226+
loadTimeData.getString('braveRewards'),
227+
'/rewards',
228+
'brave_settings:rewards',
229+
'rewards',
230+
)
231+
shieldsEl.insertAdjacentElement('afterend', rewardsEl)
224232
// Add Embed Blocking item
225233
const embedEl = createMenuElement(
226234
loadTimeData.getString('socialBlocking'),
227235
'/socialBlocking',
228236
'brave_settings:social-permissions',
229237
'socialBlocking',
230238
)
231-
shieldsEl.insertAdjacentElement('afterend', embedEl)
239+
rewardsEl.insertAdjacentElement('afterend', embedEl)
232240
// Add privacy
233241
const privacyEl = getMenuElement(templateContent, '/privacy')
234242
embedEl.insertAdjacentElement('afterend', privacyEl)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2021 The Brave Authors. All rights reserved.
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
# you can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
import("//tools/polymer/polymer.gni")
7+
import("//ui/webui/resources/tools/js_modulizer.gni")
8+
import("../settings.gni")
9+
10+
# ES Module conversion from HTML Imports code
11+
12+
group("web_modules") {
13+
public_deps = [
14+
":brave_rewards_page_module",
15+
":modules",
16+
]
17+
}
18+
19+
polymer_modulizer("brave_rewards_page") {
20+
js_file = "brave_rewards_page.js"
21+
html_file = "brave_rewards_page.html"
22+
html_type = "dom-module"
23+
auto_imports = settings_auto_imports + [ "brave/browser/resources/settings/brave_rewards_page/brave_rewards_browser_proxy.html|BraveRewardsBrowserProxy, BraveRewardsBrowserProxyImpl" ]
24+
namespace_rewrites = settings_namespace_rewrites
25+
}
26+
27+
js_modulizer("modules") {
28+
input_files = [ "brave_rewards_browser_proxy.js" ]
29+
namespace_rewrites = settings_namespace_rewrites
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<link rel="href" src="chrome://resources/html/cr.html">
2+
<script src="brave_rewards_browser_proxy.js"></script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
7+
8+
/** @interface */
9+
export class BraveRewardsBrowserProxy {
10+
isRewardsEnabled() {}
11+
getRewardsParameters() {}
12+
}
13+
14+
/**
15+
* @implements {settings.BraveRewardsBrowserProxy}
16+
*/
17+
export class BraveRewardsBrowserProxyImpl {
18+
/** @override */
19+
isRewardsEnabled () {
20+
return new Promise((resolve) => chrome.braveRewards.shouldShowOnboarding(
21+
(showOnboarding) => { resolve(!showOnboarding) }))
22+
}
23+
/** @override */
24+
getRewardsParameters () {
25+
return new Promise((resolve) => chrome.braveRewards.getRewardsParameters(
26+
(parameters) => { resolve(parameters) }))
27+
}
28+
}
29+
30+
addSingletonGetter(BraveRewardsBrowserProxyImpl)

0 commit comments

Comments
 (0)