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: add single choice and approval voting type #46

Merged
merged 58 commits into from
Feb 21, 2024

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Feb 16, 2024

Summary

Closes: #15

Add support for approval voting

Changes

  • changes some typing to support number[] as choices type
  • edited UI to support selecting multiple choices

How to test

  1. You can test with http://localhost:8080/#/s-tn:wan-test.eth (wallet private key in sx.js test/integration/offchain/index.test.ts)
  2. There's 2 proposals with each voting type for testing

wa0x6e and others added 30 commits February 13, 2024 00:30
Co-authored-by: Wiktor Tkaczyński <wiktor.tkaczynski@gmail.com>
Copy link
Contributor

@samuveth samuveth left a comment

Choose a reason for hiding this comment

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

After I voted it shows a message You have already votes on this proposal but I see zero votes and no current results until I refresh the page. Shouldn't it refresh the results after I voted?

apps/ui/src/views/Proposal.vue Outdated Show resolved Hide resolved
@Sekhmet
Copy link
Member

Sekhmet commented Feb 21, 2024

Shouldn't it refresh the results after I voted?

For SX it will take some time before vote is indexed so we do not refresh (it can take few minutes sometimes for indexer to see transaction). Maybe it makes more sense here but it shouldn’t be part of this PR

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Feb 21, 2024

I agree with it not being part of this PR.

We have a pendingTransaction store on the UI, which receive the tx after a vote. What I would to would be to add some kind of watcher there, and refresh the related UI store (proposal, space, etc ...) when tx pass, then all dependent component will refresh by themselves.

Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

Other than this one small change all looks good to me, great job!

}>();

const emit = defineEmits<{
(e: 'handleVoteClick', value: Choice);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(e: 'handleVoteClick', value: Choice);
(e: 'voteClick', value: Choice);

We tend to call handler function with handle prefix, but emit names don't have that prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to keep the Click suffix ? If not, it will look better like

@vote="handleVoteClick"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, we have a handleVoteClick function in 2 places: ProposalListsItem.vue and Proposal.vue.

Wouldn't it be cleaner if we move this inside ProposalVote ?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed vote makes more sense as I took better look at the usage.

Also, we have a handleVoteClick function in 2 places: ProposalListsItem.vue and Proposal.vue.

I don't think we can as it's just wrapper that gets actual buttons from the outside.

Copy link
Contributor Author

@wa0x6e wa0x6e Feb 21, 2024

Choose a reason for hiding this comment

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

In that case, we could move everything inside ProposalVote, and just call it with

<ProposalVote v-if="proposal" :proposal="proposal" show-type="['basic']"> // To show only basic type
<ProposalVote v-if="proposal" :proposal="proposal"> // To show everything

apps/ui/src/components/ProposalVoteBasic.vue Outdated Show resolved Hide resolved
apps/ui/src/components/ProposalVoteSingleChoice.vue Outdated Show resolved Hide resolved
@Sekhmet
Copy link
Member

Sekhmet commented Feb 21, 2024

Also CI is failing.

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Feb 21, 2024

Also CI is failing.

This one is due to a typing issue, which I am not able to resolve. If you have some advices

@Sekhmet
Copy link
Member

Sekhmet commented Feb 21, 2024

diff --git a/packages/sx.js/src/clients/offchain/types.ts b/packages/sx.js/src/clients/offchain/types.ts
index 01e9ab22..87dd8e02 100644
--- a/packages/sx.js/src/clients/offchain/types.ts
+++ b/packages/sx.js/src/clients/offchain/types.ts
@@ -1,10 +1,6 @@
 import type { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
 
-enum Choice {
-  Against = 2,
-  For = 1,
-  Abstain = 3
-}
+type Choice = number | number[];
 
 export type SignatureData = {
   address: string;

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Feb 21, 2024

Still no luck, for some reasons, it's using the Vote type from src/types and not from offchain

@Sekhmet
Copy link
Member

Sekhmet commented Feb 21, 2024

@wa0x6e it will work if you run yarn build first, I will update our scripts so it will rebuild sx.js before running yarn typecheck.

@Sekhmet
Copy link
Member

Sekhmet commented Feb 21, 2024

Fixed typecheck script on master: c76f035

Copy link
Member

@Sekhmet Sekhmet left a comment

Choose a reason for hiding this comment

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

tACK

@Sekhmet Sekhmet merged commit ff6f988 into master Feb 21, 2024
3 checks passed
@Sekhmet Sekhmet deleted the add-approval-and-single-choice-voting-type branch February 21, 2024 15:19
@wa0x6e wa0x6e restored the add-approval-and-single-choice-voting-type branch February 21, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add voting for offchain spaces
3 participants