diff --git a/src/validations/index.ts b/src/validations/index.ts index ba48e05da..440609eae 100644 --- a/src/validations/index.ts +++ b/src/validations/index.ts @@ -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 }; diff --git a/src/validations/timeperiod/examples.json b/src/validations/timeperiod/examples.json new file mode 100644 index 000000000..02381e38e --- /dev/null +++ b/src/validations/timeperiod/examples.json @@ -0,0 +1,14 @@ +[ + { + "name": "Example of a prop entry time constrained validation", + "validation": { + "name": "timeperiod", + "params": { + "propEntryStart": 1659108444521, + "propEntryEnd": 1659194844521 + } + }, + "network": "1", + "userAddress": "" + } +] diff --git a/src/validations/timeperiod/index.ts b/src/validations/timeperiod/index.ts new file mode 100644 index 000000000..193ab54c7 --- /dev/null +++ b/src/validations/timeperiod/index.ts @@ -0,0 +1,27 @@ +export default async function validate( + author: string, + space, + proposal, + options +): Promise { + 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; +}