Skip to content

Commit

Permalink
[passport-gated]: update required parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
santteegt committed Oct 10, 2023
1 parent a6e305f commit 1585762
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/validations/passport-gated/examples.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
[
{
"name": "Example of a passport gated validation",
"author": "0x000000000000000000000000000000000000dead",
"space": "fabien.eth",
"network": "1",
"snapshot": "latest",
"params": {
"scoreThreshold": 0
},
"valid": true
},
{
"name": "Example of a passport gated validation",
"author": "0x24F15402C6Bb870554489b2fd2049A85d75B982f",
"space": "fabien.eth",
"network": "1",
"snapshot": "latest",
"params": {
"scoreThreshold": 20,
"stamps": ["Ens", "Github", "Snapshot"],
"operator": "OR"
},
Expand All @@ -18,9 +30,9 @@
"network": "1",
"snapshot": "latest",
"params": {
"scoreThreshold": 20,
"stamps": ["Ens", "Github", "Snapshot"],
"operator": "OR",
"scoreThreshold": 20
"operator": "OR"
},
"valid": false
}
Expand Down
6 changes: 4 additions & 2 deletions src/validations/passport-gated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ export default class extends Validation {
async validate(currentAddress = this.author): Promise<boolean> {
const requiredStamps = this.params.stamps || [];
const operator = this.params.operator;
const scoreThreshold = this.params.scoreThreshold || 0;
if (!operator) throw new Error('Operator is required');
const scoreThreshold = this.params.scoreThreshold;

if (scoreThreshold === undefined) throw new Error('Score threshold is required');
if (requiredStamps.length > 0 && !operator) throw new Error('Operator is required');

const provider = snapshot.utils.getProvider(this.network);
const proposalTs = (await provider.getBlock(this.snapshot)).timestamp;
Expand Down
2 changes: 1 addition & 1 deletion src/validations/passport-gated/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"default": 0
}
},
"required": ["stamps", "operator"],
"required": ["scoreThreshold"],
"additionalProperties": false
}
}
Expand Down

0 comments on commit 1585762

Please sign in to comment.