@@ -348,25 +348,20 @@ async function switchChain(provider: EIP1193Provider, chain: Chain) {
348
348
method : "wallet_switchEthereumChain" ,
349
349
params : [ { chainId : hexChainId } ] ,
350
350
} ) ;
351
- // biome-ignore lint/suspicious/noExplicitAny: TODO: fix any
352
- } catch ( e : any ) {
351
+ } catch {
353
352
// if chain does not exist, add the chain
354
- if ( e ?. code === 4902 || e ?. data ?. originalError ?. code === 4902 ) {
355
- const apiChain = await getChainMetadata ( chain ) ;
356
- await provider . request ( {
357
- method : "wallet_addEthereumChain" ,
358
- params : [
359
- {
360
- chainId : hexChainId ,
361
- chainName : apiChain . name ,
362
- nativeCurrency : apiChain . nativeCurrency ,
363
- rpcUrls : getValidPublicRPCUrl ( apiChain ) , // no client id on purpose here
364
- blockExplorerUrls : apiChain . explorers ?. map ( ( x ) => x . url ) ,
365
- } ,
366
- ] ,
367
- } ) ;
368
- } else {
369
- throw e ;
370
- }
353
+ const apiChain = await getChainMetadata ( chain ) ;
354
+ await provider . request ( {
355
+ method : "wallet_addEthereumChain" ,
356
+ params : [
357
+ {
358
+ chainId : hexChainId ,
359
+ chainName : apiChain . name ,
360
+ nativeCurrency : apiChain . nativeCurrency ,
361
+ rpcUrls : getValidPublicRPCUrl ( apiChain ) , // no client id on purpose here
362
+ blockExplorerUrls : apiChain . explorers ?. map ( ( x ) => x . url ) ,
363
+ } ,
364
+ ] ,
365
+ } ) ;
371
366
}
372
367
}
0 commit comments