Skip to content

Commit 56d7b26

Browse files
committed
refactor: use caip2Id to determine EVM networks instead of network list
1 parent 4db3409 commit 56d7b26

File tree

3 files changed

+26
-79
lines changed

3 files changed

+26
-79
lines changed

website/src/supportedNetworks/components/NetworkDetailsPage.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
import { NetworkType } from '@pinax/graph-networks-registry'
2-
import type { ComponentPropsWithoutRef } from 'react'
31
import { memo } from 'react'
42

5-
import { classNames } from '@edgeandnode/gds'
63
import { Subgraph, Substreams, SubstreamsPoweredSubgraph } from '@edgeandnode/gds/icons'
74

85
import { Card, TimeIcon } from '@/components'
96
import { useI18n } from '@/i18n'
10-
import { isNonEVMNetwork } from '@/supportedNetworks/utils'
7+
import { isEVMNetwork, type Network } from '../utils'
118

129
type NetworkDetailsPageProps = {
13-
network: {
14-
id: string
15-
fullName: string
16-
networkType: NetworkType
17-
protocol: string
18-
chainId: number | string
19-
nativeCurrency: string
20-
docs: string
21-
}
10+
network: Network
2211
}
2312

2413
const EVMResources = memo(() => {
@@ -128,7 +117,7 @@ const NetworkDetailsPage = memo(({ network }: NetworkDetailsPageProps) => {
128117
return (
129118
<>
130119
<h3 className="text-h18 mt-0">{t('index.supportedNetworks.guides')}</h3>
131-
{isNonEVMNetwork(network.id) ? <NonEVMResources /> : <EVMResources />}
120+
{isEVMNetwork(network) ? <EVMResources /> : <NonEVMResources />}
132121
</>
133122
)
134123
})

website/src/supportedNetworks/components/NetworkPage.tsx

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NetworkType } from '@pinax/graph-networks-registry'
22
import Head from 'next/head'
3-
import { useRouter } from 'next/router'
43
import { useData } from 'nextra/hooks'
54
import { memo } from 'react'
65

@@ -9,22 +8,7 @@ import { NetworkIcon } from '@edgeandnode/go'
98

109
import NetworkDetailsPage from './NetworkDetailsPage'
1110
import { useI18n } from '@/i18n'
12-
import { getIconVariant, shouldShowSkeleton } from '@/supportedNetworks/utils'
13-
14-
type CAIP2Id = `${string}:${string | number}`
15-
16-
interface Network {
17-
id: string
18-
fullName: string
19-
shortName?: string
20-
networkType: NetworkType
21-
graphNode?: {
22-
protocol: string
23-
}
24-
caip2Id?: CAIP2Id
25-
nativeToken?: string
26-
docsUrl?: string
27-
}
11+
import { getIconVariant, shouldShowSkeleton, type Network } from '../utils'
2812

2913
interface NetworkPageProps {
3014
network?: Network
@@ -38,9 +22,10 @@ export const NetworkPage = memo(({ network }: NetworkPageProps) => {
3822
id: '',
3923
fullName: '',
4024
networkType: NetworkType.Mainnet,
25+
caip2Id: '',
4126
}
27+
4228
const { t } = useI18n()
43-
const router = useRouter()
4429

4530
return (
4631
<>
@@ -120,17 +105,7 @@ export const NetworkPage = memo(({ network }: NetworkPageProps) => {
120105

121106
<hr />
122107

123-
<NetworkDetailsPage
124-
network={{
125-
id: networkData.id,
126-
fullName: networkData.fullName,
127-
networkType: networkData.networkType,
128-
protocol: networkData.graphNode?.protocol ?? '',
129-
chainId: networkData.caip2Id?.split(':')[1] ?? '',
130-
nativeCurrency: networkData.nativeToken ?? '',
131-
docs: networkData.docsUrl ?? '',
132-
}}
133-
/>
108+
<NetworkDetailsPage network={networkData} />
134109
</div>
135110
</>
136111
)

website/src/supportedNetworks/utils.ts

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { NetworkType } from '@pinax/graph-networks-registry'
2+
13
// Networks that should use the "mono" icon variant
24
export const MONO_ICON_NETWORKS = [
35
'vana',
@@ -25,38 +27,6 @@ export const MONO_ICON_NETWORKS = [
2527
// Skeleton networks (no icon available)
2628
export const MISSING_ICON_NETWORKS = ['ink-sepolia']
2729

28-
// Non-EVM networks
29-
export const NON_EVM_NETWORKS = [
30-
'eos',
31-
'jungle4',
32-
'kylin',
33-
'telos-testnet',
34-
'telos',
35-
'wax-testnet',
36-
'wax',
37-
'arweave-mainnet',
38-
'gnosis-chiado-cl',
39-
'gnosis-cl',
40-
'holesky-cl',
41-
'mainnet-cl',
42-
'sepolia-cl',
43-
'btc',
44-
'litecoin',
45-
'injective-mainnet',
46-
'injective-testnet',
47-
'mantra-mainnet',
48-
'mantra-testnet',
49-
'near-mainnet',
50-
'near-testnet',
51-
'solana-accounts',
52-
'solana-devnet',
53-
'solana-mainnet',
54-
'solana-mainnet-beta',
55-
'solana-testnet',
56-
'starknet-mainnet',
57-
'starknet-testnet',
58-
]
59-
6030
// Networks with Token API support (TODO: remove once the registry has this information)
6131
export const TOKEN_API_NETWORKS = ['mainnet', 'base', 'bsc', 'arbitrum-one', 'matic', 'optimism']
6232

@@ -68,14 +38,23 @@ export const shouldShowSkeleton = (networkId: string): boolean => {
6838
return MISSING_ICON_NETWORKS.includes(networkId) || !networkId
6939
}
7040

71-
export const isNonEVMNetwork = (networkId: string): boolean => {
72-
return NON_EVM_NETWORKS.includes(networkId)
73-
}
74-
7541
export const supportsTokenAPI = (networkId: string): boolean => {
7642
return TOKEN_API_NETWORKS.includes(networkId)
7743
}
7844

45+
export interface Network {
46+
id: string
47+
fullName: string
48+
shortName?: string
49+
networkType: NetworkType
50+
graphNode?: {
51+
protocol: string
52+
}
53+
caip2Id: string
54+
nativeToken?: string
55+
docsUrl?: string
56+
}
57+
7958
export interface NetworkData {
8059
id: string
8160
shortName: string
@@ -128,3 +107,7 @@ export const processNetworksData = (networks: NetworkData[]): ProcessedNetwork[]
128107
})
129108
.sort((a, b) => a.fullName.localeCompare(b.fullName))
130109
}
110+
111+
export const isEVMNetwork = (network: Network | NetworkData): boolean => {
112+
return network.caip2Id.startsWith('eip155:')
113+
}

0 commit comments

Comments
 (0)