Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/vitwit/resolute into hemanth…
Browse files Browse the repository at this point in the history
…/select-network
  • Loading branch information
Hemanthghs committed Nov 27, 2023
2 parents 9a5dd21 + 1d9abac commit 85e4063
Show file tree
Hide file tree
Showing 9 changed files with 972 additions and 77 deletions.
77 changes: 77 additions & 0 deletions frontend/src/store/features/gov/govService.ts
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;
Loading

0 comments on commit 85e4063

Please sign in to comment.