Skip to content

Commit 733a432

Browse files
author
devofficer
committed
fix: useCheckLightCurate to use graphql instead of web3 api
1 parent d29f873 commit 733a432

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed
Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
1-
import { useEffect, useState } from 'react'
2-
import { useWeb3Context } from 'web3-react'
3-
import { ethers } from 'ethers'
1+
import { useMemo } from 'react'
42
import { useParams } from 'react-router'
5-
import _gtcr from '../assets/abis/GeneralizedTCR.json'
3+
import { useQuery } from '@apollo/client'
4+
import { TCR_EXISTENCE_TEST } from 'utils/graphql'
65

7-
const useCheckLightCurate = () => {
8-
const { library, active } = useWeb3Context()
6+
const useCheckLightCurate = (): [boolean, boolean] => {
97
const { tcrAddress } = useParams<{ tcrAddress: string }>()
10-
11-
const [isLightCurate, setLightCurate] = useState<boolean>(false)
12-
13-
useEffect(() => {
14-
const checkLightCurate = async () => {
15-
try {
16-
if (!active) return
17-
const tcr = new ethers.Contract(tcrAddress, _gtcr, library)
18-
19-
// Call a function only available on GTCR Classic. If
20-
// it throws, its not a light curate instance.
21-
await tcr.itemCount()
22-
setLightCurate(false)
23-
// eslint-disable-next-line no-unused-vars
24-
} catch (err) {
25-
console.info(
26-
`Contract call used to verify if this is a Light Curate instance. Ignore exception.`
27-
)
28-
setLightCurate(true)
29-
}
8+
const { loading, data } = useQuery(TCR_EXISTENCE_TEST, {
9+
variables: {
10+
tcrAddress: tcrAddress.toLowerCase()
3011
}
31-
checkLightCurate()
32-
}, [active, library, tcrAddress])
12+
})
13+
const isLightCurate = useMemo<boolean>(() => data?.lregistry ?? false, [data])
3314

34-
return isLightCurate
15+
return [isLightCurate, loading]
3516
}
3617

3718
export default useCheckLightCurate

src/pages/item-details-router.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const ItemDetailsRouter = () => {
2929
}>()
3030
const { networkStatus } = useTcrNetwork()
3131
const search = window.location.search
32-
const isLightCurate = useCheckLightCurate()
32+
const [isLightCurate, checkingLightCurate] = useCheckLightCurate()
3333

34-
if (isLightCurate === undefined || networkStatus !== NETWORK_STATUS.supported)
34+
if (checkingLightCurate || networkStatus !== NETWORK_STATUS.supported)
3535
return <Loading />
3636

3737
if (isLightCurate)

src/pages/items-router.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ const Items = loadable(
2424

2525
const ItemsRouter = () => {
2626
const { tcrAddress } = useParams<{ tcrAddress: string }>()
27-
const isLightCurate = useCheckLightCurate()
27+
const [isLightCurate, checkingLightCurate] = useCheckLightCurate()
2828
const { networkStatus } = useTcrNetwork()
2929

30-
if (
31-
typeof isLightCurate === 'undefined' ||
32-
networkStatus !== NETWORK_STATUS.supported
33-
)
30+
if (checkingLightCurate || networkStatus !== NETWORK_STATUS.supported)
3431
return <Loading />
3532

3633
if (isLightCurate)

0 commit comments

Comments
 (0)