-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add proposal votes endpoint and related schemas #1547
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
59abf90
feat: add proposal votes endpoint and related schemas
brunod-e ba68cf1
refactor: rename 'reason' to 'support' in proposal voting logic
brunod-e 4101beb
feat: add proposalVotes query and response types to GraphQL schema
brunod-e e233a61
feat: improve votes endpoint
brunod-e d911e25
refactor: rename proposalVotes to votes across GraphQL schema and rel…
brunod-e 1b2f692
Merge branch 'dev' into feat/votes-rest-endpoint
brunod-e b95714f
chore: remove votesOnChain from gateway
pikonha bdf5402
fix: parse voterAddressesIn to array
pikonha d3dc6b7
fix: remove votesOnchain references
brunod-e 2b3b089
Merge branch 'dev' into feat/votes-rest-endpoint
brunod-e 1dea8f9
fix: rename addressArray to addresses in GetAccountPower query and re…
brunod-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 +1,3 @@ | ||
| export * from "./voters"; | ||
| export * from "./proposals"; | ||
| export * from "./votes"; |
This file contains hidden or 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,60 @@ | ||
| import { z } from "@hono/zod-openapi"; | ||
| import { votesOnchain } from "ponder:schema"; | ||
| import { isAddress } from "viem"; | ||
|
|
||
| export type DBVote = typeof votesOnchain.$inferSelect; | ||
|
|
||
| export const VotesRequestSchema = z.object({ | ||
| skip: z.coerce | ||
| .number() | ||
| .int() | ||
| .min(0, "Skip must be a non-negative integer") | ||
| .optional() | ||
| .default(0), | ||
| limit: z.coerce | ||
| .number() | ||
| .int() | ||
| .min(1, "Limit must be a positive integer") | ||
| .max(1000, "Limit cannot exceed 1000") | ||
| .optional() | ||
| .default(10), | ||
| account: z.string().refine((val) => isAddress(val)), | ||
brunod-e marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sortBy: z.enum(["timestamp", "votingPower"]).default("timestamp").optional(), | ||
| sortOrder: z.enum(["asc", "desc"]).default("desc").optional(), | ||
brunod-e marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| support: z.coerce.number().int().optional(), | ||
brunod-e marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
brunod-e marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| export type VotesRequest = z.infer<typeof VotesRequestSchema>; | ||
|
|
||
| export const VoteResponseSchema = z.object({ | ||
| voter: z.string(), | ||
| transactionHash: z.string(), | ||
| proposalId: z.string(), | ||
| support: z.number(), | ||
| votingPower: z.string(), | ||
| reason: z.string().nullable(), | ||
| timestamp: z.number(), | ||
| }); | ||
|
|
||
| export type VoteResponse = z.infer<typeof VoteResponseSchema>; | ||
|
|
||
| export const VotesResponseSchema = z.object({ | ||
| items: z.array(VoteResponseSchema), | ||
| totalCount: z.number(), | ||
| }); | ||
|
|
||
| export type VotesResponse = z.infer<typeof VotesResponseSchema>; | ||
|
|
||
| export const VotesMapper = { | ||
| toApi: (vote: DBVote): VoteResponse => { | ||
| return { | ||
| voter: vote.voterAccountId, | ||
| transactionHash: vote.txHash, | ||
| proposalId: vote.proposalId, | ||
| support: Number(vote.support), | ||
| votingPower: vote.votingPower.toString(), | ||
| reason: vote.reason || null, | ||
| timestamp: Number(vote.timestamp), | ||
| }; | ||
| }, | ||
| }; | ||
This file contains hidden or 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 hidden or 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
brunod-e marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.