-
Notifications
You must be signed in to change notification settings - Fork 1
/
useContractList.ts
36 lines (29 loc) · 891 Bytes
/
useContractList.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import _ from 'lodash';
import { useQuery } from '@tanstack/react-query';
import { CONTRACT_LIST_QUERY, client, camelize } from '../utils';
import { IContract } from '../types';
import { User } from 'next-auth';
type useContractListProps = {
token?: string;
user?: Partial<User>;
};
const useContractList = ({ token, user }: useContractListProps) => {
const contractListQueryResult = async () => {
if (!token) return;
const result = await client({
token,
userId: _.get(user, 'address'),
}).request(CONTRACT_LIST_QUERY);
return camelize(_.get(result, 'contracts'));
};
const { status, error, data, isLoading } = useQuery<
Array<Partial<IContract>>,
Error
>({
queryKey: ['contractList'],
queryFn: contractListQueryResult,
enabled: !!token,
});
return { status, error, data, isLoading };
};
export default useContractList;