Skip to content

Commit

Permalink
docs(38): fix nftswap.sol bug
Browse files Browse the repository at this point in the history
fix nftswap.sol bug
  • Loading branch information
XdpCs committed Nov 3, 2024
1 parent 49015d9 commit 4009276
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions 38_NFTSwap/NFTSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ contract NFTSwap is IERC721Receiver {

// 将NFT转给买家
_nft.safeTransferFrom(address(this), msg.sender, _tokenId);
// 将ETH转给卖家,多余ETH给买家退款
// 将ETH转给卖家
payable(_order.owner).transfer(_order.price);
// 多余ETH给买家退款
if (msg.value > _order.price) {
payable(_order.owner).transfer(_order.price);
payable(msg.sender).transfer(msg.value - _order.price);
}

Expand Down
10 changes: 6 additions & 4 deletions Languages/en/38_NFTSwap_en/NFTSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ contract NFTSwap is IERC721Receiver {
_nft.safeTransferFrom(address(this), msg.sender, _tokenId);
// Transfer ETH to the seller, and refund the excess ETH to the buyer
payable(_order.owner).transfer(_order.price);
payable(msg.sender).transfer(msg.value - _order.price);
if (msg.value > _order.price) {
payable(msg.sender).transfer(msg.value - _order.price);
}

// Release the Purchase event
emit Purchase(msg.sender, _nftAddr, _tokenId, _order.price);

delete nftList[_nftAddr][_tokenId]; // delete order

// Release the Purchase event
emit Purchase(msg.sender, _nftAddr, _tokenId, msg.value);
}

// Cancellation: The seller cancels the pending order
Expand Down

0 comments on commit 4009276

Please sign in to comment.