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 Apr 26, 2020
1 parent 44b1a64 commit 0334325
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
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
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();
isSuperReferralActive_ = false;
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
14 changes: 14 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/browser/binance/binance_util.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 Down Expand Up @@ -67,6 +68,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 +104,15 @@ void BraveAppearanceHandler::GetIsSuperReferralActive(
base::Value(IsSuperReferralActive(profile_)));
}

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

AllowJavascript();
ResolveJavascriptCallback(args->GetList()[0],
base::Value(::binance::IsBinanceSupported(profile_)));
}

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 0334325

Please sign in to comment.