Skip to content

Assign empty string to NFT symbol if symbol returned by SimpleHash is null #17818

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
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 3 additions & 15 deletions browser/brave_wallet/asset_discovery_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,7 @@ TEST_F(AssetDiscoveryManagerUnitTest, ParseNFTsFromSimpleHash) {
"name": "Token #2",
"image_url": "https://nftimages-cdn.simplehash.com/2.png",
"contract": {
"type": "ERC721",
"symbol": "TWO"
"type": "ERC721"
},
"collection": {
"spam_score": 0
Expand Down Expand Up @@ -1699,7 +1698,8 @@ TEST_F(AssetDiscoveryManagerUnitTest, ParseNFTsFromSimpleHash) {
EXPECT_EQ(result->second[1]->is_erc721, true);
EXPECT_EQ(result->second[1]->is_erc1155, false);
EXPECT_EQ(result->second[1]->is_nft, true);
EXPECT_EQ(result->second[1]->symbol, "TWO");
// If symbol is null, it should be saved as an empty string
EXPECT_EQ(result->second[1]->symbol, "");
EXPECT_EQ(result->second[1]->decimals, 0);
EXPECT_EQ(result->second[1]->visible, true);
EXPECT_EQ(result->second[1]->token_id, "0x2");
Expand All @@ -1714,7 +1714,6 @@ TEST_F(AssetDiscoveryManagerUnitTest, ParseNFTsFromSimpleHash) {
// 4. Missing token_id
// 5. Missing standard
// 6. Missing spam_score
// 7. Missing symbol
json = R"({
"next": "https://api.simplehash.com/api/v0/nfts/next",
"previous": null,
Expand Down Expand Up @@ -1785,17 +1784,6 @@ TEST_F(AssetDiscoveryManagerUnitTest, ParseNFTsFromSimpleHash) {
},
"collection": {
}
},
{
"chain": "polygon",
"contract_address": "0x7777777777777777777777777777777777777777",
"token_id": "7",
"contract": {
"type": "ERC721"
},
"collection": {
"spam_score": 0
}
}
]
})";
Expand Down
9 changes: 6 additions & 3 deletions components/brave_wallet/browser/asset_discovery_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,15 @@ AssetDiscoveryManager::ParseNFTsFromSimpleHash(const base::Value& json_value,
// is_nft
token->is_nft = true;

// symbol (required)
// symbol
auto* symbol = contract->FindString("symbol");
if (!symbol) {
continue;
// If symbol is null, assign an empty string to avoid display issues
// on the frontend
token->symbol = "";
} else {
token->symbol = *symbol;
}
token->symbol = *symbol;

// decimals
token->decimals = 0;
Expand Down