Skip to content
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

added display-type to generated serialized json for attributes #128

Merged
Merged
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
33 changes: 17 additions & 16 deletions cadence/contracts/utils/SerializeMetadata.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ access(all) contract SerializeMetadata {
// Append results from the token-level Display view to the serialized JSON compatible string
if nftDisplay != nil {
serializedResult = serializedResult
.concat(name).concat(Serialize.tryToJSONString(nftDisplay!.name)!).concat(", ")
.concat(description).concat(Serialize.tryToJSONString(nftDisplay!.description)!).concat(", ")
.concat(image).concat(Serialize.tryToJSONString(nftDisplay!.thumbnail.uri())!)
.concat(name).concat(Serialize.tryToJSONString(nftDisplay!.name)!).concat(", ")
.concat(description).concat(Serialize.tryToJSONString(nftDisplay!.description)!).concat(", ")
.concat(image).concat(Serialize.tryToJSONString(nftDisplay!.thumbnail.uri())!)
// Append the `externa_url` value from NFTCollectionDisplay view if present
if collectionDisplay != nil {
return serializedResult.concat(", ")
.concat(externalURL).concat(Serialize.tryToJSONString(collectionDisplay!.externalURL.url)!)
.concat(externalURL).concat(Serialize.tryToJSONString(collectionDisplay!.externalURL.url)!)
}
}

Expand All @@ -100,10 +100,10 @@ access(all) contract SerializeMetadata {

// Without token-level view, serialize as contract-level metadata
return serializedResult
.concat(name).concat(Serialize.tryToJSONString(collectionDisplay!.name)!).concat(", ")
.concat(description).concat(Serialize.tryToJSONString(collectionDisplay!.description)!).concat(", ")
.concat(image).concat(Serialize.tryToJSONString(collectionDisplay!.squareImage.file.uri())!).concat(", ")
.concat(externalLink).concat(Serialize.tryToJSONString(collectionDisplay!.externalURL.url)!)
.concat(name).concat(Serialize.tryToJSONString(collectionDisplay!.name)!).concat(", ")
.concat(description).concat(Serialize.tryToJSONString(collectionDisplay!.description)!).concat(", ")
.concat(image).concat(Serialize.tryToJSONString(collectionDisplay!.squareImage.file.uri())!).concat(", ")
.concat(externalLink).concat(Serialize.tryToJSONString(collectionDisplay!.externalURL.url)!)
}

/// Serializes given Traits view as a JSON compatible string. If a given Trait is not serializable, it is skipped
Expand All @@ -129,9 +129,10 @@ access(all) contract SerializeMetadata {
continue
}
serializedResult = serializedResult.concat("{")
.concat("\"trait_type\": ").concat(Serialize.tryToJSONString(trait.name)!)
.concat(", \"value\": ").concat(value!)
.concat("}")
.concat("\"trait_type\": ").concat(Serialize.tryToJSONString(trait.name)!)
.concat(", \"display_type\": ").concat(Serialize.tryToJSONString(trait.display_type)!)
Copy link
Contributor

@sisyphusSmiling sisyphusSmiling Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this value is optional in both Cadence and in OpenSea's standard, I'm wondering if we should conditionally include this here. Otherwise the serialized field may contain nil values for a field that is listed as optionally included.

Suggested change
.concat(", \"display_type\": ").concat(Serialize.tryToJSONString(trait.display_type)!)
.concat(", \"display_type\": ").concat(Serialize.tryToJSONString(trait.displayType)!)

.concat(", \"value\": ").concat(value!)
.concat("}")
if i < traits!.traits.length - 1 {
serializedResult = serializedResult.concat(",")
}
Expand Down Expand Up @@ -160,11 +161,11 @@ access(all) contract SerializeMetadata {
let externalLink = "\"external_link\": "

return "data:application/json;utf8,{"
.concat(name).concat(Serialize.tryToJSONString(ftDisplay.name)!).concat(", ")
.concat(symbol).concat(Serialize.tryToJSONString(ftDisplay.symbol)!).concat(", ")
.concat(description).concat(Serialize.tryToJSONString(ftDisplay.description)!).concat(", ")
.concat(externalLink).concat(Serialize.tryToJSONString(ftDisplay.externalURL.url)!)
.concat("}")
.concat(name).concat(Serialize.tryToJSONString(ftDisplay.name)!).concat(", ")
.concat(symbol).concat(Serialize.tryToJSONString(ftDisplay.symbol)!).concat(", ")
.concat(description).concat(Serialize.tryToJSONString(ftDisplay.description)!).concat(", ")
.concat(externalLink).concat(Serialize.tryToJSONString(ftDisplay.externalURL.url)!)
.concat("}")
}

/// Derives a symbol for use as an ERC20 or ERC721 symbol from a given string, presumably a Cadence contract name.
Expand Down
Loading