Fix: special case handle POAP ERC721 metadata because keys are non-standard. Also default to "" for mandatory values in ERC721 metadata so generally, more ERC721 with partially missing metadata will be more likely to get displayed

pull/2905/head
Hwee-Boon Yar 3 years ago
parent 9197d99da0
commit c14386efe7
  1. 11
      AlphaWallet/Tokens/Types/TokensDataStore.swift

@ -627,14 +627,15 @@ class TokensDataStore {
} else {
var jsonDictionary = json
if let tokenObject = tokens.first(where: { $0.contractAddress.sameContract(as: address) }) {
//We must make sure the value stored is at least an empty string, never nil because we need to deserialise/decode it
jsonDictionary["tokenId"] = JSON(tokenId)
jsonDictionary["contractName"] = JSON(tokenObject.name)
jsonDictionary["symbol"] = JSON(tokenObject.symbol)
jsonDictionary["name"] = jsonDictionary["name"]
jsonDictionary["imageUrl"] = jsonDictionary["image"]
jsonDictionary["thumbnailUrl"] = jsonDictionary["image"]
//We make sure the value stored is at least an empty string, never nil because we need to deserialise/decode it
jsonDictionary["externalLink"] = JSON(jsonDictionary["external_url"].stringValue)
jsonDictionary["name"] = JSON(jsonDictionary["name"].stringValue)
jsonDictionary["imageUrl"] = JSON(jsonDictionary["image"].string ?? jsonDictionary["image_url"].string ?? "")
jsonDictionary["thumbnailUrl"] = jsonDictionary["imageUrl"]
//POAP tokens (https://blockscout.com/xdai/mainnet/address/0x22C1f6050E56d2876009903609a2cC3fEf83B415/transactions), eg. https://api.poap.xyz/metadata/2503/278569, use `home_url` as the key for what they should use `external_url` for and they use `external_url` to point back to the token URI
jsonDictionary["externalLink"] = JSON(jsonDictionary["home_url"].string ?? jsonDictionary["external_url"].string ?? "")
}
if let jsonString = jsonDictionary.rawString() {
return (contract: address, json: jsonString)

Loading…
Cancel
Save