Skip to content

Commit

Permalink
questions: replace enum Question Status -> bool isActive
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Oct 13, 2024
1 parent c72230f commit 19eaa42
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/spaces/Space.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ contract Space is ISpace, Ownable {
title: question.title(),
description: question.description(),
deadline: question.deadline(),
status: question.getStatus(),
isActive: question.isActive(),
userHasVoted: question.hasVoted(user)
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/spaces/interfaces/ISpace.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import { IQuestion, QuestionStatus } from "../../voting/interfaces/IQuestion.sol";
import { IQuestion } from "../../voting/interfaces/IQuestion.sol";
import { IFollowerSinceStamp } from "../../stamps/interfaces/IFollowerSinceStamp.sol";
import { IFollowerSincePoints } from "../../points/interfaces/IFollowerSincePoints.sol";

Expand Down Expand Up @@ -136,7 +136,7 @@ interface ISpace {
string title;
string description;
uint256 deadline;
QuestionStatus status;
bool isActive;
bool userHasVoted;
}

Expand Down
14 changes: 5 additions & 9 deletions src/voting/Question.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IQuestion, QuestionStatus } from "./interfaces/IQuestion.sol";
import { IQuestion } from "./interfaces/IQuestion.sol";
import { IPoints } from "../points/interfaces/IPoints.sol";

/// @title Abstract Question Contract for Voting System
Expand All @@ -25,7 +25,7 @@ abstract contract Question is Ownable, IQuestion {

/// @dev Modifier to check if the voting is still active
modifier whileActive() {
if (block.timestamp >= deadline) revert VotingEnded();
if (!isActive()) revert VotingEnded();
_;
}

Expand Down Expand Up @@ -131,7 +131,7 @@ abstract contract Question is Ownable, IQuestion {
deadline: deadline,
totalVoteCount: totalVotes,
options: optionViews,
status: getStatus(),
isActive: isActive(),
owner: owner(),
started: deploymentTime,
userOptionVoted: userOptionVoted,
Expand All @@ -157,12 +157,8 @@ abstract contract Question is Ownable, IQuestion {
}

/// @inheritdoc IQuestion
function getStatus() public view returns (QuestionStatus) {
if (block.timestamp < deadline) {
return QuestionStatus.Active;
} else {
return QuestionStatus.Ended;
}
function isActive() public view returns (bool) {
return block.timestamp < deadline;
}

/// @inheritdoc IQuestion
Expand Down
16 changes: 4 additions & 12 deletions src/voting/interfaces/IQuestion.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ pragma solidity ^0.8.20;

import { IPoints } from "../../points/interfaces/IPoints.sol";

/// @dev Represents the current status of a question
enum QuestionStatus {
Null,
Active,
Ended
}

/// @title Question Interface for a Voting System
/// @dev Interface for managing questions in a voting system with various options and views
interface IQuestion {
// Enums

/// @dev Defines the type of question
enum QuestionType {
Null,
Expand All @@ -38,7 +30,7 @@ interface IQuestion {
uint256 deadline; // The voting deadline, can be updated with Question.updateDeadline()
uint256 totalVoteCount; // The total number of votes across all options, calculated in Question.getQuestionView()
OptionView[] options; // Array of all voting options with their details, populated in Question.getQuestionView()
QuestionStatus status; // The current status of the question (Null, Active, or Ended), determined by Question.getStatus()
bool isActive; // Whether the question is currently active, determined by Question.isActive()
address owner; // The owner of the question contract, set in the constructor and managed by Ownable
uint256 started; // The timestamp when the question was deployed, set in the Question constructor
uint256 userOptionVoted; // The option ID the user voted for (0 if not voted), set in Question.getQuestionView()
Expand Down Expand Up @@ -135,9 +127,9 @@ interface IQuestion {
function getQuestionView(address user) external view returns (QuestionView memory);

// Public functions
/// @notice Get the current status of the question
/// @return The current QuestionStatus of the question
function getStatus() external view returns (QuestionStatus);
/// @notice Check if the question is currently active
/// @return True if the question is active, false otherwise
function isActive() external view returns (bool);

/// @notice Check if a specific user has voted for a specific option
/// @param voter The address of the voter to check
Expand Down

0 comments on commit 19eaa42

Please sign in to comment.