@@ -10,6 +10,8 @@ import Logger from '../../util/Logger';
1010import { WalletDevice } from '@metamask/transaction-controller' ;
1111
1212import { PermissionController } from '@metamask/permission-controller' ;
13+ import { isStrictHexString } from '@metamask/utils' ;
14+ import type { Hex } from '@metamask/utils' ;
1315import { NavigationContainerRef } from '@react-navigation/native' ;
1416import { Core } from '@walletconnect/core' ;
1517import { ErrorResponse } from '@walletconnect/jsonrpc-types' ;
@@ -296,7 +298,7 @@ class WalletConnect2Session {
296298 chainId,
297299 accounts,
298300 } : {
299- chainId : number ;
301+ chainId : Hex ;
300302 accounts : string [ ] ;
301303 } ) => {
302304 try {
@@ -326,20 +328,20 @@ class WalletConnect2Session {
326328 return ;
327329 }
328330 }
329- if ( chainId === 0 ) {
331+ if ( ! isStrictHexString ( chainId ) || chainId . toLowerCase ( ) === '0x0' ) {
330332 DevLogger . log (
331333 `WC2::updateSession invalid chainId --- skip ${ typeof chainId } chainId=${ chainId } accounts=${ accounts } )` ,
332334 ) ;
333335 // overwrite chainId with actual value.
334- const selectedChainId = parseInt ( selectChainId ( store . getState ( ) ) ) ;
336+ const selectedChainId = selectChainId ( store . getState ( ) ) ;
335337 DevLogger . log (
336338 `WC2::updateSession overwrite invalid chain Id with selectedChainId=${ selectedChainId } ` ,
337339 ) ;
338340 chainId = selectedChainId ;
339341 }
340342 await this . web3Wallet . updateSession ( {
341343 topic : this . session . topic ,
342- chainId,
344+ chainId : parseInt ( chainId , 16 ) ,
343345 accounts,
344346 } ) ;
345347 } catch ( err ) {
@@ -566,13 +568,12 @@ export class WC2Manager {
566568 DevLogger . log ( `WC2::init approvedAccounts` , approvedAccounts ) ;
567569 }
568570
569- const nChainId = parseInt ( chainId , 16 ) ;
570571 DevLogger . log (
571- `WC2::init updateSession session=${ sessionKey } chainId=${ chainId } nChainId= ${ nChainId } selectedAddress=${ selectedAddress } ` ,
572+ `WC2::init updateSession session=${ sessionKey } chainId=${ chainId } selectedAddress=${ selectedAddress } ` ,
572573 approvedAccounts ,
573574 ) ;
574575 await this . sessions [ sessionKey ] . updateSession ( {
575- chainId : nChainId ,
576+ chainId,
576577 accounts : approvedAccounts ,
577578 } ) ;
578579 } catch ( err ) {
0 commit comments