1
- import { Chain as Metadata } from '@wagmi/chains' ;
2
1
import { getAddress } from 'viem' ;
2
+ import { Chain } from '@/../script/index' ;
3
3
import { RenderDiff } from '@/components/diff/utils/RenderDiff' ;
4
4
import { Copyable } from '@/components/ui/Copyable' ;
5
5
import { classNames , toUppercase } from '@/lib/utils' ;
6
6
import { ExternalLink } from '../layout/ExternalLink' ;
7
7
8
+ type Metadata = Chain [ 'metadata' ] ;
8
9
type MetadataKey = keyof Metadata ;
9
10
10
11
type Props = {
@@ -14,79 +15,74 @@ type Props = {
14
15
} ;
15
16
16
17
const hiddenField = ( field : MetadataKey ) => {
17
- return [ 'network' ] . includes ( field ) ;
18
+ return [ 'networkId' , 'ens' , 'features' , 'icon' , 'slip44' , 'faucets' , 'chain' , 'parent' ] . includes (
19
+ field
20
+ ) ;
18
21
} ;
19
22
20
23
const formatFieldDisplayName = ( field : MetadataKey ) => {
21
- if ( field === 'id' ) return 'Chain ID' ;
24
+ if ( field === 'chainId' ) return 'Chain ID' ;
25
+ if ( field === 'explorers' ) return 'Block Explorers' ;
22
26
if ( field === 'name' ) return 'Name' ;
23
- if ( field === 'rpcUrls' ) return 'RPC URLs' ;
24
- if ( field === 'blockExplorers' ) return 'Block Explorers' ;
25
27
if ( field === 'nativeCurrency' ) return 'Native Currency' ;
26
- if ( field === 'contracts' ) return 'Multicall3' ;
28
+ if ( field === 'rpc' ) return 'RPC URLs' ;
29
+ if ( field === 'shortName' ) return 'Short Name' ;
30
+ if ( field === 'infoURL' ) return 'Info URL' ;
27
31
return field ;
28
32
} ;
29
33
30
- const formatRpcUrls = ( data : Metadata [ 'rpcUrls' ] ) => {
31
- const renderRpcUrls = ( rpcUrls : Metadata [ 'rpcUrls' ] [ 'default' ] ) => (
32
- < ul >
33
- { rpcUrls . http . map ( ( url ) => (
34
- < li className = 'text-secondary text-sm' key = { url } >
35
- < Copyable content = { url } />
36
- </ li >
37
- ) ) }
38
- { rpcUrls . webSocket &&
39
- rpcUrls . webSocket . map ( ( url ) => (
40
- < li className = 'text-secondary text-sm' key = { url } >
41
- < Copyable content = { url } />
42
- </ li >
43
- ) ) }
44
- </ ul >
45
- ) ;
34
+ const formatShortName = ( shortName : string ) => {
35
+ return < Copyable content = { shortName . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) } /> ; // Remove leading and trailing quotes.
36
+ } ;
46
37
38
+ const formatInfoURL = ( infoURL : string ) => {
39
+ return < ExternalLink href = { infoURL } text = { infoURL } /> ;
40
+ } ;
41
+
42
+ const formatNativeCurrency = ( nativeCurrency : Metadata [ 'nativeCurrency' ] ) => {
47
43
return (
48
- < div >
49
- { Object . entries ( data ) . map ( ( [ key , rpcUrls ] , index ) => (
50
- < div key = { key } >
51
- < h3 className = { classNames ( 'font-bold' , index > 0 && 'mt-6' ) } > { toUppercase ( key ) } </ h3 >
52
- { renderRpcUrls ( rpcUrls ) }
53
- </ div >
54
- ) ) }
55
- </ div >
44
+ < >
45
+ < div >
46
+ { nativeCurrency . name } ({ nativeCurrency . symbol } )
47
+ </ div >
48
+ < div className = 'text-secondary text-sm' > { nativeCurrency . decimals } decimals</ div >
49
+ </ >
56
50
) ;
57
51
} ;
58
52
59
- const formatBlockExplorerUrls = ( data : Metadata [ 'blockExplorers' ] ) => {
53
+ const formatRpcUrls = ( rpcUrls : Metadata [ 'rpc' ] ) => {
54
+ return rpcUrls . map ( ( url ) => (
55
+ < Copyable className = 'text-secondary text-sm' key = { url } content = { url } />
56
+ ) ) ;
57
+ } ;
58
+
59
+ const formatBlockExplorerUrls = ( data : Metadata [ 'explorers' ] ) => {
60
60
if ( ! data ) return null ;
61
61
return (
62
62
< div >
63
- { Object . entries ( data ) . map ( ( [ key , blockExplorer ] , index ) => (
63
+ { Object . entries ( data ) . map ( ( [ key , blockExplorer ] ) => (
64
64
< div key = { key } >
65
- < h3 className = { classNames ( 'font-bold' , index > 0 && 'mt-6' ) } > { toUppercase ( key ) } </ h3 >
66
- < p className = 'text-secondary text-sm' >
67
- < ExternalLink href = { blockExplorer . url } text = { blockExplorer . url } />
68
- </ p >
65
+ < Copyable
66
+ className = 'text-secondary text-sm'
67
+ content = { < ExternalLink href = { blockExplorer . url } text = { blockExplorer . url } /> }
68
+ textToCopy = { blockExplorer . url }
69
+ />
69
70
</ div >
70
71
) ) }
71
72
</ div >
72
73
) ;
73
74
} ;
74
75
75
76
const formatFieldInfo = ( field : MetadataKey , contents : Metadata [ MetadataKey ] ) => {
76
- if ( field === 'id ' ) return < Copyable content = { contents ?. toString ( ) || '' } /> ;
77
+ if ( field === 'chainId ' ) return < Copyable content = { contents ?. toString ( ) || '' } /> ;
77
78
if ( field === 'name' ) return < Copyable content = { contents ?. toString ( ) || '' } /> ;
78
- if ( field === 'rpcUrls' ) return formatRpcUrls ( contents as Metadata [ 'rpcUrls' ] ) ;
79
- if ( field === 'blockExplorers' ) {
80
- return formatBlockExplorerUrls ( contents as Metadata [ 'blockExplorers' ] ) ;
81
- }
82
- if ( field === 'nativeCurrency' ) {
83
- const c = contents as Metadata [ 'nativeCurrency' ] ;
84
- return `${ c . name } (${ c . symbol } )` ;
85
- }
86
- if ( field === 'contracts' ) {
87
- const c = contents as Metadata [ 'contracts' ] ;
88
- const multicall3 = c ?. multicall3 ?. address ;
89
- return multicall3 ? getAddress ( multicall3 ) : 'None' ;
79
+ if ( field === 'rpc' ) return formatRpcUrls ( contents as Metadata [ 'rpc' ] ) ;
80
+ if ( field === 'shortName' ) return formatShortName ( contents as Metadata [ 'shortName' ] ) ;
81
+ if ( field === 'infoURL' ) return formatInfoURL ( contents as Metadata [ 'infoURL' ] ) ;
82
+ if ( field === 'nativeCurrency' )
83
+ return formatNativeCurrency ( contents as Metadata [ 'nativeCurrency' ] ) ;
84
+ if ( field === 'explorers' ) {
85
+ return formatBlockExplorerUrls ( contents as Metadata [ 'explorers' ] ) ;
90
86
}
91
87
return JSON . stringify ( contents ) ;
92
88
} ;
@@ -97,21 +93,14 @@ export const DiffMetadata = ({ base, target, onlyShowDiff }: Props) => {
97
93
< >
98
94
{ fields . map ( ( field ) => {
99
95
if ( hiddenField ( field ) ) return null ;
100
-
101
- // When comparing the contracts field, we only consider the Multicall3 field. The other
102
- // fields are around ENS which is just mainnet (and a testnet).
103
- const isEqual =
104
- field === 'contracts'
105
- ? JSON . stringify ( base [ field ] ?. multicall3 ?. address ) ===
106
- JSON . stringify ( target [ field ] ?. multicall3 ?. address )
107
- : JSON . stringify ( base [ field ] ) === JSON . stringify ( target [ field ] ) ;
96
+ const isEqual = JSON . stringify ( base [ field ] ) === JSON . stringify ( target [ field ] ) ;
108
97
const showField = ! isEqual || ! onlyShowDiff ;
109
98
110
99
return (
111
100
showField && (
112
101
< div
113
102
key = { field }
114
- className = 'grid grid-cols-12 items-center border-b border-zinc-500/10 py-6 dark:border-zinc-500/20'
103
+ className = 'grid grid-cols-12 border-b border-zinc-500/10 py-6 dark:border-zinc-500/20'
115
104
>
116
105
< div className = 'col-span-2' > { formatFieldDisplayName ( field ) } </ div >
117
106
< div className = 'col-span-5 pr-4' > { formatFieldInfo ( field , base [ field ] ) } </ div >
0 commit comments