Skip to content

Commit

Permalink
getUserVoteTypeFromProposal typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorizen committed Apr 5, 2024
1 parent 53b16b3 commit 95a9935
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/callers/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {

type UserVoteType = {
vote: {
options?: {
option?: VoteStates
options: {
option: VoteStates
}[]
}
}
Expand Down Expand Up @@ -110,12 +110,15 @@ export const getProposalVotesCountByID = async (id: string): Promise<number> =>
return data?.proposal?.[0]?.proposal_votes_aggregate.aggregate?.count ?? 0
}

export const getUserVoteTypeFromProposal = async (proposalId: string | number, address: string) => {
export const getUserVoteTypeFromProposal = async (
proposalId: string | number,
address: string,
): Promise<VoteStates> => {
const response = await fetch(
`${CONFIG.CHAIN_API_URL}/cosmos/gov/v1beta1/proposals/${proposalId}/votes/${address}`,
)

const { vote }: UserVoteType = await response.json()

return vote.options?.[0]?.option
return vote.options[0].option
}
2 changes: 1 addition & 1 deletion src/components/Forms/VoteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function VoteForm({
if (voteType) {
setNewDefaultVoteOption(voteType)

setAlreadySelectedVote(voteType as VoteStates)
setAlreadySelectedVote(voteType)
}
} catch (e) {
ErrorHandler.processWithoutFeedback(e as Error)
Expand Down

0 comments on commit 95a9935

Please sign in to comment.