mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
captureKeyringTypesWithMissingIdentities() when 'Missing identity for address' in permissions/specifications (#13521)
* captureKeyringTypesWithMissingIdentities() when 'Missing identity for address' in permissions/specifications * Fix unit tests
This commit is contained in:
parent
007bc6fcba
commit
5bc4287f65
@ -78,11 +78,15 @@ export const getCaveatSpecifications = ({ getIdentities }) => {
|
||||
* in the current MetaMask instance.
|
||||
* @param options.getIdentities - A function that returns the
|
||||
* `PreferencesController` identity objects for all Ethereum accounts in the
|
||||
* @param options.captureKeyringTypesWithMissingIdentities - A function that
|
||||
* captures extra error information about the "Missing identity for address"
|
||||
* error.
|
||||
* current MetaMask instance.
|
||||
*/
|
||||
export const getPermissionSpecifications = ({
|
||||
getAllAccounts,
|
||||
getIdentities,
|
||||
captureKeyringTypesWithMissingIdentities,
|
||||
}) => {
|
||||
return {
|
||||
[PermissionKeys.eth_accounts]: {
|
||||
@ -119,8 +123,10 @@ export const getPermissionSpecifications = ({
|
||||
|
||||
return accounts.sort((firstAddress, secondAddress) => {
|
||||
if (!identities[firstAddress]) {
|
||||
captureKeyringTypesWithMissingIdentities(identities, accounts);
|
||||
throw new Error(`Missing identity for address: "${firstAddress}".`);
|
||||
} else if (!identities[secondAddress]) {
|
||||
captureKeyringTypesWithMissingIdentities(identities, accounts);
|
||||
throw new Error(
|
||||
`Missing identity for address: "${secondAddress}".`,
|
||||
);
|
||||
|
@ -247,6 +247,7 @@ describe('PermissionController specifications', () => {
|
||||
const { methodImplementation } = getPermissionSpecifications({
|
||||
getIdentities,
|
||||
getAllAccounts,
|
||||
captureKeyringTypesWithMissingIdentities: jest.fn(),
|
||||
})[RestrictedMethods.eth_accounts];
|
||||
|
||||
await expect(() => methodImplementation()).rejects.toThrow(
|
||||
@ -272,6 +273,7 @@ describe('PermissionController specifications', () => {
|
||||
const { methodImplementation } = getPermissionSpecifications({
|
||||
getIdentities,
|
||||
getAllAccounts,
|
||||
captureKeyringTypesWithMissingIdentities: jest.fn(),
|
||||
})[RestrictedMethods.eth_accounts];
|
||||
|
||||
await expect(() => methodImplementation()).rejects.toThrow(
|
||||
|
@ -503,6 +503,30 @@ export default class MetamaskController extends EventEmitter {
|
||||
getAllAccounts: this.keyringController.getAccounts.bind(
|
||||
this.keyringController,
|
||||
),
|
||||
captureKeyringTypesWithMissingIdentities: (
|
||||
identities = {},
|
||||
accounts = [],
|
||||
) => {
|
||||
const accountsMissingIdentities = accounts.filter(
|
||||
(address) => !identities[address],
|
||||
);
|
||||
const keyringTypesWithMissingIdentities = accountsMissingIdentities.map(
|
||||
(address) =>
|
||||
this.keyringController.getKeyringForAccount(address)?.type,
|
||||
);
|
||||
|
||||
const identitiesCount = Object.keys(identities || {}).length;
|
||||
|
||||
const accountTrackerCount = Object.keys(
|
||||
this.accountTracker.store.getState().accounts || {},
|
||||
).length;
|
||||
|
||||
captureException(
|
||||
new Error(
|
||||
`Attempt to get permission specifications failed because their were ${accounts.length} accounts, but ${identitiesCount} identities, and the ${keyringTypesWithMissingIdentities} keyrings included accounts with missing identities. Meanwhile, there are ${accountTrackerCount} accounts in the account tracker.`,
|
||||
),
|
||||
);
|
||||
},
|
||||
}),
|
||||
unrestrictedMethods,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user