From 08da709ba7397d7a32676e228fc104332e87c7b7 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 13 Jul 2023 16:45:30 +0200 Subject: [PATCH] refactor _checkAuhtorized --- contracts/token/ERC721/ERC721.sol | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/contracts/token/ERC721/ERC721.sol b/contracts/token/ERC721/ERC721.sol index a315bf17c..22751b1ee 100644 --- a/contracts/token/ERC721/ERC721.sol +++ b/contracts/token/ERC721/ERC721.sol @@ -207,11 +207,12 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er * WARNING: This function relies on {_isAuthorized}, so it doesn't check whether `owner` is the actual owner of `tokenId` and will skip the check if `spender == owner` */ function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual { - // That first check is needed because the error is different, and should as precedence over insufficient approval - if (owner == address(0)) { - revert ERC721NonexistentToken(tokenId); - } else if (!_isAuthorized(owner, spender, tokenId)) { - revert ERC721InsufficientApproval(spender, tokenId); + if (!_isAuthorized(owner, spender, tokenId)) { + if (owner == address(0)) { + revert ERC721NonexistentToken(tokenId); + } else { + revert ERC721InsufficientApproval(spender, tokenId); + } } }