Skip to content

Commit

Permalink
feat(passport-gated): stamps as optional parameter (#4357)
Browse files Browse the repository at this point in the history
* feat(passport-gated): stamps as optional parameter

* fix: Operator

* Fixes

* Fix messaged

* Fix message

* Fix message

* If no stamps default to none as operator

---------

Co-authored-by: Santiago Gonzalez <[email protected]>
Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2023
1 parent 3a684fd commit 5bcf00f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 18 deletions.
19 changes: 13 additions & 6 deletions src/components/MessageWarningValidation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ const tPath = computed(() => {
</BaseLink>
</template>

<template v-else-if="validationName === 'passport-gated'">
<template v-if="validationName === 'passport-gated'">
<template v-if="validationName === 'passport-gated'">
{{
$t(`${tPath}.passport-gated.invalidMessage`, {
scoreThreshold: validationParams?.scoreThreshold || 0
})
}}<span v-if="props.validationParams?.operator === 'NONE'">. </span>

<template v-else>
{{
$t(`${tPath}.passport-gated.invalidMessage`, {
operator: validationParams?.operator === 'AND' ? 'all' : 'one',
stamps: validationParams?.stamps.join(', '),
scoreThreshold: validationParams?.scoreThreshold || 0
$t(`${tPath}.passport-gated.invalidMessageStamps`, {
operator:
props.validationParams?.operator === 'AND' ? 'all' : 'one',
stamps:
validationParams.stamps && validationParams.stamps.join(', ')
})
}}
</template>
Expand Down
33 changes: 28 additions & 5 deletions src/components/ModalValidation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,23 @@ type Validations = Record<
>;
const validationDefinition = computed(() => {
return (
const definition =
validations.value?.[input.value.name]?.schema?.definitions?.Validation ||
null
);
null;
if (input.value.name === 'passport-gated')
return definePassportGated(clone(definition));
return definition;
});
function definePassportGated(definition: any) {
if (input.value.params.operator === 'NONE')
delete definition.properties.stamps;
return definition;
}
const validationErrors = computed(() => {
return validateForm(validationDefinition.value || {}, input.value.params);
});
Expand Down Expand Up @@ -75,12 +86,14 @@ function handleSelect(n: string) {
}
}
if (n === 'passport-gated' && !input.value.params.operator) {
input.value.params.operator = 'OR';
if (n === 'passport-gated') {
if (!input.value.params.operator) input.value.params.operator = 'NONE';
}
}
function handleSubmit() {
if (input.value.name === 'passport-gated') handlePassportGated();
if (!isValid.value || !isValidParams.value) {
strategiesFormRef.value?.forceShowError();
formRef?.value?.forceShowError();
Expand All @@ -91,6 +104,16 @@ function handleSubmit() {
emit('close');
}
function handlePassportGated() {
if (!input.value.params.stamps?.[0]) {
input.value.params.stamps = undefined;
input.value.params.operator = 'NONE';
}
if (input.value.params.operator === 'NONE') {
input.value.params.stamps = undefined;
}
}
function removeVoteValidationOnly(validations: Validations) {
Object.keys(validations).forEach(key => {
if (validations[key]?.voteValidationOnly) {
Expand Down
33 changes: 28 additions & 5 deletions src/components/ModalVoteValidation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ const isValidationsLoaded = ref(false);
const updateIndex = ref(0);
const validationDefinition = computed(() => {
return (
const definition =
validations.value?.[input.value.name]?.schema?.definitions?.Validation ||
null
);
null;
if (input.value.name === 'passport-gated')
return definePassportGated(clone(definition));
return definition;
});
function definePassportGated(definition: any) {
if (input.value.params.operator === 'NONE')
delete definition.properties.stamps;
return definition;
}
const validationErrors = computed(() => {
return validateForm(validationDefinition.value || {}, input.value.params);
});
Expand All @@ -73,12 +84,14 @@ function select(n: string) {
}
}
if (n === 'passport-gated' && !input.value.params.operator) {
input.value.params.operator = 'OR';
if (n === 'passport-gated') {
if (!input.value.params.operator) input.value.params.operator = 'NONE';
}
}
function handleSubmit() {
if (input.value.name === 'passport-gated') handlePassportGatedNoneOperator();
if (!isValid.value || !isValidParams.value) {
strategiesFormRef.value?.forceShowError();
formRef?.value?.forceShowError();
Expand All @@ -89,6 +102,16 @@ function handleSubmit() {
emit('close');
}
function handlePassportGatedNoneOperator() {
if (!input.value.params.stamps?.[0]) {
input.value.params.stamps = undefined;
input.value.params.operator = 'NONE';
}
if (input.value.params.operator === 'NONE') {
input.value.params.stamps = undefined;
}
}
function removeProposalValidationOnly(validations: Validations) {
Object.keys(validations).forEach(key => {
if (validations[key]?.proposalValidationOnly) {
Expand Down
6 changes: 4 additions & 2 deletions src/locales/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@
"passport-gated": {
"label": "Gitcoin Passport gated",
"description": "Protect your space from spam by requiring users to have a Gitcoin Passport to create a proposal.",
"invalidMessage": "You need a Gitcoin Passport with score above {scoreThreshold} and {operator} of the following stamps to vote on this proposal: {stamps}. "
"invalidMessage": "You need a Gitcoin Passport with score above {scoreThreshold}",
"invalidMessageStamps": " and {operator} of the following stamps to create a proposal: {stamps} "
},
"arbitrum": {
"label": "Arbitrum DAO votable supply",
Expand Down Expand Up @@ -782,7 +783,8 @@
"passport-gated": {
"label": "Gitcoin Passport gated",
"description": "Protect your proposals from spam and vote manipulation by requiring users to have a Gitcoin Passport.",
"invalidMessage": "You need a Gitcoin Passport with score above {scoreThreshold} and {operator} of the following stamps to vote on this proposal: {stamps}. "
"invalidMessage": "You need a Gitcoin Passport with score above {scoreThreshold}",
"invalidMessageStamps": " and {operator} of the following stamps to vote on this proposal: {stamps} "
}
},
"safeSnap": {
Expand Down

1 comment on commit 5bcf00f

@vercel
Copy link

@vercel vercel bot commented on 5bcf00f Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.