@@ -23,9 +23,7 @@ contract KiddoPerks is Ownable {
23
23
error KiddoPerks__CannotCompleteRemovedTask (uint256 id );
24
24
error KiddoPerks__ChildAlreadyRemoved (uint256 id );
25
25
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 );
29
27
error KiddoPerks__PerkAlreadyRedeemmed (uint256 id , address by );
30
28
error KiddoPerks__NoValidChild (address childAddr );
31
29
error KiddoPerks__CannotMintAnyNFTYet (address who );
@@ -41,15 +39,13 @@ contract KiddoPerks is Ownable {
41
39
uint256 public s_childrenNextId = 0 ;
42
40
43
41
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;
46
43
uint256 public s_perksNextId = 0 ;
47
44
48
45
mapping (uint256 => Task) public s_tasks;
49
46
uint256 public s_taskNextId = 0 ;
50
47
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;
53
49
54
50
struct Task {
55
51
uint256 id;
@@ -83,7 +79,9 @@ contract KiddoPerks is Ownable {
83
79
*
84
80
* @param newParentAddress New parent address
85
81
*/
86
- function setParent (address newParentAddress ) public onlyOwner {
82
+ function setParent (
83
+ address newParentAddress
84
+ ) public onlyOwner {
87
85
parent = newParentAddress;
88
86
transferOwnership (newParentAddress);
89
87
@@ -93,23 +91,19 @@ contract KiddoPerks is Ownable {
93
91
/**
94
92
* Tasks
95
93
*/
96
- function createTask (
97
- string memory title ,
98
- uint256 tokensReward
99
- ) public onlyOwner {
94
+ function createTask (string memory title , uint256 tokensReward ) public onlyOwner {
100
95
s_tasks[s_taskNextId] = Task (s_taskNextId, title, tokensReward, false );
101
96
s_taskNextId++ ;
102
97
emit TaskCreated (title);
103
98
}
104
99
105
- function taskBy (uint256 id ) public view returns (Task memory ) {
100
+ function taskBy (
101
+ uint256 id
102
+ ) public view returns (Task memory ) {
106
103
return s_tasks[id];
107
104
}
108
105
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) {
113
107
if (taskId >= s_taskNextId) {
114
108
revert KiddoPerks__TaskNotFound (taskId);
115
109
}
@@ -124,7 +118,9 @@ contract KiddoPerks is Ownable {
124
118
emit TokenMinted (by, taskCompleted.tokensReward);
125
119
}
126
120
127
- function removeTask (uint256 id ) public onlyOwner {
121
+ function removeTask (
122
+ uint256 id
123
+ ) public onlyOwner {
128
124
if (id >= s_taskNextId) {
129
125
revert KiddoPerks__NotValidId (id);
130
126
}
@@ -138,10 +134,7 @@ contract KiddoPerks is Ownable {
138
134
emit TaskRemoved (id);
139
135
}
140
136
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 ) {
145
138
return s_completedTasksByUser[by][taskId];
146
139
}
147
140
@@ -158,21 +151,22 @@ contract KiddoPerks is Ownable {
158
151
/**
159
152
* Perks
160
153
*/
161
- function createPerk (
162
- string memory title ,
163
- uint256 tokensRequired
164
- ) public onlyOwner {
154
+ function createPerk (string memory title , uint256 tokensRequired ) public onlyOwner {
165
155
Perk memory newPerk = Perk (s_perksNextId, title, tokensRequired, false );
166
156
s_perks[s_perksNextId] = newPerk;
167
157
s_perksNextId++ ;
168
158
emit PerkCreated (title, tokensRequired);
169
159
}
170
160
171
- function perkBy (uint256 id ) public view returns (Perk memory ) {
161
+ function perkBy (
162
+ uint256 id
163
+ ) public view returns (Perk memory ) {
172
164
return s_perks[id];
173
165
}
174
166
175
- function removePerk (uint256 id ) public onlyOwner {
167
+ function removePerk (
168
+ uint256 id
169
+ ) public onlyOwner {
176
170
if (id >= s_perksNextId) {
177
171
revert KiddoPerks__NotValidId (id);
178
172
}
@@ -195,20 +189,19 @@ contract KiddoPerks is Ownable {
195
189
return allPerks;
196
190
}
197
191
198
- function redeemPerk (uint256 perkId ) public onlyValidChild (msg .sender ) {
192
+ function redeemPerk (
193
+ uint256 perkId
194
+ ) public onlyValidChild (msg .sender ) {
199
195
Perk memory perk = s_perks[perkId];
200
196
uint256 userTokenBalance = token.balanceOf (msg .sender );
201
197
if (userTokenBalance < perk.tokensRequired) {
202
- revert KiddoPerks__NotEnoughTokenBalance (
203
- perkId, msg .sender , perk.tokensRequired
204
- );
198
+ revert KiddoPerks__NotEnoughTokenBalance (perkId, msg .sender , perk.tokensRequired);
205
199
}
206
200
if (s_perksRedeemedBy[perkId][msg .sender ]) {
207
201
revert KiddoPerks__PerkAlreadyRedeemmed (perkId, msg .sender );
208
202
}
209
203
210
- bool sent =
211
- token.transferFrom (msg .sender , address (this ), perk.tokensRequired);
204
+ bool sent = token.transferFrom (msg .sender , address (this ), perk.tokensRequired);
212
205
if (! sent) {
213
206
revert ("Error on token transfer " );
214
207
}
@@ -228,11 +221,15 @@ contract KiddoPerks is Ownable {
228
221
emit ChildAdded (name, childAddr);
229
222
}
230
223
231
- function childBy (uint256 id ) public view returns (Child memory ) {
224
+ function childBy (
225
+ uint256 id
226
+ ) public view returns (Child memory ) {
232
227
return s_children[id];
233
228
}
234
229
235
- function removeChild (uint256 id ) public onlyOwner {
230
+ function removeChild (
231
+ uint256 id
232
+ ) public onlyOwner {
236
233
if (id >= s_childrenNextId) {
237
234
revert KiddoPerks__NotValidId (id);
238
235
}
@@ -264,16 +261,15 @@ contract KiddoPerks is Ownable {
264
261
if (numTaskCompletedByChild >= MIN_TASK_COMPLETED_NFT) {
265
262
revert KiddoPerks__CannotMintAnyNFTYet (msg .sender );
266
263
}
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 ]);
271
265
}
272
266
273
267
/**
274
268
* Modifiers
275
269
*/
276
- modifier onlyValidChild (address childAddress ) {
270
+ modifier onlyValidChild (
271
+ address childAddress
272
+ ) {
277
273
if (s_validChildAddresses[childAddress] == false ) {
278
274
revert KiddoPerks__NoValidChild (childAddress);
279
275
}
0 commit comments