Skip to content

Commit

Permalink
fix: revert changes to dapp request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w committed Aug 2, 2024
1 parent a335e12 commit f9fbb13
Showing 1 changed file with 6 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
JsonRpcRequestParams,
JsonRpcResponse,
} from '../dAppConnection/models';
import ModuleManager from '@src/background/vmModules/ModuleManager';

export function DAppRequestHandlerMiddleware(
handlers: DAppRequestHandler[],
Expand All @@ -28,15 +27,6 @@ export function DAppRequestHandlerMiddleware(
const handler = handlerMap.get(context.request.params.request.method);
// Call correct handler method based on authentication status
let promise: Promise<JsonRpcResponse<unknown>>;

if (!context.domainMetadata) {
context.response = {
error: ethErrors.rpc.invalidRequest('Unknown request domain'),
};

return next();
}

if (handler) {
const params: JsonRpcRequestParams<DAppProviderRequest> = {
...context.request.params,
Expand All @@ -56,36 +46,13 @@ export function DAppRequestHandlerMiddleware(
if (!activeNetwork) {
promise = Promise.reject(ethErrors.provider.disconnected());
} else {
const module = await ModuleManager.loadModule(
context.request.params.scope,
context.request.params.request.method
promise = engine(activeNetwork).then((e) =>
e.handle<unknown, unknown>({
...context.request.params.request,
id: crypto.randomUUID(),
jsonrpc: '2.0',
})
);

if (module) {
promise = module.onRpcRequest(
{
chainId: activeNetwork.caipId,
dappInfo: {
icon: context.domainMetadata.icon ?? '',
name: context.domainMetadata.name ?? '',
url: context.domainMetadata.domain,
},
requestId: context.request.id,
sessionId: context.request.params.sessionId,
method: context.request.params.request.method,
params: context.request.params.request.params,
},
activeNetwork
);
} else {
promise = engine(activeNetwork).then((e) =>
e.handle<unknown, unknown>({
...context.request.params.request,
id: crypto.randomUUID(),
jsonrpc: '2.0',
})
);
}
}
}

Expand Down

0 comments on commit f9fbb13

Please sign in to comment.