feat(wallet): remove Goerli network (#24438)

* feat(wallet): remove Goerli network

* Fix unit-tests

* fix iOS build.

* Remove Goerli usage in Android

* Apply code formatting

* Apply code formatting second round

* Apply code formatting third round

* review(simoarpe): remove TokenUtils.getAllTokens

* Fix android lint errors

* Apply code formatting

* fix unit tests

---------

Co-authored-by: Nuo Xu <nuoxu.nx@gmail.com>
Co-authored-by: Simone Arpe <simon.arpe@gmail.com>
This commit is contained in:
Anirudha Bose
2024-07-24 11:52:21 +02:00
committed by GitHub
co-authored by Nuo Xu Simone Arpe
parent de3adb13d1
commit 4ddbd94fef
52 changed files with 322 additions and 380 deletions
@@ -136,7 +136,6 @@ public class AssetUtils {
BraveWalletConstants.AVALANCHE_MAINNET_CHAIN_ID,
Arrays.asList("avax", "avaxc")),
// Testnets
Map.entry(BraveWalletConstants.GOERLI_CHAIN_ID, List.of("eth")),
Map.entry(BraveWalletConstants.SEPOLIA_CHAIN_ID, List.of("eth")),
Map.entry(BraveWalletConstants.SOLANA_TESTNET, List.of("sol")),
Map.entry(BraveWalletConstants.SOLANA_DEVNET, List.of("sol")),
@@ -5,8 +5,6 @@
package org.chromium.chrome.browser.crypto_wallet.util;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import org.chromium.base.Callbacks;
@@ -104,62 +102,64 @@ public class TokenUtils {
return tokenStream.toArray(BlockchainToken[] ::new);
}
public static void getVisibleUserAssetsFiltered(BraveWalletService braveWalletService,
NetworkInfo selectedNetwork, int coinType, TokenType tokenType,
public static void getVisibleUserAssetsFiltered(
BraveWalletService braveWalletService,
NetworkInfo selectedNetwork,
int coinType,
TokenType tokenType,
Callbacks.Callback1<BlockchainToken[]> callback) {
braveWalletService.getUserAssets(
selectedNetwork.chainId, coinType, (BlockchainToken[] tokens) -> {
selectedNetwork.chainId,
coinType,
(BlockchainToken[] tokens) -> {
BlockchainToken[] filteredTokens =
filterTokens(selectedNetwork, tokens, tokenType, true);
callback.call(filteredTokens);
});
}
@SuppressLint("WrongCommentType")
/*
* Wrapper for {@link BlockchainRegistry#getAllTokens} with Goerli contract address
* modifications.
*
* <b>Note:</b>: all calls to {@link BlockchainRegistry#getAllTokens} should be intercepted by
* this method.
*/
public static void getAllTokens(
@NonNull BlockchainRegistry blockchainRegistry,
String chainId,
int coinType,
BlockchainRegistry.GetAllTokens_Response callback) {
blockchainRegistry.getAllTokens(
chainId,
coinType,
tokens -> callback.call(Utils.fixupTokensRegistry(tokens, chainId)));
}
/**
* Gets all tokens from a given single network, includes user assets and filters out tokens
* different from a given type.
*
* @param braveWalletService BraveWalletService to retrieve user asset from core.
* @param blockchainRegistry BraveChainRegistry to retrieve all tokens from core.
* @param selectedNetwork Selected network whose tokens will be retrieved.
* @param tokenType Token type used for filtering.
* @param callback Callback containing a filtered array of tokens for the given network.
*/
public static void getAllTokensFiltered(BraveWalletService braveWalletService,
BlockchainRegistry blockchainRegistry, NetworkInfo selectedNetwork, TokenType tokenType,
public static void getAllTokensFiltered(
BraveWalletService braveWalletService,
BlockchainRegistry blockchainRegistry,
NetworkInfo selectedNetwork,
TokenType tokenType,
Callbacks.Callback1<BlockchainToken[]> callback) {
getAllTokens(blockchainRegistry, selectedNetwork.chainId, selectedNetwork.coin,
tokens
-> braveWalletService.getUserAssets(
selectedNetwork.chainId, selectedNetwork.coin, userTokens -> {
BlockchainToken[] filteredTokens = filterTokens(selectedNetwork,
distinctiveConcatenatedArrays(tokens, userTokens), tokenType,
false);
callback.call(filteredTokens);
}));
blockchainRegistry.getAllTokens(
selectedNetwork.chainId,
selectedNetwork.coin,
tokens ->
braveWalletService.getUserAssets(
selectedNetwork.chainId,
selectedNetwork.coin,
userTokens -> {
BlockchainToken[] filteredTokens =
filterTokens(
selectedNetwork,
distinctiveConcatenatedArrays(
tokens, userTokens),
tokenType,
false);
callback.call(filteredTokens);
}));
}
public static void getUserOrAllTokensFiltered(BraveWalletService braveWalletService,
BlockchainRegistry blockchainRegistry, NetworkInfo selectedNetwork, int coinType,
TokenType tokenType, boolean userAssetsOnly,
public static void getUserOrAllTokensFiltered(
BraveWalletService braveWalletService,
BlockchainRegistry blockchainRegistry,
NetworkInfo selectedNetwork,
int coinType,
TokenType tokenType,
boolean userAssetsOnly,
Callbacks.Callback1<BlockchainToken[]> callback) {
if (JavaUtils.anyNull(braveWalletService, blockchainRegistry)) return;
if (userAssetsOnly)
@@ -793,30 +793,6 @@ public class Utils {
}
}
public static String getContractAddress(String chainId, String symbol, String contractAddress) {
if (!chainId.equals(BraveWalletConstants.GOERLI_CHAIN_ID)) {
return contractAddress;
}
if (symbol.equals("USDC")) {
return "0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557";
} else if (symbol.equals("DAI")) {
return "0x73967c6a0904aa032c103b4104747e88c566b1a2";
}
return contractAddress;
}
public static String getGoerliContractAddress(String mainnetContractAddress) {
String lowerCaseAddress = mainnetContractAddress.toLowerCase(Locale.getDefault());
if (lowerCaseAddress.equals("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")) {
return "0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557";
} else if (lowerCaseAddress.equals("0x6b175474e89094c44da98b954eedeac495271d0f")) {
return "0x73967c6a0904aa032c103b4104747e88c566b1a2";
}
return "";
}
/*
* Java port of the same function in components/brave_wallet_ui/options/asset-options.ts.
*/
@@ -842,7 +818,6 @@ public class Utils {
@DrawableRes int logo;
switch (chainId) {
case BraveWalletConstants.MAINNET_CHAIN_ID:
case BraveWalletConstants.GOERLI_CHAIN_ID:
case BraveWalletConstants.SEPOLIA_CHAIN_ID:
logo = R.drawable.ic_eth_color;
break;
@@ -915,7 +890,6 @@ public class Utils {
String logo;
switch (chainId) {
case BraveWalletConstants.MAINNET_CHAIN_ID:
case BraveWalletConstants.GOERLI_CHAIN_ID:
case BraveWalletConstants.SEPOLIA_CHAIN_ID:
logo = "eth.png";
break;
@@ -987,15 +961,6 @@ public class Utils {
return Utils.getNetworkIconName(network.chainId, network.coin);
}
// Replace USDC and DAI contract addresses for Goerli network
public static BlockchainToken[] fixupTokensRegistry(BlockchainToken[] tokens, String chainId) {
for (BlockchainToken token : tokens) {
token.contractAddress =
getContractAddress(chainId, token.symbol, token.contractAddress);
}
return tokens;
}
public static AccountInfo findAccountByAddress(AccountInfo[] accounts, String address) {
for (AccountInfo acc : accounts) {
if (acc.address.toLowerCase(Locale.getDefault())
@@ -101,7 +101,6 @@ public final class WalletConstants {
public static final Map<String, Integer> KNOWN_TEST_CHAINS_MAP =
Map.of(
BraveWalletConstants.GOERLI_CHAIN_ID, CoinType.ETH, //
BraveWalletConstants.SEPOLIA_CHAIN_ID, CoinType.ETH, //
BraveWalletConstants.LOCALHOST_CHAIN_ID, CoinType.ETH, //
BraveWalletConstants.SOLANA_TESTNET, CoinType.SOL, //