Skip to content

Commit

Permalink
remove disabledRpcMethodPreferences, need migration
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Jun 25, 2024
1 parent 4ded566 commit b0258ad
Show file tree
Hide file tree
Showing 14 changed files with 3 additions and 141 deletions.
24 changes: 0 additions & 24 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default class PreferencesController {
useNonceField: false,
usePhishDetect: true,
dismissSeedBackUpReminder: false,
disabledRpcMethodPreferences: {},
useMultiAccountBalanceChecker: true,
hasDismissedOpenSeaToBlockaidBanner: false,
useSafeChainsListValidation: true,
Expand Down Expand Up @@ -558,25 +557,6 @@ export default class PreferencesController {
});
}

/**
* A setter for the user preference to enable/disable rpc methods
*
* @param {string} methodName - The RPC method name to change the setting of
* @param {bool} isEnabled - true to enable the rpc method
*/
async setDisabledRpcMethodPreference(methodName, isEnabled) {
const currentRpcMethodPreferences =
this.store.getState().disabledRpcMethodPreferences;
const updatedRpcMethodPreferences = {
...currentRpcMethodPreferences,
[methodName]: isEnabled,
};

this.store.updateState({
disabledRpcMethodPreferences: updatedRpcMethodPreferences,
});
}

/**
* A setter for the incomingTransactions in preference to be updated
*
Expand All @@ -593,10 +573,6 @@ export default class PreferencesController {
this.store.updateState({ enableMV3TimestampSave: value });
}

getRpcMethodPreferences() {
return this.store.getState().disabledRpcMethodPreferences;
}

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
setSnapsAddSnapAccountModalDismissed(value) {
this.store.updateState({ snapsAddSnapAccountModalDismissed: value });
Expand Down
53 changes: 3 additions & 50 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
} from '../../../shared/constants/security-provider';

///: BEGIN:ONLY_INCLUDE_IF(blockaid)
import {
EIP712_PRIMARY_TYPE_PERMIT,
SIGNING_METHODS,
} from '../../../shared/constants/transaction';
import { getBlockaidMetricsProps } from '../../../ui/helpers/utils/metrics';
import { EIP712_PRIMARY_TYPE_PERMIT } from '../../../shared/constants/transaction';
///: END:ONLY_INCLUDE_IF
import { REDESIGN_APPROVAL_TYPES } from '../../../ui/pages/confirmations/utils/confirm';
import { getSnapAndHardwareInfoForMetrics } from './snap-keyring/metrics';
Expand All @@ -42,7 +38,6 @@ const RATE_LIMIT_TYPES = {
* default is RANDOM_SAMPLE
*/
const RATE_LIMIT_MAP = {
[MESSAGE_TYPE.ETH_SIGN]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V3]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V4]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
Expand Down Expand Up @@ -154,7 +149,6 @@ let globalRateLimitCount = 0;
* @param {Function} opts.getDeviceModel
* @param {Function} opts.isConfirmationRedesignEnabled
* @param {RestrictedControllerMessenger} opts.snapAndHardwareMessenger
* @param {AppStateController} opts.appStateController
* @param {number} [opts.globalRateLimitTimeout] - time, in milliseconds, of the sliding
* time window that should limit the number of method calls tracked to globalRateLimitMaxAmount.
* @param {number} [opts.globalRateLimitMaxAmount] - max number of method calls that should
Expand All @@ -174,9 +168,6 @@ export default function createRPCMethodTrackingMiddleware({
getDeviceModel,
isConfirmationRedesignEnabled,
snapAndHardwareMessenger,
///: BEGIN:ONLY_INCLUDE_IF(blockaid)
appStateController,
///: END:ONLY_INCLUDE_IF
}) {
return async function rpcMethodTrackingMiddleware(
/** @type {any} */ req,
Expand Down Expand Up @@ -355,18 +346,8 @@ export default function createRPCMethodTrackingMiddleware({
return callback();
}

// The rpc error methodNotFound implies that 'eth_sign' is disabled in Advanced Settings
const isDisabledEthSignAdvancedSetting =
method === MESSAGE_TYPE.ETH_SIGN &&
res.error?.code === errorCodes.rpc.methodNotFound;

const isDisabledRPCMethod = isDisabledEthSignAdvancedSetting;

let event;
if (isDisabledRPCMethod) {
event = eventType.FAILED;
eventProperties.error = res.error;
} else if (res.error?.code === errorCodes.provider.userRejectedRequest) {
if (res.error?.code === errorCodes.provider.userRejectedRequest) {
event = eventType.REJECTED;
} else if (
res.error?.code === errorCodes.rpc.internal &&
Expand All @@ -379,41 +360,13 @@ export default function createRPCMethodTrackingMiddleware({
event = eventType.APPROVED;
}

let blockaidMetricProps = {};

///: BEGIN:ONLY_INCLUDE_IF(blockaid)
if (!isDisabledRPCMethod) {
if (SIGNING_METHODS.includes(method)) {
const securityAlertResponse =
appStateController.getSignatureSecurityAlertResponse(
req.securityAlertResponse?.securityAlertId,
);

blockaidMetricProps = getBlockaidMetricsProps({
securityAlertResponse,
});
}
}
///: END:ONLY_INCLUDE_IF

const properties = {
...eventProperties,
...blockaidMetricProps,
// if security_alert_response from blockaidMetricProps is Benign, force set security_alert_reason to empty string
security_alert_reason:
blockaidMetricProps.security_alert_response ===
BlockaidResultType.Benign
? ''
: blockaidMetricProps.security_alert_reason,
};

trackEvent({
event,
category: MetaMetricsEventCategory.InpageProvider,
referrer: {
url: origin,
},
properties,
properties: eventProperties,
});

return callback();
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export const SENTRY_BACKGROUND_STATE = {
PreferencesController: {
advancedGasFee: true,
currentLocale: true,
disabledRpcMethodPreferences: true,
dismissSeedBackUpReminder: true,
featureFlags: true,
forgottenPassword: true,
Expand Down
4 changes: 0 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3249,10 +3249,6 @@ export default class MetamaskController extends EventEmitter {
preferencesController.setDismissSeedBackUpReminder.bind(
preferencesController,
),
setDisabledRpcMethodPreference:
preferencesController.setDisabledRpcMethodPreference.bind(
preferencesController,
),
getRpcMethodPreferences:
preferencesController.getRpcMethodPreferences.bind(
preferencesController,
Expand Down
3 changes: 0 additions & 3 deletions test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
"metamask": {
"ipfsGateway": "",
"dismissSeedBackUpReminder": false,
"disabledRpcMethodPreferences": {
"eth_sign": false
},
"usePhishDetect": true,
"participateInMetaMetrics": false,
"gasEstimateType": "fee-market",
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/accounts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export const accountSnapFixtures = (title: string | undefined) => {
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp(false)
.withPreferencesController({
disabledRpcMethodPreferences: {
eth_sign: true,
},
})
.build(),
ganacheOptions: multipleGanacheOptions,
title,
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/tests/metrics/signature-approved.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ describe('Signature Approved Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withPreferencesController({
disabledRpcMethodPreferences: {
eth_sign: true,
},
})
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
participateInMetaMetrics: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
"useNonceField": false,
"usePhishDetect": true,
"dismissSeedBackUpReminder": true,
"disabledRpcMethodPreferences": { "eth_sign": false },
"useMultiAccountBalanceChecker": true,
"hasDismissedOpenSeaToBlockaidBanner": false,
"useSafeChainsListValidation": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"useNonceField": false,
"usePhishDetect": true,
"dismissSeedBackUpReminder": true,
"disabledRpcMethodPreferences": { "eth_sign": false },
"useMultiAccountBalanceChecker": true,
"hasDismissedOpenSeaToBlockaidBanner": false,
"useSafeChainsListValidation": true,
Expand Down
10 changes: 0 additions & 10 deletions test/e2e/tests/signature/eth-sign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ describe('Eth sign', function () {
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({
disabledRpcMethodPreferences: {
eth_sign: true,
},
})
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
Expand Down Expand Up @@ -99,11 +94,6 @@ describe('Eth sign', function () {
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({
disabledRpcMethodPreferences: {
eth_sign: true,
},
})
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
Expand Down
13 changes: 0 additions & 13 deletions ui/components/app/modals/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import ConfirmDeleteNetwork from './confirm-delete-network';
import ConvertTokenToNftModal from './convert-token-to-nft-modal/convert-token-to-nft-modal';
import CustomizeNonceModal from './customize-nonce';
import EditApprovalPermission from './edit-approval-permission';
import EthSignModal from './eth-sign-modal/eth-sign-modal';
import FadeModal from './fade-modal';
import NewAccountModal from './new-account-modal';
import RejectTransactions from './reject-transactions';
Expand Down Expand Up @@ -179,18 +178,6 @@ const MODALS = {
},
},

ETH_SIGN: {
contents: <EthSignModal />,
mobileModalStyle: {
...modalContainerMobileStyle,
},
laptopModalStyle: {
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},
CONFIRM_REMOVE_ACCOUNT: {
contents: <ConfirmRemoveAccount />,
mobileModalStyle: {
Expand Down
6 changes: 0 additions & 6 deletions ui/pages/settings/advanced-tab/advanced-tab.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
displayWarning,
restoreUserData,
setAutoLockTimeLimit,
setDisabledRpcMethodPreference,
setDismissSeedBackUpReminder,
setFeatureFlag,
setShowExtensionInFullSizeView,
Expand All @@ -27,7 +26,6 @@ export const mapStateToProps = (state) => {
} = state;
const {
featureFlags: { sendHexData } = {},
disabledRpcMethodPreferences,
useNonceField,
dismissSeedBackUpReminder,
} = metamask;
Expand All @@ -49,7 +47,6 @@ export const mapStateToProps = (state) => {
autoLockTimeLimit,
useNonceField,
dismissSeedBackUpReminder,
disabledRpcMethodPreferences,
};
};

Expand Down Expand Up @@ -82,9 +79,6 @@ export const mapDispatchToProps = (dispatch) => {
setDismissSeedBackUpReminder: (value) => {
return dispatch(setDismissSeedBackUpReminder(value));
},
setDisabledRpcMethodPreference: (methodName, isEnabled) => {
return dispatch(setDisabledRpcMethodPreference(methodName, isEnabled));
},
};
};

Expand Down
4 changes: 0 additions & 4 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,6 @@ export function getTestNetworkBackgroundColor(state) {
}
}

export function getDisabledRpcMethodPreferences(state) {
return state.metamask.disabledRpcMethodPreferences;
}

export function getShouldShowFiat(state) {
const isMainNet = getIsMainnet(state);
const isLineaMainNet = getIsLineaMainnet(state);
Expand Down
14 changes: 0 additions & 14 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4227,20 +4227,6 @@ export function setDismissSeedBackUpReminder(
};
}

export function setDisabledRpcMethodPreference(
methodName: string,
value: number,
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
return async (dispatch: MetaMaskReduxDispatch) => {
dispatch(showLoadingIndication());
await submitRequestToBackground('setDisabledRpcMethodPreference', [
methodName,
value,
]);
dispatch(hideLoadingIndication());
};
}

export function getRpcMethodPreferences(): ThunkAction<
void,
MetaMaskReduxState,
Expand Down

0 comments on commit b0258ad

Please sign in to comment.