(Wallet) Add Wallet model null checks (#23502)

This commit is contained in:
Simone Arpe
2024-05-08 22:21:59 +02:00
committed by GitHub
parent 89a9434147
commit 5413889a3c
2 changed files with 20 additions and 9 deletions
@@ -287,7 +287,7 @@ public abstract class BraveActivity extends ChromeActivity
private JsonRpcService mJsonRpcService;
private MiscAndroidMetrics mMiscAndroidMetrics;
private SwapService mSwapService;
private WalletModel mWalletModel;
@Nullable private WalletModel mWalletModel;
private BlockchainRegistry mBlockchainRegistry;
private TxService mTxService;
private EthTxManagerProxy mEthTxManagerProxy;
@@ -481,6 +481,11 @@ public abstract class BraveActivity extends ChromeActivity
cleanUpMiscAndroidMetrics();
}
/**
* Gets Wallet model for Brave activity. It may be {@code null} if native initialization has not
* completed yet.
*/
@Nullable
public WalletModel getWalletModel() {
return mWalletModel;
}
@@ -509,9 +514,10 @@ public abstract class BraveActivity extends ChromeActivity
}
private void maybeShowPendingTransactions() {
assert mWalletModel != null;
// trigger to observer to refresh data to process the pending request
mWalletModel.getCryptoModel().refreshTransactions();
if (mWalletModel != null) {
// Trigger to observer to refresh data to process the pending request.
mWalletModel.getCryptoModel().refreshTransactions();
}
}
private void maybeShowSignTxRequestLayout() {
@@ -683,13 +689,15 @@ public abstract class BraveActivity extends ChromeActivity
}
public void showAccountCreation(@CoinType.EnumType int coinType) {
assert mWalletModel != null : " mWalletModel is null ";
mWalletModel.getDappsModel().addAccountCreationRequest(coinType);
if (mWalletModel != null) {
mWalletModel.getDappsModel().addAccountCreationRequest(coinType);
}
}
private void updateWalletBadgeVisibility() {
assert mWalletModel != null;
mWalletModel.getDappsModel().updateWalletBadgeVisibility();
if (mWalletModel != null) {
mWalletModel.getDappsModel().updateWalletBadgeVisibility();
}
}
private void verifySubscription() {
@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.app.domain;
import android.content.Context;
import androidx.annotation.NonNull;
import org.chromium.brave_wallet.mojom.AssetRatioService;
import org.chromium.brave_wallet.mojom.BlockchainRegistry;
import org.chromium.brave_wallet.mojom.BraveWalletService;
@@ -31,7 +33,7 @@ public class WalletModel {
private AssetRatioService mAssetRatioService;
private SwapService mSwapService;
private final CryptoModel mCryptoModel;
private final DappsModel mDappsModel;
@NonNull private final DappsModel mDappsModel;
private final KeyringModel mKeyringModel;
private Context mContext;
private CryptoActions mCryptoActions;
@@ -140,6 +142,7 @@ public class WalletModel {
return mCryptoModel.getNetworkModel();
}
@NonNull
public DappsModel getDappsModel() {
return mDappsModel;
}