Skip to content

Commit

Permalink
update displayType trait serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Oct 23, 2024
1 parent b441888 commit 6f57cf5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cadence/contracts/utils/SerializeMetadata.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ access(all) contract SerializeMetadata {
/// @param traits: The Traits view to be serialized
///
/// @returns: A JSON compatible string containing the serialized traits as:
/// `\"attributes\": [{\"trait_type\": \"<trait.name>\", \"value\": \"<trait.value>\"}, {...}]`
/// `\"attributes\": [{\"trait_type\": \"<trait.name>\", \"display_type\": \"<trait.displayType>\", \"value\": \"<trait.value>\"}, {...}]`
///
access(all)
fun serializeNFTTraitsAsAttributes(_ traits: MetadataViews.Traits): String {
Expand All @@ -129,10 +129,13 @@ access(all) contract SerializeMetadata {
continue
}
serializedResult = serializedResult.concat("{")
.concat("\"trait_type\": ").concat(Serialize.tryToJSONString(trait.name)!)
.concat(", \"display_type\": ").concat(Serialize.tryToJSONString(trait.displayType)!)
.concat(", \"value\": ").concat(value!)
.concat("}")
.concat("\"trait_type\": ").concat(Serialize.tryToJSONString(trait.name)!)
if trait.displayType != nil {
serializedResult = serializedResult.concat(", \"display_type\": ")
.concat(Serialize.tryToJSONString(trait.displayType)!)
}
serializedResult = serializedResult.concat(", \"value\": ").concat(value!)
.concat("}")
if i < traits!.traits.length - 1 {
serializedResult = serializedResult.concat(",")
}
Expand Down

0 comments on commit 6f57cf5

Please sign in to comment.