Makes wallet observers implementations separate from Activities and Fragments on Android
This commit is contained in:
-8
@@ -32,24 +32,16 @@ import org.chromium.brave_wallet.mojom.NetworkInfo;
|
||||
import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TxService;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.AssetRatioServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.BlockchainRegistryFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.BraveWalletServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.JsonRpcServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.TxServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.AddAccountActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
|
||||
import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.CryptoAccountTypeInfo;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.WalletListItemModel;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.ApprovedTxObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.PortfolioHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
-5
@@ -23,15 +23,10 @@ import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.chrome.browser.night_mode.GlobalNightModeStateProviderHolder;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
-4
@@ -21,12 +21,8 @@ import androidx.appcompat.widget.Toolbar;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
-8
@@ -39,27 +39,19 @@ import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TxService;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.AssetRatioServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.BlockchainRegistryFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.BraveWalletServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.JsonRpcServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.TxServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.AccountDetailActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BuySendSwapActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
|
||||
import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.WalletListItemModel;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.ApprovedTxObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetsPricesHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.BalanceHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.SmoothLineChartEquallySpaced;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
+43
-5
@@ -14,6 +14,7 @@ import org.chromium.brave_wallet.mojom.EthTxManagerProxy;
|
||||
import org.chromium.brave_wallet.mojom.JsonRpcService;
|
||||
import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.brave_wallet.mojom.SolanaTxManagerProxy;
|
||||
import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TxService;
|
||||
import org.chromium.chrome.browser.crypto_wallet.AssetRatioServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.BlockchainRegistryFactory;
|
||||
@@ -21,14 +22,17 @@ import org.chromium.chrome.browser.crypto_wallet.BraveWalletServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.JsonRpcServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.TxServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.TxServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserverImpl;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserverImpl.KeyringServiceObserverImplDelegate;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.TxServiceObserverImpl;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.TxServiceObserverImpl.TxServiceObserverImplDelegate;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
public abstract class BraveWalletBaseActivity extends AsyncInitializationActivity
|
||||
implements ConnectionErrorHandler, TxServiceObserver, KeyringServiceObserver {
|
||||
implements ConnectionErrorHandler, KeyringServiceObserverImplDelegate,
|
||||
TxServiceObserverImplDelegate {
|
||||
protected KeyringService mKeyringService;
|
||||
protected BlockchainRegistry mBlockchainRegistry;
|
||||
protected JsonRpcService mJsonRpcService;
|
||||
@@ -37,6 +41,8 @@ public abstract class BraveWalletBaseActivity extends AsyncInitializationActivit
|
||||
protected SolanaTxManagerProxy mSolanaTxManagerProxy;
|
||||
protected AssetRatioService mAssetRatioService;
|
||||
protected BraveWalletService mBraveWalletService;
|
||||
private KeyringServiceObserverImpl mKeyringServiceObserver;
|
||||
private TxServiceObserverImpl mTxServiceObserver;
|
||||
|
||||
@Override
|
||||
public void onUserInteraction() {
|
||||
@@ -48,6 +54,16 @@ public abstract class BraveWalletBaseActivity extends AsyncInitializationActivit
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {
|
||||
if (mKeyringServiceObserver != null) {
|
||||
mKeyringServiceObserver.close();
|
||||
mKeyringServiceObserver.destroy();
|
||||
mKeyringServiceObserver = null;
|
||||
}
|
||||
if (mTxServiceObserver != null) {
|
||||
mTxServiceObserver.close();
|
||||
mTxServiceObserver.destroy();
|
||||
mTxServiceObserver = null;
|
||||
}
|
||||
if (mKeyringService != null) mKeyringService.close();
|
||||
if (mAssetRatioService != null) mAssetRatioService.close();
|
||||
if (mBlockchainRegistry != null) mBlockchainRegistry.close();
|
||||
@@ -81,7 +97,8 @@ public abstract class BraveWalletBaseActivity extends AsyncInitializationActivit
|
||||
}
|
||||
|
||||
mTxService = TxServiceFactory.getInstance().getTxService(this);
|
||||
mTxService.addObserver(this);
|
||||
mTxServiceObserver = new TxServiceObserverImpl(this);
|
||||
mTxService.addObserver(mTxServiceObserver);
|
||||
}
|
||||
|
||||
protected void InitEthTxManagerProxy() {
|
||||
@@ -106,7 +123,8 @@ public abstract class BraveWalletBaseActivity extends AsyncInitializationActivit
|
||||
}
|
||||
|
||||
mKeyringService = KeyringServiceFactory.getInstance().getKeyringService(this);
|
||||
mKeyringService.addObserver(this);
|
||||
mKeyringServiceObserver = new KeyringServiceObserverImpl(this);
|
||||
mKeyringService.addObserver(mKeyringServiceObserver);
|
||||
}
|
||||
|
||||
protected void InitBlockchainRegistry() {
|
||||
@@ -198,6 +216,14 @@ public abstract class BraveWalletBaseActivity extends AsyncInitializationActivit
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (mKeyringServiceObserver != null) {
|
||||
mKeyringServiceObserver.close();
|
||||
mKeyringServiceObserver.destroy();
|
||||
}
|
||||
if (mTxServiceObserver != null) {
|
||||
mTxServiceObserver.close();
|
||||
mTxServiceObserver.destroy();
|
||||
}
|
||||
if (mKeyringService != null) mKeyringService.close();
|
||||
if (mAssetRatioService != null) mAssetRatioService.close();
|
||||
if (mBlockchainRegistry != null) mBlockchainRegistry.close();
|
||||
@@ -218,4 +244,16 @@ public abstract class BraveWalletBaseActivity extends AsyncInitializationActivit
|
||||
public void locked() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backedUp() {}
|
||||
|
||||
@Override
|
||||
public void onNewUnapprovedTx(TransactionInfo txInfo) {}
|
||||
|
||||
@Override
|
||||
public void onUnapprovedTxUpdated(TransactionInfo txInfo) {}
|
||||
|
||||
@Override
|
||||
public void onTransactionStatusChanged(TransactionInfo txInfo) {}
|
||||
}
|
||||
|
||||
+7
@@ -135,6 +135,7 @@ public class BraveWalletDAppsActivity extends BraveWalletBaseActivity
|
||||
}
|
||||
});
|
||||
}
|
||||
mPendingTxHelper.destroy();
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -168,6 +169,9 @@ public class BraveWalletDAppsActivity extends BraveWalletBaseActivity
|
||||
if (accountInfosTemp == null) {
|
||||
accountInfosTemp = new AccountInfo[] {};
|
||||
}
|
||||
if (mPendingTxHelper != null) {
|
||||
mPendingTxHelper.destroy();
|
||||
}
|
||||
mPendingTxHelper =
|
||||
new PendingTxHelper(getTxService(), accountInfosTemp, false, true);
|
||||
mPendingTxHelper.mHasNoPendingTxAfterProcessing.observe(
|
||||
@@ -237,5 +241,8 @@ public class BraveWalletDAppsActivity extends BraveWalletBaseActivity
|
||||
if (activity != null) {
|
||||
activity.getWalletModel().getCryptoModel().clearDappsState();
|
||||
}
|
||||
if (mPendingTxHelper != null) {
|
||||
mPendingTxHelper.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -26,15 +26,14 @@ import org.chromium.chrome.browser.crypto_wallet.JsonRpcServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.modal.BraveWalletPanel;
|
||||
import org.chromium.chrome.browser.crypto_wallet.modal.DAppsDialog;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarConfiguration;
|
||||
import org.chromium.chrome.browser.util.ConfigurationUtils;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
public class DAppsWalletController implements ConnectionErrorHandler, KeyringServiceObserver,
|
||||
BraveWalletPanel.BraveWalletPanelServices {
|
||||
public class DAppsWalletController
|
||||
implements ConnectionErrorHandler, BraveWalletPanel.BraveWalletPanelServices {
|
||||
private Context mContext;
|
||||
private View mAnchorViewHost;
|
||||
private AssetRatioService mAssetRatioService;
|
||||
|
||||
+11
-3
@@ -56,7 +56,8 @@ import org.chromium.chrome.browser.crypto_wallet.activities.BuySendSwapActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
|
||||
import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.WalletListItemModel;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserverImpl;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserverImpl.KeyringServiceObserverImplDelegate;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
|
||||
@@ -66,7 +67,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||
implements View.OnClickListener, OnWalletListItemClick, KeyringServiceObserver {
|
||||
implements View.OnClickListener, OnWalletListItemClick, KeyringServiceObserverImplDelegate {
|
||||
public static final String TAG_FRAGMENT =
|
||||
EditVisibleAssetsBottomSheetDialogFragment.class.getName();
|
||||
private WalletCoinAdapter walletCoinAdapter;
|
||||
@@ -76,6 +77,7 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo
|
||||
private Boolean mIsAssetsListChanged;
|
||||
private static final String TAG = "EditVisibleAssetsBottomSheetDialogFragment";
|
||||
private WalletModel mWalletModel;
|
||||
private KeyringServiceObserverImpl mKeyringServiceObserver;
|
||||
|
||||
public interface DismissListener {
|
||||
void onDismiss(Boolean isAssetsListChanged);
|
||||
@@ -191,6 +193,11 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo
|
||||
if (mDismissListener != null) {
|
||||
mDismissListener.onDismiss(mIsAssetsListChanged);
|
||||
}
|
||||
if (mKeyringServiceObserver != null) {
|
||||
mKeyringServiceObserver.close();
|
||||
mKeyringServiceObserver.destroy();
|
||||
mKeyringServiceObserver = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setupFullHeight(BottomSheetDialog bottomSheetDialog) {
|
||||
@@ -277,7 +284,8 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo
|
||||
}
|
||||
KeyringService keyringService = getKeyringService();
|
||||
assert keyringService != null;
|
||||
keyringService.addObserver(this);
|
||||
mKeyringServiceObserver = new KeyringServiceObserverImpl(this);
|
||||
keyringService.addObserver(mKeyringServiceObserver);
|
||||
}
|
||||
|
||||
private void showAddAssetDialog() {
|
||||
|
||||
+1
@@ -469,6 +469,7 @@ public class PortfolioFragment
|
||||
PendingTxHelper pendingTxHelper = new PendingTxHelper(getTxService(), accountInfos, false);
|
||||
pendingTxHelper.fetchTransactions(() -> {
|
||||
mPendingTxInfos = pendingTxHelper.getTransactions();
|
||||
pendingTxHelper.destroy();
|
||||
if (callback != null) callback.run();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,14 +26,13 @@ import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.app.BraveActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.KeyringServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AndroidUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.WalletConstants;
|
||||
import org.chromium.chrome.browser.util.ConfigurationUtils;
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
public class DAppsDialog extends Dialog implements ConnectionErrorHandler, KeyringServiceObserver {
|
||||
public class DAppsDialog extends Dialog implements ConnectionErrorHandler {
|
||||
public static final String TAG_FRAGMENT = DAppsDialog.class.getName();
|
||||
|
||||
private View mRootView;
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/* Copyright (c) 2021 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.crypto_wallet.observers;
|
||||
|
||||
public interface KeyringServiceObserver
|
||||
extends org.chromium.brave_wallet.mojom.KeyringServiceObserver, WalletMojoObserverBase {
|
||||
@Override
|
||||
default void keyringCreated(String keyring_id) {}
|
||||
|
||||
@Override
|
||||
default void keyringRestored(String keyring_id) {}
|
||||
|
||||
@Override
|
||||
default void keyringReset() {}
|
||||
|
||||
@Override
|
||||
default void locked() {}
|
||||
|
||||
@Override
|
||||
default void unlocked() {}
|
||||
|
||||
@Override
|
||||
default void backedUp() {}
|
||||
|
||||
@Override
|
||||
default void accountsChanged() {}
|
||||
|
||||
@Override
|
||||
default void autoLockMinutesChanged() {}
|
||||
|
||||
@Override
|
||||
default void selectedAccountChanged(int coin) {}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/* Copyright (c) 2022 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.crypto_wallet.observers;
|
||||
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
public class KeyringServiceObserverImpl
|
||||
implements org.chromium.brave_wallet.mojom.KeyringServiceObserver {
|
||||
public interface KeyringServiceObserverImplDelegate {
|
||||
default void locked() {}
|
||||
default void backedUp() {}
|
||||
}
|
||||
|
||||
private KeyringServiceObserverImplDelegate mDelegate;
|
||||
|
||||
public KeyringServiceObserverImpl(KeyringServiceObserverImplDelegate delegate) {
|
||||
mDelegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyringCreated(String keyring_id) {}
|
||||
|
||||
@Override
|
||||
public void keyringRestored(String keyring_id) {}
|
||||
|
||||
@Override
|
||||
public void keyringReset() {}
|
||||
|
||||
@Override
|
||||
public void locked() {
|
||||
if (mDelegate == null) return;
|
||||
|
||||
mDelegate.locked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlocked() {}
|
||||
|
||||
@Override
|
||||
public void backedUp() {
|
||||
if (mDelegate == null) return;
|
||||
|
||||
mDelegate.backedUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accountsChanged() {}
|
||||
|
||||
@Override
|
||||
public void autoLockMinutesChanged() {}
|
||||
|
||||
@Override
|
||||
public void selectedAccountChanged(int coin) {}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
mDelegate = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
public void destroy() {
|
||||
mDelegate = null;
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/* Copyright (c) 2022 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.crypto_wallet.observers;
|
||||
|
||||
import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
|
||||
public interface TxServiceObserver
|
||||
extends org.chromium.brave_wallet.mojom.TxServiceObserver, WalletMojoObserverBase {
|
||||
@Override
|
||||
default void onNewUnapprovedTx(TransactionInfo txInfo) {}
|
||||
|
||||
@Override
|
||||
default void onUnapprovedTxUpdated(TransactionInfo txInfo) {}
|
||||
|
||||
@Override
|
||||
default void onTransactionStatusChanged(TransactionInfo txInfo) {}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/* Copyright (c) 2022 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.crypto_wallet.observers;
|
||||
|
||||
import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
public class TxServiceObserverImpl implements org.chromium.brave_wallet.mojom.TxServiceObserver {
|
||||
public interface TxServiceObserverImplDelegate {
|
||||
default void onNewUnapprovedTx(TransactionInfo txInfo) {}
|
||||
default void onUnapprovedTxUpdated(TransactionInfo txInfo) {}
|
||||
default void onTransactionStatusChanged(TransactionInfo txInfo) {}
|
||||
}
|
||||
|
||||
private TxServiceObserverImplDelegate mDelegate;
|
||||
|
||||
public TxServiceObserverImpl(TxServiceObserverImplDelegate delegate) {
|
||||
mDelegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewUnapprovedTx(TransactionInfo txInfo) {
|
||||
if (mDelegate == null) return;
|
||||
|
||||
mDelegate.onNewUnapprovedTx(txInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnapprovedTxUpdated(TransactionInfo txInfo) {
|
||||
if (mDelegate == null) return;
|
||||
|
||||
mDelegate.onUnapprovedTxUpdated(txInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionStatusChanged(TransactionInfo txInfo) {
|
||||
if (mDelegate == null) return;
|
||||
|
||||
mDelegate.onTransactionStatusChanged(txInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
mDelegate = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
public void destroy() {
|
||||
mDelegate = null;
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
/* Copyright (c) 2022 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.crypto_wallet.observers;
|
||||
|
||||
import org.chromium.mojo.bindings.Interface;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
|
||||
public interface WalletMojoObserverBase extends Interface {
|
||||
@Override
|
||||
default void close() {}
|
||||
|
||||
@Override
|
||||
default void onConnectionError(MojoException e) {}
|
||||
}
|
||||
@@ -14,7 +14,8 @@ import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TransactionStatus;
|
||||
import org.chromium.brave_wallet.mojom.TransactionType;
|
||||
import org.chromium.brave_wallet.mojom.TxService;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.TxServiceObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.TxServiceObserverImpl;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.TxServiceObserverImpl.TxServiceObserverImplDelegate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -25,7 +26,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class PendingTxHelper implements TxServiceObserver {
|
||||
public class PendingTxHelper implements TxServiceObserverImplDelegate {
|
||||
private TxService mTxService;
|
||||
private AccountInfo[] mAccountInfos;
|
||||
private HashMap<String, TransactionInfo[]> mTxInfos;
|
||||
@@ -43,6 +44,7 @@ public class PendingTxHelper implements TxServiceObserver {
|
||||
public LiveData<List<TransactionInfo>> mTransactionInfoLd;
|
||||
public LiveData<TransactionInfo> mSelectedPendingRequest;
|
||||
public LiveData<Boolean> mHasNoPendingTxAfterProcessing;
|
||||
private TxServiceObserverImpl mTxServiceObserver;
|
||||
|
||||
public PendingTxHelper(TxService txService, AccountInfo[] accountInfos, boolean returnAll) {
|
||||
assert txService != null;
|
||||
@@ -67,7 +69,16 @@ public class PendingTxHelper implements TxServiceObserver {
|
||||
boolean shouldObserveTxUpdates) {
|
||||
this(txService, accountInfos, returnAll);
|
||||
if (shouldObserveTxUpdates) {
|
||||
txService.addObserver(this);
|
||||
mTxServiceObserver = new TxServiceObserverImpl(this);
|
||||
txService.addObserver(mTxServiceObserver);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (mTxServiceObserver != null) {
|
||||
mTxServiceObserver.close();
|
||||
mTxServiceObserver.destroy();
|
||||
mTxServiceObserver = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1155,6 +1155,7 @@ public class Utils {
|
||||
pendingTxHelper.fetchTransactions(() -> {
|
||||
HashMap<String, TransactionInfo[]> pendingTxInfos =
|
||||
pendingTxHelper.getTransactions();
|
||||
pendingTxHelper.destroy();
|
||||
SolanaTransactionsGasHelper solanaTransactionsGasHelper =
|
||||
new SolanaTransactionsGasHelper(
|
||||
activity, getTransactionArray(pendingTxInfos));
|
||||
|
||||
Reference in New Issue
Block a user