Skip to content

Commit

Permalink
Add timeperiod validation for proposal entries (#674)
Browse files Browse the repository at this point in the history
* Add timeperiod validation for proposal entries

Signed-off-by: Steve Finkelstein <[email protected]>

* Add timeperiod space validation to index export

Signed-off-by: Steve Finkelstein <[email protected]>

Co-authored-by: mkt <[email protected]>
  • Loading branch information
stevef and mktcode authored Aug 9, 2022
1 parent b8aa4d2 commit 055f636
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/validations/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import basic from './basic';
import aaveSpaceValidation from './aave';
import nounsSpaceValidation from './nouns';
import timeperiodSpaceValidation from './timeperiod';

export default {
basic,
aave: aaveSpaceValidation,
nouns: nounsSpaceValidation
nouns: nounsSpaceValidation,
timeperiod: timeperiodSpaceValidation
};
14 changes: 14 additions & 0 deletions src/validations/timeperiod/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "Example of a prop entry time constrained validation",
"validation": {
"name": "timeperiod",
"params": {
"propEntryStart": 1659108444521,
"propEntryEnd": 1659194844521
}
},
"network": "1",
"userAddress": ""
}
]
27 changes: 27 additions & 0 deletions src/validations/timeperiod/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default async function validate(
author: string,
space,
proposal,
options
): Promise<boolean> {
const onlyMembers = options.onlyMembers || space.filters?.onlyMembers;
const members = (space.members || []).map((address) => address.toLowerCase());
const {propEntryStart = 0, propEntryEnd = 0} = options;

if (!propEntryStart || !propEntryEnd || (propEntryStart >= propEntryEnd)) return false;

if (members.includes(author.toLowerCase())) return true;

if (onlyMembers) return false;

const now = new Date().getTime();
const startTime = new Date(propEntryStart).getTime();
const endTime = new Date(propEntryEnd).getTime();

// Only allow proposals being submitted in this time window.
if (now >= startTime && now <= endTime) {
return true;
}

return false;
}

0 comments on commit 055f636

Please sign in to comment.