Skip to content

Commit

Permalink
Hide auto-contribute section in brave://settings when region is JP
Browse files Browse the repository at this point in the history
  • Loading branch information
emerick committed Nov 12, 2021
1 parent 4608fbf commit 93989a7
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 56 deletions.
16 changes: 16 additions & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,22 @@ void BraveRewardsGetExternalWalletFunction::OnGetExternalWallet(
Respond(TwoArguments(base::Value(static_cast<int>(result)), std::move(data)));
}

BraveRewardsGetExternalWalletTypeFunction::
~BraveRewardsGetExternalWalletTypeFunction() {}

ExtensionFunction::ResponseAction
BraveRewardsGetExternalWalletTypeFunction::Run() {
Profile* profile = Profile::FromBrowserContext(browser_context());
RewardsService* rewards_service =
RewardsServiceFactory::GetForProfile(profile);
if (!rewards_service) {
return RespondNow(Error("Rewards service is not initialized"));
}

return RespondNow(
OneArgument(base::Value(rewards_service->GetExternalWalletType())));
}

BraveRewardsDisconnectWalletFunction::
~BraveRewardsDisconnectWalletFunction() {
}
Expand Down
10 changes: 10 additions & 0 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ class BraveRewardsGetExternalWalletFunction : public ExtensionFunction {
ledger::type::ExternalWalletPtr wallet);
};

class BraveRewardsGetExternalWalletTypeFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.getExternalWalletType", UNKNOWN)

protected:
~BraveRewardsGetExternalWalletTypeFunction() override;

ResponseAction Run() override;
};

class BraveRewardsDisconnectWalletFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.disconnectWallet", UNKNOWN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class BraveRewardsBrowserProxy {
getLocale() { /* Intentionally empty */ }
getRewardsEnabled() { /* Intentionally empty */ }
getRewardsParameters() { /* Intentionally empty */ }
getExternalWalletType() { /* Intentionally empty */ }
}

/**
Expand All @@ -31,6 +32,11 @@ export class BraveRewardsBrowserProxyImpl {
return new Promise((resolve) => chrome.braveRewards.getRewardsParameters(
(parameters) => { resolve(parameters) }))
}
/** @override */
getExternalWalletType () {
return new Promise((resolve) => chrome.braveRewards.getExternalWalletType(
(type) => { resolve(type) }))
}
}

addSingletonGetter(BraveRewardsBrowserProxyImpl)
100 changes: 51 additions & 49 deletions browser/resources/settings/brave_rewards_page/brave_rewards_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
disabled="[[!prefs.brave.brave_ads.enabled.value]]">
</settings-dropdown-menu>
</div>
<template is="dom-if" if="[[shouldAllowAdsSubdivisionTargeting_()]]" restamp>
<template is="dom-if" if="[[shouldAllowAdsSubdivisionTargeting_]]" restamp>
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsStateLevelAdTargetingLabel}</div>
Expand All @@ -55,58 +55,60 @@
<div class="settings-box continuation">
<p>$i18nRaw{braveRewardsStateLevelAdTargetingDescLabel}</p>
</div>
<div class="settings-box space-between">
<div class="label rewards-primary-title">$i18n{braveRewardsAutoContributeTitle}</div>
<settings-toggle-button
pref="{{prefs.brave.rewards.ac.enabled}}">
</settings-toggle-button>
</div>
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsAutoContributeMonthlyLimitLabel}</div>
<template is="dom-if" if="[[shouldShowAutoContributeSettings_]]">
<div class="settings-box space-between">
<div class="label rewards-primary-title">$i18n{braveRewardsAutoContributeTitle}</div>
<settings-toggle-button
pref="{{prefs.brave.rewards.ac.enabled}}">
</settings-toggle-button>
</div>
<settings-dropdown-menu
label="$i18n{braveRewardsAutoContributeMonthlyLimitLabel}"
pref="{{prefs.brave.rewards.ac.amount}}"
menu-options="[[autoContributeMonthlyLimit_]]"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-dropdown-menu>
</div>
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsAutoContributeMinVisitTimeLabel}</div>
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsAutoContributeMonthlyLimitLabel}</div>
</div>
<settings-dropdown-menu
label="$i18n{braveRewardsAutoContributeMonthlyLimitLabel}"
pref="{{prefs.brave.rewards.ac.amount}}"
menu-options="[[autoContributeMonthlyLimit_]]"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-dropdown-menu>
</div>
<settings-dropdown-menu
label="$i18n{braveRewardsAutoContributeMinVisitTimeLabel}"
pref="{{prefs.brave.rewards.ac.min_visit_time}}"
menu-options="[[autoContributeMinVisitTimeOptions_]]"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-dropdown-menu>
</div>
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsAutoContributeMinVisitsLabel}</div>
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsAutoContributeMinVisitTimeLabel}</div>
</div>
<settings-dropdown-menu
label="$i18n{braveRewardsAutoContributeMinVisitTimeLabel}"
pref="{{prefs.brave.rewards.ac.min_visit_time}}"
menu-options="[[autoContributeMinVisitTimeOptions_]]"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-dropdown-menu>
</div>
<settings-dropdown-menu
label="$i18n{braveRewardsAutoContributeMinVisitsLabel}"
pref="{{prefs.brave.rewards.ac.min_visits}}"
menu-options="[[autoContributeMinVisitsOptions_]]"
<div class="settings-box continuation">
<div class="flex cr-padded-text">
<div>$i18n{braveRewardsAutoContributeMinVisitsLabel}</div>
</div>
<settings-dropdown-menu
label="$i18n{braveRewardsAutoContributeMinVisitsLabel}"
pref="{{prefs.brave.rewards.ac.min_visits}}"
menu-options="[[autoContributeMinVisitsOptions_]]"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-dropdown-menu>
</div>
<settings-toggle-button
label="$i18n{braveRewardsAutoContributeShowNonVerifiedSitesLabel}"
pref="{{prefs.brave.rewards.ac.allow_non_verified}}"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-dropdown-menu>
</div>
<settings-toggle-button
label="$i18n{braveRewardsAutoContributeShowNonVerifiedSitesLabel}"
pref="{{prefs.brave.rewards.ac.allow_non_verified}}"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-toggle-button>
<settings-toggle-button
label="$i18n{braveRewardsAutoContributeAllowVideoContributionsLabel}"
pref="{{prefs.brave.rewards.ac.allow_video_contributions}}"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-toggle-button>
<div class="settings-box continuation">
<p>$i18nRaw{braveRewardsAutoContributeDescLabel}</p></p>
</div>
</settings-toggle-button>
<settings-toggle-button
label="$i18n{braveRewardsAutoContributeAllowVideoContributionsLabel}"
pref="{{prefs.brave.rewards.ac.allow_video_contributions}}"
disabled="[[!prefs.brave.rewards.ac.enabled.value]]">
</settings-toggle-button>
<div class="settings-box continuation">
<p>$i18nRaw{braveRewardsAutoContributeDescLabel}</p></p>
</div>
</template>
<div class="settings-box">
<div class="label rewards-primary-title">$i18n{braveRewardsTipButtonsTitle}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,18 @@ class SettingsBraveRewardsPage extends SettingsBraveRewardsPageBase {
]
}
},
autoContributeMonthlyLimit_: Array
autoContributeMonthlyLimit_: {
type: Array,
value: []
},
shouldAllowAdsSubdivisionTargeting_: {
type: Boolean,
value: false
},
shouldShowAutoContributeSettings_: {
type: Boolean,
value: true
}
}
}

