11import React , { useEffect , useMemo } from 'react'
2- import {
3- Route ,
4- Switch ,
5- Redirect
6- } from 'react-router-dom'
2+ import { Route , Switch , Redirect } from 'react-router-dom'
73import { ApolloProvider } from '@apollo/client'
84import { useWeb3Context , Connectors } from 'web3-react'
95import getNetworkEnv from 'utils/network-env'
10-
116import loadable from '@loadable/component'
127import ErrorPage from 'pages/error-page'
138import NoWeb3Detected from 'pages/no-web3'
@@ -19,7 +14,7 @@ import usePathValidation from 'hooks/use-path-validation'
1914import useGraphQLClient from 'hooks/use-graphql-client'
2015import { Web3ContextCurate } from 'types/web3-cotext'
2116
22- const { Connector } = Connectors ;
17+ const { Connector } = Connectors
2318
2419const ItemsRouter = loadable (
2520 ( ) => import ( /* webpackPrefetch: true */ 'pages/items-router' ) ,
@@ -41,30 +36,38 @@ const ClassicFactory = loadable(
4136 { fallback : < Loading /> }
4237)
4338
44-
4539const AppRouter = ( ) => {
46- const { networkId, error } : Web3ContextCurate = useWeb3Context ( ) ;
47- const isUnsupported = useMemo ( ( ) => error ?. code === Connector . errorCodes . UNSUPPORTED_NETWORK , [ error ] )
48- const tcrAddress = getNetworkEnv ( 'REACT_APP_DEFAULT_TCR_ADDRESSES' , networkId as number ) ;
40+ const { networkId, error } : Web3ContextCurate = useWeb3Context ( )
41+ const isUnsupported = useMemo (
42+ ( ) => error ?. code === Connector . errorCodes . UNSUPPORTED_NETWORK ,
43+ [ error ]
44+ )
45+ const tcrAddress = getNetworkEnv (
46+ 'REACT_APP_DEFAULT_TCR_ADDRESSES' ,
47+ networkId as number
48+ )
4949 const [ pathResolved , invalidTcrAddr ] = usePathValidation ( )
5050 const client = useGraphQLClient ( networkId )
5151
5252 useEffect ( ( ) => {
5353 if ( isUnsupported && window . ethereum ) {
54- const chainIdTokens = window . location . pathname . match ( / \/ t c r \/ ( \d + ) \/ / ) ;
55- const chainId = hexlify ( chainIdTokens && chainIdTokens ?. length > 1 ? chainIdTokens [ 1 ] : DEFAULT_NETWORK ) ;
54+ const chainIdTokens = window . location . pathname . match ( / \/ t c r \/ ( \d + ) \/ / )
55+ const chainId = hexlify (
56+ chainIdTokens && chainIdTokens ?. length > 1
57+ ? chainIdTokens [ 1 ]
58+ : DEFAULT_NETWORK
59+ )
5660
5761 window . ethereum . request ( {
5862 method : 'wallet_switchEthereumChain' ,
5963 params : [ { chainId } ]
60- } ) ;
64+ } )
6165 }
62- } , [ isUnsupported ] ) ;
66+ } , [ isUnsupported ] )
6367
64- if ( Object . entries ( connectors ) . length === 0 )
65- return < NoWeb3Detected />
68+ if ( Object . entries ( connectors ) . length === 0 ) return < NoWeb3Detected />
6669
67- if ( isUnsupported && error ) {
70+ if ( isUnsupported && error )
6871 return (
6972 < ErrorPage
7073 code = { ' ' }
@@ -78,16 +81,16 @@ const AppRouter = () => {
7881 }
7982 />
8083 )
81- } else if ( ! networkId || ! pathResolved ) {
82- return < Loading />
83- } else if ( invalidTcrAddr || ! client ) {
84- return < ErrorPage />
85- }
84+ else if ( ! networkId || ! pathResolved ) return < Loading />
85+ else if ( invalidTcrAddr || ! client ) return < ErrorPage />
8686
8787 return (
8888 < ApolloProvider client = { client } >
8989 < Switch >
90- < Route path = "/tcr/:chainId/:tcrAddress/:itemID" component = { ItemDetailsRouter } />
90+ < Route
91+ path = "/tcr/:chainId/:tcrAddress/:itemID"
92+ component = { ItemDetailsRouter }
93+ />
9194 < Route path = "/tcr/:chainId/:tcrAddress" component = { ItemsRouter } />
9295 < Route path = "/factory" exact component = { Factory } />
9396 < Route path = "/factory-classic" exact component = { ClassicFactory } />
@@ -98,4 +101,4 @@ const AppRouter = () => {
98101 )
99102}
100103
101- export default AppRouter ;
104+ export default AppRouter
0 commit comments