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

Display wallet icon when viewing brave, add button in wallet to open a tab to brave://wallet/swap #17947

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
implements BrowsingDataBridge.OnClearBrowsingDataListener, BraveVpnObserver,
OnBraveSetDefaultBrowserListener, ConnectionErrorHandler, PrefObserver,
BraveSafeBrowsingApiHandler.BraveSafeBrowsingApiHandlerDelegate {
public static final String BRAVE_SWAP_URL = "brave://wallet/swap";
public static final String BRAVE_REWARDS_SETTINGS_URL = "brave://rewards/";
public static final String BRAVE_REWARDS_SETTINGS_WALLET_VERIFICATION_URL =
"brave://rewards/#verify";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,23 @@ public static void openBuySendSwapActivity(Activity activity,
BuySendSwapActivity.ActivityType activityType, String swapFromAssetSymbol,
String chainId) {
assert activity != null;
Intent buySendSwapActivityIntent = new Intent(activity, BuySendSwapActivity.class);
buySendSwapActivityIntent.putExtra(
BuySendSwapActivity.ACTIVITY_TYPE, activityType.getValue());
buySendSwapActivityIntent.putExtra(BuySendSwapActivity.ASSET_SYMBOL, swapFromAssetSymbol);
buySendSwapActivityIntent.putExtra(BuySendSwapActivity.ASSET_CHAIN_ID, chainId);
activity.startActivity(buySendSwapActivityIntent);
if (activityType == BuySendSwapActivity.ActivityType.SWAP) {
try {
BraveActivity.getBraveActivity().openNewOrSelectExistingTab(
BraveActivity.BRAVE_SWAP_URL);
TabUtils.bringChromeTabbedActivityToTheTop(activity);
} catch (BraveActivity.BraveActivityNotFoundException e) {
Log.e(TAG, "on Swap tab: " + e);
}
} else {
Intent buySendSwapActivityIntent = new Intent(activity, BuySendSwapActivity.class);
buySendSwapActivityIntent.putExtra(
BuySendSwapActivity.ACTIVITY_TYPE, activityType.getValue());
buySendSwapActivityIntent.putExtra(
BuySendSwapActivity.ASSET_SYMBOL, swapFromAssetSymbol);
buySendSwapActivityIntent.putExtra(BuySendSwapActivity.ASSET_CHAIN_ID, chainId);
activity.startActivity(buySendSwapActivityIntent);
}
}

public static void openAssetDetailsActivity(
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ source_set("ui") {
}
if (is_android) {
sources += [
"webui/brave_wallet/android/swap_page_handler.cc",
"webui/brave_wallet/android/swap_page_handler.h",
"webui/brave_wallet/android/swap_page_ui.cc",
"webui/brave_wallet/android/swap_page_ui.h",
"webui/brave_wallet/common_handler/wallet_handler.cc",
Expand Down
29 changes: 29 additions & 0 deletions browser/ui/webui/brave_wallet/android/swap_page_handler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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/.

#include "brave/browser/ui/webui/brave_wallet/android/swap_page_handler.h"

#include <utility>

#include "brave/browser/brave_wallet/brave_wallet_provider_delegate_impl_helper.h"

SwapPageHandler::SwapPageHandler(
mojo::PendingReceiver<brave_wallet::mojom::PageHandler> receiver,
Profile* profile,
ui::MojoWebUIController* webui_controller)
: WalletPageHandler(std::move(receiver), profile),
webui_controller_(webui_controller) {
DCHECK(webui_controller_);
}

SwapPageHandler::~SwapPageHandler() = default;

void SwapPageHandler::ShowApprovePanelUI() {
if (!webui_controller_) {
return;
}

::brave_wallet::ShowPanel(webui_controller_->web_ui()->GetWebContents());
}
31 changes: 31 additions & 0 deletions browser/ui/webui/brave_wallet/android/swap_page_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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/.

#ifndef BRAVE_BROWSER_UI_WEBUI_BRAVE_WALLET_ANDROID_SWAP_PAGE_HANDLER_H_
#define BRAVE_BROWSER_UI_WEBUI_BRAVE_WALLET_ANDROID_SWAP_PAGE_HANDLER_H_

#include "brave/browser/ui/webui/brave_wallet/page_handler/wallet_page_handler.h"

#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "ui/webui/mojo_web_ui_controller.h"

class SwapPageHandler : WalletPageHandler {
public:
SwapPageHandler(
mojo::PendingReceiver<brave_wallet::mojom::PageHandler> receiver,
Profile* profile,
ui::MojoWebUIController* webui_controller);

SwapPageHandler(const SwapPageHandler&) = delete;
SwapPageHandler& operator=(const SwapPageHandler&) = delete;
~SwapPageHandler() override;

void ShowApprovePanelUI() override;

private:
ui::MojoWebUIController* const webui_controller_;
};

#endif // BRAVE_BROWSER_UI_WEBUI_BRAVE_WALLET_ANDROID_SWAP_PAGE_HANDLER_H_
8 changes: 5 additions & 3 deletions browser/ui/webui/brave_wallet/android/swap_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

#include "brave/browser/brave_wallet/asset_ratio_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_ipfs_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_provider_delegate_impl_helper.h"
#include "brave/browser/brave_wallet/brave_wallet_service_factory.h"
#include "brave/browser/brave_wallet/json_rpc_service_factory.h"
#include "brave/browser/brave_wallet/keyring_service_factory.h"
#include "brave/browser/brave_wallet/swap_service_factory.h"
#include "brave/browser/brave_wallet/tx_service_factory.h"
#include "brave/browser/ui/webui/brave_wallet/android/swap_page_handler.h"

#include "brave/components/brave_wallet/browser/blockchain_registry.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
Expand Down Expand Up @@ -126,9 +128,8 @@ void SwapPageUI::CreatePageHandler(
DCHECK(page);
auto* profile = Profile::FromWebUI(web_ui());
DCHECK(profile);

page_handler_ =
std::make_unique<WalletPageHandler>(std::move(page_receiver), profile);
page_handler_ = std::make_unique<SwapPageHandler>(std::move(page_receiver),
profile, this);
wallet_handler_ =
std::make_unique<WalletHandler>(std::move(wallet_receiver), profile);

Expand Down Expand Up @@ -160,4 +161,5 @@ void SwapPageUI::CreatePageHandler(
if (blockchain_registry) {
blockchain_registry->Bind(std::move(blockchain_registry_receiver));
}
brave_wallet::WalletInteractionDetected(web_ui()->GetWebContents());
}
8 changes: 3 additions & 5 deletions browser/ui/webui/brave_wallet/android/swap_page_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
#include <memory>
#include <string>

#include "content/public/browser/web_ui_controller.h"

#include "brave/browser/ui/webui/brave_wallet/common_handler/wallet_handler.h"
#include "brave/browser/ui/webui/brave_wallet/page_handler/wallet_page_handler.h"

#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "content/public/browser/web_ui_controller.h"
#include "ui/webui/mojo_web_ui_controller.h"

class SwapPageHandler;
class SwapPageUI : public ui::MojoWebUIController,
public brave_wallet::mojom::PageHandlerFactory {
public:
Expand Down Expand Up @@ -63,7 +61,7 @@ class SwapPageUI : public ui::MojoWebUIController,
mojo::PendingReceiver<brave_wallet::mojom::IpfsService>
ipfs_service_receiver) override;

std::unique_ptr<WalletPageHandler> page_handler_;
SergeyZhukovsky marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<SwapPageHandler> page_handler_;
std::unique_ptr<WalletHandler> wallet_handler_;

mojo::Receiver<brave_wallet::mojom::PageHandlerFactory>
Expand Down