Skip to content

Commit 60874d6

Browse files
Fix NFT carousel to render video files instead of passing them to Next.js Image (#98)
1 parent 46cbaec commit 60874d6

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

packages/nextjs/components/address-vision/NftsCarousel.tsx

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ type Nft = {
99
imageUrl: string;
1010
contract: Address;
1111
identifier: number;
12+
isVideo: boolean;
13+
};
14+
15+
const isVideoUrl = (url: string): boolean => {
16+
if (!url) return false;
17+
const videoExtensions = [".mp4", ".webm", ".ogg", ".mov"];
18+
const lowerUrl = url.toLowerCase();
19+
return videoExtensions.some(ext => lowerUrl.includes(ext));
1220
};
1321

1422
export const NftsCarousel = ({ nfts, chain, address }: { nfts: Nft[]; chain: Chain; address: Address }) => {
@@ -52,12 +60,16 @@ export const NftsCarousel = ({ nfts, chain, address }: { nfts: Nft[]; chain: Cha
5260

5361
const nftDataFormatted = nfts
5462
.filter((nft: any) => nft.image_url && nft.identifier !== "0")
55-
.map((nft: any, index: number) => ({
56-
imageUrl: nft.display_image_url || nft.image_url,
57-
contract: nft.contract,
58-
identifier: nft.identifier,
59-
index,
60-
}));
63+
.map((nft: any, index: number) => {
64+
const imageUrl = nft.display_image_url || nft.image_url;
65+
return {
66+
imageUrl,
67+
contract: nft.contract,
68+
identifier: nft.identifier,
69+
index,
70+
isVideo: isVideoUrl(imageUrl),
71+
};
72+
});
6173

6274
if (nftDataFormatted.length === 0) {
6375
return <div>No NFT data.</div>;
@@ -93,16 +105,34 @@ export const NftsCarousel = ({ nfts, chain, address }: { nfts: Nft[]; chain: Cha
93105
className="flex h-32 w-32 items-center justify-center"
94106
>
95107
<div className="flex h-full w-full items-center justify-center">
96-
<Image
97-
src={imageErrors[nft.index] ? "/base.svg" : nft.imageUrl}
98-
className="rounded-box h-full w-full object-contain"
99-
alt={`NFT ${nft.index}`}
100-
width={128}
101-
height={128}
102-
onError={() => {
103-
handleImageError(nft.index);
104-
}}
105-
/>
108+
{imageErrors[nft.index] ? (
109+
<Image
110+
src="/base.svg"
111+
className="rounded-box h-full w-full object-contain"
112+
alt={`NFT ${nft.index}`}
113+
width={128}
114+
height={128}
115+
/>
116+
) : nft.isVideo ? (
117+
<video
118+
src={nft.imageUrl}
119+
className="rounded-box h-full w-full object-contain"
120+
autoPlay
121+
loop
122+
muted
123+
playsInline
124+
onError={() => handleImageError(nft.index)}
125+
/>
126+
) : (
127+
<Image
128+
src={nft.imageUrl}
129+
className="rounded-box h-full w-full object-contain"
130+
alt={`NFT ${nft.index}`}
131+
width={128}
132+
height={128}
133+
onError={() => handleImageError(nft.index)}
134+
/>
135+
)}
106136
</div>
107137
</a>
108138
</div>

0 commit comments

Comments
 (0)