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

MetadataResolution fixes & royalties #34

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 29 additions & 2 deletions contracts/nft/BaseCollection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ access(all) contract interface BaseCollection: ViewResolver {
return <- c.createEmptyCollection(nftType: rt)
}
)
case Type<FlowtyDrops.DropResolver>():
return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath))
case Type<MetadataViews.NFTCollectionDisplay>():
let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2])!
let tmp = c.MetadataCap.borrow()
Expand All @@ -88,8 +90,33 @@ access(all) contract interface BaseCollection: ViewResolver {
}

return tmp!.collectionInfo.getDisplay()
case Type<FlowtyDrops.DropResolver>():
return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath))
case Type<MetadataViews.Royalties>():
let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2])!
let tmp = c.MetadataCap.borrow()
if tmp == nil {
return nil
}

return tmp!.collectionInfo.getDisplay()
}

// These views require the {BaseCollection} interface
if let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2]) {
let tmp = c.MetadataCap.borrow()
if tmp == nil {
return nil
}

switch viewType {
case Type<MetadataViews.NFTCollectionDisplay>():
return tmp!.collectionInfo.getDisplay()
case Type<MetadataViews.Royalties>():
let keys = tmp!.metadata.keys
if keys.length == 0 || keys.length > 1 {
return nil
}
return tmp!.borrowMetadata(id: keys[0])!.getRoyalties()
}
}

return nil
Expand Down
8 changes: 5 additions & 3 deletions contracts/nft/BaseNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,21 @@ access(all) contract interface BaseNFT: ViewResolver {
if let entry = md.borrowMetadata(id: self.metadataID) {
switch view {
case Type<MetadataViews.Traits>():
return entry.traits
return entry.getTraits()
case Type<MetadataViews.Editions>():
return entry.editions
return entry.getEditions()
case Type<MetadataViews.Display>():
let num = (entry.editions?.infoList?.length ?? 0) > 0 ? entry.editions!.infoList[0].number : self.id

return MetadataViews.Display(
name: entry.name.concat(" #").concat(num.toString()),
description: entry.description,
thumbnail: NFTMetadata.UriFile(entry.thumbnail.uri())
thumbnail: entry.getThumbnail()
)
case Type<MetadataViews.ExternalURL>():
return entry.externalURL
case Type<MetadataViews.Royalties>():
return entry.royalties
}
}

Expand Down
20 changes: 20 additions & 0 deletions contracts/nft/NFTMetadata.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ access(all) contract NFTMetadata {

access(all) let data: {String: AnyStruct}

access(all) fun getThumbnail(): {MetadataViews.File} {
return self.thumbnail
}

access(all) fun getTraits(): MetadataViews.Traits? {
return self.traits
}

access(all) fun getEditions(): MetadataViews.Editions? {
return self.editions
}

access(all) fun getExternalURL(): MetadataViews.ExternalURL? {
return self.externalURL
}

access(all) fun getRoyalties(): MetadataViews.Royalties? {
return self.royalties
}

init(
name: String,
description: String,
Expand Down
Loading