[Wallet] Drop balance and tx related P3A metrics (#36303)
[Wallet] Remove some wallet p3a metrics
This commit is contained in:
+16
-25
@@ -56,7 +56,6 @@ import org.chromium.chrome.browser.crypto_wallet.util.SolanaTransactionsGasHelpe
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.TransactionUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.util.LiveDataUtil;
|
||||
import org.chromium.chrome.browser.util.TabUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -302,32 +301,24 @@ public class ApproveTxBottomSheetDialogFragment extends WalletBottomSheetDialogF
|
||||
AccountInfo txAccountInfo,
|
||||
AccountInfo[] accounts,
|
||||
BlockchainToken[] filterByTokens) {
|
||||
LiveDataUtil.observeOnce(
|
||||
getWalletModel().getCryptoModel().getNetworkModel().mCryptoNetworks,
|
||||
allNetworks -> {
|
||||
Utils.getTxExtraInfo(
|
||||
new WeakReference<>((BraveWalletBaseActivity) getActivity()),
|
||||
TokenUtils.TokenType.ALL,
|
||||
allNetworks,
|
||||
Utils.getTxExtraInfo(
|
||||
new WeakReference<>((BraveWalletBaseActivity) getActivity()),
|
||||
TokenUtils.TokenType.ALL,
|
||||
txNetwork,
|
||||
accounts,
|
||||
filterByTokens,
|
||||
false,
|
||||
(assetPrices, fullTokenList, nativeAssetsBalances, blockchainTokensBalances) -> {
|
||||
if (!canUpdateUi() || mTxInfo == null) return;
|
||||
fillAssetDependentControls(
|
||||
mTxInfo,
|
||||
view,
|
||||
txNetwork,
|
||||
txAccountInfo,
|
||||
accounts,
|
||||
filterByTokens,
|
||||
false,
|
||||
(assetPrices,
|
||||
fullTokenList,
|
||||
nativeAssetsBalances,
|
||||
blockchainTokensBalances) -> {
|
||||
if (!canUpdateUi() || mTxInfo == null) return;
|
||||
fillAssetDependentControls(
|
||||
mTxInfo,
|
||||
view,
|
||||
txNetwork,
|
||||
txAccountInfo,
|
||||
accounts,
|
||||
assetPrices,
|
||||
fullTokenList,
|
||||
mSolanaEstimatedTxFee);
|
||||
});
|
||||
assetPrices,
|
||||
fullTokenList,
|
||||
mSolanaEstimatedTxFee);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TxService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class AsyncUtils {
|
||||
@@ -363,21 +362,6 @@ public class AsyncUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static class GetP3ABalancesContext extends SingleResponseBaseContext
|
||||
implements Callback1<HashMap<Integer, HashSet<String>>> {
|
||||
public HashMap<Integer, HashSet<String>> activeAddresses;
|
||||
|
||||
public GetP3ABalancesContext(Runnable responseCompleteCallback) {
|
||||
super(responseCompleteCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(HashMap<Integer, HashSet<String>> activeAddresses) {
|
||||
this.activeAddresses = activeAddresses;
|
||||
super.fireResponseCompleteCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class BaseGetNftMetadataContext extends SingleResponseBaseContext {
|
||||
public BlockchainToken asset;
|
||||
public String tokenMetadata;
|
||||
|
||||
@@ -8,34 +8,23 @@ package org.chromium.chrome.browser.crypto_wallet.util;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.chromium.brave_wallet.mojom.AccountInfo;
|
||||
import org.chromium.brave_wallet.mojom.BlockchainRegistry;
|
||||
import org.chromium.brave_wallet.mojom.BlockchainToken;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletService;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.JsonRpcService;
|
||||
import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.brave_wallet.mojom.NetworkInfo;
|
||||
import org.chromium.brave_wallet.mojom.ProviderError;
|
||||
import org.chromium.chrome.browser.BraveLocalState;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletBaseActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetBalanceResponseBaseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetBalanceResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetBlockchainTokensBalancesResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetErc20TokenBalanceResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetErc721TokenBalanceResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetNativeAssetsBalancesResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetSolanaBalanceResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.GetSplTokenAccountBalanceResponseContext;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AsyncUtils.MultiResponseHandler;
|
||||
import org.chromium.chrome.browser.preferences.BravePref;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class BalanceHelper {
|
||||
/** Get assets balances for all accounts on selected network. */
|
||||
@@ -217,142 +206,6 @@ public class BalanceHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public static void getP3ABalances(
|
||||
WeakReference<BraveWalletBaseActivity> activityRef,
|
||||
List<NetworkInfo> allNetworks,
|
||||
NetworkInfo selectedNetwork,
|
||||
AsyncUtils.Callback1<HashMap<Integer, HashSet<String>>> callback) {
|
||||
BraveWalletBaseActivity activity = activityRef.get();
|
||||
if (activity == null || activity.isFinishing()) return;
|
||||
KeyringService keyringService = activity.getKeyringService();
|
||||
BraveWalletService braveWalletService = activity.getBraveWalletService();
|
||||
BlockchainRegistry blockchainRegistry = activity.getBlockchainRegistry();
|
||||
JsonRpcService jsonRpcService = activity.getJsonRpcService();
|
||||
assert braveWalletService != null
|
||||
&& blockchainRegistry != null
|
||||
&& keyringService != null
|
||||
&& jsonRpcService != null;
|
||||
if (JavaUtils.anyNull(
|
||||
braveWalletService, blockchainRegistry, keyringService, jsonRpcService)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean P3AEnabled = BraveLocalState.get().getBoolean(BravePref.P3A_ENABLED);
|
||||
|
||||
HashMap<Integer, HashSet<String>> activeAddresses = new HashMap<Integer, HashSet<String>>();
|
||||
for (int coinType : Utils.P3ACoinTypes) {
|
||||
activeAddresses.put(coinType, new HashSet<String>());
|
||||
}
|
||||
|
||||
if (!P3AEnabled) {
|
||||
callback.call(activeAddresses);
|
||||
return;
|
||||
} else {
|
||||
Utils.getP3ANetworks(
|
||||
allNetworks,
|
||||
relevantNetworks -> {
|
||||
// Exclude selectedNetwork if in relevantNetworks, also sort by CoinType
|
||||
HashMap<Integer, ArrayList<NetworkInfo>> sortedNetworks =
|
||||
filterAndSortNetworksP3A(relevantNetworks, selectedNetwork);
|
||||
int numNetworks = 0;
|
||||
for (int coinType : Utils.P3ACoinTypes) {
|
||||
numNetworks += sortedNetworks.get(coinType).size();
|
||||
}
|
||||
|
||||
MultiResponseHandler multiResponse =
|
||||
new MultiResponseHandler(numNetworks * 2);
|
||||
ArrayList<GetNativeAssetsBalancesResponseContext>
|
||||
nativeAssetsBalancesResponses =
|
||||
new ArrayList<GetNativeAssetsBalancesResponseContext>();
|
||||
ArrayList<GetBlockchainTokensBalancesResponseContext>
|
||||
blockchainTokensBalancesResponses =
|
||||
new ArrayList<GetBlockchainTokensBalancesResponseContext>();
|
||||
|
||||
for (int coinType : Utils.P3ACoinTypes) {
|
||||
processP3ACoinNetworks(
|
||||
coinType,
|
||||
sortedNetworks.get(coinType),
|
||||
keyringService,
|
||||
jsonRpcService,
|
||||
braveWalletService,
|
||||
blockchainRegistry,
|
||||
multiResponse,
|
||||
nativeAssetsBalancesResponses,
|
||||
blockchainTokensBalancesResponses);
|
||||
}
|
||||
|
||||
multiResponse.setWhenAllCompletedAction(
|
||||
() -> {
|
||||
updateActiveAddresses(
|
||||
nativeAssetsBalancesResponses.toArray(
|
||||
new GetNativeAssetsBalancesResponseContext[0]),
|
||||
blockchainTokensBalancesResponses.toArray(
|
||||
new GetBlockchainTokensBalancesResponseContext
|
||||
[0]),
|
||||
activeAddresses);
|
||||
callback.call(activeAddresses);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void processP3ACoinNetworks(
|
||||
@CoinType.EnumType int coinType,
|
||||
List<NetworkInfo> networks,
|
||||
KeyringService keyringService,
|
||||
JsonRpcService jsonRpcService,
|
||||
BraveWalletService braveWalletService,
|
||||
BlockchainRegistry blockchainRegistry,
|
||||
MultiResponseHandler multiResponse,
|
||||
ArrayList<GetNativeAssetsBalancesResponseContext> nativeAssetsBalancesResponses,
|
||||
ArrayList<GetBlockchainTokensBalancesResponseContext>
|
||||
blockchainTokensBalancesResponses) {
|
||||
if (JavaUtils.anyNull(braveWalletService, blockchainRegistry, jsonRpcService)) return;
|
||||
|
||||
keyringService.getAllAccounts(
|
||||
allAccounts -> {
|
||||
for (NetworkInfo network : networks) {
|
||||
AccountInfo[] accountInfoArray =
|
||||
AssetUtils.filterAccountsByNetwork(
|
||||
allAccounts.accounts, network.coin, network.chainId);
|
||||
|
||||
TokenUtils.getVisibleUserAssetsFiltered(
|
||||
braveWalletService,
|
||||
network,
|
||||
coinType,
|
||||
TokenUtils.TokenType.ALL,
|
||||
tokens -> {
|
||||
// Assets balances.
|
||||
GetNativeAssetsBalancesResponseContext
|
||||
getNativeAssetsBalancesContext =
|
||||
new GetNativeAssetsBalancesResponseContext(
|
||||
multiResponse.singleResponseComplete);
|
||||
getNativeAssetsBalances(
|
||||
jsonRpcService,
|
||||
network,
|
||||
accountInfoArray,
|
||||
getNativeAssetsBalancesContext);
|
||||
nativeAssetsBalancesResponses.add(
|
||||
getNativeAssetsBalancesContext);
|
||||
|
||||
// Tokens balances.
|
||||
GetBlockchainTokensBalancesResponseContext
|
||||
getBlockchainTokensBalancesContext =
|
||||
new GetBlockchainTokensBalancesResponseContext(
|
||||
multiResponse.singleResponseComplete);
|
||||
getBlockchainTokensBalances(
|
||||
jsonRpcService,
|
||||
network,
|
||||
accountInfoArray,
|
||||
tokens,
|
||||
getBlockchainTokensBalancesContext);
|
||||
blockchainTokensBalancesResponses.add(
|
||||
getBlockchainTokensBalancesContext);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static <T extends GetBalanceResponseBaseContext> T addBalanceResponseContext(
|
||||
ArrayList<GetBalanceResponseBaseContext> contexts,
|
||||
T context,
|
||||
@@ -363,51 +216,4 @@ public class BalanceHelper {
|
||||
contexts.add(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
private static HashMap<Integer, ArrayList<NetworkInfo>> filterAndSortNetworksP3A(
|
||||
List<NetworkInfo> relevantNetworks, NetworkInfo selectedNetwork) {
|
||||
HashMap<Integer, ArrayList<NetworkInfo>> networksPerCoin =
|
||||
new HashMap<Integer, ArrayList<NetworkInfo>>();
|
||||
networksPerCoin.put(CoinType.ETH, new ArrayList<NetworkInfo>());
|
||||
networksPerCoin.put(CoinType.SOL, new ArrayList<NetworkInfo>());
|
||||
networksPerCoin.put(CoinType.FIL, new ArrayList<NetworkInfo>());
|
||||
for (NetworkInfo network : relevantNetworks) {
|
||||
if (network.chainId.equals(selectedNetwork.chainId)) continue;
|
||||
switch (network.coin) {
|
||||
case CoinType.ETH:
|
||||
networksPerCoin.get(CoinType.ETH).add(network);
|
||||
break;
|
||||
case CoinType.SOL:
|
||||
networksPerCoin.get(CoinType.SOL).add(network);
|
||||
break;
|
||||
case CoinType.FIL:
|
||||
networksPerCoin.get(CoinType.FIL).add(network);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return networksPerCoin;
|
||||
}
|
||||
|
||||
public static void updateActiveAddresses(
|
||||
GetNativeAssetsBalancesResponseContext[] nativeAssetsBalancesResponses,
|
||||
GetBlockchainTokensBalancesResponseContext[] blockchainTokensBalancesResponses,
|
||||
HashMap<Integer, HashSet<String>> activeAddresses) {
|
||||
for (GetNativeAssetsBalancesResponseContext ctx : nativeAssetsBalancesResponses) {
|
||||
for (Map.Entry<String, Double> nativeEntry : ctx.nativeAssetsBalances.entrySet()) {
|
||||
if (nativeEntry.getValue() > 0.0d) {
|
||||
activeAddresses.get(ctx.coinType).add(nativeEntry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (GetBlockchainTokensBalancesResponseContext ctx : blockchainTokensBalancesResponses) {
|
||||
for (Map.Entry<String, HashMap<String, Double>> accEntry :
|
||||
ctx.blockchainTokensBalances.entrySet()) {
|
||||
for (Map.Entry<String, Double> tokenEntry : accEntry.getValue().entrySet()) {
|
||||
if (tokenEntry.getValue() > 0.0d) {
|
||||
activeAddresses.get(ctx.coinType).add(accEntry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.chromium.base.ApiCompatibilityUtils;
|
||||
import org.chromium.base.CommandLine;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.base.shared_preferences.SharedPreferencesManager;
|
||||
import org.chromium.base.supplier.MonotonicObservableSupplier;
|
||||
@@ -53,7 +52,6 @@ import org.chromium.brave_wallet.mojom.AssetRatioService;
|
||||
import org.chromium.brave_wallet.mojom.BlockchainRegistry;
|
||||
import org.chromium.brave_wallet.mojom.BlockchainToken;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletConstants;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletP3a;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletService;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.JsonRpcService;
|
||||
@@ -85,7 +83,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -114,8 +111,6 @@ public class Utils {
|
||||
public static final BigInteger MAX_UINT256 =
|
||||
BigInteger.ONE.shiftLeft(256).subtract(BigInteger.ONE);
|
||||
|
||||
public static int[] P3ACoinTypes = {CoinType.ETH, CoinType.SOL, CoinType.FIL};
|
||||
|
||||
public static List<String> getRecoveryPhraseAsList(final String recoveryPhrase) {
|
||||
final String[] recoveryPhraseArray = recoveryPhrase.split(" ");
|
||||
return new ArrayList<>(Arrays.asList(recoveryPhraseArray));
|
||||
@@ -1103,7 +1098,6 @@ public class Utils {
|
||||
*
|
||||
* @param activityRef Weak reference to Brave Wallet base activity.
|
||||
* @param tokenType Token type used for filtering (e.g. {@code TokenType.NON_NFTS}).
|
||||
* @param allNetworks List of all networks, used to log P3A records.
|
||||
* @param selectedNetwork Currently selected network.
|
||||
* @param accountInfos Array of account info.
|
||||
* @param filterByTokens Tokens used for fetching prices and balances. It may be {@code null}
|
||||
@@ -1119,7 +1113,6 @@ public class Utils {
|
||||
public static void getTxExtraInfo(
|
||||
WeakReference<BraveWalletBaseActivity> activityRef,
|
||||
TokenUtils.TokenType tokenType,
|
||||
List<NetworkInfo> allNetworks,
|
||||
NetworkInfo selectedNetwork,
|
||||
AccountInfo[] accountInfos,
|
||||
BlockchainToken[] filterByTokens,
|
||||
@@ -1219,43 +1212,10 @@ public class Utils {
|
||||
getNativeAssetsBalancesContext.nativeAssetsBalances,
|
||||
getBlockchainTokensBalancesContext
|
||||
.blockchainTokensBalances);
|
||||
logP3ARecords(
|
||||
JavaUtils.asArray(getNativeAssetsBalancesContext),
|
||||
JavaUtils.asArray(getBlockchainTokensBalancesContext),
|
||||
activityRef,
|
||||
allNetworks,
|
||||
selectedNetwork);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets P3A networks (i.e. networks with chain Id contained in {@code
|
||||
* WalletConstants.KNOWN_TEST_CHAIN_IDS)} excluding testnet chains by default. Testnet chain
|
||||
* counting can be enabled using the switch `--p3a-count-wallet-test-networks`.
|
||||
*
|
||||
* @param allNetworks Given network list that will be filtered.
|
||||
* @param callback Callback containing a filtered list of P3A networks.
|
||||
*/
|
||||
public static void getP3ANetworks(
|
||||
List<NetworkInfo> allNetworks, AsyncUtils.Callback1<List<NetworkInfo>> callback) {
|
||||
ArrayList<NetworkInfo> relevantNetworks = new ArrayList<NetworkInfo>();
|
||||
boolean countTestNetworks =
|
||||
CommandLine.getInstance()
|
||||
.hasSwitch(BraveWalletConstants.P3A_COUNT_TEST_NETWORKS_SWITCH);
|
||||
for (NetworkInfo network : allNetworks) {
|
||||
// Exclude testnet chain data by default.
|
||||
// Testnet chain counting can be enabled via the
|
||||
// --p3a-count-wallet-test-networks switch
|
||||
if (countTestNetworks
|
||||
|| !WalletConstants.KNOWN_TEST_CHAIN_IDS.contains(network.chainId)) {
|
||||
relevantNetworks.add(network);
|
||||
}
|
||||
}
|
||||
|
||||
callback.call(relevantNetworks);
|
||||
}
|
||||
|
||||
public static boolean isNativeToken(NetworkInfo selectedNetwork, BlockchainToken token) {
|
||||
return token.symbol.equals(selectedNetwork.symbol);
|
||||
}
|
||||
@@ -1312,46 +1272,6 @@ public class Utils {
|
||||
return num.doubleValue();
|
||||
}
|
||||
|
||||
private static void logP3ARecords(
|
||||
AsyncUtils.GetNativeAssetsBalancesResponseContext[] nativeAssetsBalancesResponses,
|
||||
AsyncUtils.GetBlockchainTokensBalancesResponseContext[]
|
||||
blockchainTokensBalancesResponses,
|
||||
WeakReference<BraveWalletBaseActivity> activityRef,
|
||||
List<NetworkInfo> allNetworks,
|
||||
NetworkInfo selectedNetwork) {
|
||||
BraveWalletBaseActivity activity = activityRef.get();
|
||||
if (activity == null
|
||||
|| activity.isFinishing()
|
||||
|| JavaUtils.anyNull(activity.getBraveWalletP3A())) {
|
||||
return;
|
||||
}
|
||||
BraveWalletP3a braveWalletP3A = activity.getBraveWalletP3A();
|
||||
|
||||
AsyncUtils.MultiResponseHandler multiResponse = new AsyncUtils.MultiResponseHandler(1);
|
||||
|
||||
AsyncUtils.GetP3ABalancesContext getP3ABalancesContext =
|
||||
new AsyncUtils.GetP3ABalancesContext(multiResponse.singleResponseComplete);
|
||||
BalanceHelper.getP3ABalances(
|
||||
activityRef, allNetworks, selectedNetwork, getP3ABalancesContext);
|
||||
|
||||
multiResponse.setWhenAllCompletedAction(
|
||||
() -> {
|
||||
HashMap<Integer, HashSet<String>> activeAddresses =
|
||||
getP3ABalancesContext.activeAddresses;
|
||||
// P3A active accounts
|
||||
BalanceHelper.updateActiveAddresses(
|
||||
nativeAssetsBalancesResponses,
|
||||
blockchainTokensBalancesResponses,
|
||||
activeAddresses);
|
||||
for (int coinType : P3ACoinTypes) {
|
||||
HashSet<String> active = activeAddresses.get(coinType);
|
||||
if (active != null) {
|
||||
braveWalletP3A.recordActiveWalletCount(active.size(), coinType);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets truncated address from a valid full contract address.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user