Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Aug 21, 2024
1 parent 72e96be commit 172158c
Showing 1 changed file with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,14 @@ contract InstantRewards is Ownable, Pausable, ReentrancyGuard {
error InvalidSigner();
error InvalidAddress();
error TaskAlreadyClaimed();
error TransferFailed();

constructor(address signerAddress_, address owner) Ownable() {
if (signerAddress_ == address(0)) revert InvalidAddress();
transferOwnership(owner);
signerAddress = signerAddress_;
}

// Helper function to convert uint to string
function _uint2str(uint _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len;
while (_i != 0) {
k = k - 1;
uint8 temp = (uint8(48 + (_i % 10)));
bstr[k] = bytes1(temp);
_i /= 10;
}
return string(bstr);
}

function _verify(ClaimData memory claimData) private view {
bytes32 payloadHash = _calculateHash(claimData);

Expand Down Expand Up @@ -89,7 +68,8 @@ contract InstantRewards is Ownable, Pausable, ReentrancyGuard {

taskCompletedByUser[claimData.to][claimData.taskId] = true;

payable(claimData.to).transfer(claimData.amount);
(bool success, ) = claimData.to.call{value: claimData.amount}("");
if (!success) revert TransferFailed();

emit Claimed(claimData.to, claimData.taskId, claimData.amount);
}

Check warning

Code scanning / Slither

Low-level calls Warning

Expand All @@ -100,6 +80,7 @@ contract InstantRewards is Ownable, Pausable, ReentrancyGuard {
}

function withdraw(address wallet) external onlyOwner {
if (wallet == address(0)) revert InvalidAddress();
payable(wallet).transfer(address(this).balance);
}

Expand Down

0 comments on commit 172158c

Please sign in to comment.