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: Show hints on proposal editor to get verified or to get turbo #773

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/ui/src/components/TurboMessage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { TURBO_URL } from '@/helpers/turbo';

defineProps<{
text: string;
}>();
</script>

<template>
<div
class="flex items-center gap-2 mb-3 border bg-purple-300/20 border-purple-300 text-purple-400 rounded-lg px-3 py-2"
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved
>
<IH-fire class="shrink-0" />
<div class="leading-6">
{{ text }}
<a
:href="TURBO_URL"
target="_blank"
class="text-purple-400 underline font-semibold"
>Turbo</a
>.
</div>
</div>
</template>
22 changes: 22 additions & 0 deletions apps/ui/src/helpers/turbo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const MAX_BODY_LENGTH = {
default: 10000,
turbo: 40000
};

export const MAX_CHOICES = {
default: 500,
Copy link
Member

Choose a reason for hiding this comment

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

Can you change default to be 10 for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? to test?
try running this in the console

for (let i = 0; i < 500; i++) {
  document.querySelector(".static .s-base.mb-5 button.rounded-full.border.button.text-skin-link.bg-skin-bg.w-full.flex.items-center.justify-center.space-x-1").click();
}

turbo: 1000
};

export const MAX_1D_PROPOSALS = {
default: 20,
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved
turbo: 40
};

export const MAX_7D_PROPOSALS = {
default: 100,
turbo: 200
};

export const TURBO_URL =
'https://docs.snapshot.org/user-guides/spaces/turbo-plan';
4 changes: 3 additions & 1 deletion apps/ui/src/helpers/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ const getErrors = (errors: Partial<ErrorObject>[]) => {
let current = output;
for (let i = 0; i < path.length - 1; i++) {
const subpath = path[i];
if (!current[subpath]) current[subpath] = {};
if (typeof current[subpath] !== 'object' || current[subpath] === null) {
current[subpath] = {};
}
current = current[subpath];
}

Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/networks/offchain/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ function formatSpace(
discord: '',
coingecko: space.coingecko || '',
proposal_count: space.proposalsCount,
proposal_count_1d: space.proposalsCount1d,
proposal_count_7d: space.proposalsCount7d,
vote_count: space.votesCount,
follower_count: space.followersCount,
voting_power_symbol: space.symbol,
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/networks/offchain/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const SPACE_FRAGMENT = gql`
onlyMembers
}
proposalsCount
proposalsCount1d
proposalsCount7d
votesCount
followersCount
children {
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/networks/offchain/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export type ApiSpace = {
onlyMembers: boolean;
};
proposalsCount: number;
proposalsCount1d: number;
proposalsCount7d: number;
votesCount: number;
followersCount: number;
children: [ApiRelatedSpace];
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export type Space = {
treasury_chain: number | null;
}[];
proposal_count: number;
proposal_count_1d?: number;
proposal_count_7d?: number;
vote_count: number;
follower_count?: number;
created: number;
Expand Down
57 changes: 40 additions & 17 deletions apps/ui/src/views/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
import { NavigationGuard } from 'vue-router';
import { StrategyWithTreasury } from '@/composables/useTreasuries';
import { resolver } from '@/helpers/resolver';
import { omit } from '@/helpers/utils';
import {
MAX_1D_PROPOSALS,
MAX_7D_PROPOSALS,
MAX_BODY_LENGTH,
MAX_CHOICES
} from '@/helpers/turbo';
import { _n, omit } from '@/helpers/utils';
import { validateForm } from '@/helpers/validation';
import { getNetwork, offchainNetworks } from '@/networks';
import { Contact, Transaction, VoteType } from '@/types';

const MAX_BODY_LENGTH = {
default: 10000,
turbo: 40000
} as const;

const TITLE_DEFINITION = {
type: 'string',
title: 'Title',
Expand All @@ -27,15 +28,6 @@ const DISCUSSION_DEFINITION = {
examples: ['e.g. https://forum.balancer.fi/t/proposal…']
};

const CHOICES_DEFINITION = {
type: 'array',
title: 'Choices',
minItems: 1,
maxItems: 500,
items: [{ type: 'string', minLength: 1, maxLength: 32 }],
additionalItems: { type: 'string', maxLength: 32 }
};

const { setTitle } = useTitle();
const { proposals, createDraft } = useEditor();
const { param } = useRouteParser('id');
Expand Down Expand Up @@ -134,6 +126,15 @@ const bodyDefinition = computed(() => ({
maxLength: MAX_BODY_LENGTH[space.value?.turbo ? 'turbo' : 'default'],
examples: ['Propose something…']
}));

const choicesDefinition = computed(() => ({
type: 'array',
title: 'Choices',
minItems: 1,
maxItems: MAX_CHOICES[space.value?.turbo ? 'turbo' : 'default'],
items: [{ type: 'string', minLength: 1, maxLength: 32 }],
additionalItems: { type: 'string', maxLength: 32 }
}));
const formErrors = computed(() => {
if (!proposal.value) return {};

Expand All @@ -147,7 +148,7 @@ const formErrors = computed(() => {
title: TITLE_DEFINITION,
body: bodyDefinition.value,
discussion: DISCUSSION_DEFINITION,
choices: CHOICES_DEFINITION
choices: choicesDefinition.value
}
},
{
Expand All @@ -169,6 +170,15 @@ const canSubmit = computed(() => {
: !web3.value.authLoading;
});

const isProposalLimitReached = computed(() => {
if (!space.value) return false;

return (
(space.value.proposal_count_1d || 0) >= MAX_1D_PROPOSALS.default ||
(space.value.proposal_count_7d || 0) >= MAX_7D_PROPOSALS.default
);
});

async function handleProposeClick() {
if (!space.value || !proposal.value) return;

Expand Down Expand Up @@ -384,6 +394,10 @@ export default defineComponent({
action="propose"
@fetch-voting-power="handleFetchVotingPower"
/>
<TurboMessage
v-if="!space?.turbo && isProposalLimitReached"
:text="`Post up to ${MAX_1D_PROPOSALS.turbo} proposals daily and ${MAX_7D_PROPOSALS.turbo} monthly with`"
/>

<UiInputString
:key="proposalKey || ''"
Expand Down Expand Up @@ -418,6 +432,11 @@ export default defineComponent({
:definition="bodyDefinition"
:error="formErrors.body"
/>
<TurboMessage
v-if="!space?.turbo && proposal.body.length > MAX_BODY_LENGTH.default"
:text="`Write up to ${_n(MAX_BODY_LENGTH.turbo, 'compact')} characters content with`"
/>

<div class="s-base mb-5">
<UiInputString
:key="proposalKey || ''"
Expand Down Expand Up @@ -467,7 +486,11 @@ export default defineComponent({
enforcedVoteType ? [enforcedVoteType] : space.voting_types
"
/>
<EditorChoices v-model="proposal" :definition="CHOICES_DEFINITION" />
<EditorChoices v-model="proposal" :definition="choicesDefinition" />
<TurboMessage
v-if="!space?.turbo && proposal.choices.length > MAX_CHOICES.default"
:text="`Add up to ${_n(MAX_CHOICES.turbo, 'compact')} choices with`"
/>
<div>
<h4 class="eyebrow mb-2.5" v-text="'Timeline'" />
<ProposalTimeline :data="space" />
Expand Down
Loading