-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/vitwit/resolute into hemanth…
…/select-network
- Loading branch information
Showing
9 changed files
with
972 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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,77 @@ | ||
import Axios, { AxiosResponse } from 'axios'; | ||
import { convertPaginationToParams, cleanURL } from '../../../utils/util'; | ||
import { | ||
GetProposalsInVotingResponse, | ||
GovProposal, | ||
ProposalVote, | ||
} from '@/types/gov'; | ||
|
||
const proposalsURL = '/cosmos/gov/v1beta1/proposals'; | ||
const proposalTallyURL = (id: number): string => | ||
`/cosmos/gov/v1beta1/proposals/${id}/tally`; | ||
|
||
const voterVoteURL = (id: number, voter: string): string => | ||
`/cosmos/gov/v1beta1/proposals/${id}/votes/${voter}`; | ||
|
||
const depositParamsURL = `/cosmos/gov/v1beta1/params/deposit`; | ||
|
||
const fetchProposals = ( | ||
baseURL: string, | ||
key: string | undefined, | ||
limit: number | undefined, | ||
status: number | ||
): Promise<AxiosResponse<GetProposalsInVotingResponse>> => { | ||
let uri = `${cleanURL(baseURL)}${proposalsURL}`; | ||
uri += `?proposal_status=${status}`; | ||
|
||
const params = convertPaginationToParams({ | ||
key: key, | ||
limit: limit, | ||
}); | ||
|
||
if (params !== '') uri += `&${params}`; | ||
return Axios.get(uri); | ||
}; | ||
|
||
const fetchProposalTally = ( | ||
baseURL: string, | ||
proposalId: number | ||
): Promise<AxiosResponse> => { | ||
const uri = `${cleanURL(baseURL)}${proposalTallyURL(proposalId)}`; | ||
return Axios.get(uri); | ||
}; | ||
|
||
const fetchVoterVote = ( | ||
baseURL: string, | ||
proposalId: number, | ||
voter: string, | ||
key: string | undefined, | ||
limit: number | undefined | ||
): Promise<AxiosResponse<ProposalVote>> => { | ||
let uri = `${cleanURL(baseURL)}${voterVoteURL(proposalId, voter)}`; | ||
const params = convertPaginationToParams({ | ||
key: key, | ||
limit: limit, | ||
}); | ||
if (params !== '') uri += `?${params}`; | ||
return Axios.get(uri); | ||
}; | ||
|
||
const fetchProposal = ( | ||
baseURL: string, | ||
proposalId: number | ||
): Promise<AxiosResponse<{ proposal: GovProposal }>> => | ||
Axios.get(`${cleanURL(baseURL)}${proposalsURL}/${proposalId}`); | ||
|
||
const fetchDepositParams = (baseURL: string): Promise<AxiosResponse> => | ||
Axios.get(`${cleanURL(baseURL)}${depositParamsURL}`); | ||
|
||
const result = { | ||
proposals: fetchProposals, | ||
tally: fetchProposalTally, | ||
votes: fetchVoterVote, | ||
proposal: fetchProposal, | ||
depositParams: fetchDepositParams, | ||
}; | ||
|
||
export default result; |
Oops, something went wrong.