diff --git a/src/components/SettingsVotingBlock.vue b/src/components/SettingsVotingBlock.vue index bc00b288816..9c769dc5157 100644 --- a/src/components/SettingsVotingBlock.vue +++ b/src/components/SettingsVotingBlock.vue @@ -66,6 +66,13 @@ const { form } = useFormSpaceSettings(props.context); :label="$t('settings.hideAbstain')" :disabled="isViewOnly" /> + + diff --git a/src/composables/useAliasAction.ts b/src/composables/useAliasAction.ts index 11299396ca2..5d26b014857 100644 --- a/src/composables/useAliasAction.ts +++ b/src/composables/useAliasAction.ts @@ -76,10 +76,10 @@ export function useAliasAction() { try { await checkAlias(); if (aliasWallet.value && isValidAlias.value) { - return await action(); + return await action(aliasWallet.value); } await setAlias(); - return await action(); + return await action(aliasWallet.value); } catch (e) { console.error(e); loading.value = false; diff --git a/src/composables/useClient.ts b/src/composables/useClient.ts index b7b95fac13d..c82c0ffe6f8 100644 --- a/src/composables/useClient.ts +++ b/src/composables/useClient.ts @@ -10,6 +10,7 @@ export function useClient() { const { web3 } = useWeb3(); const auth = getInstance(); const route = useRoute(); + const { actionWithAlias } = useAliasAction(); const DEFINED_APP = (route?.query.app as string) || 'snapshot'; @@ -35,13 +36,57 @@ export function useClient() { } } + const signParams = { + get provider() { + return auth.web3; + }, + get address() { + return web3.value.account; + } + }; + + function vote(client, votePayload, { provider, address } = signParams) { + return client.vote(provider, address, votePayload); + } + + function proposal( + client, + proposalPayload, + { provider, address } = signParams + ) { + return client.proposal(provider, address, proposalPayload); + } + + function deleteProposal( + client, + deleteProposalPayload, + { provider, address } = signParams + ) { + return client.cancelProposal(provider, address, deleteProposalPayload); + } + + function bindWithAlias(actionFn) { + return (client, payload) => { + return actionWithAlias(aliasWallet => + actionFn(client, payload, { + provider: aliasWallet, + address: aliasWallet.address + }) + ); + }; + } + async function sendEIP712(space, type, payload) { const client = isGnosisSafe.value ? clientGnosisSafe : clientEIP712; if (type === 'proposal') { + const shouldUseAlias = space.voting?.aliased && !isGnosisSafe.value; + const proposalFn = shouldUseAlias ? bindWithAlias(proposal) : proposal; + let plugins = {}; if (Object.keys(payload.metadata?.plugins).length !== 0) plugins = payload.metadata.plugins; - return client.proposal(auth.web3, web3.value.account, { + + const proposalPayload = { space: space.id, type: payload.type, title: payload.name, @@ -52,23 +97,40 @@ export function useClient() { end: payload.end, snapshot: payload.snapshot, plugins: JSON.stringify(plugins), - app: DEFINED_APP - }); + app: DEFINED_APP, + from: web3.value.account + }; + + return proposalFn(client, proposalPayload); } else if (type === 'vote') { - return client.vote(auth.web3, web3.value.account, { + const shouldUseAlias = space.voting?.aliased && !isGnosisSafe.value; + const voteFn = shouldUseAlias ? bindWithAlias(vote) : vote; + + const votePayload = { space: space.id, proposal: payload.proposal.id, type: payload.proposal.type, choice: payload.choice, privacy: payload.privacy, app: DEFINED_APP, - reason: payload.reason - }); + reason: payload.reason, + from: web3.value.account + }; + + return voteFn(client, votePayload); } else if (type === 'delete-proposal') { - return client.cancelProposal(auth.web3, web3.value.account, { + const shouldUseAlias = space.voting?.aliased && !isGnosisSafe.value; + const deleteProposalFn = shouldUseAlias + ? bindWithAlias(deleteProposal) + : deleteProposal; + + const deleteProposalPayload = { space: space.id, - proposal: payload.proposal.id - }); + proposal: payload.proposal.id, + from: web3.value.account + }; + + return deleteProposalFn(client, deleteProposalPayload); } else if (type === 'settings') { return client.space(auth.web3, web3.value.account, { space: space.id, diff --git a/src/composables/useFormSpaceSettings.ts b/src/composables/useFormSpaceSettings.ts index 9005239f977..bc334026c72 100644 --- a/src/composables/useFormSpaceSettings.ts +++ b/src/composables/useFormSpaceSettings.ts @@ -25,7 +25,8 @@ const EMPTY_SPACE_FORM = { period: 0, quorum: 0, type: '', - privacy: '' + privacy: '', + aliased: false }, validation: clone(DEFAULT_PROPOSAL_VALIDATION), voteValidation: clone(DEFAULT_VOTE_VALIDATION), diff --git a/src/helpers/interfaces.ts b/src/helpers/interfaces.ts index ccd4580f8ad..90930aa7509 100644 --- a/src/helpers/interfaces.ts +++ b/src/helpers/interfaces.ts @@ -171,6 +171,7 @@ export interface ExtendedSpace { quorum: number | null; type: string | null; privacy: string | null; + aliased: boolean; }; } diff --git a/src/helpers/queries.ts b/src/helpers/queries.ts index 533e2f1292b..e46be141519 100644 --- a/src/helpers/queries.ts +++ b/src/helpers/queries.ts @@ -462,6 +462,7 @@ export const SPACE_QUERY = gql` quorum privacy hideAbstain + aliased } strategies { name diff --git a/src/locales/default.json b/src/locales/default.json index 763cc668655..9d95e70139e 100644 --- a/src/locales/default.json +++ b/src/locales/default.json @@ -448,6 +448,8 @@ "voting": "Voting", "votingDelay": "Voting delay", "votingPeriod": "Voting period", + "enableAliased": "Allow actions with session keys", + "enableAliasedHint": "Voting, creating and deleting proposals will no longer require the user to manually sign each time.", "hours": "Hours", "days": "Days", "quorum": {