|
| 1 | +// import { useState } from "react"; |
| 2 | +// import { |
| 3 | +// useKlerosCore, |
| 4 | +// usePnkAllowance, |
| 5 | +// usePnkApprovalEvent, |
| 6 | +// } from "hooks/contracts/generated"; |
| 7 | +// import { notUndefined } from "utils/index"; |
| 8 | + |
| 9 | +// export const usePNKAllowance = (user?: string | null) => { |
| 10 | +// const [isFetched, setIsFetched] = useState<boolean>(false); |
| 11 | +// const klerosCore = useKlerosCore(); |
| 12 | +// const { data: allowance, refetch } = usePnkAllowance({ |
| 13 | +// enabled: !isFetched && notUndefined([user, klerosCore]), |
| 14 | +// args: [user, klerosCore?.address], |
| 15 | +// onSuccess: () => setIsFetched(true), |
| 16 | +// }); |
| 17 | +// usePnkApprovalEvent({ |
| 18 | +// listener: () => refetch(), |
| 19 | +// }); |
| 20 | +// return allowance; |
| 21 | +// }; |
| 22 | + |
1 | 23 | import useSWR from "swr"; |
2 | | -import { PNK } from "@kleros/kleros-v2-contracts/typechain-types/src/token/PNK"; |
3 | | -import { useConnectedContract } from "hooks/useConnectedContract"; |
4 | | -import { CONTRACTS } from "utils/getContract"; |
| 24 | +import { useProvider } from "wagmi"; |
| 25 | +import { usePnk, useKlerosCore } from "hooks/contracts/generated"; |
5 | 26 |
|
6 | | -export const usePNKAllowance = (user?: string | null) => { |
7 | | - const pnkContract = useConnectedContract("PNK") as PNK; |
| 27 | +export const usePNKAllowance = (user?: `0x${string}` | null) => { |
| 28 | + const provider = useProvider(); |
| 29 | + const pnkContract = usePnk({ signerOrProvider: provider }); |
| 30 | + const klerosCore = useKlerosCore(); |
8 | 31 | return useSWR( |
9 | 32 | () => (pnkContract && user ? `PNKAllowance{user}` : false), |
10 | 33 | async () => { |
11 | | - if (pnkContract && user) { |
12 | | - return await pnkContract.allowance( |
13 | | - user, |
14 | | - CONTRACTS["KlerosCore"].address |
15 | | - ); |
| 34 | + if (pnkContract && user && klerosCore) { |
| 35 | + return await pnkContract.allowance(user, klerosCore.address); |
16 | 36 | } else { |
17 | 37 | return undefined; |
18 | 38 | } |
|
0 commit comments