@@ -16,49 +16,44 @@ const usePathValidation = () => {
1616 const isOldPath = / \/ t c r \/ 0 x / . test ( pathname )
1717
1818 if ( isOldPath ) {
19- const searchParams = new URLSearchParams ( search )
2019 let chainId = null
2120 const matches = pathname . match ( / t c r \/ ( 0 x [ 0 - 9 a - z A - Z ] + ) / )
2221 const tcrAddress = matches ? matches [ 1 ] . toLowerCase ( ) : null
2322
24- if ( searchParams . has ( 'chainId' ) ) chainId = searchParams . get ( 'chainId' )
23+ const DEFAULT_TCR_ADDRESSES = JSON . parse (
24+ process . env . REACT_APP_DEFAULT_TCR_ADDRESSES as string
25+ )
26+ const ADDRs = Object . values ( DEFAULT_TCR_ADDRESSES ) . map ( addr =>
27+ ( addr as string ) . toLowerCase ( )
28+ )
29+ const CHAIN_IDS = Object . keys ( DEFAULT_TCR_ADDRESSES )
30+ const tcrIndex = ADDRs . findIndex ( addr => addr === tcrAddress )
31+
32+ if ( tcrIndex >= 0 ) chainId = Number ( CHAIN_IDS [ tcrIndex ] )
2533 else {
26- const DEFAULT_TCR_ADDRESSES = JSON . parse (
27- process . env . REACT_APP_DEFAULT_TCR_ADDRESSES as string
28- )
29- const ADDRs = Object . values ( DEFAULT_TCR_ADDRESSES ) . map ( addr =>
30- ( addr as string ) . toLowerCase ( )
34+ const SUBGRAPH_URLS = JSON . parse (
35+ process . env . REACT_APP_SUBGRAPH_URL as string
3136 )
32- const CHAIN_IDS = Object . keys ( DEFAULT_TCR_ADDRESSES )
33- const tcrIndex = ADDRs . findIndex ( addr => addr === tcrAddress )
34-
35- if ( tcrIndex >= 0 ) chainId = Number ( CHAIN_IDS [ tcrIndex ] )
36- else {
37- const SUBGRAPH_URLS = JSON . parse (
38- process . env . REACT_APP_SUBGRAPH_URL as string
39- )
40- const queryResults = await Promise . all (
41- Object . values ( SUBGRAPH_URLS ) . map ( subgraph => {
42- const client = new ApolloClient ( {
43- link : new HttpLink ( { uri : subgraph as string } ) ,
44- cache : new InMemoryCache ( )
45- } )
46- return client . query ( {
47- query : TCR_EXISTENCE_TEST ,
48- variables : {
49- tcrAddress
50- }
51- } )
37+ const queryResults = await Promise . all (
38+ Object . values ( SUBGRAPH_URLS ) . map ( subgraph => {
39+ const client = new ApolloClient ( {
40+ link : new HttpLink ( { uri : subgraph as string } ) ,
41+ cache : new InMemoryCache ( )
5242 } )
53- )
54- const validIndex = queryResults . findIndex (
55- ( { data : { lregistry, registry } } ) =>
56- lregistry !== null || registry !== null
57- )
43+ return client . query ( {
44+ query : TCR_EXISTENCE_TEST ,
45+ variables : {
46+ tcrAddress
47+ }
48+ } )
49+ } )
50+ )
51+ const validIndex = queryResults . findIndex (
52+ ( { data : { lregistry, registry } } ) =>
53+ lregistry !== null || registry !== null
54+ )
5855
59- if ( validIndex >= 0 )
60- chainId = Object . keys ( SUBGRAPH_URLS ) [ validIndex ]
61- }
56+ if ( validIndex >= 0 ) chainId = Object . keys ( SUBGRAPH_URLS ) [ validIndex ]
6257 }
6358
6459 if ( chainId ) {
0 commit comments