diff --git a/src/app/[username]/page.js b/src/app/[username]/page.js index 08024f2..79fa6c7 100644 --- a/src/app/[username]/page.js +++ b/src/app/[username]/page.js @@ -1,14 +1,20 @@ -"use client" -import { useEffect, useState } from 'react'; -import { useAccount, useChainId } from 'wagmi'; -import Moralis from 'moralis'; -import ProfileNftCard from '../../components/profileNftCard'; -import TokenNftCard from '../../components/tokenNftCard'; -import Header1 from '../../components/header1'; -import Footer from '../../components/footer'; -import Link from 'next/link'; -import { useRouter } from 'next/navigation'; -import { Avatar, Identity, Name, Badge, Address } from '@coinbase/onchainkit/identity'; +"use client"; +import { useEffect, useState } from "react"; +import { useAccount, useChainId } from "wagmi"; +import Moralis from "moralis"; +import ProfileNftCard from "../../components/profileNftCard"; +import TokenNftCard from "../../components/tokenNftCard"; +import Header1 from "../../components/header1"; +import Footer from "../../components/footer"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { + Avatar, + Identity, + Name, + Badge, + Address, +} from "@coinbase/onchainkit/identity"; function HomePage({ params }) { const { username } = params; @@ -20,50 +26,50 @@ function HomePage({ params }) { const [mintedNFTs, setMintedNFTs] = useState([]); const [matchedNFTs, setMatchedNFTs] = useState([]); const [matchedWebxrs, setMatchedWebxr] = useState([]); - const [name, setName] = useState(''); - const [basename, setBaseName] = useState(''); - const [coverImage, setCoverImage] = useState(''); - const [profileImage, setProfileImage] = useState(''); - const [bio, setBio] = useState(''); - const [website, setWebsite] = useState(''); - const [x, setX] = useState(''); - const [instagram, setInstagram] = useState(''); - const [guestname, setGuestName] = useState(''); - const [guestbasename, setGuestBaseName] = useState(''); - const [guestcoverImage, setGuestCoverImage] = useState(''); - const [guestprofileImage, setGuestProfileImage] = useState(''); - const [guestbio, setGuestBio] = useState(''); - const [guestwebsite, setGuestWebsite] = useState(''); - const [guestx, setGuestX] = useState(''); - const [guestinstagram, setGuestInstagram] = useState(''); - const [walletAddress, setGuestWalletAddress] = useState(''); - const [activeSection, setActiveSection] = useState('assets'); + const [name, setName] = useState(""); + const [basename, setBaseName] = useState(""); + const [coverImage, setCoverImage] = useState(""); + const [profileImage, setProfileImage] = useState(""); + const [bio, setBio] = useState(""); + const [website, setWebsite] = useState(""); + const [x, setX] = useState(""); + const [instagram, setInstagram] = useState(""); + const [guestname, setGuestName] = useState(""); + const [guestbasename, setGuestBaseName] = useState(""); + const [guestcoverImage, setGuestCoverImage] = useState(""); + const [guestprofileImage, setGuestProfileImage] = useState(""); + const [guestbio, setGuestBio] = useState(""); + const [guestwebsite, setGuestWebsite] = useState(""); + const [guestx, setGuestX] = useState(""); + const [guestinstagram, setGuestInstagram] = useState(""); + const [walletAddress, setGuestWalletAddress] = useState(""); + const [activeSection, setActiveSection] = useState("assets"); const [showForm, setShowForm] = useState(false); const [owner, setOwner] = useState(false); const [showCreatorOptions, setShowCreatorOptions] = useState(false); const [hoveredOption, setHoveredOption] = useState(null); - const [status, setStatus] = useState(''); - const [discord, setDiscord] = useState(''); - const [selectedSocialLink, setSelectedSocialLink] = useState(''); - const [link, setLink] = useState(''); - const [guestdiscord, setGuestDiscord] = useState(''); - const [guestselectedSocialLink, setGuestSelectedSocialLink] = useState(''); - const [guestlink, setGuestLink] = useState(''); + const [status, setStatus] = useState(""); + const [discord, setDiscord] = useState(""); + const [selectedSocialLink, setSelectedSocialLink] = useState(""); + const [link, setLink] = useState(""); + const [guestdiscord, setGuestDiscord] = useState(""); + const [guestselectedSocialLink, setGuestSelectedSocialLink] = useState(""); + const [guestlink, setGuestLink] = useState(""); const apikey = process.env.NEXT_PUBLIC_MORALIS_API_KEY; - const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com'; + const baseUri = process.env.NEXT_PUBLIC_URI || "https://app.myriadflow.com"; const handleVerify = () => { - setShowForm(true) + setShowForm(true); }; useEffect(() => { // Check if the URL has a hash and set the active section if (window.location.hash) { - const section = window.location.hash.substring(1); - setActiveSection(section); + const section = window.location.hash.substring(1); + setActiveSection(section); } -}, []); + }, []); useEffect(() => { const fetchNFTs = async () => { @@ -72,9 +78,9 @@ function HomePage({ params }) { const assets = await Moralis.EvmApi.nft.getWalletNFTs({ chain: chainId, - format: 'decimal', + format: "decimal", mediaItems: false, - address: walletAddress + address: walletAddress, }); setMintedNFTs(assets.raw.result); @@ -93,12 +99,15 @@ function HomePage({ params }) { const getUserData = async () => { if (address) { try { - const response = await fetch(`${baseUri}/profiles/username/${username}`, { - method: 'GET', - headers: { - 'content-Type': 'application/json', - }, - }); + const response = await fetch( + `${baseUri}/profiles/username/${username}`, + { + method: "GET", + headers: { + "content-Type": "application/json", + }, + } + ); if (response.ok) { const data = await response.json(); @@ -116,10 +125,10 @@ function HomePage({ params }) { setGuestSelectedSocialLink(data.selected_social_link); setGuestLink(data.link); } else { - console.log('No user found'); + console.log("No user found"); } } catch (error) { - console.error('Error fetching user data', error); + console.error("Error fetching user data", error); } } }; @@ -130,12 +139,15 @@ function HomePage({ params }) { const getUserData = async () => { if (address) { try { - const response = await fetch(`${baseUri}/profiles/wallet/${address}`, { - method: 'GET', - headers: { - 'content-Type': 'application/json', - }, - }); + const response = await fetch( + `${baseUri}/profiles/wallet/${address}`, + { + method: "GET", + headers: { + "content-Type": "application/json", + }, + } + ); if (response.ok) { const data = await response.json(); @@ -152,10 +164,10 @@ function HomePage({ params }) { setSelectedSocialLink(data.selected_social_link); setLink(data.link); } else { - console.log('No user found'); + console.log("No user found"); } } catch (error) { - console.error('Error fetching user data', error); + console.error("Error fetching user data", error); } } }; @@ -165,36 +177,49 @@ function HomePage({ params }) { useEffect(() => { const fetchPhygitals = async () => { try { - const phyres = await fetch(`${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' + const phyres = await fetch( + `${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, } - }); + ); if (!phyres.ok) { - throw new Error('Failed to fetch data'); + throw new Error("Failed to fetch data"); } const phyresult = await phyres.json(); console.log("Phygitals:", phyresult); - const matched = await Promise.all(phyresult.map(async (phygital) => { - const amountBought = await mintedNFTs.reduce(async (countPromise, nft) => { - const count = await countPromise; - return count + (nft?.token_address === phygital.contract_address ? 1 : 0); - }, Promise.resolve(0)); - return { - ...phygital, - amount_bought: amountBought - }; - })); - - const filteredMatched = matched.filter(phygital => phygital.amount_bought > 0); + const matched = await Promise.all( + phyresult.map(async (phygital) => { + const amountBought = await mintedNFTs.reduce( + async (countPromise, nft) => { + const count = await countPromise; + return ( + count + + (nft?.token_address === phygital.contract_address ? 1 : 0) + ); + }, + Promise.resolve(0) + ); + return { + ...phygital, + amount_bought: amountBought, + }; + }) + ); + + const filteredMatched = matched.filter( + (phygital) => phygital.amount_bought > 0 + ); setMatchedNFTs(filteredMatched); console.log("Matched NFTs:", filteredMatched); } catch (error) { - console.error('Error fetching data:', error); + console.error("Error fetching data:", error); } }; @@ -206,76 +231,97 @@ function HomePage({ params }) { useEffect(() => { const fetchPhygitals = async () => { try { - const phyres = await fetch(`${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' + const phyres = await fetch( + `${baseUri}/phygitals/all/554b4903-9a06-4031-98f4-48276c427f78`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, } - }); + ); if (!phyres.ok) { - throw new Error('Failed to fetch data'); + throw new Error("Failed to fetch data"); } const phyresult = await phyres.json(); console.log("Phygitals:", phyresult); - const matchedfantoken = await Promise.all(phyresult.map(async (phygital) => { - const amountBought = await mintedNFTs.reduce(async (countPromise, nft) => { - const count = await countPromise; - if (nft?.contract_type === 'ERC1155') { - try { - const response = await fetch(`${baseUri}/get-mint-fantoken/${walletAddress}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' + const matchedfantoken = await Promise.all( + phyresult.map(async (phygital) => { + const amountBought = await mintedNFTs.reduce( + async (countPromise, nft) => { + const count = await countPromise; + if (nft?.contract_type === "ERC1155") { + try { + const response = await fetch( + `${baseUri}/get-mint-fantoken/${walletAddress}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ); + + if (!response.ok) { + throw new Error("Failed to fetch minted tokens"); + } + + const mintedFanTokens = await response.json(); + + const matchingFanToken = mintedFanTokens.find((token) => { + return ( + token.nftContractAddress === + phygital.contract_address && + token.token_id === nft.token_id + ); + }); + return count + (matchingFanToken ? 1 : 0); + } catch (error) { + console.error("Error fetching minted tokens:", error); + return count; } - }); - - if (!response.ok) { - throw new Error('Failed to fetch minted tokens'); } - - const mintedFanTokens = await response.json(); - - const matchingFanToken = mintedFanTokens.find(token => { - return token.nftContractAddress === phygital.contract_address && - token.token_id === nft.token_id; - }); - return count + (matchingFanToken ? 1 : 0); - } catch (error) { - console.error('Error fetching minted tokens:', error); return count; - } - } - return count; - }, Promise.resolve(0)); - return { - ...phygital, - amount_bought: amountBought - }; - })); - const filteredMatchedFanToken = matchedfantoken.filter(phygital => phygital.amount_bought > 0); - const response = await fetch(`${baseUri}/webxr/all/554b4903-9a06-4031-98f4-48276c427f78`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json' + }, + Promise.resolve(0) + ); + return { + ...phygital, + amount_bought: amountBought, + }; + }) + ); + const filteredMatchedFanToken = matchedfantoken.filter( + (phygital) => phygital.amount_bought > 0 + ); + const response = await fetch( + `${baseUri}/webxr/all/554b4903-9a06-4031-98f4-48276c427f78`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, } - }); + ); if (!response.ok) { - throw new Error('Failed to fetch minted tokens'); + throw new Error("Failed to fetch minted tokens"); } const webxr = await response.json(); - const matchingWebxr = webxr.filter(web => - filteredMatchedFanToken.some(phygital => phygital.id === web.phygital_id) + const matchingWebxr = webxr.filter((web) => + filteredMatchedFanToken.some( + (phygital) => phygital.id === web.phygital_id + ) ); setMatchedWebxr(matchingWebxr); console.log("Matched Fantoken:", filteredMatchedFanToken); console.log("Matched webxr:", matchingWebxr); } catch (error) { - console.error('Error fetching data:', error); + console.error("Error fetching data:", error); } }; @@ -288,22 +334,25 @@ function HomePage({ params }) { const getPhygitalData = async () => { if (walletAddress) { try { - const response = await fetch(`${baseUri}/phygitals/deployer_address/${walletAddress}`, { - method: 'GET', - headers: { - 'content-Type': 'application/json', - }, - }); + const response = await fetch( + `${baseUri}/phygitals/deployer_address/${walletAddress}`, + { + method: "GET", + headers: { + "content-Type": "application/json", + }, + } + ); if (response.ok) { const data = await response.json(); setOwner(true); console.log("Phygital data based on address", data); } else { - console.log('No Phygital found'); + console.log("No Phygital found"); } } catch (error) { - console.error('Error fetching user data', error); + console.error("Error fetching user data", error); } } }; @@ -314,23 +363,26 @@ function HomePage({ params }) { const getElevateData = async () => { if (walletAddress) { try { - const response = await fetch(`${baseUri}/elevate/walletaddress/${walletAddress}`, { - method: "GET", - headers: { - 'Content-Type': 'application/json', - }, - }); + const response = await fetch( + `${baseUri}/elevate/walletaddress/${walletAddress}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ); if (response.ok) { const data = await response.json(); setStatus(data.status); } else { - console.log('No user found'); + console.log("No user found"); } } catch (error) { - console.error('Error fetching user data', error); + console.error("Error fetching user data", error); } } else { - console.log('No wallet address provided'); + console.log("No wallet address provided"); } }; @@ -344,98 +396,129 @@ function HomePage({ params }) {
{bio || "Short bio of the person here"}
++ {bio || "Short bio of the person here"} +
- Thank you for your interest in the MyriadFlow Elevate Program! We look forward to reviewing your application. Please keep checking your provided email address, and this page for further communication. Best of luck! + Thank you for your interest in the MyriadFlow + Elevate Program! We look forward to reviewing your + application. Please keep checking your provided + email address, and this page for further + communication. Best of luck!
{guestbio || "Short bio of the person here"}
++ {guestbio || "Short bio of the person here"} +