Skip to content

Commit

Permalink
feat: use reservoir chains
Browse files Browse the repository at this point in the history
  • Loading branch information
r3lays committed Dec 14, 2023
1 parent 0643707 commit 59526ed
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions hooks/useIsUnsupportedChain.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
import { reservoirChains } from '@reservoir0x/reservoir-sdk'
import { useEffect, useState } from 'react'
import { useNetwork } from 'wagmi'

interface Chain {
name: string
chainId: number
}
type Chain = Omit<(typeof reservoirChains)['mainnet'], 'websocketUrl'>

const TESTNET_CHAINS: Chain[] = [
{ name: 'Goerli', chainId: 5 },
{ name: 'Sepolia', chainId: 11155111 },
{ name: 'Polygon Mumbai', chainId: 80001 },
{ name: 'BaseGoerli', chainId: 84531 },
{ name: 'Scroll Testnet', chainId: 534352 },
{ name: 'Zora Testnet', chainId: 999 },
reservoirChains.goerli,
reservoirChains.sepolia,
reservoirChains.mumbai,
reservoirChains.baseGoerli,
reservoirChains.scrollTestnet,
reservoirChains.zoraTestnet,
]

const MAINNET_CHAINS: Chain[] = [
reservoirChains.mainnet,
reservoirChains.polygon,
reservoirChains.arbitrum,
reservoirChains.optimism,
reservoirChains.zora,
reservoirChains.bsc,
reservoirChains.avalanche,
reservoirChains.base,
reservoirChains.linea,
reservoirChains.zkSync,
reservoirChains.polygonZkEvm,
reservoirChains.scroll,
]

const IS_TESTNET_DEPLOYMENT = process.env.NEXT_PUBLIC_HOST_URL?.includes(
'testnets.reservoir.tools'
)

export default () => {
const [unsupportedChain, setUnsupportedChain] = useState<
{ name: string; chainId: number } | undefined
>(undefined)
const [unsupportedChain, setUnsupportedChain] = useState<Chain | undefined>(
undefined
)
const { chain } = useNetwork()

useEffect(() => {
setUnsupportedChain(
TESTNET_CHAINS.find(({ chainId }) => chain?.id === chainId)
(IS_TESTNET_DEPLOYMENT ? TESTNET_CHAINS : MAINNET_CHAINS).find(
({ id }) => chain?.id === id
)
)
}, [chain])
return {
Expand Down

0 comments on commit 59526ed

Please sign in to comment.