Skip to content

Commit

Permalink
feat: allow creation of offchain proposals with weighted voting type
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Mar 14, 2024
1 parent 9b03f8b commit 7292c7c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apps/ui/src/components/EditorVotingType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const VOTING_TYPES_INFO = computed(() => ({
approval: {
label: 'Approval voting',
description: 'Voters can select multiple choices, each choice receiving full voting power.'
},
weighted: {
label: 'Weighted voting',
description: 'Each voter may spread voting power across any number of choices.'
}
}));
Expand Down
29 changes: 29 additions & 0 deletions apps/ui/src/components/ProposalVoteWeighted.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
import { Choice, Proposal } from '@/types';
defineProps<{
sendingType: Choice | null;
proposal: Proposal;
}>();
// const emit = defineEmits<{
// (e: 'vote', value: Choice);
// }>();
</script>

<template>
<div class="flex flex-col space-y-3">
<div class="flex flex-col space-y-2">
<UiButton
v-for="(choice, index) in proposal.choices"
:key="index"
class="!h-[48px] text-left w-full flex items-center"
>
<div class="grow truncate">
{{ choice }}
</div>
</UiButton>
</div>
<UiButton primary class="!h-[48px] w-full" :loading="!!sendingType"> Vote </UiButton>
</div>
</template>
7 changes: 6 additions & 1 deletion apps/ui/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export const COINGECKO_BASE_ASSETS = {

export const MAX_SYMBOL_LENGTH = 12;
export const BASIC_CHOICES = ['For', 'Against', 'Abstain'];
export const SUPPORTED_VOTING_TYPES: VoteType[] = ['basic', 'single-choice', 'approval'] as const;
export const SUPPORTED_VOTING_TYPES: VoteType[] = [
'basic',
'single-choice',
'approval',
'weighted'
] as const;
2 changes: 1 addition & 1 deletion apps/ui/src/networks/offchain/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const EDITOR_PROPOSAL_VALIDATION_VOTING_STRATEGIES = [];
export const EDITOR_EXECUTION_STRATEGIES = [];
export const EDITOR_SNAPSHOT_OFFSET = 4;
export const EDITOR_APP_NAME = 'snapshot-v2';
export const EDITOR_VOTING_TYPES = ['basic', 'single-choice', 'approval'];
export const EDITOR_VOTING_TYPES = ['basic', 'single-choice', 'approval', 'weighted'];

export const DEFAULT_VOTING_DELAY = 60 * 60 * 24 * 7;
6 changes: 6 additions & 0 deletions apps/ui/src/views/Proposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ watchEffect(() => {
:sending-type="sendingType"
@vote="handleVoteClick"
/>
<ProposalVoteWeighted
v-else-if="proposal.type === 'weighted'"
:proposal="proposal"
:sending-type="sendingType"
@vote="handleVoteClick"
/>
</ProposalVote>
</template>

Expand Down

0 comments on commit 7292c7c

Please sign in to comment.