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

Pr17947 pr17981 display wallet icon when viewing bravewalletswap (Uplift to 1.51.x) #18023

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 @@ -97,7 +97,8 @@ public void onStart() {

private void updateViewState() {
if (getView() == null) return;
if (!mIsCustomNetwork && mNetworkInfo.coin == CoinType.ETH
if (!mIsCustomNetwork
&& (mNetworkInfo.coin == CoinType.ETH || mNetworkInfo.coin == CoinType.SOL)
&& Utils.allowSwap(mNetworkInfo.chainId)) {
mSwapLayout.setVisibility(View.VISIBLE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ public static ParsedTransaction parseTransaction(TransactionInfo txInfo,
parsedTransaction.isSwap = txType == TransactionType.SOLANA_SWAP;
parsedTransaction.contractAddressError = checkForContractAddressError(fullTokenList,
solTxData.toWalletAddress != null ? solTxData.toWalletAddress : to);
if (parsedTransaction.isSwap) {
parsedTransaction.sellToken = nativeAsset;
parsedTransaction.buyToken = nativeAsset;
}
} else if (txInfo.txType == TransactionType.ERC20_TRANSFER && txInfo.txArgs.length > 1) {
final String address = txInfo.txArgs[0];
final String amount = txInfo.txArgs[1];
Expand Down Expand Up @@ -546,8 +550,12 @@ public Pair<String, String> makeTxListItemTitles(Context context) {
} else if (this.isSwap) {
action = String.format(context.getResources().getString(R.string.wallet_tx_info_swap),
this.senderLabel, strDate);
detailInfo = String.format(Locale.getDefault(), "%.4f", this.value) + " ETH -> "
+ "0x Exchange Proxy";
detailInfo = String.format(Locale.getDefault(), "%.4f", this.value);
if (this.type == TransactionType.SOLANA_SWAP) {
detailInfo += " SOL -> " + this.recipientLabel;
} else {
detailInfo += " ETH -> 0x Exchange Proxy";
}
} else {
action = String.format(context.getResources().getString(R.string.wallet_tx_info_sent),
this.senderLabel, this.formatValueToDisplay(), this.symbol, actionFiatValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void maybeGetSolanaGasEstimations(Runnable runWhenDone) {
== TransactionType
.SOLANA_SPL_TOKEN_TRANSFER_WITH_ASSOCIATED_TOKEN_ACCOUNT_CREATION
|| txInfo.txType == TransactionType.SOLANA_DAPP_SIGN_AND_SEND_TRANSACTION
|| txInfo.txType == TransactionType.SOLANA_DAPP_SIGN_TRANSACTION) {
|| txInfo.txType == TransactionType.SOLANA_DAPP_SIGN_TRANSACTION
|| txInfo.txType == TransactionType.SOLANA_SWAP) {
solanaTransactions.add(txInfo);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,20 @@ public static void hideKeyboard(Activity activity) {
public static void openBuySendSwapActivity(Activity activity,
BuySendSwapActivity.ActivityType activityType, String swapFromAssetSymbol) {
assert activity != null;
Intent buySendSwapActivityIntent = new Intent(activity, BuySendSwapActivity.class);
buySendSwapActivityIntent.putExtra("activityType", activityType.getValue());
buySendSwapActivityIntent.putExtra("swapFromAssetSymbol", swapFromAssetSymbol);
activity.startActivity(buySendSwapActivityIntent);
if (activityType == BuySendSwapActivity.ActivityType.SWAP) {
try {
BraveActivity.getBraveActivity().openNewOrSelectExistingTab(
BraveActivity.BRAVE_SWAP_URL);
TabUtils.bringChromeTabbedActivityToTheTop(activity);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "on Swap tab: " + e);
}
} else {
Intent buySendSwapActivityIntent = new Intent(activity, BuySendSwapActivity.class);
buySendSwapActivityIntent.putExtra("activityType", activityType.getValue());
buySendSwapActivityIntent.putExtra("swapFromAssetSymbol", swapFromAssetSymbol);
activity.startActivity(buySendSwapActivityIntent);
}
}

public static void openBuySendSwapActivity(
Expand Down Expand Up @@ -1215,8 +1225,9 @@ private static void workWithTransactions(BraveWalletBaseActivity activity,
private static WalletListItemModel makeWalletItem(Context context, TransactionInfo txInfo,
NetworkInfo selectedNetwork, ParsedTransaction parsedTx) {
Pair<String, String> itemTitles = parsedTx.makeTxListItemTitles(context);
WalletListItemModel itemModel = new WalletListItemModel(
R.drawable.ic_eth, itemTitles.first, itemTitles.second, "", null, null);
WalletListItemModel itemModel =
new WalletListItemModel(Utils.getCoinIcon(selectedNetwork.coin), itemTitles.first,
itemTitles.second, "", null, null);
updateWalletCoinTransactionStatus(itemModel, context, txInfo);

itemModel.setChainSymbol(selectedNetwork.symbol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public final class WalletConstants {
BraveWalletConstants.OPTIMISM_MAINNET_CHAIN_ID,
BraveWalletConstants.ARBITRUM_MAINNET_CHAIN_ID);

public static List<String> SWAP_SUPPORTED_NETWORKS = Arrays.asList(
BraveWalletConstants.MAINNET_CHAIN_ID, BraveWalletConstants.GOERLI_CHAIN_ID);
public static List<String> SWAP_SUPPORTED_NETWORKS =
Arrays.asList(BraveWalletConstants.MAINNET_CHAIN_ID,
BraveWalletConstants.GOERLI_CHAIN_ID, BraveWalletConstants.SOLANA_MAINNET);

// Solana
public static final String SOL = "SOL";
Expand All @@ -86,7 +87,7 @@ public final class WalletConstants {
TransactionType.SOLANA_SYSTEM_TRANSFER, TransactionType.SOLANA_SPL_TOKEN_TRANSFER,
TransactionType.SOLANA_SPL_TOKEN_TRANSFER_WITH_ASSOCIATED_TOKEN_ACCOUNT_CREATION,
TransactionType.SOLANA_DAPP_SIGN_TRANSACTION,
TransactionType.SOLANA_DAPP_SIGN_AND_SEND_TRANSACTION);
TransactionType.SOLANA_DAPP_SIGN_AND_SEND_TRANSACTION, TransactionType.SOLANA_SWAP);

public static List<Integer> SOLANA_DAPPS_TRANSACTION_TYPES =
Arrays.asList(TransactionType.SOLANA_DAPP_SIGN_TRANSACTION,
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,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_;
std::unique_ptr<SwapPageHandler> page_handler_;
std::unique_ptr<WalletHandler> wallet_handler_;

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