Skip to content

Commit

Permalink
Introduce new web Wallet behind feature flag
Browse files Browse the repository at this point in the history
Implements new build flag `ENABLE_BRAVE_ANDROID_WEB_WALLET` and Gn constant
`brave_android_web_wallet_enabled`. When feature flag is set to false old native version
is used for Android Wallet. To enable/disable Android web Wallet use
`brave_android_web_wallet_enabled` in `android/buildflags/buildflags.gni`.
  • Loading branch information
simoarpe committed Nov 24, 2023
1 parent 538091a commit eb57e1f
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 45 deletions.
6 changes: 2 additions & 4 deletions android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import("//brave/android/buildflags/buildflags.gni")
import("//brave/components/ai_chat/core/common/buildflags/buildflags.gni")
import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//brave/components/p3a/buildflags.gni")
import("//brave/components/webcompat_reporter/buildflags/buildflags.gni")
import("//build/config/android/rules.gni")

declare_args() {
brave_android_developer_options_code = ""
}

java_cpp_enum("brave_android_java_enums_srcjar") {
sources = [
"//brave/chromium_src/chrome/browser/notifications/notification_handler_impl.h",
Expand All @@ -29,5 +26,6 @@ java_cpp_template("brave_config_java") {
"BRAVE_ANDROID_ENABLE_IPFS=$enable_ipfs",
"BRAVE_ANDROID_WEBCOMPAT_REPORT_ENDPOINT=\"$webcompat_report_api_endpoint\"",
"BRAVE_ANDROID_AI_CHAT_ENABLED=$enable_ai_chat",
"BRAVE_ANDROID_WEB_WALLET_ENABLED=$brave_android_web_wallet_enabled",
]
}
13 changes: 13 additions & 0 deletions android/buildflags/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import("//brave/android/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")

buildflag_header("buildflags") {
header = "buildflags.h"
flags =
[ "ENABLE_BRAVE_ANDROID_WEB_WALLET=$brave_android_web_wallet_enabled" ]
}
9 changes: 9 additions & 0 deletions android/buildflags/buildflags.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

declare_args() {
brave_android_developer_options_code = ""
brave_android_web_wallet_enabled = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

package org.chromium.chrome.browser.crypto_wallet.activities;

import static org.chromium.chrome.browser.crypto_wallet.adapters.CryptoFragmentPageAdapter.ACCOUNTS_FRAGMENT_POSITION;
import static org.chromium.chrome.browser.crypto_wallet.adapters.CryptoFragmentPageAdapter.MARKET_FRAGMENT_POSITION;
import static org.chromium.chrome.browser.crypto_wallet.adapters.CryptoFragmentPageAdapter.PORTFOLIO_FRAGMENT_POSITION;
import static org.chromium.chrome.browser.crypto_wallet.adapters.CryptoFragmentPageAdapter.TRANSACTIONS_ACTIVITY_FRAGMENT_POSITION;
import static org.chromium.chrome.browser.crypto_wallet.util.Utils.ONBOARDING_ACTION;
import static org.chromium.chrome.browser.crypto_wallet.util.Utils.ONBOARDING_FIRST_PAGE_ACTION;
import static org.chromium.chrome.browser.crypto_wallet.util.Utils.RESTORE_WALLET_ACTION;
Expand Down Expand Up @@ -32,6 +36,7 @@
import org.chromium.brave_wallet.mojom.NetworkInfo;
import org.chromium.brave_wallet.mojom.OnboardingAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveConfig;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.app.domain.NetworkModel;
import org.chromium.chrome.browser.app.domain.WalletModel;
Expand Down Expand Up @@ -345,7 +350,38 @@ private void showMainLayout() {
addRemoveSecureFlag(false);

mCryptoOnboardingLayout.setVisibility(View.GONE);
WalletUtils.openWebWallet();
if (BraveConfig.WEB_WALLET_ENABLED) {
WalletUtils.openWebWallet();
} else {
mCryptoLayout.setVisibility(View.VISIBLE);

mBottomNavigationView.setOnItemSelectedListener(
menuItem -> {
final int menuItemId = menuItem.getItemId();
if (menuItemId == R.id.action_wallet_portfolio) {
mViewPager.setCurrentItem(PORTFOLIO_FRAGMENT_POSITION, true);
} else if (menuItemId == R.id.action_wallet_activity) {
mViewPager.setCurrentItem(
TRANSACTIONS_ACTIVITY_FRAGMENT_POSITION, true);
} else if (menuItemId == R.id.action_wallet_accounts) {
mViewPager.setCurrentItem(ACCOUNTS_FRAGMENT_POSITION, true);
} else if (menuItemId == R.id.action_wallet_explore) {
mViewPager.setCurrentItem(MARKET_FRAGMENT_POSITION, true);
}
return true;
});

if (mKeyringService != null) {
mKeyringService.isWalletBackedUp(
backed_up -> {
if (!backed_up) {
showWalletBackupBanner();
} else {
findViewById(R.id.wallet_backup_banner).setVisibility(View.GONE);
}
});
}
}
}

private void addBackupWalletSequence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.chromium.brave_wallet.mojom.BraveWalletService;
import org.chromium.brave_wallet.mojom.JsonRpcService;
import org.chromium.brave_wallet.mojom.KeyringService;
import org.chromium.chrome.browser.BraveConfig;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.crypto_wallet.AssetRatioServiceFactory;
import org.chromium.chrome.browser.crypto_wallet.BraveWalletServiceFactory;
Expand Down Expand Up @@ -121,7 +122,9 @@ public void showWalletPanel() {

private void createAndShowWalletPanel() {
boolean showExpandButton =
mVisibleUrl != null && !mVisibleUrl.getHost().equals(BRAVE_WALLET_HOST);
!BraveConfig.WEB_WALLET_ENABLED
|| (mVisibleUrl != null
&& !mVisibleUrl.getHost().equals(BRAVE_WALLET_HOST));
mBraveWalletPanel =
new BraveWalletPanel(
mAnchorViewHost, mDialogOrPanelDismissListener, this, showExpandButton);
Expand Down
43 changes: 29 additions & 14 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import("//brave/android/buildflags/buildflags.gni")
import("//brave/browser/ethereum_remote_client/buildflags/buildflags.gni")
import("//brave/browser/shell_integrations/buildflags/buildflags.gni")
import("//brave/build/config.gni")
Expand Down Expand Up @@ -45,12 +46,6 @@ source_set("ui") {
"webui/brave_rewards_page_ui.h",
"webui/brave_rewards_source.cc",
"webui/brave_rewards_source.h",
"webui/brave_wallet/line_chart/line_chart_ui.cc",
"webui/brave_wallet/line_chart/line_chart_ui.h",
"webui/brave_wallet/market/market_ui.cc",
"webui/brave_wallet/market/market_ui.h",
"webui/brave_wallet/nft/nft_ui.cc",
"webui/brave_wallet/nft/nft_ui.h",
"webui/brave_web_ui_controller_factory.cc",
"webui/brave_web_ui_controller_factory.h",
"webui/brave_webui_source.cc",
Expand All @@ -59,6 +54,24 @@ source_set("ui") {
"webui/skus_internals_ui.h",
]

if (!is_android || brave_android_web_wallet_enabled) {
sources += [
"webui/brave_wallet/line_chart/line_chart_ui.cc",
"webui/brave_wallet/line_chart/line_chart_ui.h",
"webui/brave_wallet/market/market_ui.cc",
"webui/brave_wallet/market/market_ui.h",
"webui/brave_wallet/nft/nft_ui.cc",
"webui/brave_wallet/nft/nft_ui.h",
]

deps += [
"//brave/components/brave_wallet_ui/line_chart:line_chart_display_generated",
"//brave/components/brave_wallet_ui/market:market_display_generated",
"//brave/components/brave_wallet_ui/nft:nft_display_generated",
"//brave/components/brave_wallet_ui/page:brave_wallet_page_generated",
]
}

# It doesn't make sense to view the webcompat webui on iOS & Android.
if (!is_android && !is_ios) {
sources += [
Expand Down Expand Up @@ -491,6 +504,7 @@ source_set("ui") {

deps += [
"//base",
"//brave/android/buildflags",
"//brave/app:command_ids",
"//brave/app/vector_icons:vector_icons",
"//brave/browser:browser_process",
Expand Down Expand Up @@ -540,10 +554,6 @@ source_set("ui") {
"//brave/components/brave_wallet/browser:constants",
"//brave/components/brave_wallet/browser:pref_names",
"//brave/components/brave_wallet/browser:utils",
"//brave/components/brave_wallet_ui/line_chart:line_chart_display_generated",
"//brave/components/brave_wallet_ui/market:market_display_generated",
"//brave/components/brave_wallet_ui/nft:nft_display_generated",
"//brave/components/brave_wallet_ui/page:brave_wallet_page_generated",
"//brave/components/brave_wayback_machine/buildflags",
"//brave/components/constants",
"//brave/components/cosmetic_filters/resources/data:generated_resources",
Expand Down Expand Up @@ -1044,11 +1054,16 @@ source_set("ui") {
"//brave/components/brave_wallet/common",
"//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",
"//brave/components/brave_wallet_ui/page/screens/fund-wallet/android:brave_wallet_deposit_page_generated",
"//brave/components/brave_wallet_ui/page/screens/send/android:brave_wallet_send_page_generated",
"//brave/components/brave_wallet_ui/page/screens/swap/android:brave_wallet_swap_page_generated",
]

if (!brave_android_web_wallet_enabled) {
deps += [
"//brave/components/brave_wallet_ui/page/screens/android-buy/android:brave_wallet_fund_wallet_page_generated",
"//brave/components/brave_wallet_ui/page/screens/fund-wallet/android:brave_wallet_deposit_page_generated",
"//brave/components/brave_wallet_ui/page/screens/send/android:brave_wallet_send_page_generated",
"//brave/components/brave_wallet_ui/page/screens/swap/android:brave_wallet_swap_page_generated",
]
}
}

if (ethereum_remote_client_enabled && !is_android) {
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -4081,7 +4081,7 @@ If you don't accept this request, VPN will not reconnect and your internet conne
</message>
<message name="IDS_BRAVE_LEO_CONFIRM_TEXT" desc="Text for Leo confirm button text.">
Confirm
</message>
</message>
<message name="IDS_ELLIPSIS_TEXT" desc="Generic ellipsis text" translateable="false">
...
</message>
Expand Down
33 changes: 32 additions & 1 deletion browser/ui/webui/brave_wallet/android/android_wallet_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

#include <utility>

#include "brave/android/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
#include "brave/components/brave_wallet_page/resources/grit/brave_wallet_page_generated_map.h"
#else
#include "brave/components/brave_wallet_page/resources/grit/brave_wallet_deposit_page_generated_map.h"
#include "brave/components/brave_wallet_page/resources/grit/brave_wallet_fund_wallet_page_generated_map.h"
#include "brave/components/brave_wallet_page/resources/grit/brave_wallet_page_generated_map.h"
#include "brave/components/brave_wallet_page/resources/grit/brave_wallet_send_page_generated_map.h"
#include "brave/components/brave_wallet_page/resources/grit/brave_wallet_swap_page_generated_map.h"
#endif // BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
#include "brave/components/l10n/common/localization_util.h"

#include "brave/browser/ui/webui/brave_wallet/wallet_common_ui.h"
Expand Down Expand Up @@ -61,11 +65,38 @@ AndroidWalletPageUI::AndroidWalletPageUI(content::WebUI* web_ui,
}

// Add required resources.
#if BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
if (url.host() == kWalletPageHost) {
webui::SetupWebUIDataSource(source,
base::make_span(kBraveWalletPageGenerated,
kBraveWalletPageGeneratedSize),
IDR_WALLET_PAGE_HTML);
#else
if (url.path() == kWalletSwapPagePath) {
webui::SetupWebUIDataSource(
source,
base::make_span(kBraveWalletSwapPageGenerated,
kBraveWalletSwapPageGeneratedSize),
IDR_BRAVE_WALLET_SWAP_PAGE_HTML);
} else if (url.path() == kWalletSendPagePath) {
webui::SetupWebUIDataSource(
source,
base::make_span(kBraveWalletSendPageGenerated,
kBraveWalletSendPageGeneratedSize),
IDR_BRAVE_WALLET_SEND_PAGE_HTML);
} else if (url.path() == kWalletBuyPagePath) {
webui::SetupWebUIDataSource(
source,
base::make_span(kBraveWalletFundWalletPageGenerated,
kBraveWalletFundWalletPageGeneratedSize),
IDR_BRAVE_WALLET_FUND_WALLET_PAGE_HTML);
} else if (url.path() == kWalletDepositPagePath) {
webui::SetupWebUIDataSource(
source,
base::make_span(kBraveWalletDepositPageGenerated,
kBraveWalletDepositPageGeneratedSize),
IDR_BRAVE_WALLET_DEPOSIT_PAGE_HTML);
#endif // BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
} else {
NOTREACHED() << "Failed to find page resources for:" << url.path();
}
Expand Down
12 changes: 12 additions & 0 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,15 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
ipfs::IpfsServiceFactory::IsIpfsEnabled(profile)) ||
#endif // BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
#if BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
(url.is_valid() && url.host_piece() == kWalletPageHost) ||
#else
(url.is_valid() && url.host_piece() == kWalletPageHost &&
(url.path() == kWalletSwapPagePath ||
url.path() == kWalletSendPagePath ||
url.path().starts_with(kWalletBuyPagePath) ||
url.path().starts_with(kWalletDepositPagePath))) ||
#endif // BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
#else
(base::FeatureList::IsEnabled(
brave_news::features::kBraveNewsFeedUpdate) &&
Expand Down Expand Up @@ -308,7 +316,11 @@ bool ShouldBlockWalletWebUI(content::BrowserContext* browser_context,
}
auto* keyring_service =
brave_wallet::KeyringServiceFactory::GetServiceForContext(profile);
#if BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
return keyring_service && !keyring_service->IsWalletCreatedSync();
#else
return keyring_service && keyring_service->IsLockedSync();
#endif
}
#endif // BUILDFLAG(IS_ANDROID)
} // namespace
Expand Down
1 change: 1 addition & 0 deletions build/android/java/templates/BraveConfig.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class BraveConfig {
public static final boolean IPFS_ENABLED = BRAVE_ANDROID_ENABLE_IPFS;
public static final boolean AI_CHAT_ENABLED = BRAVE_ANDROID_AI_CHAT_ENABLED;
public static final String WEBCOMPAT_REPORT_ENDPOINT = BRAVE_ANDROID_WEBCOMPAT_REPORT_ENDPOINT;
public static final boolean WEB_WALLET_ENABLED = BRAVE_ANDROID_WEB_WALLET_ENABLED;
}
1 change: 1 addition & 0 deletions chromium_src/chrome/browser/DEPS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_rules = [
"+brave/app",
"+brave/android/buildflags/buildflags.h",
"+brave/browser",
"+brave/build/android/jni_headers",
"+brave/common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "chrome/browser/ui/webui/chrome_untrusted_web_ui_configs.h"

#include "base/feature_list.h"
#include "brave/android/buildflags/buildflags.h"
#include "brave/browser/ui/webui/brave_wallet/ledger/ledger_ui.h"
#include "brave/browser/ui/webui/brave_wallet/line_chart/line_chart_ui.h"
#include "brave/browser/ui/webui/brave_wallet/market/market_ui.h"
Expand Down Expand Up @@ -49,12 +50,16 @@

void RegisterChromeUntrustedWebUIConfigs() {
RegisterChromeUntrustedWebUIConfigs_ChromiumImpl();

#if !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_BRAVE_ANDROID_WEB_WALLET)
content::WebUIConfigMap::GetInstance().AddUntrustedWebUIConfig(
std::make_unique<market::UntrustedMarketUIConfig>());
content::WebUIConfigMap::GetInstance().AddUntrustedWebUIConfig(
std::make_unique<nft::UntrustedNftUIConfig>());
content::WebUIConfigMap::GetInstance().AddUntrustedWebUIConfig(
std::make_unique<line_chart::UntrustedLineChartUIConfig>());
#endif

#if !BUILDFLAG(IS_ANDROID)
content::WebUIConfigMap::GetInstance().AddUntrustedWebUIConfig(
std::make_unique<ledger::UntrustedLedgerUIConfig>());
Expand Down
Loading

0 comments on commit eb57e1f

Please sign in to comment.