import {LoadingOverlay} from "@mantine/core"; import {Contract, providers} from "ethers"; import {useEffect, useState} from "react"; import "./App.css"; import epicNFT from "./lib/epicNFT.json"; import {withEth} from "./lib/eth"; function App() { const [currentAccount, setCurrentAccount] = useState(""); const [mintedNFT, setMintedNFT] = useState(0); const [maxNFT, setMaxNFT] = useState(0); const [loading, setLoading] = useState(false); const [link, setLink] = useState(""); const contractAddress = process.env.REACT_APP_STAGING_CONTRACT_ADDRESS; const collectionAddress = process.env.REACT_APP_COLLECTION_ADDRESS; const contractABI = epicNFT.abi; const checkIfWalletConnected = withEth(async (ethereum) => { const accounts = await ethereum.request({method: "eth_accounts"}); if (accounts.length !== 0) { console.log(`Found authorized account ${accounts[0]}`); setCurrentAccount(accounts[0]); } }); const connectWallet = withEth(async (ethereum) => { const accounts = await ethereum.request({method: "eth_requestAccounts"}); console.log(`connected to ${accounts[0]}`); setCurrentAccount(accounts[0]); }); const mintNFT = withEth(async (ethereum) => { const signer = new providers.Web3Provider(ethereum).getSigner(); const contract = new Contract(contractAddress, contractABI, signer); const txn = await contract.mint(); setLink(""); setLoading(true); console.log(`Mining ${txn.hash}…`); await txn.wait(); setLoading(false); console.log(`Minted. See transaction: https://rinkeby.etherscan.io/tx/${txn.hash}`); }); const getNFTCount = withEth(async (ethereum) => { const signer = new providers.Web3Provider(ethereum).getSigner(); const contract = new Contract(contractAddress, contractABI, signer); const count = await contract.nftMintedCount(); setMintedNFT(count.toNumber()); const max = await contract.getMaxNFTAllowed(); setMaxNFT(max.toNumber()); }); useEffect(() => { checkIfWalletConnected(); }, [checkIfWalletConnected]); useEffect(() => { getNFTCount(); }, [getNFTCount]); useEffect(() => { let contract; const handleNewEpicNFT = (from, tokenID) => { console.log(from, tokenID.toNumber()); setMintedNFT(tokenID + 1); setLink(`https://testnets.opensea.io/assets/${contractAddress}/${tokenID.toNumber()}`); }; if (window.ethereum) { const signer = new providers.Web3Provider(window.ethereum).getSigner(); contract = new Contract(contractAddress, contractABI, signer); contract.on("NewEpicNFTMinted", handleNewEpicNFT); } return () => { if (contract) { contract.off("NewEpicNFTMinted", handleNewEpicNFT); } }; }, [contractABI, contractAddress]); return (

EpicNFTs Collection

Each unique. Each beautiful. Discover your NFT today.

{currentAccount ? ( ) : ( )}

{mintedNFT} EpicNFTs on {maxNFT} already minted

{link && (

Hey there! We've minted your NFT. It may be blank right now.
It can take a max of 10 min to show up on OpenSea. Here's the{" "} link

)}
); } export default App;