Expand All @@ -138,15 +149,27 @@ class SettingsBraveRewardsPage extends SettingsBraveRewardsPageBase {
super.ready()
this.openRewardsPanel_ = () => {
chrome.braveRewards.openBrowserActionUI('brave_rewards_panel.html')
this.getExternalWalletTypeForAutoContributeSettings_()
this.populateAutoContributeAmountDropdown_()
}
this.browserProxy_.getLocale().then((locale) => {
this.shouldAllowAdsSubdivisionTargeting_ = locale === 'en-US'
})
this.browserProxy_.getRewardsEnabled().then((enabled) => {
if (enabled) {
this.getExternalWalletTypeForAutoContributeSettings_()
this.populateAutoContributeAmountDropdown_()
}
})
}

getExternalWalletTypeForAutoContributeSettings_() {
this.browserProxy_.getExternalWalletType().then((type) => {
// Show auto-contribute settings unless the external wallet type is bitFlyer
this.shouldShowAutoContributeSettings_ = type !== 'bitflyer'
})
}

populateAutoContributeAmountDropdown_() {
this.browserProxy_.getRewardsParameters().then((params) => {
let autoContributeChoices = [
Expand All @@ -161,11 +184,6 @@ class SettingsBraveRewardsPage extends SettingsBraveRewardsPageBase {
this.autoContributeMonthlyLimit_ = autoContributeChoices
})
}

async shouldAllowAdsSubdivisionTargeting_() {
const locale = await this.browserProxy_.getLocale()
return locale === 'en-US'
}
}

customElements.define(
Expand Down
17 changes: 17 additions & 0 deletions common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,23 @@
}
]
},
{
"name": "getExternalWalletType",
"type": "function",
"description": "Get external wallet type",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "type",
"type": "string"
}
]
}
]
},
{
"name": "disconnectWallet",
"type": "function",
Expand Down
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ class RewardsService : public KeyedService {

virtual void GetExternalWallet(GetExternalWalletCallback callback) = 0;

virtual std::string GetExternalWalletType() const = 0;

virtual const std::vector<std::string> GetExternalWalletProviders() const = 0;

virtual void ProcessRewardsPageUrl(
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class RewardsServiceImpl : public RewardsService,

void GetExternalWallet(GetExternalWalletCallback callback) override;

std::string GetExternalWalletType() const;
std::string GetExternalWalletType() const override;

const std::vector<std::string> GetExternalWalletProviders() const override;

Expand Down

0 comments on commit 93989a7

Please sign in to comment.