Skip to content

Commit

Permalink
Bitcoin UI (#19243)
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive authored Jul 26, 2023
1 parent 356662e commit c2eff20
Show file tree
Hide file tree
Showing 140 changed files with 2,429 additions and 1,508 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static NetworkInfo getAllNetworkOption(Context context) {
allNetworkInfo.chainId = "all";
allNetworkInfo.chainName = context.getString(R.string.brave_wallet_network_filter_all);
allNetworkInfo.coin = 0;
allNetworkInfo.supportedKeyrings = new int[0];
allNetworkInfo.decimals = 0;
allNetworkInfo.iconUrls = new String[0];
allNetworkInfo.activeRpcEndpointIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private boolean validateInputsAddChain(View view) {
return false;
}
chain.chainId = strChainId;
chain.supportedKeyrings = new int[0];

EditText chainName = view.findViewById(R.id.chain_name);
String strChainName = chainName.getText().toString().trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public void validateNetworkInfoTest() {
String varName = f.getName();
if (varName.equals("chainId") || varName.equals("chainName")
|| varName.equals("blockExplorerUrls") || varName.equals("iconUrls")
|| varName.equals("rpcEndpoints")
|| varName.equals("rpcEndpoints") || varName.equals("supportedKeyrings")
|| varName.equals("activeRpcEndpointIndex") || varName.equals("symbol")
|| varName.equals("symbolName") || varName.equals("isEip1559")) {
continue;
Expand All @@ -502,6 +502,7 @@ public void validateNetworkInfoTest() {
}
}
testStruct.chainId = "";
testStruct.supportedKeyrings = new int[0];
testStruct.chainName = "";
testStruct.blockExplorerUrls = new String[0];
testStruct.iconUrls = new String[0];
Expand Down
1 change: 1 addition & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "brave/components/brave_wallet/browser/ethereum_provider_impl.h"
#include "brave/components/brave_wallet/browser/solana_provider_impl.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/constants/webui_url_constants.h"
Expand Down
3 changes: 1 addition & 2 deletions browser/brave_wallet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ source_set("brave_wallet") {
"//brave/components/brave_wallet/browser:constants",
"//brave/components/brave_wallet/browser:utils",
"//brave/components/brave_wallet/common",
"//brave/components/brave_wallet/common:common_utils",
"//brave/components/brave_wallet/common:mojom",
"//chrome/browser:browser_process",
"//chrome/browser/profiles:profiles",
Expand Down Expand Up @@ -231,7 +230,7 @@ source_set("browser_tests") {
"//brave/app:command_ids",
"//brave/browser",
"//brave/browser/ui/sidebar",
"//brave/components/brave_wallet/common:common_utils",
"//brave/components/brave_wallet/common",
"//brave/components/brave_wallet/common:pref_names",
"//brave/components/sidebar",
"//chrome/browser/ui",
Expand Down
5 changes: 3 additions & 2 deletions browser/brave_wallet/bitcoin_wallet_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h"
#include "brave/browser/brave_wallet/keyring_service_factory.h"
#include "brave/components/brave_wallet/browser/bitcoin/bitcoin_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

Expand Down Expand Up @@ -81,7 +82,7 @@ KeyedService* BitcoinWalletServiceFactory::BuildServiceInstanceFor(
default_storage_partition->GetURLLoaderFactoryForBrowserProcess();
return new BitcoinWalletService(
KeyringServiceFactory::GetServiceForContext(context),
shared_url_loader_factory);
user_prefs::UserPrefs::Get(context), shared_url_loader_factory);
}

content::BrowserContext* BitcoinWalletServiceFactory::GetBrowserContextToUse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "brave/components/brave_wallet/browser/brave_wallet_pin_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/common/common_utils.h"

#include "chrome/browser/profiles/incognito_helpers.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_wallet/brave_wallet_context_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "brave/browser/brave_wallet/brave_wallet_context_utils.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/components/brave_wallet/common/common_util.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/brave_wallet/browser/permission_utils.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/constants/brave_paths.h"
#include "brave/components/constants/pref_names.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_wallet/brave_wallet_pin_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "brave/components/brave_wallet/browser/brave_wallet_pin_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service.h"
#include "brave/components/brave_wallet/browser/brave_wallet_service_delegate.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_wallet/brave_wallet_policy_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "brave/browser/ui/brave_browser.h"
#include "brave/browser/ui/sidebar/sidebar_controller.h"
#include "brave/browser/ui/sidebar/sidebar_model.h"
#include "brave/components/brave_wallet/common/common_util.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/brave_wallet/common/pref_names.h"
#include "brave/components/sidebar/sidebar_item.h"
#include "chrome/browser/profiles/profile.h"
Expand Down
50 changes: 13 additions & 37 deletions browser/brave_wallet/keyring_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include "brave/components/brave_wallet/browser/hd_keyring.h"
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom-shared.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/brave_wallet_types.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/brave_wallet/common/hex_utils.h"
#include "brave/components/brave_wallet/common/switches.h"
Expand Down Expand Up @@ -386,23 +386,6 @@ class KeyringServiceUnitTest : public testing::Test {
return service->AddAccountSync(coin, keyring_id, name);
}

static mojom::AccountInfoPtr AddBitcoinAccount(
KeyringService* service,
const std::string& account_name,
const std::string& network_id,
mojom::KeyringId keyring_id) {
mojom::AccountInfoPtr result;
base::RunLoop run_loop;
service->AddBitcoinAccount(
account_name, network_id, keyring_id,
base::BindLambdaForTesting([&](mojom::AccountInfoPtr account_info) {
result = std::move(account_info);
run_loop.Quit();
}));
run_loop.Run();
return result;
}

static void ImportFilecoinAccounts(
KeyringService* service,
TestKeyringServiceObserver* observer,
Expand Down Expand Up @@ -4761,38 +4744,31 @@ TEST_F(KeyringServiceUnitTest, BitcoinReceiveChangeAddresses) {
service.GetKeyringInfoSync(mojom::kBitcoinKeyring84Id)->account_infos,
testing::IsEmpty());

EXPECT_FALSE(service.GetBitcoinAddresses(mojom::kBitcoinKeyring84Id, 0));

AddBitcoinAccount(&service, "Btc Acc", mojom::kBitcoinMainnet,
mojom::kBitcoinKeyring84Id);
auto added_account = AddAccount(&service, mojom::CoinType::BTC,
mojom::kBitcoinKeyring84Id, "Btc Acc");

EXPECT_THAT(
service.GetKeyringInfoSync(mojom::kBitcoinKeyring84Id)->account_infos,
testing::SizeIs(1u));
auto btc_acc = service.GetKeyringInfoSync(mojom::kBitcoinKeyring84Id)
->account_infos[0]
->Clone();
EXPECT_EQ(btc_acc->address, "bc1ql5f64jdzjsvgehlpxvdgm9ygp0xta7xpnueh03");
EXPECT_EQ(btc_acc, added_account);
EXPECT_EQ(btc_acc->address, "");
EXPECT_EQ(btc_acc->name, "Btc Acc");
EXPECT_EQ(btc_acc->account_id->kind, mojom::AccountKind::kDerived);
EXPECT_EQ(btc_acc->account_id->coin, mojom::CoinType::BTC);
EXPECT_EQ(btc_acc->account_id->keyring_id, mojom::kBitcoinKeyring84Id);

EXPECT_EQ(
service.GetBitcoinAddresses(mojom::kBitcoinKeyring84Id, 0)->at(0).first,
"bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu");
EXPECT_EQ(
service.GetBitcoinAddresses(mojom::kBitcoinKeyring84Id, 0)->at(0).second,
mojom::BitcoinKeyId::New(0, 0, 0));

EXPECT_EQ(
service.GetBitcoinAddresses(mojom::kBitcoinKeyring84Id, 0)->at(30).first,
"bc1q8c6fshw2dlwun7ekn9qwf37cu2rn755upcp6el");
EXPECT_EQ(
service.GetBitcoinAddresses(mojom::kBitcoinKeyring84Id, 0)->at(30).second,
mojom::BitcoinKeyId::New(0, 1, 0));
EXPECT_EQ(service.GetBitcoinAddresses(*btc_acc->account_id)->at(0).first,
"bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu");
EXPECT_EQ(service.GetBitcoinAddresses(*btc_acc->account_id)->at(0).second,
mojom::BitcoinKeyId::New(0, 0, 0));

EXPECT_FALSE(service.GetBitcoinAddresses(mojom::kBitcoinKeyring84Id, 1));
EXPECT_EQ(service.GetBitcoinAddresses(*btc_acc->account_id)->at(30).first,
"bc1q8c6fshw2dlwun7ekn9qwf37cu2rn755upcp6el");
EXPECT_EQ(service.GetBitcoinAddresses(*btc_acc->account_id)->at(30).second,
mojom::BitcoinKeyId::New(0, 1, 0));
}

TEST_F(KeyringServiceUnitTest, MigrateSelectedAccount) {
Expand Down
1 change: 1 addition & 0 deletions browser/brave_wallet/solana_provider_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "brave/components/brave_wallet/browser/permission_utils.h"
#include "brave/components/brave_wallet/browser/tx_service.h"
#include "brave/components/brave_wallet/common/brave_wallet_constants.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/brave_wallet/common/solana_utils.h"
#include "brave/components/brave_wallet/renderer/resource_helper.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ source_set("extensions") {
"//brave/components/brave_shields/common",
"//brave/components/brave_vpn/common/buildflags",
"//brave/components/brave_wallet/browser:utils",
"//brave/components/brave_wallet/common:common_utils",
"//brave/components/brave_wallet/common",
"//brave/components/brave_wayback_machine/buildflags",
"//brave/components/constants",
"//brave/components/de_amp/common",
Expand Down
1 change: 1 addition & 0 deletions browser/extensions/api/brave_wallet_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "brave/common/extensions/api/brave_wallet.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/l10n/common/localization_util.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
Expand Down
11 changes: 7 additions & 4 deletions browser/profiles/brave_renderer_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h"
#include "brave/browser/ethereum_remote_client/ethereum_remote_client_constants.h"
#include "brave/common/brave_renderer_configuration.mojom.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/de_amp/browser/de_amp_util.h"
#include "brave/components/de_amp/common/pref_names.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -85,8 +85,9 @@ BraveRendererUpdater::GetRendererConfigurations() {
renderer_profile->GetOriginalProfile() == profile_) {
auto renderer_configuration =
GetRendererConfiguration(it.GetCurrentValue());
if (renderer_configuration)
if (renderer_configuration) {
rv.push_back(std::move(renderer_configuration));
}
}
}
return rv;
Expand All @@ -96,8 +97,9 @@ mojo::AssociatedRemote<brave::mojom::BraveRendererConfiguration>
BraveRendererUpdater::GetRendererConfiguration(
content::RenderProcessHost* render_process_host) {
IPC::ChannelProxy* channel = render_process_host->GetChannel();
if (!channel)
if (!channel) {
return mojo::AssociatedRemote<brave::mojom::BraveRendererConfiguration>();
}

mojo::AssociatedRemote<brave::mojom::BraveRendererConfiguration>
renderer_configuration;
Expand Down Expand Up @@ -125,8 +127,9 @@ bool BraveRendererUpdater::CheckActiveWallet() {

void BraveRendererUpdater::UpdateAllRenderers() {
auto renderer_configurations = GetRendererConfigurations();
for (auto& renderer_configuration : renderer_configurations)
for (auto& renderer_configuration : renderer_configurations) {
UpdateRenderer(&renderer_configuration);
}
}

void BraveRendererUpdater::UpdateRenderer(
Expand Down
3 changes: 1 addition & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ source_set("ui") {
"//brave/components/brave_shields/resources/panel:brave_shields_panel_generated",
"//brave/components/brave_sync",
"//brave/components/brave_sync:sync_service_impl_helper",
"//brave/components/brave_wallet/common:common_utils",
"//brave/components/brave_wallet/common",
"//brave/components/brave_welcome/common",
"//brave/components/brave_welcome_ui:generated_resources",
"//brave/components/commands/common",
Expand Down Expand Up @@ -993,7 +993,6 @@ source_set("ui") {
"//brave/browser/ui/webui/brave_wallet/common_handler",
"//brave/components/brave_wallet/browser:hd_keyring",
"//brave/components/brave_wallet/common",
"//brave/components/brave_wallet/common:common_utils",
"//brave/components/brave_wallet/common:mojom",
"//brave/components/brave_wallet_ui:resources",
"//brave/components/brave_wallet_ui/page/screens/android-buy/android:brave_wallet_fund_wallet_page_generated",
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "brave/components/brave_rewards/common/rewards_util.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/brave_vpn/common/features.h"
#include "brave/components/brave_wallet/common/common_util.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/commands/common/features.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/views/toolbar/brave_toolbar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "brave/browser/ui/views/toolbar/bookmark_button.h"
#include "brave/browser/ui/views/toolbar/wallet_button.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/constants/pref_names.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
Expand Down
3 changes: 1 addition & 2 deletions browser/ui/views/toolbar/wallet_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

#include "brave/browser/brave_wallet/brave_wallet_tab_helper.h"
#include "brave/browser/ui/brave_icon_with_badge_image_source.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/l10n/common/localization_util.h"
#include "brave/components/vector_icons/vector_icons.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <vector>

#include "brave/browser/brave_wallet/keyring_service_factory.h"
#include "brave/components/brave_wallet/browser/brave_wallet_utils.h"
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "chrome/browser/profiles/profile.h"

namespace brave_wallet {
Expand All @@ -38,9 +38,8 @@ void WalletHandler::GetWalletInfo(GetWalletInfoCallback callback) {
DCHECK_EQ(default_keyring->id, mojom::kDefaultKeyringId);
std::move(callback).Run(mojom::WalletInfo::New(
default_keyring->is_keyring_created, default_keyring->is_locked,
default_keyring->is_backed_up, brave_wallet::IsFilecoinEnabled(),
brave_wallet::IsSolanaEnabled(), brave_wallet::IsBitcoinEnabled(),
brave_wallet::IsNftPinningEnabled(), brave_wallet::IsPanelV2Enabled()));
default_keyring->is_backed_up, IsFilecoinEnabled(), IsSolanaEnabled(),
IsBitcoinEnabled(), IsNftPinningEnabled(), IsPanelV2Enabled()));
}

} // namespace brave_wallet
1 change: 1 addition & 0 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "brave/components/brave_federated/features.h"
#include "brave/components/brave_rewards/common/rewards_util.h"
#include "brave/components/brave_shields/common/features.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
Expand Down
3 changes: 1 addition & 2 deletions browser/ui/webui/settings/brave_wallet_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
#include "brave/components/brave_wallet/browser/json_rpc_service.h"
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wallet/common/features.h"
#include "brave/components/brave_wallet/common/common_utils.h"
#include "brave/components/brave_wallet/common/value_conversion_utils.h"
#include "brave/components/l10n/common/localization_util.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/web_ui.h"
#include "ui/base/l10n/l10n_util.h"

Expand Down
Loading

0 comments on commit c2eff20

Please sign in to comment.