Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(passport-gated): stamps as optional parameter #4357

Merged
merged 11 commits into from
Nov 18, 2023
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