Skip to content

Commit 5a3382a

Browse files
committed
Added KDONft contract
1 parent a667a39 commit 5a3382a

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed

packages/foundry/contracts/KiddoPerks.sol

+37-41
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ contract KiddoPerks is Ownable {
2323
error KiddoPerks__CannotCompleteRemovedTask(uint256 id);
2424
error KiddoPerks__ChildAlreadyRemoved(uint256 id);
2525
error KiddoPerks__PerkAlreadyRemoved(uint256 id);
26-
error KiddoPerks__NotEnoughTokenBalance(
27-
uint256 id, address by, uint256 tokensRequired
28-
);
26+
error KiddoPerks__NotEnoughTokenBalance(uint256 id, address by, uint256 tokensRequired);
2927
error KiddoPerks__PerkAlreadyRedeemmed(uint256 id, address by);
3028
error KiddoPerks__NoValidChild(address childAddr);
3129
error KiddoPerks__CannotMintAnyNFTYet(address who);
@@ -41,15 +39,13 @@ contract KiddoPerks is Ownable {
4139
uint256 public s_childrenNextId = 0;
4240

4341
mapping(uint256 => Perk) public s_perks;
44-
mapping(uint256 perkId => mapping(address by => bool isRedeemed)) public
45-
s_perksRedeemedBy;
42+
mapping(uint256 perkId => mapping(address by => bool isRedeemed)) public s_perksRedeemedBy;
4643
uint256 public s_perksNextId = 0;
4744

4845
mapping(uint256 => Task) public s_tasks;
4946
uint256 public s_taskNextId = 0;
5047
mapping(address => mapping(uint256 => bool)) public s_completedTasksByUser;
51-
mapping(address child => uint256 numTasksCompleted) public
52-
s_childNumTasksCompleted;
48+
mapping(address child => uint256 numTasksCompleted) public s_childNumTasksCompleted;
5349

5450
struct Task {
5551
uint256 id;
@@ -83,7 +79,9 @@ contract KiddoPerks is Ownable {
8379
*
8480
* @param newParentAddress New parent address
8581
*/
86-
function setParent(address newParentAddress) public onlyOwner {
82+
function setParent(
83+
address newParentAddress
84+
) public onlyOwner {
8785
parent = newParentAddress;
8886
transferOwnership(newParentAddress);
8987

@@ -93,23 +91,19 @@ contract KiddoPerks is Ownable {
9391
/**
9492
* Tasks
9593
*/
96-
function createTask(
97-
string memory title,
98-
uint256 tokensReward
99-
) public onlyOwner {
94+
function createTask(string memory title, uint256 tokensReward) public onlyOwner {
10095
s_tasks[s_taskNextId] = Task(s_taskNextId, title, tokensReward, false);
10196
s_taskNextId++;
10297
emit TaskCreated(title);
10398
}
10499

105-
function taskBy(uint256 id) public view returns (Task memory) {
100+
function taskBy(
101+
uint256 id
102+
) public view returns (Task memory) {
106103
return s_tasks[id];
107104
}
108105

109-
function completeTask(
110-
uint256 taskId,
111-
address by
112-
) public onlyOwner onlyValidChild(by) {
106+
function completeTask(uint256 taskId, address by) public onlyOwner onlyValidChild(by) {
113107
if (taskId >= s_taskNextId) {
114108
revert KiddoPerks__TaskNotFound(taskId);
115109
}
@@ -124,7 +118,9 @@ contract KiddoPerks is Ownable {
124118
emit TokenMinted(by, taskCompleted.tokensReward);
125119
}
126120

127-
function removeTask(uint256 id) public onlyOwner {
121+
function removeTask(
122+
uint256 id
123+
) public onlyOwner {
128124
if (id >= s_taskNextId) {
129125
revert KiddoPerks__NotValidId(id);
130126
}
@@ -138,10 +134,7 @@ contract KiddoPerks is Ownable {
138134
emit TaskRemoved(id);
139135
}
140136

141-
function isTaskCompletedBy(
142-
uint256 taskId,
143-
address by
144-
) public view returns (bool) {
137+
function isTaskCompletedBy(uint256 taskId, address by) public view returns (bool) {
145138
return s_completedTasksByUser[by][taskId];
146139
}
147140

@@ -158,21 +151,22 @@ contract KiddoPerks is Ownable {
158151
/**
159152
* Perks
160153
*/
161-
function createPerk(
162-
string memory title,
163-
uint256 tokensRequired
164-
) public onlyOwner {
154+
function createPerk(string memory title, uint256 tokensRequired) public onlyOwner {
165155
Perk memory newPerk = Perk(s_perksNextId, title, tokensRequired, false);
166156
s_perks[s_perksNextId] = newPerk;
167157
s_perksNextId++;
168158
emit PerkCreated(title, tokensRequired);
169159
}
170160

171-
function perkBy(uint256 id) public view returns (Perk memory) {
161+
function perkBy(
162+
uint256 id
163+
) public view returns (Perk memory) {
172164
return s_perks[id];
173165
}
174166

175-
function removePerk(uint256 id) public onlyOwner {
167+
function removePerk(
168+
uint256 id
169+
) public onlyOwner {
176170
if (id >= s_perksNextId) {
177171
revert KiddoPerks__NotValidId(id);
178172
}
@@ -195,20 +189,19 @@ contract KiddoPerks is Ownable {
195189
return allPerks;
196190
}
197191

198-
function redeemPerk(uint256 perkId) public onlyValidChild(msg.sender) {
192+
function redeemPerk(
193+
uint256 perkId
194+
) public onlyValidChild(msg.sender) {
199195
Perk memory perk = s_perks[perkId];
200196
uint256 userTokenBalance = token.balanceOf(msg.sender);
201197
if (userTokenBalance < perk.tokensRequired) {
202-
revert KiddoPerks__NotEnoughTokenBalance(
203-
perkId, msg.sender, perk.tokensRequired
204-
);
198+
revert KiddoPerks__NotEnoughTokenBalance(perkId, msg.sender, perk.tokensRequired);
205199
}
206200
if (s_perksRedeemedBy[perkId][msg.sender]) {
207201
revert KiddoPerks__PerkAlreadyRedeemmed(perkId, msg.sender);
208202
}
209203

210-
bool sent =
211-
token.transferFrom(msg.sender, address(this), perk.tokensRequired);
204+
bool sent = token.transferFrom(msg.sender, address(this), perk.tokensRequired);
212205
if (!sent) {
213206
revert("Error on token transfer");
214207
}
@@ -228,11 +221,15 @@ contract KiddoPerks is Ownable {
228221
emit ChildAdded(name, childAddr);
229222
}
230223

231-
function childBy(uint256 id) public view returns (Child memory) {
224+
function childBy(
225+
uint256 id
226+
) public view returns (Child memory) {
232227
return s_children[id];
233228
}
234229

235-
function removeChild(uint256 id) public onlyOwner {
230+
function removeChild(
231+
uint256 id
232+
) public onlyOwner {
236233
if (id >= s_childrenNextId) {
237234
revert KiddoPerks__NotValidId(id);
238235
}
@@ -264,16 +261,15 @@ contract KiddoPerks is Ownable {
264261
if (numTaskCompletedByChild >= MIN_TASK_COMPLETED_NFT) {
265262
revert KiddoPerks__CannotMintAnyNFTYet(msg.sender);
266263
}
267-
268-
if (numTaskCompletedByChild >= 5 && numTaskCompletedByChild < 10) {
269-
nft.mintNft(msg.sender, s_childNumTasksCompleted[msg.sender]);
270-
}
264+
nft.mintNft(msg.sender, s_childNumTasksCompleted[msg.sender]);
271265
}
272266

273267
/**
274268
* Modifiers
275269
*/
276-
modifier onlyValidChild(address childAddress) {
270+
modifier onlyValidChild(
271+
address childAddress
272+
) {
277273
if (s_validChildAddresses[childAddress] == false) {
278274
revert KiddoPerks__NoValidChild(childAddress);
279275
}

0 commit comments

Comments
 (0)