From 795271e3143d1d2b0a9d0f48156d16182590820b Mon Sep 17 00:00:00 2001 From: Simone Arpe Date: Thu, 31 Oct 2024 11:09:23 +0100 Subject: [PATCH] (Wallet) Show warning message changing ownership (#26280) Shows warning message when a change of ownership is requested for Solana account. Fixes two crashes affecting signing messages and transactions. --- .../chrome/browser/app/BraveActivity.java | 4 +- .../ApproveTxBottomSheetDialogFragment.java | 9 +++- .../fragments/dapps/SignMessageFragment.java | 2 +- .../dapps/SignSolTransactionsFragment.java | 12 +----- .../crypto_wallet/util/ParsedTransaction.java | 10 +++++ .../browser/ntp/IncognitoNewTabPageView.java | 3 ++ .../res/layout/approve_tx_bottom_sheet.xml | 42 ++++++++++++++++++- .../android/strings/android_brave_strings.grd | 6 +++ 8 files changed, 71 insertions(+), 17 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index dd52ef9b3d3b..7db6a62fb5d1 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -668,9 +668,7 @@ public void showWalletPanel( // if the pending requests reach the end of the chain // without returning earlier. final Runnable openWalletPanelRunnable = - () -> { - getBraveToolbarLayout().showWalletPanel(); - }; + () -> getBraveToolbarLayout().showWalletPanel(); maybeShowSignSolTransactionsRequestLayout( openWalletPanelRunnable); } diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/ApproveTxBottomSheetDialogFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/ApproveTxBottomSheetDialogFragment.java index 8be595ff12a5..4931a4e3ec7f 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/ApproveTxBottomSheetDialogFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/ApproveTxBottomSheetDialogFragment.java @@ -208,6 +208,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat assert jsonRpcService != null && keyringService != null; TextView networkName = view.findViewById(R.id.network_name); + mRejectAllTx = view.findViewById(R.id.btn_reject_transactions); if (mTxInfo.txType == TransactionType .SOLANA_SPL_TOKEN_TRANSFER_WITH_ASSOCIATED_TOKEN_ACCOUNT_CREATION) { @@ -320,7 +321,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat mTransactionConfirmationListener.onNextTransaction(); } }); - mRejectAllTx = view.findViewById(R.id.btn_reject_transactions); mRejectAllTx.setVisibility(View.VISIBLE); mRejectAllTx.setOnClickListener( v -> { @@ -391,6 +391,9 @@ private void fetchTxBalanceAndUpdateUi( } private void refreshListContentUi() { + if (mTransactionInfos == null) { + return; + } mRejectAllTx.setText( getString( R.string.brave_wallet_queue_reject_all, @@ -428,6 +431,10 @@ private ParsedTransaction fillAssetDependentControls( txType.setText(getResources().getString(R.string.swap)); } else if (parsedTx.isSolanaDappTransaction) { txType.setText(R.string.brave_wallet_approve_transaction); + if (parsedTx.isSolChangeOfOwnership()) { + view.findViewById(R.id.warning_container).setVisibility(View.VISIBLE); + view.findViewById(R.id.tab_top_space).setVisibility(View.GONE); + } } else { txType.setText(getResources().getString(R.string.send)); } diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignMessageFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignMessageFragment.java index ed8e8067596d..2d92a177ea6b 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignMessageFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignMessageFragment.java @@ -155,7 +155,7 @@ private void updateAccount(AccountId accountId) { if (accountId == null) { return; } - assert (accountId.coin == CoinType.ETH); + assert (accountId.coin == CoinType.ETH || accountId.coin == CoinType.SOL); try { BraveActivity activity = BraveActivity.getBraveActivity(); diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignSolTransactionsFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignSolTransactionsFragment.java index ae75d768d8d6..91a9f3d121f2 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignSolTransactionsFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/dapps/SignSolTransactionsFragment.java @@ -59,7 +59,6 @@ public class SignSolTransactionsFragment extends BaseDAppsBottomSheetDialogFragment { private static final String TAG = "SignTransaction"; - private static final String PARAM_ACITITY_TYPE = "sign_param"; private List mTabTitles; private List mSignSolTransactionRequests; private ViewPager2 mViewPager; @@ -136,7 +135,6 @@ public View onCreateView( } private void initComponents() { - assert getArguments() != null; updateTxPanelPerStep(); fetchSignRequestData(); Spanned associatedSPLTokenAccountInfo = @@ -151,14 +149,8 @@ private void initComponents() { mTxLearnMore.setMovementMethod(LinkMovementMethod.getInstance()); mTxLearnMore.setText(associatedSPLTokenAccountInfo); - mBtSign.setOnClickListener( - v -> { - processRequest(true); - }); - mBtCancel.setOnClickListener( - v -> { - processRequest(false); - }); + mBtSign.setOnClickListener(v -> processRequest(true)); + mBtCancel.setOnClickListener(v -> processRequest(false)); mTvTxCounter.setOnClickListener( v -> { diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/util/ParsedTransaction.java b/android/java/org/chromium/chrome/browser/crypto_wallet/util/ParsedTransaction.java index 832a3c148078..c5bced96e850 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/util/ParsedTransaction.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/util/ParsedTransaction.java @@ -85,6 +85,7 @@ public class ParsedTransaction extends ParsedTransactionFees { // Solana public boolean isSolanaDappTransaction; + private boolean solChangeOfOwnership; // There are too many fields to init here private ParsedTransaction(ParsedTransactionFees parsedTransactionFees) { @@ -251,6 +252,11 @@ public static ParsedTransaction parseTransaction( new SolanaInstructionPresenter(solanaInstruction); String lamport = presenter.getLamportAmount(); Integer instructionType = presenter.getInstructionType(); + if (instructionType != null + && (instructionType == SolanaSystemInstruction.ASSIGN_WITH_SEED + || instructionType == SolanaSystemInstruction.ASSIGN)) { + parsedTransaction.solChangeOfOwnership = true; + } boolean isInsExists = instructionType != null; if (isInsExists && (instructionType == SolanaSystemInstruction.TRANSFER @@ -754,4 +760,8 @@ public BlockchainToken getBuyToken() { public double getMinBuyAmount() { return this.minBuyAmount; } + + public boolean isSolChangeOfOwnership() { + return solChangeOfOwnership; + } } diff --git a/android/java/org/chromium/chrome/browser/ntp/IncognitoNewTabPageView.java b/android/java/org/chromium/chrome/browser/ntp/IncognitoNewTabPageView.java index 7877aa2e13d3..26759eb80dcb 100644 --- a/android/java/org/chromium/chrome/browser/ntp/IncognitoNewTabPageView.java +++ b/android/java/org/chromium/chrome/browser/ntp/IncognitoNewTabPageView.java @@ -85,6 +85,9 @@ protected void onFinishInflate() { super.onFinishInflate(); mScrollView = (NewTabPageScrollView) findViewById(R.id.ntp_scrollview); + mScrollView.setBackgroundColor(getContext().getColor(R.color.ntp_bg_incognito)); + setContentDescription( + getResources().getText(R.string.accessibility_new_incognito_tab_page)); // FOCUS_BEFORE_DESCENDANTS is needed to support keyboard shortcuts. Otherwise, pressing // any shortcut causes the UrlBar to be focused. See ViewRootImpl.leaveTouchMode(). diff --git a/android/java/res/layout/approve_tx_bottom_sheet.xml b/android/java/res/layout/approve_tx_bottom_sheet.xml index 0dcb7453f564..c4de9ecf622a 100644 --- a/android/java/res/layout/approve_tx_bottom_sheet.xml +++ b/android/java/res/layout/approve_tx_bottom_sheet.xml @@ -141,6 +141,45 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/amount_fiat" /> + + + + + + + + + Account Name + + Account ownership change requested + + + This transaction will reassign ownership of the account to a new program. This action is irreversible and may result in loss of funds. + You can create a secondary account by importing your private key.