Skip to content

Commit

Permalink
remove: indexer dependency for proposal query
Browse files Browse the repository at this point in the history
  • Loading branch information
radzionc committed Oct 18, 2023
1 parent 9ffe61b commit e78468f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions apps/enterprise/src/queries/useProposalQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@ import { useDAOQuery } from 'queries';
import { useQuery, UseQueryResult } from 'react-query';
import { Proposal } from 'dao/shared/proposal';
import { QUERY_KEY } from './queryKey';
import { useApiEndpoint } from 'hooks';
import { apiResponseToProposal, ProposalApiResponse } from 'proposal/ProposalApiResponse';
import { toDao } from 'dao/utils/toDao';
import { useContract } from 'chain/hooks/useContract';
import { enterprise } from 'types/contracts';
import { toProposal } from 'dao/utils/toProposal';

interface UseProposalQueryOptions {
daoAddress: string;
id: number;
enabled?: boolean;
}

type DaoProposalArguments = Extract<enterprise.QueryMsg, { proposal: {} }>;

export const useProposalQuery = (options: UseProposalQueryOptions): UseQueryResult<Proposal | undefined> => {
const { id, daoAddress, enabled = true } = options;
const { query } = useContract();

const { data: daoResponse } = useDAOQuery(daoAddress);

const apiEndpoint = useApiEndpoint({
path: 'v1/daos/{address}/proposals/{id}',
route: { address: daoAddress, id },
});

return useQuery(
[QUERY_KEY.PROPOSAL, daoAddress, id],
async () => {
let response = await query<DaoProposalArguments, enterprise.ProposalResponse>(daoAddress, {
proposal: {
proposal_id: id,
},
});
const dao = toDao(assertDefined(daoResponse));
const response = await fetch(apiEndpoint);
const json: ProposalApiResponse = await response.json();
return apiResponseToProposal(json, dao);
return toProposal(response, dao);
},
{
refetchOnMount: false,
Expand Down

0 comments on commit e78468f

Please sign in to comment.