Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet): Added Show Test Networks Pref #13098

Merged
merged 1 commit into from
Apr 25, 2022

Conversation

Douglashdaniel
Copy link
Contributor

Description

Added a Show test networks pref in brave://setting/wallet and passed to Wallet UI

Resolves brave/brave-browser#21650

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Screen.Recording.2022-04-20.at.10.31.55.AM.mov

@Douglashdaniel Douglashdaniel requested a review from yrliou April 20, 2022 19:27
@Douglashdaniel Douglashdaniel requested review from a team as code owners April 20, 2022 19:27
@Douglashdaniel Douglashdaniel self-assigned this Apr 20, 2022
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Apr 20, 2022
@Douglashdaniel Douglashdaniel force-pushed the show-test-networks-pref branch from 28831e5 to 38006ee Compare April 20, 2022 19:56
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@@ -512,6 +512,11 @@ void BraveWalletService::SetDefaultBaseCryptocurrency(
}
}

void BraveWalletService::GetShowWalletTestNetworks(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this method being backed by a pref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant it should cover case when changing pref changes service method outcome;)

So please add smth like this
diff --git a/browser/brave_wallet/brave_wallet_service_unittest.cc b/browser/brave_wallet/brave_wallet_service_unittest.cc
index 93c5311959..7e686898b5 100644
--- a/browser/brave_wallet/brave_wallet_service_unittest.cc
+++ b/browser/brave_wallet/brave_wallet_service_unittest.cc
@@ -459,6 +459,18 @@ 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,
@@ -1084,7 +1096,10 @@ TEST_F(BraveWalletServiceUnitTest, GetAndSetDefaultBaseCryptocurrency) {
 TEST_F(BraveWalletServiceUnitTest, GetShowWalletTestNetworks) {
   // Default value for kShowWalletTestNetworks should be false
   EXPECT_FALSE(GetPrefs()->GetBoolean(kShowWalletTestNetworks));
-  EXPECT_FALSE(GetShowWalletTestNetworks(GetPrefs()));
+  EXPECT_FALSE(GetShowWalletTestNetworks());
+
+  GetPrefs()->SetBoolean(kShowWalletTestNetworks, true);
+  EXPECT_TRUE(GetShowWalletTestNetworks());
 }
 
 TEST_F(BraveWalletServiceUnitTest, EthAddRemoveSetUserAssetVisible) {

Marking as approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha!
Updated, thank you for the help! 😎

Copy link
Member

@goodov goodov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromium_src lgtm

Copy link
Contributor

@josheleonard josheleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript looks good to me 👍

@Douglashdaniel Douglashdaniel force-pushed the show-test-networks-pref branch from 38006ee to 4498eb7 Compare April 22, 2022 14:39
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@Douglashdaniel Douglashdaniel force-pushed the show-test-networks-pref branch from eafe2a1 to c76a0e7 Compare April 22, 2022 20:17
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@@ -512,6 +512,11 @@ void BraveWalletService::SetDefaultBaseCryptocurrency(
}
}

void BraveWalletService::GetShowWalletTestNetworks(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant it should cover case when changing pref changes service method outcome;)

So please add smth like this
diff --git a/browser/brave_wallet/brave_wallet_service_unittest.cc b/browser/brave_wallet/brave_wallet_service_unittest.cc
index 93c5311959..7e686898b5 100644
--- a/browser/brave_wallet/brave_wallet_service_unittest.cc
+++ b/browser/brave_wallet/brave_wallet_service_unittest.cc
@@ -459,6 +459,18 @@ 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,
@@ -1084,7 +1096,10 @@ TEST_F(BraveWalletServiceUnitTest, GetAndSetDefaultBaseCryptocurrency) {
 TEST_F(BraveWalletServiceUnitTest, GetShowWalletTestNetworks) {
   // Default value for kShowWalletTestNetworks should be false
   EXPECT_FALSE(GetPrefs()->GetBoolean(kShowWalletTestNetworks));
-  EXPECT_FALSE(GetShowWalletTestNetworks(GetPrefs()));
+  EXPECT_FALSE(GetShowWalletTestNetworks());
+
+  GetPrefs()->SetBoolean(kShowWalletTestNetworks, true);
+  EXPECT_TRUE(GetShowWalletTestNetworks());
 }
 
 TEST_F(BraveWalletServiceUnitTest, EthAddRemoveSetUserAssetVisible) {

Marking as approved.

@Douglashdaniel Douglashdaniel force-pushed the show-test-networks-pref branch from c76a0e7 to 93ceba5 Compare April 25, 2022 14:35
@Douglashdaniel Douglashdaniel force-pushed the show-test-networks-pref branch from 93ceba5 to 352a4ea Compare April 25, 2022 15:06
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@Douglashdaniel Douglashdaniel added this to the 1.40.x - Nightly milestone Apr 25, 2022
@Douglashdaniel Douglashdaniel merged commit d519e28 into master Apr 25, 2022
@Douglashdaniel Douglashdaniel deleted the show-test-networks-pref branch April 25, 2022 22:38
Douglashdaniel added a commit that referenced this pull request May 19, 2022
feat(wallet): Added Show Test Networks Pref
@kjozwiak
Copy link
Member

Verification for master completed via #13390 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add showTestNetworks user pref in Settings
6 participants