Merge pull request #14472 from brave/android_solana_tx_list
Shows all values for Solana transactions in transactions list on Android and opens a correct block explorer for solana transactions
This commit is contained in:
@@ -66,6 +66,7 @@ import org.chromium.brave_wallet.mojom.AccountInfo;
|
||||
import org.chromium.brave_wallet.mojom.AssetRatioService;
|
||||
import org.chromium.brave_wallet.mojom.BlockchainRegistry;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletService;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.EthTxManagerProxy;
|
||||
import org.chromium.brave_wallet.mojom.JsonRpcService;
|
||||
import org.chromium.brave_wallet.mojom.KeyringInfo;
|
||||
@@ -1021,7 +1022,8 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
|
||||
}
|
||||
|
||||
public void viewOnBlockExplorer(String address) {
|
||||
Utils.openAddress("/address/" + address, mJsonRpcService, this);
|
||||
// TODO(sergz): We will need to correct that while doing Solana DApps
|
||||
Utils.openAddress("/address/" + address, mJsonRpcService, this, CoinType.ETH);
|
||||
}
|
||||
|
||||
// should only be called if the wallet is setup and unlocked
|
||||
|
||||
+1
-1
@@ -225,7 +225,7 @@ public class AccountDetailActivity
|
||||
|
||||
@Override
|
||||
public void onTransactionClick(TransactionInfo txInfo) {
|
||||
Utils.openTransaction(txInfo, mJsonRpcService, this, mName);
|
||||
Utils.openTransaction(txInfo, mJsonRpcService, this, mName, mCoinType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -354,7 +354,7 @@ public class AssetDetailActivity
|
||||
|
||||
@Override
|
||||
public void onTransactionClick(TransactionInfo txInfo) {
|
||||
Utils.openTransaction(txInfo, mJsonRpcService, this, accountInfos);
|
||||
Utils.openTransaction(txInfo, mJsonRpcService, this, accountInfos, mCoinType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -90,9 +90,11 @@ public class AddTokenFragment extends BaseDAppsFragment {
|
||||
mTokenAddress.setOnClickListener(v -> {
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof BraveWalletBaseActivity) {
|
||||
// TODO(sergz): We will need to correct that while doing Solana DApps
|
||||
Utils.openAddress(
|
||||
"/token/" + mCurrentAddSuggestTokenRequest.token.contractAddress,
|
||||
getJsonRpcService(), (BraveWalletBaseActivity) activity);
|
||||
getJsonRpcService(), (BraveWalletBaseActivity) activity,
|
||||
CoinType.ETH);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -542,8 +542,8 @@ public class ParsedTransaction extends ParsedTransactionFees {
|
||||
|
||||
String action = "";
|
||||
String detailInfo = "";
|
||||
String actionFiatValue = String.format(Locale.getDefault(), "%.2f", this.fiatValue);
|
||||
if (this.type == TransactionType.ERC20_TRANSFER) {
|
||||
String actionFiatValue = String.format(Locale.getDefault(), "%.2f", this.fiatValue);
|
||||
action = String.format(context.getResources().getString(R.string.wallet_tx_info_sent),
|
||||
this.senderLabel, this.formatValueToDisplay(), this.symbol, actionFiatValue,
|
||||
strDate);
|
||||
@@ -568,7 +568,8 @@ public class ParsedTransaction extends ParsedTransactionFees {
|
||||
+ "0x Exchange Proxy";
|
||||
} else {
|
||||
action = String.format(context.getResources().getString(R.string.wallet_tx_info_sent),
|
||||
this.senderLabel, this.formatValueToDisplay(), this.symbol, "0.00", strDate);
|
||||
this.senderLabel, this.formatValueToDisplay(), this.symbol, actionFiatValue,
|
||||
strDate);
|
||||
detailInfo = this.senderLabel + " -> " + this.recipientLabel;
|
||||
}
|
||||
|
||||
|
||||
@@ -1082,7 +1082,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void openTransaction(TransactionInfo txInfo, JsonRpcService jsonRpcService,
|
||||
AppCompatActivity activity, String accountName) {
|
||||
AppCompatActivity activity, String accountName, int coinType) {
|
||||
assert txInfo != null;
|
||||
if (txInfo.txStatus == TransactionStatus.UNAPPROVED) {
|
||||
if (activity instanceof ApprovedTxObserver) {
|
||||
@@ -1094,39 +1094,40 @@ public class Utils {
|
||||
if (txInfo.txHash == null || txInfo.txHash.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
openAddress("/tx/" + txInfo.txHash, jsonRpcService, activity);
|
||||
openAddress("/tx/" + txInfo.txHash, jsonRpcService, activity, coinType);
|
||||
}
|
||||
}
|
||||
|
||||
public static void openAddress(
|
||||
String toAppend, JsonRpcService jsonRpcService, AppCompatActivity activity) {
|
||||
public static void openAddress(String toAppend, JsonRpcService jsonRpcService,
|
||||
AppCompatActivity activity, int coinType) {
|
||||
assert jsonRpcService != null;
|
||||
jsonRpcService.getChainId(CoinType.ETH, chainId -> {
|
||||
jsonRpcService.getAllNetworks(CoinType.ETH, networks -> {
|
||||
for (NetworkInfo network : networks) {
|
||||
if (!chainId.equals(network.chainId)) {
|
||||
continue;
|
||||
}
|
||||
String blockExplorerUrl = Arrays.toString(network.blockExplorerUrls);
|
||||
if (blockExplorerUrl.length() > 2) {
|
||||
blockExplorerUrl =
|
||||
blockExplorerUrl.substring(1, blockExplorerUrl.length() - 1)
|
||||
+ toAppend;
|
||||
TabUtils.openUrlInNewTab(false, blockExplorerUrl);
|
||||
TabUtils.bringChromeTabbedActivityToTheTop(activity);
|
||||
break;
|
||||
}
|
||||
jsonRpcService.getNetwork(coinType, network -> {
|
||||
String blockExplorerUrl = Arrays.toString(network.blockExplorerUrls);
|
||||
if (blockExplorerUrl.length() > 2) {
|
||||
blockExplorerUrl = blockExplorerUrl.substring(1, blockExplorerUrl.length() - 1);
|
||||
}
|
||||
if (coinType == CoinType.ETH) {
|
||||
blockExplorerUrl += toAppend;
|
||||
} else if (coinType == CoinType.SOL) {
|
||||
int iPos = blockExplorerUrl.indexOf("?cluster=");
|
||||
if (iPos != -1) {
|
||||
blockExplorerUrl = blockExplorerUrl.substring(0, iPos - 1) + toAppend
|
||||
+ blockExplorerUrl.substring(iPos);
|
||||
} else {
|
||||
blockExplorerUrl += toAppend;
|
||||
}
|
||||
});
|
||||
}
|
||||
TabUtils.openUrlInNewTab(false, blockExplorerUrl);
|
||||
TabUtils.bringChromeTabbedActivityToTheTop(activity);
|
||||
});
|
||||
}
|
||||
|
||||
public static void openTransaction(TransactionInfo txInfo, JsonRpcService jsonRpcService,
|
||||
AppCompatActivity activity, AccountInfo[] accountInfos) {
|
||||
AppCompatActivity activity, AccountInfo[] accountInfos, int coinType) {
|
||||
assert txInfo != null;
|
||||
AccountInfo account = findAccount(accountInfos, txInfo.fromAddress);
|
||||
openTransaction(txInfo, jsonRpcService, activity,
|
||||
account != null ? account.name : stripAccountAddress(txInfo.fromAddress));
|
||||
account != null ? account.name : stripAccountAddress(txInfo.fromAddress), coinType);
|
||||
}
|
||||
|
||||
public static void setUpTransactionList(BraveWalletBaseActivity activity,
|
||||
@@ -1154,13 +1155,37 @@ public class Utils {
|
||||
pendingTxHelper.fetchTransactions(() -> {
|
||||
HashMap<String, TransactionInfo[]> pendingTxInfos =
|
||||
pendingTxHelper.getTransactions();
|
||||
workWithTransactions(activity, selectedNetwork, pendingTxInfos, accounts,
|
||||
walletListItemModel, assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances, rvTransactions, callback, walletTxCoinAdapter);
|
||||
SolanaTransactionsGasHelper solanaTransactionsGasHelper =
|
||||
new SolanaTransactionsGasHelper(
|
||||
activity, getTransactionArray(pendingTxInfos));
|
||||
solanaTransactionsGasHelper.maybeGetSolanaGasEstimations(() -> {
|
||||
workWithTransactions(activity, selectedNetwork, pendingTxInfos, accounts,
|
||||
walletListItemModel, assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances, rvTransactions, callback, walletTxCoinAdapter,
|
||||
solanaTransactionsGasHelper.getPerTxFee());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static TransactionInfo[] getTransactionArray(
|
||||
HashMap<String, TransactionInfo[]> txInfos) {
|
||||
TransactionInfo[] result = new TransactionInfo[0];
|
||||
for (String key : txInfos.keySet()) {
|
||||
TransactionInfo[] txs = txInfos.get(key);
|
||||
result = concatWithArrayCopy(result, txs);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static <T> T[] concatWithArrayCopy(T[] array1, T[] array2) {
|
||||
T[] result = Arrays.copyOf(array1, array1.length + array2.length);
|
||||
System.arraycopy(array2, 0, result, array1.length, array2.length);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void workWithTransactions(BraveWalletBaseActivity activity,
|
||||
NetworkInfo selectedNetwork, HashMap<String, TransactionInfo[]> pendingTxInfos,
|
||||
AccountInfo[] accounts, WalletListItemModel walletListItemModel,
|
||||
@@ -1168,7 +1193,7 @@ public class Utils {
|
||||
HashMap<String, Double> nativeAssetsBalances,
|
||||
HashMap<String, HashMap<String, Double>> blockchainTokensBalances,
|
||||
RecyclerView rvTransactions, OnWalletListItemClick callback,
|
||||
WalletCoinAdapter walletTxCoinAdapter) {
|
||||
WalletCoinAdapter walletTxCoinAdapter, HashMap<String, Long> perTxSolanaFee) {
|
||||
walletTxCoinAdapter.setWalletCoinAdapterType(
|
||||
WalletCoinAdapter.AdapterType.VISIBLE_ASSETS_LIST);
|
||||
List<WalletListItemModel> walletListItemModelList = new ArrayList<>();
|
||||
@@ -1178,8 +1203,12 @@ public class Utils {
|
||||
for (String accountName : pendingTxInfos.keySet()) {
|
||||
TransactionInfo[] txInfos = pendingTxInfos.get(accountName);
|
||||
for (TransactionInfo txInfo : txInfos) {
|
||||
long solanaEstimatedTxFee = 0;
|
||||
if (perTxSolanaFee.get(txInfo.id) != null) {
|
||||
solanaEstimatedTxFee = perTxSolanaFee.get(txInfo.id);
|
||||
}
|
||||
ParsedTransaction parsedTx = ParsedTransaction.parseTransaction(txInfo,
|
||||
selectedNetwork, accounts, assetPrices, 0, fullTokenList,
|
||||
selectedNetwork, accounts, assetPrices, solanaEstimatedTxFee, fullTokenList,
|
||||
nativeAssetsBalances, blockchainTokensBalances);
|
||||
WalletListItemModel itemModel =
|
||||
makeWalletItem((Context) activity, txInfo, selectedNetwork, parsedTx);
|
||||
|
||||
Reference in New Issue
Block a user