-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathuseLabelInfoQuery.ts
57 lines (51 loc) · 1.41 KB
/
useLabelInfoQuery.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { useQuery } from "@tanstack/react-query";
import { DEFAULT_CHAIN } from "consts/chains";
import { useGraphqlBatcher } from "context/GraphqlBatcher";
import { graphql } from "src/graphql";
import { LabelInfoQuery } from "src/graphql/graphql";
const labelQuery = graphql(`
query LabelInfo($address: String, $disputeID: ID!) {
dispute(id: $disputeID) {
period
shifts(where: { juror: $address }) {
ethAmount
pnkAmount
}
rounds {
drawnJurors(where: { juror: $address }, first: 1) {
vote {
... on ClassicVote {
choice
}
}
}
}
disputeKitDispute {
localRounds {
... on ClassicRound {
contributions(where: { contributor: $address }) {
amount
rewardAmount
}
}
}
}
}
}
`);
export const useLabelInfoQuery = (address?: string | null, disputeID?: string) => {
const isEnabled = !!(address && disputeID);
const { graphqlBatcher } = useGraphqlBatcher();
return useQuery<LabelInfoQuery>({
queryKey: [`labelQuery${[address, disputeID]}`],
enabled: isEnabled,
staleTime: 60000,
queryFn: async () =>
await graphqlBatcher.fetch({
id: crypto.randomUUID(),
document: labelQuery,
chainId: DEFAULT_CHAIN,
variables: { address, disputeID },
}),
});
};