@@ -15,79 +15,112 @@ interface InfoPanelProps {
1515 example : Example
1616}
1717
18- export default function InfoPanel ( { network} : InfoPanelProps ) {
19- const { getColor, getNetworkColor } = useTheme ( )
18+ interface InfoRowProps {
19+ label : string
20+ value : React . ReactNode
21+ }
22+
23+ interface ExternalLinkProps extends React . AnchorHTMLAttributes < HTMLAnchorElement > {
24+ networkColor : string
25+ }
26+
27+ const ExternalLinkIcon = ( ) => (
28+ < svg width = "10" height = "10" viewBox = "0 0 24 24" fill = "none" stroke = "currentColor"
29+ strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
30+ < path d = "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
31+ < polyline points = "15 3 21 3 21 9" />
32+ < line x1 = "10" y1 = "14" x2 = "21" y2 = "3" />
33+ </ svg >
34+ )
35+
36+ const InfoRow = ( { label, value } : InfoRowProps ) => {
37+ const { getColor } = useTheme ( )
38+ return (
39+ < div className = "flex justify-between items-center" >
40+ < span style = { { color : getColor ( 'textSecondary' ) } } > { label } :</ span >
41+ < div className = "text-right" > { value } </ div >
42+ </ div >
43+ )
44+ }
45+
46+ const ExternalLink = ( { networkColor, children, ...props } : ExternalLinkProps ) => (
47+ < a
48+ { ...props }
49+ target = "_blank"
50+ rel = "noopener noreferrer"
51+ className = "hover:underline truncate max-w-32 inline-flex items-center"
52+ style = { { color : networkColor } }
53+ >
54+ { children }
55+ < ExternalLinkIcon />
56+ </ a >
57+ )
58+
59+ const NetworkInfo = ( { network } : { network : Network } ) => {
60+ const { getNetworkColor, getColor } = useTheme ( )
61+ const networkColor = getNetworkColor ( 'primary' )
2062
21-
22- const NetworkInfo = ( ) => (
63+ return (
2364 < div className = "space-y-3" >
2465 < div className = "flex items-center space-x-2" >
2566 < NetworkBadge network = { network } />
2667 < h3 className = "text-sm font-medium" > { network . name } </ h3 >
2768 </ div >
2869
2970 < div className = "text-xs space-y-2" >
30- < InfoRow label = "Token" value = { `${ network . tokenSymbol } (${ network . tokenDecimals } decimals)` } />
71+ < InfoRow
72+ label = "Token"
73+ value = { `${ network . tokenSymbol } (${ network . tokenDecimals } decimals)` }
74+ />
3175
3276 < InfoRow
3377 label = "Explorer"
3478 value = {
35- < a
79+ < ExternalLink
3680 href = { network . explorer }
37- target = "_blank"
38- rel = "noopener noreferrer"
39- className = "hover:underline truncate max-w-32 inline-flex items-center"
40- style = { { color : getNetworkColor ( 'primary' ) } }
81+ networkColor = { networkColor }
4182 >
4283 { network . explorer . replace ( / ^ h t t p s ? : \/ \/ / , '' ) }
43- < svg width = "10" height = "10" viewBox = "0 0 24 24" className = "ml-1" fill = "none" stroke = "currentColor" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
44- < path d = "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" > </ path >
45- < polyline points = "15 3 21 3 21 9" > </ polyline >
46- < line x1 = "10" y1 = "14" x2 = "21" y2 = "3" > </ line >
47- </ svg >
48- </ a >
84+ </ ExternalLink >
4985 }
5086 />
5187
5288 < InfoRow
5389 label = "Faucet"
5490 value = {
55- < a
91+ < ExternalLink
5692 href = { network . faucet }
57- target = "_blank"
58- rel = "noopener noreferrer"
59- className = "hover:underline truncate max-w-32 inline-flex items-center"
60- style = { { color : getNetworkColor ( 'primary' ) } }
93+ networkColor = { networkColor }
6194 >
6295 Get tokens
63- < svg width = "10" height = "10" viewBox = "0 0 24 24" className = "ml-1" fill = "none" stroke = "currentColor" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
64- < path d = "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" > </ path >
65- < polyline points = "15 3 21 3 21 9" > </ polyline >
66- < line x1 = "10" y1 = "14" x2 = "21" y2 = "3" > </ line >
67- </ svg >
68- </ a >
96+ </ ExternalLink >
6997 }
7098 />
7199 </ div >
72100
73101 < div
74102 className = "mt-3 p-2 rounded-md text-xs flex items-center space-x-2"
75- style = { { backgroundColor : `${ getNetworkColor ( 'primary' ) } 10` } }
103+ style = { { backgroundColor : `${ networkColor } 10` } }
76104 >
77- < svg width = "16" height = "16" viewBox = "0 0 24 24" fill = "none" stroke = { getNetworkColor ( 'primary' ) } strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
78- < circle cx = "12" cy = "12" r = "10" > </ circle >
79- < line x1 = "12" y1 = "16" x2 = "12" y2 = "12" > </ line >
80- < line x1 = "12" y1 = "8" x2 = "12.01" y2 = "8" > </ line >
105+ < svg width = "16" height = "16" viewBox = "0 0 24 24" fill = "none"
106+ stroke = { networkColor } strokeWidth = "2" strokeLinecap = "round"
107+ strokeLinejoin = "round" >
108+ < circle cx = "12" cy = "12" r = "10" />
109+ < line x1 = "12" y1 = "16" x2 = "12" y2 = "12" />
110+ < line x1 = "12" y1 = "8" x2 = "12.01" y2 = "8" />
81111 </ svg >
82112 < span style = { { color : getColor ( 'textSecondary' ) } } >
83113 Connect to { network . endpoint } to interact with the { network . name } testnet
84114 </ span >
85115 </ div >
86116 </ div >
87- ) ;
117+ )
118+ }
88119
89-
90- const TestAccounts = ( ) => (
120+ const TestAccounts = ( ) => {
121+ const { getColor } = useTheme ( )
122+
123+ return (
91124 < div className = "space-y-3" >
92125 < p className = "text-xs mb-3" style = { { color : getColor ( 'textSecondary' ) } } >
93126 These well-known accounts have funds on testnets:
@@ -120,46 +153,30 @@ export default function InfoPanel({ network}: InfoPanelProps) {
120153 ) ) }
121154 </ div >
122155 </ div >
123- ) ;
156+ )
157+ }
124158
125-
126- const tabs = [
159+ export default function InfoPanel ( { network } : InfoPanelProps ) {
160+ const tabs = React . useMemo ( ( ) => [
127161 {
128162 id : 'network' ,
129163 label : 'Network Info' ,
130- content : < NetworkInfo />
164+ content : < NetworkInfo network = { network } />
131165 } ,
132166 {
133167 id : 'accounts' ,
134168 label : 'Test Accounts' ,
135169 content : < TestAccounts />
136170 }
137- ] ;
171+ ] , [ network ] )
138172
139173 return (
140174 < Card className = "overflow-hidden" >
141175 < Tabs
142176 tabs = { tabs }
143177 variant = "boxed"
144- networkColored = { true }
178+ networkColored
145179 />
146180 </ Card >
147- ) ;
148- }
149-
150-
151- interface InfoRowProps {
152- label : string ;
153- value : React . ReactNode ;
154- }
155-
156- function InfoRow ( { label, value } : InfoRowProps ) {
157- const { getColor } = useTheme ( ) ;
158-
159- return (
160- < div className = "flex justify-between items-center" >
161- < span style = { { color : getColor ( 'textSecondary' ) } } > { label } :</ span >
162- < div className = "text-right" > { value } </ div >
163- </ div >
164- ) ;
181+ )
165182}
0 commit comments