From 352a4ea84252935d6a3ab6319e9e9842e4266a1c Mon Sep 17 00:00:00 2001 From: Douglas Daniel Date: Wed, 20 Apr 2022 13:23:27 -0600 Subject: [PATCH] feat(wallet): Added Show Test Networks Pref --- app/brave_generated_resources.grd | 3 +++ browser/brave_prefs_browsertest.cc | 2 ++ .../brave_wallet_service_unittest.cc | 20 +++++++++++++++++++ .../api/settings_private/brave_prefs_util.cc | 2 ++ .../wallet_networks_subpage.html | 5 +++++ .../settings_localized_strings_provider.cc | 2 ++ .../browser/brave_wallet_prefs.cc | 1 + .../browser/brave_wallet_service.cc | 5 +++++ .../browser/brave_wallet_service.h | 2 ++ .../browser/brave_wallet_utils.cc | 4 ++++ .../brave_wallet/browser/brave_wallet_utils.h | 1 + components/brave_wallet/browser/pref_names.cc | 1 + components/brave_wallet/browser/pref_names.h | 1 + .../brave_wallet/common/brave_wallet.mojom | 3 +++ .../common/actions/wallet_actions.ts | 1 + .../brave_wallet_ui/common/async/handlers.ts | 2 ++ .../common/reducers/wallet_reducer.ts | 7 +++++++ 17 files changed, 62 insertions(+) diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index a377fa67165e..27724778b77b 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -956,6 +956,9 @@ Are you sure you want to do this? Show Brave Wallet icon on toolbar + + Show test networks + Hide Brave Wallet icon on toolbar diff --git a/browser/brave_prefs_browsertest.cc b/browser/brave_prefs_browsertest.cc index e58c17597ef2..2fcf245293d0 100644 --- a/browser/brave_prefs_browsertest.cc +++ b/browser/brave_prefs_browsertest.cc @@ -114,6 +114,8 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) { brave_wallet::mojom::DefaultWallet::BraveWalletPreferExtension); EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( kShowWalletIconOnToolbar)); + EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( + kShowWalletTestNetworks)); EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( kBraveWalletBackupComplete)); EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( diff --git a/browser/brave_wallet/brave_wallet_service_unittest.cc b/browser/brave_wallet/brave_wallet_service_unittest.cc index 692f2068bb6e..975f085501c7 100644 --- a/browser/brave_wallet/brave_wallet_service_unittest.cc +++ b/browser/brave_wallet/brave_wallet_service_unittest.cc @@ -459,6 +459,17 @@ class BraveWalletServiceUnitTest : public testing::Test { return default_cryptocurrency; } + bool GetShowWalletTestNetworks() { + base::RunLoop run_loop; + bool show_wallet_test_networks; + service_->GetShowWalletTestNetworks(base::BindLambdaForTesting([&](bool b) { + show_wallet_test_networks = b; + run_loop.Quit(); + })); + run_loop.Run(); + return show_wallet_test_networks; + } + void SimulateOnGetImportInfo(const std::string& new_password, bool result, const ImportInfo& info, @@ -1081,6 +1092,15 @@ TEST_F(BraveWalletServiceUnitTest, GetAndSetDefaultBaseCryptocurrency) { EXPECT_EQ(GetDefaultBaseCryptocurrency(), "ETH"); } +TEST_F(BraveWalletServiceUnitTest, GetShowWalletTestNetworks) { + // Default value for kShowWalletTestNetworks should be false + EXPECT_FALSE(GetPrefs()->GetBoolean(kShowWalletTestNetworks)); + EXPECT_FALSE(GetShowWalletTestNetworks()); + + GetPrefs()->SetBoolean(kShowWalletTestNetworks, true); + EXPECT_TRUE(GetShowWalletTestNetworks()); +} + TEST_F(BraveWalletServiceUnitTest, EthAddRemoveSetUserAssetVisible) { mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken(); eth_0x4_token->chain_id = "0x4"; diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc index 7d44434058a4..87f41a8fe403 100644 --- a/browser/extensions/api/settings_private/brave_prefs_util.cc +++ b/browser/extensions/api/settings_private/brave_prefs_util.cc @@ -261,6 +261,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() { settings_api::PrefType::PREF_TYPE_STRING; (*s_brave_allowlist)[kShowWalletIconOnToolbar] = settings_api::PrefType::PREF_TYPE_BOOLEAN; + (*s_brave_allowlist)[kShowWalletTestNetworks] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; (*s_brave_allowlist)[kBraveWalletAutoLockMinutes] = settings_api::PrefType::PREF_TYPE_NUMBER; diff --git a/browser/resources/settings/brave_wallet_page/wallet_networks_subpage.html b/browser/resources/settings/brave_wallet_page/wallet_networks_subpage.html index 8e159e2c5562..d424330a15ca 100644 --- a/browser/resources/settings/brave_wallet_page/wallet_networks_subpage.html +++ b/browser/resources/settings/brave_wallet_page/wallet_networks_subpage.html @@ -69,6 +69,11 @@ + +