Skip to content

Commit 0aaf2e7

Browse files
authored
fix refreshTopSuggestions (#709)
* fix refreshTopSuggestions * bump version
1 parent 2825e16 commit 0aaf2e7

File tree

4 files changed

+280
-244
lines changed

4 files changed

+280
-244
lines changed

contracts/schemes/Competition.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,22 @@ contract Competition {
317317
* @param _proposalId proposal id
318318
* @param _suggestionId suggestion id
319319
*/
320+
// solhint-disable-next-line code-complexity
320321
function refreshTopSuggestions(bytes32 _proposalId, uint256 _suggestionId) private {
321322
uint256[] storage topSuggestions = proposals[_proposalId].topSuggestions;
322-
if (topSuggestions.length < proposals[_proposalId].numberOfWinners) {
323+
uint256 topSuggestionsLength = topSuggestions.length;
324+
uint256 i;
325+
if (topSuggestionsLength < proposals[_proposalId].numberOfWinners) {
326+
for (i = 0; i < topSuggestionsLength; i++) {
327+
if (topSuggestions[i] == _suggestionId) {
328+
return;
329+
}
330+
}
323331
topSuggestions.push(_suggestionId);
324332
} else {
325333
/** get the index of the smallest element **/
326334
uint256 smallest = 0;
327-
for (uint256 i; i < proposals[_proposalId].numberOfWinners; i++) {
335+
for (i = 0; i < proposals[_proposalId].numberOfWinners; i++) {
328336
if (suggestions[topSuggestions[i]].totalVotes <
329337
suggestions[topSuggestions[smallest]].totalVotes) {
330338
smallest = i;

0 commit comments

Comments
 (0)