diff --git a/contracts/nft/BaseCollection.cdc b/contracts/nft/BaseCollection.cdc index ef2482f..a14624a 100644 --- a/contracts/nft/BaseCollection.cdc +++ b/contracts/nft/BaseCollection.cdc @@ -80,6 +80,8 @@ access(all) contract interface BaseCollection: ViewResolver { return <- c.createEmptyCollection(nftType: rt) } ) + case Type(): + return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath)) case Type(): let c = getAccount(addr).contracts.borrow<&{BaseCollection}>(name: segments[2])! let tmp = c.MetadataCap.borrow() @@ -88,8 +90,33 @@ access(all) contract interface BaseCollection: ViewResolver { } return tmp!.collectionInfo.getDisplay() - case Type(): - return FlowtyDrops.DropResolver(cap: acct.capabilities.get<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerPublicPath)) + case Type(): + 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(): + return tmp!.collectionInfo.getDisplay() + case Type(): + let keys = tmp!.metadata.keys + if keys.length == 0 || keys.length > 1 { + return nil + } + return tmp!.borrowMetadata(id: keys[0])!.getRoyalties() + } } return nil diff --git a/contracts/nft/BaseNFT.cdc b/contracts/nft/BaseNFT.cdc index aae87aa..195c133 100644 --- a/contracts/nft/BaseNFT.cdc +++ b/contracts/nft/BaseNFT.cdc @@ -81,19 +81,21 @@ access(all) contract interface BaseNFT: ViewResolver { if let entry = md.borrowMetadata(id: self.metadataID) { switch view { case Type(): - return entry.traits + return entry.getTraits() case Type(): - return entry.editions + return entry.getEditions() case Type(): 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(): return entry.externalURL + case Type(): + return entry.royalties } } diff --git a/contracts/nft/NFTMetadata.cdc b/contracts/nft/NFTMetadata.cdc index bef4635..ce08096 100644 --- a/contracts/nft/NFTMetadata.cdc +++ b/contracts/nft/NFTMetadata.cdc @@ -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,