Skip to content

Commit

Permalink
fix serializeNFTMetadataAsURI conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Oct 23, 2024
1 parent 7f55229 commit 6f9f862
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cadence/contracts/utils/SerializeMetadata.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ access(all) contract SerializeMetadata {
// Serialize the display values from the NFT's Display & NFTCollectionDisplay views
let nftDisplay = nft.resolveView(Type<MetadataViews.Display>()) as! MetadataViews.Display?
let collectionDisplay = nft.resolveView(Type<MetadataViews.NFTCollectionDisplay>()) as! MetadataViews.NFTCollectionDisplay?
// Serialize the display & collection display views - nil if both views are nil
let display = self.serializeFromDisplays(nftDisplay: nftDisplay, collectionDisplay: collectionDisplay)

// Get the Traits view from the NFT, returning early if no traits are found
let traits = nft.resolveView(Type<MetadataViews.Traits>()) as! MetadataViews.Traits?
let attributes = self.serializeNFTTraitsAsAttributes(traits ?? MetadataViews.Traits([]))

// Return an empty string if nothing is serializable
if display == nil && attributes == nil {
// Return an empty string if all views are nil
if display == nil && traits == nil {
return ""
}
// Init the data format prefix & concatenate the serialized display & attributes
Expand Down
1 change: 0 additions & 1 deletion cadence/tests/serialize_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ fun testDictToJSONStringSucceeds() {
var expectedTwo: String = "{\"arr\": [\"127\", \"Hello, World!\"], \"bool\": \"true\"}"

var actual: String? = Serialize.dictToJSONString(dict: dict, excludedNames: nil)
log(actual)
Test.assertEqual(true, expectedOne == actual! || expectedTwo == actual!)

actual = Serialize.tryToJSONString(dict)
Expand Down

0 comments on commit 6f9f862

Please sign in to comment.