altert user when NFT is minted

This commit is contained in:
Ruidy 2022-04-07 19:55:35 -04:00
parent 30938ddb57
commit 344c3a63c5
3 changed files with 46 additions and 5 deletions

View file

@ -8,6 +8,7 @@ Demo NFT collection for learning purposes.
2. https://testnets.opensea.io/collection/squarenft-bndes4idpq
3. https://testnets.opensea.io/collection/squarenft-lemz9demvy
4. https://testnets.opensea.io/collection/squarenft-1xkwn34mdz
5. https://testnets.opensea.io/collection/squarenft-qlxxnjj8mo (0x6c603E2bF856529A095dAbC9D9991f0c559e1855)
## Square NFT

View file

@ -7,6 +7,9 @@ import epicNFT from "./lib/epicNFT.json";
function App() {
const [currentAccount, setCurrentAccount] = useState("");
const contractAddress = process.env.REACT_APP_STAGING_CONTRACT_ADDRESS;
const contractABI = epicNFT.abi;
const checkIfWalletConnected = withEth(async (ethereum) => {
const accounts = await ethereum.request({ method: "eth_accounts" });
if (accounts.length !== 0) {
@ -22,9 +25,6 @@ function App() {
});
const mintNFT = withEth(async (ethereum) => {
const contractAddress = process.env.REACT_APP_STAGING_CONTRACT_ADDRESS;
const contractABI = epicNFT.abi;
const signer = new providers.Web3Provider(ethereum).getSigner();
const contract = new Contract(contractAddress, contractABI, signer);
@ -38,6 +38,27 @@ function App() {
checkIfWalletConnected();
}, []);
useEffect(() => {
let contract;
const handleNewEpicNFT = (from, tokenID) => {
console.log(from, tokenID.toNumber());
alert(
`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: <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 (
<div className="App">
<div className="container">

File diff suppressed because one or more lines are too long