Hi there,
I am writing a simple contact, need to escrow and release ERC20 tokens, but when I have created multiple escrows, and trying to release the tokens accordingly, always get this error "SafeERC20: approve from non-zero to non-zero allowance error".
The releasing code is:
function releaseEscrow(uint _orderId) external onlySeller(_orderId){
Escrow memory _escrow = escrows[_orderId];
require(escrows[_orderId].status == EscrowStatus.Funded,"USDT has not been deposited");
_escrow.status = EscrowStatus.TokenApproved;
uint256 totalFees = escrow.sellerfee + escrow.buyerfee + escrow.additionalGasFees;
feesAvailable += _totalFees;
// here we tell the curreny that the buyer can ONLY have 'value' funds.
tokenccy.safeApprove(_escrow.buyer,(_escrow.value - _totalFees));
require(_escrow.status == EscrowStatus.TokenApproved,"USDT has not been approved!");
_escrow.status = EscrowStatus.Completed;
tokenccy.safeTransfer( escrow.buyer, (escrow.value - _totalFees) );
delete escrows[_orderId];
emit EscrowComplete(_orderId, _escrow);
}
Just wondering what could be the problem here. Thanks in advance.