i have differents parts of code to call a mint function.
the parts are this
2 modifiers
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!");
require(supply.current() + _mintAmount <= maxSupply, "Max supply exceeded!");
_;
}
modifier mintCompliancePresale(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!");
require(supply.current() + _mintAmount <= maxPresaleSupply, "Max supply exceeded!");
_;
}
One is for normal mint, and the other one is for presale minting only.
And that connects with my mint functions.
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) {
require(!paused, "The contract is paused!");
require(msg.value >= cost * _mintAmount, "Insufficient funds!");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
_mintLoop(msg.sender, _mintAmount);
}
function presaleMint(uint256 _mintAmount) public payable mintCompliancePresale(_mintAmount) {
require(!paused, "The contract is paused!");
require(msg.value >= cost * _mintAmount, "Insufficient funds!");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
_mintLoop(msg.sender, _mintAmount);
}
2 functions, one for normal mint and another one for presale minting.
and that connects with my mint loop
function _mintLoop(address _receiver, uint256 _mintAmount) internal {
for (uint256 i = 0; i < _mintAmount; i++) {
supply.increment();
_safeMint(_receiver, supply.current());
}
}
Now, my question is how can i improve the 2 modifiers and 2 mint functions in just 1 modifier and 1 minting function? Is it possible to do?
I dont think 2 modifiers and 2 minting functions have sense. It works, but i think there is an error inside it.