Skip to content

Commit

Permalink
add borrowViewResolver in packNFT contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
loic1 committed Aug 30, 2024
1 parent 773c3d8 commit 8c20681
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
11 changes: 10 additions & 1 deletion pds/contracts/PackNFT_AllDay.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
)
case Type<MetadataViews.Royalties>():
let royaltyReceiver: Capability<&{FungibleToken.Receiver}> =
getAccount({{.RoyaltyAddress}}).capabilities.get<&{FungibleToken.Receiver}>(MetadataViews.getRoyaltyReceiverPublicPath())!
getAccount(0xe4cf4bdc1751c65d).capabilities.get<&{FungibleToken.Receiver}>(MetadataViews.getRoyaltyReceiverPublicPath())
return MetadataViews.Royalties(
[
MetadataViews.Royalty(
Expand Down Expand Up @@ -374,6 +374,15 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
return &self.ownedNFTs[id]
}

/// Return a reference to a ViewResolver for an NFT in the Collection.
///
access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
return nft as &{ViewResolver.Resolver}
}
return nil
}

/// Create an empty Collection of the same type and returns it to the caller.
///
access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
Expand Down
18 changes: 13 additions & 5 deletions pds/contracts/PackNFT.cdc → pds/contracts/PackNFT_Pinnacle.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Crypto
import NonFungibleToken from "NonFungibleToken"
import IPackNFT from "IPackNFT"
import MetadataViews from "MetadataViews"
import ViewResolver from "ViewResolver"

/// Contract that defines Pack NFTs.
///
Expand Down Expand Up @@ -284,6 +285,13 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
return &self.ownedNFTs[id]
}

access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
return nft as &{ViewResolver.Resolver}
}
return nil
}

/// Create an empty Collection of the same type and returns it to the caller.
///
access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
Expand Down Expand Up @@ -334,8 +342,8 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
switch viewType {
case Type<MetadataViews.NFTCollectionData>():
let collectionData = MetadataViews.NFTCollectionData(
storagePath: /storage/exampleNFTCollection,
publicPath: /public/exampleNFTCollection,
storagePath: /storage/PinnaclePackNFTCollection,
publicPath: /public/PinnaclePackNFTCollectionPub,
publicCollection: Type<&Collection>(),
publicLinkedType: Type<&Collection>(),
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
Expand All @@ -351,9 +359,9 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
mediaType: "image/svg+xml"
)
return MetadataViews.NFTCollectionDisplay(
name: "The Example Collection",
description: "This collection is used as an example to help you develop your next Flow NFT.",
externalURL: MetadataViews.ExternalURL("https://example-nft.onflow.org"),
name: "Pinnacle Pack NFT Collection",
description: "",
externalURL: MetadataViews.ExternalURL(""),
squareImage: media,
bannerImage: media,
socials: {
Expand Down
9 changes: 9 additions & 0 deletions pds/contracts/PackNFT_TopShot.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
return &self.ownedNFTs[id]
}

/// Return a reference to a ViewResolver for an NFT in the Collection.
///
access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
return nft as &{ViewResolver.Resolver}
}
return nil
}

/// Create an empty Collection of the same type and returns it to the caller.
///
access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
Expand Down

0 comments on commit 8c20681

Please sign in to comment.