Skip to content

Commit 1269fc4

Browse files
author
devofficer
committed
chore: usePathValidation not to consider chainId param anymore
1 parent 733a432 commit 1269fc4

File tree

3 files changed

+31
-45
lines changed

3 files changed

+31
-45
lines changed

src/bootstrap/app-router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { DEFAULT_NETWORK } from 'config/networks'
1212
import { hexlify } from 'utils/string'
1313
import usePathValidation from 'hooks/use-path-validation'
1414
import useGraphQLClient from 'hooks/use-graphql-client'
15-
import { Web3ContextCurate } from 'types/web3-cotext'
15+
import { Web3ContextCurate } from 'types/web3-context'
1616

1717
const { Connector } = Connectors
1818

src/hooks/use-path-validation.ts

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,44 @@ const usePathValidation = () => {
1616
const isOldPath = /\/tcr\/0x/.test(pathname)
1717

1818
if (isOldPath) {
19-
const searchParams = new URLSearchParams(search)
2019
let chainId = null
2120
const matches = pathname.match(/tcr\/(0x[0-9a-zA-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) {

src/types/web3-cotext.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)