-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timeperiod validation for proposal entries (#674)
* 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
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |