generated from NomicFoundation/hardhat-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.noImage { | ||
height: 100%; | ||
background-color: var(--box-bg); | ||
border-radius: 10px; | ||
} | ||
|
||
.noImage::after { | ||
content: "?"; | ||
height: 100%; | ||
width: 100%; | ||
font-size: 5em; | ||
opacity: 0.2; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.imageContainer { | ||
aspect-ratio: 1; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.image { | ||
object-fit: cover; | ||
max-height: 100%; | ||
border-radius: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useState } from "react" | ||
import { MoralisNFT } from "../../types/Token" | ||
|
||
import classes from "./NFTMedia.module.css" | ||
|
||
const getIPFSHashFromURL = (url: string) => { | ||
const match = url.match( | ||
/^ipfs:\/\/(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(\d|\w|\.)+)*$/ | ||
) | ||
return match ? match[1] : null | ||
} | ||
|
||
const NFTMedia = ({ nft }: { nft: MoralisNFT }) => { | ||
const [imageError, setImageError] = useState(false) | ||
const metadata = JSON.parse(nft.metadata || "{}") | ||
const alt = metadata.name || "NFT image" | ||
|
||
let src = "" | ||
let type = "image/*" | ||
|
||
if (!nft.media) { | ||
return <div className={classes.noImage}></div> | ||
} | ||
|
||
switch (nft.media.status) { | ||
case "success": | ||
// use media url | ||
src = nft.media.media_collection.high.url | ||
type = nft.media.mimetype | ||
break | ||
|
||
case "host_unavailable": | ||
// could be an ipfs url or an unreachable url | ||
const ipfsHash = getIPFSHashFromURL(nft.media.original_media_url) | ||
if (ipfsHash) { | ||
src = `https://cloudflare-ipfs.com/ipfs/${ipfsHash}` | ||
} else { | ||
src = nft.media.original_media_url | ||
} | ||
break | ||
|
||
default: | ||
src = nft.media.original_media_url | ||
break | ||
} | ||
return ( | ||
<> | ||
{(imageError || !src) && <div className={classes.noImage}></div>} | ||
{!imageError && src && ( | ||
<div className={classes.imageContainer}> | ||
{type.includes("image") && ( | ||
<img | ||
src={src} | ||
alt={alt} | ||
className={classes.image} | ||
onError={() => setImageError(true)} | ||
/> | ||
)} | ||
{type.includes("video") && ( | ||
<video | ||
src={src} | ||
className={classes.image} | ||
onError={() => setImageError(true)} | ||
autoPlay | ||
muted | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default NFTMedia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a55a3b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mech – ./
mech-gnosis-guild.vercel.app
mech-git-main-gnosis-guild.vercel.app
mech-omega.vercel.app
mech.mom
www.mech.mom