Skip to content

Commit dbd3436

Browse files
committed
fix: (bitcoin module) Fix to gran bitcoin module properly
1 parent a65794c commit dbd3436

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/background/connections/middlewares/DAppRequestHandlerMiddleware.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
JsonRpcResponse,
1212
} from '../dAppConnection/models';
1313
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';
1416

1517
export function DAppRequestHandlerMiddleware(
1618
handlers: DAppRequestHandler[],
@@ -49,9 +51,18 @@ export function DAppRequestHandlerMiddleware(
4951
? handler.handleAuthenticated(params)
5052
: handler.handleUnauthenticated(params);
5153
} 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+
5566

5667
if (!context.network) {
5768
promise = Promise.reject(ethErrors.provider.disconnected());

0 commit comments

Comments
 (0)