Skip to content

Fix asset discovery for cUSDT #17403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions browser/brave_wallet/asset_discovery_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,25 @@ TEST_F(AssetDiscoveryManagerUnitTest, DiscoverEthAssets) {
TestDiscoverEthAssets({"0xB4B2802129071b2B9eBb8cBB01EA1E4D14B34961"}, false,
{});

// One account returns the cUSDT token response for no balance detected
// (successful), yields no discovered contract addresses
const char cusdt_balance_not_detected_response[] = R"({
"jsonrpc":"2.0",
"id":1,
"result":"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
})";

requests = {
{GetNetwork(mojom::kMainnetChainId, mojom::CoinType::ETH),
{
{"0xB4B2802129071b2B9eBb8cBB01EA1E4D14B34961",
cusdt_balance_not_detected_response},
}},
};
SetInterceptorForDiscoverEthAssets(requests);
TestDiscoverEthAssets({"0xB4B2802129071b2B9eBb8cBB01EA1E4D14B34961"}, false,
{});

// One account, with a balance, yields discovered contract address
requests = {
{GetNetwork(mojom::kMainnetChainId, mojom::CoinType::ETH),
Expand Down
14 changes: 8 additions & 6 deletions components/brave_wallet/browser/asset_discovery_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,14 @@ void AssetDiscoveryManager::OnGetERC20TokenBalances(

// Populate the map using the balance_results
for (size_t i = 0; i < balance_results.size(); i++) {
if (balance_results[i]->balance.has_value() &&
balance_results[i]->balance !=
"0x000000000000000000000000000000000000000000000000000000000000000"
"0") {
chain_id_to_contract_addresses_with_balance[chain_id].push_back(
contract_addresses[i]);
if (balance_results[i]->balance.has_value()) {
uint256_t balance_uint;
bool success =
HexValueToUint256(balance_results[i]->balance.value(), &balance_uint);
if (success && balance_uint > 0) {
chain_id_to_contract_addresses_with_balance[chain_id].push_back(
contract_addresses[i]);
}
}
}

Expand Down