From 81ff275079ff64a8c4411cf274cb44bd41f1f341 Mon Sep 17 00:00:00 2001 From: ChaituVR Date: Mon, 16 Sep 2024 17:25:35 +0530 Subject: [PATCH 1/6] feat: Show hints for turbo --- apps/ui/src/components/TurboMessage.vue | 20 ++++++++ apps/ui/src/helpers/turbo.ts | 22 +++++++++ apps/ui/src/helpers/validation.ts | 4 +- apps/ui/src/networks/offchain/api/index.ts | 2 + apps/ui/src/networks/offchain/api/queries.ts | 2 + apps/ui/src/networks/offchain/api/types.ts | 2 + apps/ui/src/types.ts | 2 + apps/ui/src/views/Editor.vue | 52 +++++++++++++------- 8 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 apps/ui/src/components/TurboMessage.vue create mode 100644 apps/ui/src/helpers/turbo.ts diff --git a/apps/ui/src/components/TurboMessage.vue b/apps/ui/src/components/TurboMessage.vue new file mode 100644 index 000000000..770fc691f --- /dev/null +++ b/apps/ui/src/components/TurboMessage.vue @@ -0,0 +1,20 @@ + + + diff --git a/apps/ui/src/helpers/turbo.ts b/apps/ui/src/helpers/turbo.ts new file mode 100644 index 000000000..db5332d38 --- /dev/null +++ b/apps/ui/src/helpers/turbo.ts @@ -0,0 +1,22 @@ +export const MAX_BODY_LENGTH = { + default: 10000, + turbo: 40000 +} as const; + +export const MAX_CHOICES = { + default: 500, + turbo: 1000 +}; + +export const MAX_1D_PROPOSALS = { + default: 20, + turbo: 40 +}; + +export const MAX_7D_PROPOSALS = { + default: 100, + turbo: 200 +}; + +export const TURBO_URL = + 'https://docs.snapshot.org/user-guides/spaces/turbo-plan'; diff --git a/apps/ui/src/helpers/validation.ts b/apps/ui/src/helpers/validation.ts index b53764b29..c084a6aa2 100644 --- a/apps/ui/src/helpers/validation.ts +++ b/apps/ui/src/helpers/validation.ts @@ -296,7 +296,9 @@ const getErrors = (errors: Partial[]) => { 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]; } diff --git a/apps/ui/src/networks/offchain/api/index.ts b/apps/ui/src/networks/offchain/api/index.ts index 208e59967..cf043ee51 100644 --- a/apps/ui/src/networks/offchain/api/index.ts +++ b/apps/ui/src/networks/offchain/api/index.ts @@ -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, diff --git a/apps/ui/src/networks/offchain/api/queries.ts b/apps/ui/src/networks/offchain/api/queries.ts index 6943058a4..f4c235332 100644 --- a/apps/ui/src/networks/offchain/api/queries.ts +++ b/apps/ui/src/networks/offchain/api/queries.ts @@ -51,6 +51,8 @@ const SPACE_FRAGMENT = gql` onlyMembers } proposalsCount + proposalsCount1d + proposalsCount7d votesCount followersCount children { diff --git a/apps/ui/src/networks/offchain/api/types.ts b/apps/ui/src/networks/offchain/api/types.ts index c1da7aca3..865e9c3f1 100644 --- a/apps/ui/src/networks/offchain/api/types.ts +++ b/apps/ui/src/networks/offchain/api/types.ts @@ -58,6 +58,8 @@ export type ApiSpace = { onlyMembers: boolean; }; proposalsCount: number; + proposalsCount1d: number; + proposalsCount7d: number; votesCount: number; followersCount: number; children: [ApiRelatedSpace]; diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts index 461755e6b..aa148b471 100644 --- a/apps/ui/src/types.ts +++ b/apps/ui/src/types.ts @@ -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; diff --git a/apps/ui/src/views/Editor.vue b/apps/ui/src/views/Editor.vue index 6f377736a..e8360f69a 100644 --- a/apps/ui/src/views/Editor.vue +++ b/apps/ui/src/views/Editor.vue @@ -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', @@ -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'); @@ -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 {}; @@ -147,7 +148,7 @@ const formErrors = computed(() => { title: TITLE_DEFINITION, body: bodyDefinition.value, discussion: DISCUSSION_DEFINITION, - choices: CHOICES_DEFINITION + choices: choicesDefinition.value } }, { @@ -384,6 +385,14 @@ export default defineComponent({ action="propose" @fetch-voting-power="handleFetchVotingPower" /> + + +
- + +

From b81ffc89a298d68732eb16f1ea1010cc244b8b2f Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 16 Sep 2024 17:30:02 +0530 Subject: [PATCH 2/6] Update turbo.ts --- apps/ui/src/helpers/turbo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ui/src/helpers/turbo.ts b/apps/ui/src/helpers/turbo.ts index db5332d38..18869ff99 100644 --- a/apps/ui/src/helpers/turbo.ts +++ b/apps/ui/src/helpers/turbo.ts @@ -1,7 +1,7 @@ export const MAX_BODY_LENGTH = { default: 10000, turbo: 40000 -} as const; +}; export const MAX_CHOICES = { default: 500, From 0a158316358f9d8d5b7b7e897f227bf1cd6c0fce Mon Sep 17 00:00:00 2001 From: ChaituVR Date: Mon, 16 Sep 2024 17:54:32 +0530 Subject: [PATCH 3/6] Refactor --- apps/ui/src/types.ts | 4 ++-- apps/ui/src/views/Editor.vue | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts index aa148b471..db0509263 100644 --- a/apps/ui/src/types.ts +++ b/apps/ui/src/types.ts @@ -189,8 +189,8 @@ export type Space = { treasury_chain: number | null; }[]; proposal_count: number; - proposal_count_1d: number; - proposal_count_7d: number; + proposal_count_1d?: number; + proposal_count_7d?: number; vote_count: number; follower_count?: number; created: number; diff --git a/apps/ui/src/views/Editor.vue b/apps/ui/src/views/Editor.vue index e8360f69a..3892486eb 100644 --- a/apps/ui/src/views/Editor.vue +++ b/apps/ui/src/views/Editor.vue @@ -170,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; @@ -386,11 +395,7 @@ export default defineComponent({ @fetch-voting-power="handleFetchVotingPower" /> From 6a337d141b2c4ce05241e5a9401e781dc8f4a0e4 Mon Sep 17 00:00:00 2001 From: ChaituVR Date: Mon, 16 Sep 2024 20:03:02 +0530 Subject: [PATCH 4/6] fix alignments of turbo hint message --- apps/ui/src/components/TurboMessage.vue | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/ui/src/components/TurboMessage.vue b/apps/ui/src/components/TurboMessage.vue index 770fc691f..bf0a4e85c 100644 --- a/apps/ui/src/components/TurboMessage.vue +++ b/apps/ui/src/components/TurboMessage.vue @@ -1,5 +1,6 @@ + + diff --git a/apps/ui/src/components/TurboMessage.vue b/apps/ui/src/components/TurboMessage.vue deleted file mode 100644 index bf0a4e85c..000000000 --- a/apps/ui/src/components/TurboMessage.vue +++ /dev/null @@ -1,24 +0,0 @@ - - - diff --git a/apps/ui/src/helpers/turbo.ts b/apps/ui/src/helpers/turbo.ts index 18869ff99..b096b7f49 100644 --- a/apps/ui/src/helpers/turbo.ts +++ b/apps/ui/src/helpers/turbo.ts @@ -9,14 +9,18 @@ export const MAX_CHOICES = { }; export const MAX_1D_PROPOSALS = { - default: 20, + default: 3, + verified: 20, turbo: 40 }; -export const MAX_7D_PROPOSALS = { - default: 100, +export const MAX_30D_PROPOSALS = { + default: 15, + verified: 100, turbo: 200 }; export const TURBO_URL = 'https://docs.snapshot.org/user-guides/spaces/turbo-plan'; +export const VERIFIED_URL = + 'https://docs.snapshot.org/user-guides/spaces/get-verified'; diff --git a/apps/ui/src/networks/offchain/api/index.ts b/apps/ui/src/networks/offchain/api/index.ts index ed172b932..4e7fb770b 100644 --- a/apps/ui/src/networks/offchain/api/index.ts +++ b/apps/ui/src/networks/offchain/api/index.ts @@ -181,6 +181,7 @@ function formatSpace( proposal_count: space.proposalsCount, proposal_count_1d: space.proposalsCount1d, proposal_count_7d: space.proposalsCount7d, + proposal_count_30d: space.proposalsCount30d, vote_count: space.votesCount, follower_count: space.followersCount, voting_power_symbol: space.symbol, diff --git a/apps/ui/src/networks/offchain/api/queries.ts b/apps/ui/src/networks/offchain/api/queries.ts index f4c235332..30a9d9915 100644 --- a/apps/ui/src/networks/offchain/api/queries.ts +++ b/apps/ui/src/networks/offchain/api/queries.ts @@ -53,6 +53,7 @@ const SPACE_FRAGMENT = gql` proposalsCount proposalsCount1d proposalsCount7d + proposalsCount30d votesCount followersCount children { diff --git a/apps/ui/src/networks/offchain/api/types.ts b/apps/ui/src/networks/offchain/api/types.ts index 865e9c3f1..d37bcae57 100644 --- a/apps/ui/src/networks/offchain/api/types.ts +++ b/apps/ui/src/networks/offchain/api/types.ts @@ -60,6 +60,7 @@ export type ApiSpace = { proposalsCount: number; proposalsCount1d: number; proposalsCount7d: number; + proposalsCount30d: number; votesCount: number; followersCount: number; children: [ApiRelatedSpace]; diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts index a96b18cd4..2d8e7535e 100644 --- a/apps/ui/src/types.ts +++ b/apps/ui/src/types.ts @@ -191,6 +191,7 @@ export type Space = { proposal_count: number; proposal_count_1d?: number; proposal_count_7d?: number; + proposal_count_30d?: number; vote_count: number; follower_count?: number; created: number; diff --git a/apps/ui/src/views/Editor.vue b/apps/ui/src/views/Editor.vue index 7c08209ca..2e0cce4d8 100644 --- a/apps/ui/src/views/Editor.vue +++ b/apps/ui/src/views/Editor.vue @@ -4,7 +4,7 @@ import { StrategyWithTreasury } from '@/composables/useTreasuries'; import { resolver } from '@/helpers/resolver'; import { MAX_1D_PROPOSALS, - MAX_7D_PROPOSALS, + MAX_30D_PROPOSALS, MAX_BODY_LENGTH, MAX_CHOICES } from '@/helpers/turbo'; @@ -170,12 +170,20 @@ const canSubmit = computed(() => { : !web3.value.authLoading; }); -const isProposalLimitReached = computed(() => { - if (!space.value) return false; +const spaceType = computed(() => { + if (!space.value) return 'default'; + return space.value.turbo + ? 'turbo' + : space.value.verified + ? 'verified' + : 'default'; +}); +const proposalLimitReached = 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 + (space.value.proposal_count_1d || 0) >= MAX_1D_PROPOSALS[spaceType.value] || + (space.value.proposal_count_30d || 0) >= MAX_30D_PROPOSALS[spaceType.value] ); }); @@ -394,9 +402,14 @@ export default defineComponent({ action="propose" @fetch-voting-power="handleFetchVotingPower" /> - + -
@@ -487,9 +500,9 @@ export default defineComponent({ " /> -

From cce78bb587f71b41cf16be7ef1e98a5c424fb6fe Mon Sep 17 00:00:00 2001 From: ChaituVR Date: Fri, 20 Sep 2024 11:55:36 +0530 Subject: [PATCH 6/6] refactor --- apps/ui/src/components/EditorHint.vue | 15 +++++---------- apps/ui/src/views/Editor.vue | 5 ++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/ui/src/components/EditorHint.vue b/apps/ui/src/components/EditorHint.vue index 204c822f6..51dab57da 100644 --- a/apps/ui/src/components/EditorHint.vue +++ b/apps/ui/src/components/EditorHint.vue @@ -1,15 +1,10 @@