mirror of
https://github.com/status-im/community-dapp.git
synced 2025-02-23 19:48:27 +00:00
refactor(VotingContract): use more precise naming for mappings
This commit is contained in:
parent
5cc0f21e07
commit
f090cce552
@ -21,7 +21,7 @@ export function useProposeWarning(communityFound: CommunityDetail) {
|
|||||||
const [isCommunityUnderVote] = useContractCall({
|
const [isCommunityUnderVote] = useContractCall({
|
||||||
abi: votingContract.interface,
|
abi: votingContract.interface,
|
||||||
address: votingContract.address,
|
address: votingContract.address,
|
||||||
method: 'communityVotingId',
|
method: 'activeRoomIDByCommunityID',
|
||||||
args: [communityFound?.publicKey],
|
args: [communityFound?.publicKey],
|
||||||
}) ?? [undefined]
|
}) ?? [undefined]
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ contract VotingContract {
|
|||||||
IERC20 public token;
|
IERC20 public token;
|
||||||
|
|
||||||
VotingRoom[] public votingRooms;
|
VotingRoom[] public votingRooms;
|
||||||
mapping(bytes => uint256) public communityVotingId;
|
mapping(bytes => uint256) public activeRoomIDByCommunityID;
|
||||||
mapping(bytes => uint256[]) private communityVotingHistory;
|
mapping(bytes => uint256[]) private roomIDsByCommunityID;
|
||||||
mapping(uint256 => mapping(address => bool)) private voted;
|
mapping(uint256 => mapping(address => bool)) private voted;
|
||||||
|
|
||||||
bytes32 private constant EIP712DOMAIN_TYPEHASH =
|
bytes32 private constant EIP712DOMAIN_TYPEHASH =
|
||||||
@ -115,7 +115,7 @@ contract VotingContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCommunityVoting(bytes calldata publicKey) public view returns (VotingRoom memory) {
|
function getCommunityVoting(bytes calldata publicKey) public view returns (VotingRoom memory) {
|
||||||
return _getVotingRoom(communityVotingId[publicKey]);
|
return _getVotingRoom(activeRoomIDByCommunityID[publicKey]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActiveVotingRooms() public view returns (uint256[] memory) {
|
function getActiveVotingRooms() public view returns (uint256[] memory) {
|
||||||
@ -139,23 +139,23 @@ contract VotingContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCommunityHistory(bytes calldata publicKey) public view returns (VotingRoom[] memory returnVotingRooms) {
|
function getCommunityHistory(bytes calldata publicKey) public view returns (VotingRoom[] memory returnVotingRooms) {
|
||||||
returnVotingRooms = new VotingRoom[](communityVotingHistory[publicKey].length);
|
returnVotingRooms = new VotingRoom[](roomIDsByCommunityID[publicKey].length);
|
||||||
for (uint256 i = 0; i < communityVotingHistory[publicKey].length; i++) {
|
for (uint256 i = 0; i < roomIDsByCommunityID[publicKey].length; i++) {
|
||||||
returnVotingRooms[i] = _getVotingRoom(communityVotingHistory[publicKey][i]);
|
returnVotingRooms[i] = _getVotingRoom(roomIDsByCommunityID[publicKey][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeVotingRoom(VoteType voteType, bytes calldata publicKey, uint256 voteAmount) public {
|
function initializeVotingRoom(VoteType voteType, bytes calldata publicKey, uint256 voteAmount) public {
|
||||||
require(communityVotingId[publicKey] == 0, 'vote already ongoing');
|
require(activeRoomIDByCommunityID[publicKey] == 0, 'vote already ongoing');
|
||||||
if (voteType == VoteType.REMOVE) {
|
if (voteType == VoteType.REMOVE) {
|
||||||
require(directory.isCommunityInDirectory(publicKey), 'Community not in directory');
|
require(directory.isCommunityInDirectory(publicKey), 'Community not in directory');
|
||||||
}
|
}
|
||||||
if (voteType == VoteType.ADD) {
|
if (voteType == VoteType.ADD) {
|
||||||
require(!directory.isCommunityInDirectory(publicKey), 'Community already in directory');
|
require(!directory.isCommunityInDirectory(publicKey), 'Community already in directory');
|
||||||
}
|
}
|
||||||
uint256 historyLength = communityVotingHistory[publicKey].length;
|
uint256 historyLength = roomIDsByCommunityID[publicKey].length;
|
||||||
if (historyLength > 0) {
|
if (historyLength > 0) {
|
||||||
uint256 roomId = communityVotingHistory[publicKey][historyLength - 1];
|
uint256 roomId = roomIDsByCommunityID[publicKey][historyLength - 1];
|
||||||
require(
|
require(
|
||||||
block.timestamp.sub(_getVotingRoom(roomId).endAt) > TIME_BETWEEN_VOTING,
|
block.timestamp.sub(_getVotingRoom(roomId).endAt) > TIME_BETWEEN_VOTING,
|
||||||
'Community was in a vote recently'
|
'Community was in a vote recently'
|
||||||
@ -165,8 +165,8 @@ contract VotingContract {
|
|||||||
|
|
||||||
uint votingRoomID = votingRooms.length + 1;
|
uint votingRoomID = votingRooms.length + 1;
|
||||||
|
|
||||||
communityVotingId[publicKey] = votingRoomID;
|
activeRoomIDByCommunityID[publicKey] = votingRoomID;
|
||||||
communityVotingHistory[publicKey].push(votingRoomID);
|
roomIDsByCommunityID[publicKey].push(votingRoomID);
|
||||||
|
|
||||||
VotingRoom memory newVotingRoom;
|
VotingRoom memory newVotingRoom;
|
||||||
newVotingRoom.startBlock = block.number;
|
newVotingRoom.startBlock = block.number;
|
||||||
@ -191,7 +191,7 @@ contract VotingContract {
|
|||||||
|
|
||||||
votingRoom.finalized = true;
|
votingRoom.finalized = true;
|
||||||
votingRoom.endAt = block.timestamp;
|
votingRoom.endAt = block.timestamp;
|
||||||
communityVotingId[votingRoom.community] = 0;
|
activeRoomIDByCommunityID[votingRoom.community] = 0;
|
||||||
|
|
||||||
bool passed = votingRoom.totalVotesFor > votingRoom.totalVotesAgainst;
|
bool passed = votingRoom.totalVotesFor > votingRoom.totalVotesAgainst;
|
||||||
if (passed) {
|
if (passed) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user