-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathusePredictActivity.ts
More file actions
43 lines (36 loc) · 1.41 KB
/
usePredictActivity.ts
File metadata and controls
43 lines (36 loc) · 1.41 KB
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
37
38
39
40
41
42
43
import { useEffect } from 'react';
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
import Logger from '../../../../util/Logger';
import { PREDICT_CONSTANTS } from '../constants/errors';
import type { PredictActivity } from '../types';
import { usePredictNetworkManagement } from './usePredictNetworkManagement';
import { getEvmAccountFromSelectedAccountGroup } from '../utils/accounts';
import { predictQueries } from '../queries';
import { ensureError } from '../utils/predictErrorHandler';
export function usePredictActivity(): UseQueryResult<PredictActivity[], Error> {
const { ensurePolygonNetworkExists } = usePredictNetworkManagement();
const evmAccount = getEvmAccountFromSelectedAccountGroup();
const address = evmAccount?.address ?? '0x0';
useEffect(() => {
ensurePolygonNetworkExists().catch(() => undefined);
}, [ensurePolygonNetworkExists]);
const queryResult = useQuery(predictQueries.activity.options({ address }));
useEffect(() => {
if (!queryResult.error) return;
Logger.error(ensureError(queryResult.error), {
tags: {
feature: PREDICT_CONSTANTS.FEATURE_NAME,
component: 'usePredictActivity',
},
context: {
name: 'usePredictActivity',
data: {
method: 'queryFn',
action: 'activity_load',
operation: 'data_fetching',
},
},
});
}, [queryResult.error]);
return queryResult;
}