Skip to content

Commit

Permalink
update set_bridged_nft_display_view to use new util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Sep 3, 2024
1 parent 75ad26b commit b678363
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ import "MetadataViews"

import "FlowEVMBridgeResolver"

/// Builds a thumbnail file based on the provided thumbnail file type identifier and optional IPFS file path
///
access(all)
fun buildThumbnailFile(_ thumbnailURI: String, _ thumbnailFileTypeIdentifier: String, _ ipfsFilePath: String?): {MetadataViews.File} {
// Determine the inteded File type based on the provided file type identifier
let thumbnailFileType = CompositeType(thumbnailFileTypeIdentifier)
?? panic("Invalid file type identifier=".concat(thumbnailFileTypeIdentifier))

// Build the thumbnail file based on the determined file type
if thumbnailFileType == Type<MetadataViews.HTTPFile>() {
return MetadataViews.HTTPFile(url: thumbnailURI)
} else if thumbnailFileType == Type<MetadataViews.IPFSFile>() {
return MetadataViews.IPFSFile(cid: thumbnailURI, path: ipfsFilePath)
} else {
panic("Unsupported file type=".concat(thumbnailFileTypeIdentifier))
}
}

/// This transaction sets the bridged NFT Display view for all NFTs bridged from Flow EVM
///
transaction(thumbnailURI: String, thumbnailFileTypeIdentifier: String, ipfsFilePath: String?) {
Expand All @@ -28,13 +10,23 @@ transaction(thumbnailURI: String, thumbnailFileTypeIdentifier: String, ipfsFileP
let admin: auth(FlowEVMBridgeResolver.Metadata) &FlowEVMBridgeResolver.Admin

prepare(signer: auth(BorrowValue) &Account) {
let thumbnailFile = buildThumbnailFile(thumbnailURI, thumbnailFileTypeIdentifier, ipfsFilePath)
// Determine the intended File type based on the provided file type identifier
let thumbnailFileType = CompositeType(thumbnailFileTypeIdentifier)
?? panic("Invalid file type identifier=".concat(thumbnailFileTypeIdentifier))
// Build the thumbnail file
let thumbnailFile = FlowEVMBridgeResolver.buildFile(
uri: thumbnailURI,
fileType: thumbnailFileType,
ipfsFilePath: ipfsFilePath
) ?? panic("Failed to build thumbnail file")
// Build the NFT Display view
self.display = MetadataViews.Display(
name: "This name is replaced by a bridged NFT's name",
description: "This description is replaced by a bridged NFT's collection description",
thumbnail: thumbnailFile
)

// Borrow the Admin resource
self.admin = signer.storage.borrow<auth(FlowEVMBridgeResolver.Metadata) &FlowEVMBridgeResolver.Admin>(
from: FlowEVMBridgeResolver.AdminStoragePath
) ?? panic("Missing or mis-typed Admin resource")
Expand Down

0 comments on commit b678363

Please sign in to comment.