import Image from "next/image" import { useWallet } from "@solana/wallet-adapter-react" import { useNftState } from "@/contexts/NftProvider" import { useState } from "react"; export class Nft { name: string; url: string; constructor() { this.url = ""; this.name = ""; } } const DisplayNfts = () => { const { publicKey } = useWallet() const { nftState: nftState } = useNftState() const [showItems, setShowItems] = useState(false); const handleButtonClick = () => { setShowItems(!showItems); }; var myNfts = new Array(); if (nftState != null) { for (var i = 0; i < nftState.items.length; i++) { try { const nftData = nftState.items[i]; let nft = new Nft(); nft.name = nftData.content.metadata.name; nft.url = nftData.content.links.image; myNfts.push(nft); } catch (error) { console.log(error); } } } function onNftClickedCallback(nft: Nft): void { window.alert("Nft clicked: " + nft.name); } return ( <> {nftState && publicKey && (
{showItems && (
{myNfts.map((nft) => (

{nft.name}

{nft.url ? ( onNftClickedCallback(nft)} src={nft.url} alt="NFT Icon" width={64} height={64} /> ) : (
Error loading image
)}
))}
)}
)} ); } export default DisplayNfts