From a76bc35bd83077807d4cc38957b94ab94eeb8fca Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Mon, 25 Sep 2023 14:51:45 -0400 Subject: [PATCH] improve: add oshhhnap integration into modal --- src/components/ModalVote.vue | 44 ++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/components/ModalVote.vue b/src/components/ModalVote.vue index 50a42c585b7..2e187154f5d 100644 --- a/src/components/ModalVote.vue +++ b/src/components/ModalVote.vue @@ -3,6 +3,7 @@ import { shorten, getChoiceString, explorerUrl } from '@/helpers/utils'; import { getPower, voteValidation } from '@/helpers/snapshot'; import { ExtendedSpace, Proposal } from '@/helpers/interfaces'; import shutterEncryptChoice from '@/helpers/shutter'; +import { timelockEncryptionForOshhhnap } from '@/helpers/oshhhnap'; const { web3Account } = useWeb3(); @@ -33,6 +34,7 @@ const { addVotedProposalId } = useProposals(); const { isGnosisAndNotSpaceNetwork } = useGnosis(props.space); const isLoadingShutter = ref(false); +const isLoadingOshhnap = ref(false); const symbols = computed(() => props.strategies.map(strategy => strategy.params.symbol || '') @@ -69,19 +71,47 @@ async function voteShutter() { }); } +async function voteOshhhnap() { + // TODO: Implement Oshhhnap + isLoadingOshhnap.value = true; + const timelockEncryptedChoice = await timelockEncryptionForOshhhnap( + JSON.stringify(props.selectedChoices), + props.proposal.id, + props.proposal.end + ); + + if (!timelockEncryptedChoice) return null; + const resultantVote = vote({ + proposal: props.proposal, + choice: timelockEncryptedChoice, + privacy: 'oshhhnap', + reason: reason.value + }); + isLoadingOshhnap.value = false; + return resultantVote; +} + async function vote(payload) { return send(props.space, 'vote', payload); } async function handleSubmit() { let result: { id: string; ipfs?: string } | null = null; - if (props.proposal.privacy === 'shutter') result = await voteShutter(); - else - result = await vote({ - proposal: props.proposal, - choice: props.selectedChoices, - reason: reason.value - }); + switch (props.proposal.privacy) { + case 'shutter': + result = await voteShutter(); + break; + case 'oshhhnap': + result = await voteOshhhnap(); + break; + default: + result = await vote({ + proposal: props.proposal, + choice: props.selectedChoices, + reason: reason.value + }); + break; + } console.log('Result', result);