Skip to content

Commit

Permalink
Fixes brave/brave-browser#9416 - Removes Binance options from newtab …
Browse files Browse the repository at this point in the history
…settings when unsupported
  • Loading branch information
ryanml committed May 7, 2020
1 parent 311874b commit 1537774
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 7 deletions.
7 changes: 5 additions & 2 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,13 @@ source_set("browser_process") {
"binance/binance_protocol_handler.h",
"binance/binance_util.cc",
"binance/binance_util.h",
"static_values.h",
"binance/static_values.h",
]

deps += [ "//brave/components/binance/browser" ]
deps += [
"//brave/components/binance/browser",
"//components/country_codes",
]
}

if (enable_tor) {
Expand Down
4 changes: 3 additions & 1 deletion browser/binance/binance_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* 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/. */

#include "brave/browser/binance/binance_util.h"

#include "chrome/browser/profiles/profile.h"
#include "components/country_codes/country_codes.h"
#include "static_values.h"
#include "brave/browser/binance/static_values.h"

namespace binance {

Expand Down
1 change: 1 addition & 0 deletions browser/binance/static_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const std::vector<std::string> kBinanceBlacklistRegions = {
"UA",
"CU",
"IR",
"JP",
"LB",
"LY",
"KP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* @return {!Promise<Boolean>}
*/
getIsSuperReferralActive() {}

/**
* @return {!Promise<Boolean>}
*/
getIsBinanceSupported() {}
}

/**
Expand All @@ -19,6 +24,11 @@
getIsSuperReferralActive() {
return cr.sendWithPromise('getIsSuperReferralActive');
}

/** @override */
getIsBinanceSupported() {
return cr.sendWithPromise('getIsBinanceSupported')
}
}

cr.addSingletonGetter(BraveNewTabBrowserProxyImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
pref="{{prefs.brave.new_tab_page.show_rewards}}"
label="$i18n{braveNewTabBraveRewards}">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_binance}}"
label="$i18n{braveNewTabBinance}">
</settings-toggle-button>
<template is="dom-if" if="[[isBinanceSupported_]]">
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_binance}}"
label="$i18n{braveNewTabBinance}">
</settings-toggle-button>
</template>
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_top_sites}}"
label="$i18n{braveNewTabTopSites}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@

properties: {
isSuperReferralActive_: Boolean,
isBinanceSupported_: Boolean,
},

/** @override */
created: function() {
this.browserProxy_ = settings.BraveNewTabBrowserProxyImpl.getInstance();
this.isSuperReferralActive_ = false;
this.isBinanceSupported_ = false;
},

/** @override */
ready: function() {
this.browserProxy_.getIsSuperReferralActive().then(isSuperReferralActive => {
this.isSuperReferralActive_ = isSuperReferralActive;
})
this.browserProxy_.getIsBinanceSupported().then(isBinanceSupported => {
this.isBinanceSupported_ = isBinanceSupported;
})

this.addWebUIListener('super-referral-active-state-changed', (isSuperReferralActive) => {
this.isSuperReferralActive_ = isSuperReferralActive;
Expand Down
24 changes: 24 additions & 0 deletions browser/ui/webui/settings/brave_appearance_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/strings/string_number_conversions.h"
#include "brave/browser/ntp_background_images/view_counter_service_factory.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_data.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
Expand All @@ -17,6 +18,10 @@
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_ui.h"

#if BUILDFLAG(BINANCE_ENABLED)
#include "brave/browser/binance/binance_util.h"
#endif

using ntp_background_images::ViewCounterServiceFactory;
using ntp_background_images::prefs::kNewTabPageSuperReferralThemesOption;

Expand Down Expand Up @@ -67,6 +72,10 @@ void BraveAppearanceHandler::RegisterMessages() {
"getIsSuperReferralActive",
base::BindRepeating(&BraveAppearanceHandler::GetIsSuperReferralActive,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getIsBinanceSupported",
base::BindRepeating(&BraveAppearanceHandler::GetIsBinanceSupported,
base::Unretained(this)));
}

void BraveAppearanceHandler::SetBraveThemeType(const base::ListValue* args) {
Expand Down Expand Up @@ -99,6 +108,21 @@ void BraveAppearanceHandler::GetIsSuperReferralActive(
base::Value(IsSuperReferralActive(profile_)));
}

void BraveAppearanceHandler::GetIsBinanceSupported(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);

AllowJavascript();

#if !BUILDFLAG(BINANCE_ENABLED)
bool is_supported = false;
#else
bool is_supported = binance::IsBinanceSupported(profile_);
#endif

ResolveJavascriptCallback(args->GetList()[0], base::Value(is_supported));
}

void BraveAppearanceHandler::OnBraveDarkModeChanged() {
// GetBraveThemeType() should be used because settings option displays all
// available options including default.
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/settings/brave_appearance_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BraveAppearanceHandler : public settings::SettingsPageUIHandler {
void SetBraveThemeType(const base::ListValue* args);
void GetBraveThemeType(const base::ListValue* args);
void GetIsSuperReferralActive(const base::ListValue* args);
void GetIsBinanceSupported(const base::ListValue* args);

Profile* profile_ = nullptr;
PrefChangeRegistrar local_state_change_registrar_;
Expand Down

0 comments on commit 1537774

Please sign in to comment.