Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Space settings to allow voting with alias #3973

Closed
wants to merge 8 commits into from
Closed

Conversation

Todmy
Copy link
Contributor

@Todmy Todmy commented Jun 7, 2023

Issues

#3265
#3852

Changes

  1. Added an option to vote with aliases. To enable aliases, go to Settings -> Voting -> Allow actions with session keys
Screenshot 2023-06-07 at 20 27 14

How to test

  1. Go to the active proposal
  2. Create a proposal, delete it (you will be asked to sign your request)
  3. Vote in the usual way (to check if it still works)
  4. go to Settings -> Voting. And enable Allow actions with session keys. Save settings
  5. Go back to an active proposal (the previous one or a new active one)
  6. Try to vote (the alias voting). In this case, you will be proposed to sign an alias (only once). But next votings will go smoothly without any signing messages
  7. Try to create/delete proposal. It should happen without signing message with wallet
  8. Go back to Settings -> Voting -> disable Allow actions with session keys -> Save settings
  9. Go back to an active proposal and try to vote again. This time it will ask you to sign a message for each voting
  10. Create/delete a proposal. It should require to sign request

To-Do

  • [ ]

Self-review checklist

  • I have performed a full self-review of my changes
  • I have tested my changes on a preview deployment
  • I have tested my changes on different screen sizes (sm, md)
  • I have tested my changes on a custom domain
  • I have run end-to-end tests yarn cypress:test:e2e, and they have passed

@vercel
Copy link

vercel bot commented Jun 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
snapshot ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2023 1:21am

@Todmy Todmy requested review from samuveth and bonustrack June 7, 2023 18:59
@samuveth
Copy link
Contributor

samuveth commented Jun 15, 2023

Creating a proposal doesn't work for me after enabling alias.

On the space testsnap.eth and samuv.eth I get this error:
image

Edit: And for voting I also get the same error

@aurelianoB
Copy link
Contributor

same for me

@Todmy
Copy link
Contributor Author

Todmy commented Jun 15, 2023

@samuveth @aurelianoB fixed, please check

@aurelianoB
Copy link
Contributor

Thanks @Todmy, both proposal creation and vote with alias works for me now. Let's wait for @samuveth to review anyway

@snapshot-labs snapshot-labs deleted a comment Jun 15, 2023
@snapshot-labs snapshot-labs deleted a comment Jun 15, 2023
@samuveth
Copy link
Contributor

Proposal creation is not working for me when I enable alias actions. First I tried without alias setting and it worked, but when I enable it I get:
image

You can test here: https://snapshot-8uiprmz57-snapshot.vercel.app/#/samuv.eth/create
(You will need a Gitcoin Passport attached to the address you use for testing in order to create a proposal)

@@ -10,6 +10,7 @@ export function useClient() {
const { web3 } = useWeb3();
Copy link
Contributor

@samuveth samuveth Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This composable has become a little hard to read. Can we try something like this?

const ACTIONS = {
  proposal: 'proposal',
  vote: 'vote',
  deleteProposal: 'delete-proposal',
  settings: 'settings',
  deleteSpace: 'delete-space'
};

export function useClient() {

  async function executeAndHandleError(func) {
    isSending.value = true;
    try {
      return await func();
    } catch (e: any) {
      errorNotification(e?.error_description || '');
      return e;
    } finally {
      isSending.value = false;
    }
  }

  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;
    const shouldUseAlias = space.voting?.aliased && !isGnosisSafe.value;

    switch (type) {
      case ACTIONS.proposal:
        return executeAndHandleError(() => sendProposal(space, payload, client, shouldUseAlias));
      case ACTIONS.vote:
        return executeAndHandleError(() => sendVote(space, payload, client, shouldUseAlias));
      case ACTIONS.deleteProposal:
        return executeAndHandleError(() => sendDeleteProposal(space, payload, client, shouldUseAlias));
      case ACTIONS.settings:
        return executeAndHandleError(() => sendSettings(space, payload, client));
      case ACTIONS.deleteSpace:
        return executeAndHandleError(() => sendDeleteSpace(space, client));
      default:
        throw new Error(`Unknown action type: ${type}`);
    }
  }

  function sendProposal(space, payload, client, shouldUseAlias) {
    const actionFn = shouldUseAlias ? bindWithAlias(proposal) : proposal;

    let plugins = {};
    if (Object.keys(payload.metadata?.plugins).length !== 0)
      plugins = payload.metadata.plugins;

    const proposalPayload = {
      space: space.id,
      type: payload.type,
      title: payload.name,
      body: payload.body,
      discussion: payload.discussion,
      choices: payload.choices,
      start: payload.start,
      end: payload.end,
      snapshot: payload.snapshot,
      plugins: JSON.stringify(plugins),
      app: definedApp,
      from: web3.value.account
    };

    return actionFn(client, proposalPayload);
  }

  // Similarly implement sendVote, sendDeleteProposal, sendSettings, and sendDeleteSpace


}

@samuveth samuveth changed the title Space settings to allow voting with alias feat: Space settings to allow voting with alias Jul 17, 2023
@samuveth samuveth added the stale Issues that are old and soon to be closed label Sep 12, 2023
@stale stale bot closed this Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that are old and soon to be closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants