PatrickAlphaC / hardhat-nft-marketplace-fcc

114 stars 97 forks source link

Added modifier: isNotOwner #7

Closed Avelous closed 2 years ago

Avelous commented 2 years ago

Just a minimal observation that might be necessary. I observed that "Address A" lists an NFT and "Address A" can also buy the same NFT

So, In this pull request, I added a modifier, isNotOwner which prevents the owner of the NFT from buying it.

PatrickAlphaC commented 2 years ago

Awesome!

Could you add all this code as a comment? I'd love to keep it as similar to the video as possible.

Avelous commented 2 years ago

sure! here

//error
error IsNotOwner()

//modifier
modifier isNotOwner(
        address nftAddress,
        uint256 tokenId,
        address spender
    ) {
        IERC721 nft = IERC721(nftAddress);
        address owner = nft.ownerOf(tokenId);
        if (spender == owner) {
            revert IsNotOwner();
        }
        _;
    }

//Add this to the buyItem function
//Prevents the owner of an NFT from buying it
isNotOwner(nftAddress, tokenId, msg.sender)
PatrickAlphaC commented 2 years ago

No I mean in the PR, the code stay commented out as a suggestion for users.

Avelous commented 2 years ago

Alright, i commented the changes. please check now