Skip to content

Commit

Permalink
(Wallet) Show warning message changing ownership (#26280)
Browse files Browse the repository at this point in the history
Shows warning message when a change of ownership is requested for Solana account.
Fixes two crashes affecting signing messages and transactions.
  • Loading branch information
simoarpe authored Oct 31, 2024
1 parent 8c3e3e9 commit 795271e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -391,6 +391,9 @@ private void fetchTxBalanceAndUpdateUi(
}

private void refreshListContentUi() {
if (mTransactionInfos == null) {
return;
}
mRejectAllTx.setText(
getString(
R.string.brave_wallet_queue_reject_all,
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationItem> mTabTitles;
private List<SignSolTransactionsRequest> mSignSolTransactionRequests;
private ViewPager2 mViewPager;
Expand Down Expand Up @@ -136,7 +135,6 @@ public View onCreateView(
}

private void initComponents() {
assert getArguments() != null;
updateTxPanelPerStep();
fetchSignRequestData();
Spanned associatedSPLTokenAccountInfo =
Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -754,4 +760,8 @@ public BlockchainToken getBuyToken() {
public double getMinBuyAmount() {
return this.minBuyAmount;
}

public boolean isSolChangeOfOwnership() {
return solChangeOfOwnership;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
42 changes: 40 additions & 2 deletions android/java/res/layout/approve_tx_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,53 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/amount_fiat" />

<Space
android:id="@+id/tab_top_space"
android:layout_width="0dp"
android:layout_height="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_approve_dialog_additional_details"
app:layout_constraintBottom_toTopOf="@+id/warning_container" />

<LinearLayout
android:id="@+id/warning_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="#32E32444"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintBottom_toTopOf="@+id/tabs"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_approve_dialog_additional_details"
app:layout_constraintVertical_bias="0"
android:visibility="gone">

<TextView
style="@style/BraveWalletTextView"
android:text="@string/wallet_change_ownership_warning"
android:textColor="@color/brave_theme_error_txt"
android:textStyle="bold"
android:drawablePadding="6dp"
app:drawableStartCompat="@drawable/ic_warning" />

<TextView
android:layout_marginTop="8dp"
style="@style/BraveWalletTextView"
android:layout_width="match_parent"
android:text="@string/wallet_change_ownership_description"
android:textColor="@color/brave_theme_error_txt" />
</LinearLayout>

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/wallet_toolbar_bg_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_approve_dialog_additional_details"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/warning_container"
app:tabGravity="fill"
app:tabIndicator="@drawable/tab_gradient_separator"
app:tabIndicatorHeight="@dimen/brave_wallet_tab_indicator_height"
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,12 @@ Are you sure you want to do this?
<message name="IDS_ACCOUNT_NAME" desc="Brave wallet accounts text">
Account Name
</message>
<message name="IDS_WALLET_CHANGE_OWNERSHIP_WARNING" desc="Brave Wallet warning title displayed when requesting a change of ownership">
Account ownership change requested
</message>
<message name="IDS_WALLET_CHANGE_OWNERSHIP_DESCRIPTION" desc="Brave Wallet warning description displayed when requesting a change of ownership">
This transaction will reassign ownership of the account to a new program. This action is irreversible and may result in loss of funds.
</message>
<message name="IDS_ACCOUNT_NAME_TEXT" desc="Brave wallet accounts text">
You can create a secondary account by importing your private key.
</message>
Expand Down

0 comments on commit 795271e

Please sign in to comment.