File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
src/background/connections/middlewares Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import {
11
11
JsonRpcResponse ,
12
12
} from '../dAppConnection/models' ;
13
13
import { ModuleManager } from '@src/background/vmModules/ModuleManager' ;
14
+ import { caipToChainId , chainIdToCaip } from '@src/utils/caipConversion' ;
15
+ import { isBitcoinNetwork } from '@src/background/services/network/utils/isBitcoinNetwork' ;
14
16
15
17
export function DAppRequestHandlerMiddleware (
16
18
handlers : DAppRequestHandler [ ] ,
@@ -49,9 +51,18 @@ export function DAppRequestHandlerMiddleware(
49
51
? handler . handleAuthenticated ( params )
50
52
: handler . handleUnauthenticated ( params ) ;
51
53
} else {
52
- const [ module ] = await resolve (
53
- moduleManager . loadModule ( context . request . params . scope , method ) ,
54
- ) ;
54
+ const isBitcoin = context . network
55
+ ? isBitcoinNetwork ( context . network )
56
+ : false ;
57
+ const scope = context . request . params . scope ;
58
+ const chainId = isBitcoin
59
+ ? scope . startsWith ( '0x' )
60
+ ? Number ( scope ) . toString ( )
61
+ : caipToChainId ( scope ) . toString ( )
62
+ : scope ;
63
+
64
+ const [ module ] = await resolve ( moduleManager . loadModule ( chainId , method ) ) ;
65
+
55
66
56
67
if ( ! context . network ) {
57
68
promise = Promise . reject ( ethErrors . provider . disconnected ( ) ) ;
You can’t perform that action at this time.
0 commit comments