Add chain_id param to blockchainRegistry functions

This commit is contained in:
Brian R. Bondy
2022-01-12 08:32:28 -05:00
parent 01a4bd3b65
commit a75ce6eb0d
8 changed files with 75 additions and 55 deletions
@@ -505,22 +505,24 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
|| swapFromAssetSymbol.equals(eth.symbol)) { // default swap from ETH
updateBuySendAsset(eth.symbol, eth);
} else {
mBlockchainRegistry.getTokenBySymbol(swapFromAssetSymbol, token -> {
if (token != null) {
updateBuySendAsset(token.symbol, token);
}
});
mBlockchainRegistry.getTokenBySymbol(
BraveWalletConstants.MAINNET_CHAIN_ID, swapFromAssetSymbol, token -> {
if (token != null) {
updateBuySendAsset(token.symbol, token);
}
});
}
// Swap to
if (swapToAsset.equals(swapFromAssetSymbol)) { // swap from BAT
updateSwapToAsset(eth.symbol, eth);
} else {
mBlockchainRegistry.getTokenBySymbol(swapToAsset, token -> {
if (token != null) {
updateSwapToAsset(token.symbol, token);
}
});
mBlockchainRegistry.getTokenBySymbol(
BraveWalletConstants.MAINNET_CHAIN_ID, swapToAsset, token -> {
if (token != null) {
updateSwapToAsset(token.symbol, token);
}
});
}
}
}
@@ -968,10 +970,11 @@ public class BuySendSwapActivity extends AsyncInitializationActivity
if (mCurrentChainId.equals(BraveWalletConstants.MAINNET_CHAIN_ID)) {
assert mBlockchainRegistry != null;
String asset = assetFromDropDown.getText().toString();
mBlockchainRegistry.getBuyUrl(from, asset, value, url -> {
TabUtils.openUrlInNewTab(false, url);
TabUtils.bringChromeTabbedActivityToTheTop(this);
});
mBlockchainRegistry.getBuyUrl(
BraveWalletConstants.MAINNET_CHAIN_ID, from, asset, value, url -> {
TabUtils.openUrlInNewTab(false, url);
TabUtils.bringChromeTabbedActivityToTheTop(this);
});
} else {
String url = getPerNetworkUiInfo(mCurrentChainId).linkUrl;
if (url != null && !url.isEmpty()) {
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.crypto_wallet.util;
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.BraveWalletService;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
@@ -46,35 +47,38 @@ public class TokenUtils {
public static void getAllTokensFiltered(BraveWalletService braveWalletService,
BlockchainRegistry blockchainRegistry, String chainId,
BlockchainRegistry.GetAllTokensResponse callback) {
blockchainRegistry.getAllTokens((BlockchainToken[] tokens) -> {
braveWalletService.getUserAssets(chainId, (BlockchainToken[] userTokens) -> {
BlockchainToken[] filteredTokens =
filterOut(concatenateTwoArrays(tokens, userTokens), true);
callback.call(filteredTokens);
});
});
blockchainRegistry.getAllTokens(
BraveWalletConstants.MAINNET_CHAIN_ID, (BlockchainToken[] tokens) -> {
braveWalletService.getUserAssets(chainId, (BlockchainToken[] userTokens) -> {
BlockchainToken[] filteredTokens =
filterOut(concatenateTwoArrays(tokens, userTokens), true);
callback.call(filteredTokens);
});
});
}
public static void getBuyTokensFiltered(BlockchainRegistry blockchainRegistry,
BlockchainRegistry.GetAllTokensResponse callback) {
blockchainRegistry.getBuyTokens((BlockchainToken[] tokens) -> {
BlockchainToken[] filteredTokens = filterOut(tokens, true);
callback.call(filteredTokens);
});
blockchainRegistry.getBuyTokens(
BraveWalletConstants.MAINNET_CHAIN_ID, (BlockchainToken[] tokens) -> {
BlockchainToken[] filteredTokens = filterOut(tokens, true);
callback.call(filteredTokens);
});
}
public static void isCustomToken(BlockchainToken token, BlockchainRegistry blockchainRegistry,
org.chromium.mojo.bindings.Callbacks.Callback1<Boolean> callback) {
blockchainRegistry.getAllTokens((BlockchainToken[] tokens) -> {
boolean isCustom = true;
for (BlockchainToken tokenFromAll : tokens) {
if (token.contractAddress.equals(tokenFromAll.contractAddress)) {
isCustom = false;
break;
}
}
callback.call(isCustom);
});
blockchainRegistry.getAllTokens(
BraveWalletConstants.MAINNET_CHAIN_ID, (BlockchainToken[] tokens) -> {
boolean isCustom = true;
for (BlockchainToken tokenFromAll : tokens) {
if (token.contractAddress.equals(tokenFromAll.contractAddress)) {
isCustom = false;
break;
}
}
callback.call(isCustom);
});
}
private static BlockchainToken[] concatenateTwoArrays(