Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix non-EVM EVM methods filtering #28439

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isEvmAccountType } from '@metamask/keyring-api';
import { RestrictedControllerMessenger } from '@metamask/base-controller';
import { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';
import { AccountsControllerGetSelectedMultichainAccountAction } from '@metamask/accounts-controller';
import { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import type { Json, JsonRpcParams } from '@metamask/utils';
import { RestrictedEthMethods } from '../../../shared/constants/permissions';
import { unrestrictedEthSigningMethods } from '../controllers/permissions';

type AllowedActions = AccountsControllerGetSelectedAccountAction;
type AllowedActions = AccountsControllerGetSelectedMultichainAccountAction;

export type EvmMethodsToNonEvmAccountFilterMessenger =
RestrictedControllerMessenger<
Expand Down Expand Up @@ -41,8 +41,13 @@ export default function createEvmMethodsToNonEvmAccountReqFilterMiddleware({
end,
) {
const selectedAccount = messenger.call(
'AccountsController:getSelectedAccount',
'AccountsController:getSelectedMultichainAccount',
);
if (!selectedAccount) {
// If the account is undefined we just skip this middleware (this should never happen
// since it us the current internal account no matter if it's EVM or not).
return next();
}

// If it's an EVM account, there nothing to filter, so jump to the next
// middleware directly.
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5773,7 +5773,7 @@ export default class MetamaskController extends EventEmitter {
createEvmMethodsToNonEvmAccountReqFilterMiddleware({
messenger: this.controllerMessenger.getRestricted({
name: 'EvmMethodsToNonEvmAccountFilterMessenger',
allowedActions: ['AccountsController:getSelectedAccount'],
allowedActions: ['AccountsController:getSelectedMultichainAccount'],
}),
}),
);
Expand Down
Loading