-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add single choice and approval voting type (#46)
* fix: show voting buttons for offchain proposals * refactor: move the network actions to actions.ts * feat: add support for basic voting for offchain proposals * fix: fix invalid import type * fix: use correct sequencer network depending on chainId * chore: add tests * Update packages/sx.js/src/clients/offchain/ethereum-sig/index.ts Co-authored-by: Wiktor Tkaczyński <[email protected]> * refactor: use same function order definition as other networks * fix: handle offchain receipt without tx_hash * fix: fix typing * fix: throw error on sequencer error response * chore: add unit test * chore: fix tests * fix: show voting form only for supported voting type * chore: remove cumbersome describe block * fix: switch to correct chain for offchain actions * fix: avoid changing type * chore: improve test * fix: revert network enforcer * fix: remove unused import * refactor: rename voteType * refactor: rename type * feat: add support for single choice voting * fix: remove redundant tooltip * feat: add support for approval voting * chore: fix tests * refactor: extract list to constant * chore: update changeset * fix: UI fix * Update .changeset/chilly-avocados-teach.md Co-authored-by: Wiktor Tkaczyński <[email protected]> * Update apps/ui/src/networks/offchain/helpers.ts Co-authored-by: Wiktor Tkaczyński <[email protected]> * fix: fix missing parenthesis * fix: fix botched merged * refactor: extract vote form into their own component * refactor: add more type to Choice * fix(ui): fix glitched focus ring * fix(ui): remove unused class * fix(ui): DRY class * fix: fix Choice type * Update packages/sx.js/src/clients/starknet/starknet-tx/index.ts Co-authored-by: Wiktor Tkaczyński <[email protected]> * refactor: rename events name * refactor: improve event naming * fix: tentative type fix --------- Co-authored-by: Wiktor Tkaczyński <[email protected]>
- Loading branch information
Showing
17 changed files
with
210 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@snapshot-labs/sx": patch | ||
--- | ||
|
||
add approval and single choice vote support to OffchainEthereumSig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script setup lang="ts"> | ||
import { Choice, Proposal } from '@/types'; | ||
defineProps<{ | ||
sendingType: Choice | null; | ||
proposal: Proposal; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(e: 'vote', value: Choice); | ||
}>(); | ||
const selectedChoices = ref<number[]>([]); | ||
function toggleSelectedChoice(choice: number) { | ||
if (selectedChoices.value.includes(choice)) { | ||
selectedChoices.value = selectedChoices.value.filter(c => c !== choice); | ||
} else { | ||
selectedChoices.value = [...selectedChoices.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" | ||
:class="{ 'border-skin-text': selectedChoices.includes(index + 1) }" | ||
@click="toggleSelectedChoice(index + 1)" | ||
> | ||
<div class="grow truncate"> | ||
{{ choice }} | ||
</div> | ||
<IH-check v-if="selectedChoices.includes(index + 1)" class="shrink-0" /> | ||
</UiButton> | ||
</div> | ||
<UiButton | ||
primary | ||
class="!h-[48px] w-full" | ||
:loading="!!sendingType" | ||
@click="emit('vote', selectedChoices)" | ||
> | ||
Vote | ||
</UiButton> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<script setup lang="ts"> | ||
import { Choice } from '@/types'; | ||
withDefaults( | ||
defineProps<{ | ||
sendingType: Choice | null; | ||
size: number; | ||
}>(), | ||
{ size: 48 } | ||
); | ||
const emit = defineEmits<{ | ||
(e: 'vote', value: Choice); | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<div class="flex space-x-2"> | ||
<UiTooltip title="For"> | ||
<UiButton | ||
class="!text-skin-success !border-skin-success !px-0" | ||
:class="{ '!w-[48px] !h-[48px]': size === 48, '!w-[40px] !h-[40px]': size === 40 }" | ||
:loading="sendingType === 'for'" | ||
@click="emit('vote', 'for')" | ||
> | ||
<IH-check class="inline-block" /> | ||
</UiButton> | ||
</UiTooltip> | ||
<UiTooltip title="Against"> | ||
<UiButton | ||
class="!text-skin-danger !border-skin-danger !px-0" | ||
:class="{ '!w-[48px] !h-[48px]': size === 48, '!w-[40px] !h-[40px]': size === 40 }" | ||
:loading="sendingType === 'against'" | ||
@click="emit('vote', 'against')" | ||
> | ||
<IH-x class="inline-block" /> | ||
</UiButton> | ||
</UiTooltip> | ||
<UiTooltip title="Abstain"> | ||
<UiButton | ||
class="!text-gray-500 !border-gray-500 !px-0" | ||
:class="{ '!w-[48px] !h-[48px]': size === 48, '!w-[40px] !h-[40px]': size === 40 }" | ||
:loading="sendingType === 'abstain'" | ||
@click="emit('vote', 'abstain')" | ||
> | ||
<IH-minus-sm class="inline-block" /> | ||
</UiButton> | ||
</UiTooltip> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script setup lang="ts"> | ||
import { Choice, Proposal } from '@/types'; | ||
defineProps<{ | ||
sendingType: Choice | null; | ||
proposal: Proposal; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(e: 'vote', value: number); | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<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 truncate" | ||
:loading="sendingType === index + 1" | ||
@click="emit('vote', index + 1)" | ||
> | ||
{{ choice }} | ||
</UiButton> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import { Choice } from '@/types'; | ||
|
||
export function getSdkChoice(choice: Choice): number { | ||
if (choice === 'for') return 1; | ||
if (choice === 'against') return 2; | ||
return 3; | ||
export function getSdkChoice(type: string, choice: Choice): number | number[] { | ||
if (type === 'basic') { | ||
if (choice === 'for') return 1; | ||
if (choice === 'against') return 2; | ||
return 3; | ||
} | ||
|
||
if (type === 'single-choice') { | ||
return choice as number; | ||
} | ||
|
||
if (type === 'approval') { | ||
return choice as number[]; | ||
} | ||
|
||
throw new Error('Vote type not supported'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters