mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix disabled 'eth_sign' event & add 'Request Disabled' event type (#18007)
* Fix #17974 / add REQUEST_DISABLED event * RPCMiddleware: add eth_sign REQUEST_DISABLED test * don't call Signature Request for disabled eth_sign * clean: alphabetize * clean: rn isDisabledRequest -> isDisabledRPCMethod * fix test * rpc middeware: add eth_sign comment * fix eth_sign events and re-add Signature Request * send 'Signature Failed' for disabled eth_sigh
This commit is contained in:
parent
c477e29397
commit
5468c2c142
@ -1,3 +1,4 @@
|
|||||||
|
import { errorCodes } from 'eth-rpc-errors';
|
||||||
import { MESSAGE_TYPE, ORIGIN_METAMASK } from '../../../shared/constants/app';
|
import { MESSAGE_TYPE, ORIGIN_METAMASK } from '../../../shared/constants/app';
|
||||||
import { SECOND } from '../../../shared/constants/time';
|
import { SECOND } from '../../../shared/constants/time';
|
||||||
import { detectSIWE } from '../../../shared/modules/siwe';
|
import { detectSIWE } from '../../../shared/modules/siwe';
|
||||||
@ -46,6 +47,7 @@ const RATE_LIMIT_MAP = {
|
|||||||
const EVENT_NAME_MAP = {
|
const EVENT_NAME_MAP = {
|
||||||
[MESSAGE_TYPE.ETH_SIGN]: {
|
[MESSAGE_TYPE.ETH_SIGN]: {
|
||||||
APPROVED: EVENT_NAMES.SIGNATURE_APPROVED,
|
APPROVED: EVENT_NAMES.SIGNATURE_APPROVED,
|
||||||
|
FAILED: EVENT_NAMES.SIGNATURE_FAILED,
|
||||||
REJECTED: EVENT_NAMES.SIGNATURE_REJECTED,
|
REJECTED: EVENT_NAMES.SIGNATURE_REJECTED,
|
||||||
REQUESTED: EVENT_NAMES.SIGNATURE_REQUESTED,
|
REQUESTED: EVENT_NAMES.SIGNATURE_REQUESTED,
|
||||||
},
|
},
|
||||||
@ -195,13 +197,25 @@ export default function createRPCMethodTrackingMiddleware({
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
// An error code of 4001 means the user rejected the request, which we
|
|
||||||
// can use here to determine which event to track.
|
|
||||||
const event =
|
|
||||||
res.error?.code === 4001 ? eventType.REJECTED : eventType.APPROVED;
|
|
||||||
|
|
||||||
const properties = {};
|
const properties = {};
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
properties.error = res.error;
|
||||||
|
} else if (res.error?.code === 4001) {
|
||||||
|
event = eventType.REJECTED;
|
||||||
|
} else {
|
||||||
|
event = eventType.APPROVED;
|
||||||
|
}
|
||||||
|
|
||||||
if (eventType.REQUESTED === EVENT_NAMES.SIGNATURE_REQUESTED) {
|
if (eventType.REQUESTED === EVENT_NAMES.SIGNATURE_REQUESTED) {
|
||||||
properties.signature_type = method;
|
properties.signature_type = method;
|
||||||
} else {
|
} else {
|
||||||
@ -226,6 +240,7 @@ export default function createRPCMethodTrackingMiddleware({
|
|||||||
},
|
},
|
||||||
properties,
|
properties,
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback();
|
return callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { errorCodes } from 'eth-rpc-errors';
|
||||||
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
||||||
import { EVENT_NAMES } from '../../../shared/constants/metametrics';
|
import { EVENT_NAMES } from '../../../shared/constants/metametrics';
|
||||||
import { SECOND } from '../../../shared/constants/time';
|
import { SECOND } from '../../../shared/constants/time';
|
||||||
@ -213,5 +214,34 @@ describe('createRPCMethodTrackingMiddleware', () => {
|
|||||||
expect(trackEvent.mock.calls[0][0].properties.method).toBe('eth_chainId');
|
expect(trackEvent.mock.calls[0][0].properties.method).toBe('eth_chainId');
|
||||||
expect(trackEvent.mock.calls[1][0].properties.method).toBe('eth_chainId');
|
expect(trackEvent.mock.calls[1][0].properties.method).toBe('eth_chainId');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(`when '${MESSAGE_TYPE.ETH_SIGN}' is disabled in advanced settings`, () => {
|
||||||
|
it(`should track ${EVENT_NAMES.SIGNATURE_FAILED} and include error property`, async () => {
|
||||||
|
const mockError = { code: errorCodes.rpc.methodNotFound };
|
||||||
|
const req = {
|
||||||
|
method: MESSAGE_TYPE.ETH_SIGN,
|
||||||
|
origin: 'some.dapp',
|
||||||
|
};
|
||||||
|
const res = {
|
||||||
|
error: mockError,
|
||||||
|
};
|
||||||
|
const { next, executeMiddlewareStack } = getNext();
|
||||||
|
|
||||||
|
handler(req, res, next);
|
||||||
|
await executeMiddlewareStack();
|
||||||
|
|
||||||
|
expect(trackEvent).toHaveBeenCalledTimes(2);
|
||||||
|
|
||||||
|
expect(trackEvent.mock.calls[1][0]).toMatchObject({
|
||||||
|
category: 'inpage_provider',
|
||||||
|
event: EVENT_NAMES.SIGNATURE_FAILED,
|
||||||
|
properties: {
|
||||||
|
signature_type: MESSAGE_TYPE.ETH_SIGN,
|
||||||
|
error: mockError,
|
||||||
|
},
|
||||||
|
referrer: { url: 'some.dapp' },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -342,6 +342,7 @@ export const EVENT_NAMES = {
|
|||||||
PUBLIC_ADDRESS_COPIED: 'Public Address Copied',
|
PUBLIC_ADDRESS_COPIED: 'Public Address Copied',
|
||||||
PROVIDER_METHOD_CALLED: 'Provider Method Called',
|
PROVIDER_METHOD_CALLED: 'Provider Method Called',
|
||||||
SIGNATURE_APPROVED: 'Signature Approved',
|
SIGNATURE_APPROVED: 'Signature Approved',
|
||||||
|
SIGNATURE_FAILED: 'Signature Failed',
|
||||||
SIGNATURE_REJECTED: 'Signature Rejected',
|
SIGNATURE_REJECTED: 'Signature Rejected',
|
||||||
SIGNATURE_REQUESTED: 'Signature Requested',
|
SIGNATURE_REQUESTED: 'Signature Requested',
|
||||||
TOKEN_IMPORT_BUTTON_CLICKED: 'Import Token Button Clicked',
|
TOKEN_IMPORT_BUTTON_CLICKED: 'Import Token Button Clicked',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user