@@ -191,60 +191,37 @@ export async function switchNetwork(chainId) {
191
191
}
192
192
193
193
export function updateCurrentNetworkDisplay ( ) {
194
- const currentChainId = globalContext . chainIdInt
195
- ? globalContext . chainIdInt . toString ( 16 )
196
- : globalContext . chainIdPadded ;
197
194
const currentNetworkName = document . getElementById ( 'currentNetworkName' ) ;
198
195
199
- if ( currentChainId ) {
200
- // Convert chainId to proper format for comparison
201
- let normalizedChainId ;
202
- if ( typeof currentChainId === 'string' ) {
203
- if ( currentChainId . startsWith ( '0x' ) ) {
204
- normalizedChainId = currentChainId ;
205
- } else {
206
- normalizedChainId = `0x${ currentChainId } ` ;
207
- }
208
- } else {
209
- normalizedChainId = `0x${ currentChainId . toString ( 16 ) } ` ;
210
- }
211
-
212
- const network = NETWORKS . find ( ( n ) => n . chainId === normalizedChainId ) ;
196
+ if (
197
+ globalContext . chainIdInt !== undefined &&
198
+ globalContext . chainIdInt !== null
199
+ ) {
200
+ const network = NETWORKS . find ( ( n ) => {
201
+ const networkChainId = parseInt ( n . chainId , 16 ) ;
202
+ return networkChainId === globalContext . chainIdInt ;
203
+ } ) ;
213
204
214
205
if ( network ) {
215
206
currentNetworkName . textContent = `Current Network: ${ network . name } ` ;
216
207
} else {
217
- // Extract the actual chain ID from the padded version if needed
218
- let displayChainId = normalizedChainId ;
219
- if ( normalizedChainId . length > 10 ) {
220
- // If it's a padded chain ID, try to extract the actual chain ID
221
- const actualChainId = globalContext . chainIdInt
222
- ? globalContext . chainIdInt . toString ( 16 )
223
- : null ;
224
- if ( actualChainId ) {
225
- displayChainId = `0x${ actualChainId } ` ;
226
- }
227
- }
228
- currentNetworkName . textContent = `Current Network: Chain ID ${ displayChainId } ` ;
208
+ // Fallback to chain ID if network not found
209
+ currentNetworkName . textContent = `Current Network: Chain ID 0x${ globalContext . chainIdInt . toString (
210
+ 16 ,
211
+ ) } `;
229
212
}
230
213
} else {
231
214
currentNetworkName . textContent = 'Current Network: Not Connected' ;
232
215
}
233
216
}
234
217
235
218
export function updateActiveNetworkInModal ( ) {
236
- const currentChainId =
237
- globalContext . chainIdPadded ||
238
- ( globalContext . chainIdInt ? globalContext . chainIdInt . toString ( 16 ) : null ) ;
239
219
const networkItems = document . querySelectorAll ( '.network-modal-item' ) ;
240
220
241
221
networkItems . forEach ( ( item ) => {
242
222
const itemChainId = item . dataset . chainId ;
243
- const isActive =
244
- currentChainId &&
245
- ( itemChainId === currentChainId ||
246
- itemChainId === `0x${ currentChainId } ` ||
247
- itemChainId === parseInt ( currentChainId , 16 ) . toString ( 16 ) ) ;
223
+ const itemChainIdInt = parseInt ( itemChainId , 16 ) ;
224
+ const isActive = itemChainIdInt === globalContext . chainIdInt ;
248
225
249
226
if ( isActive ) {
250
227
item . classList . add ( 'active' ) ;
0 commit comments