Fix _getPermittedAccounts type safety (#10819)

feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent 966b2dcb43
commit e142bf0c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/scripts/controllers/permissions/index.js

@ -297,7 +297,7 @@ export class PermissionsController {
this.validatePermittedAccounts([account]); this.validatePermittedAccounts([account]);
const oldPermittedAccounts = this._getPermittedAccounts(origin); const oldPermittedAccounts = this._getPermittedAccounts(origin);
if (!oldPermittedAccounts) { if (oldPermittedAccounts.length === 0) {
throw new Error(`Origin does not have 'eth_accounts' permission`); throw new Error(`Origin does not have 'eth_accounts' permission`);
} else if (oldPermittedAccounts.includes(account)) { } else if (oldPermittedAccounts.includes(account)) {
throw new Error('Account is already permitted for origin'); throw new Error('Account is already permitted for origin');
@ -335,7 +335,7 @@ export class PermissionsController {
this.validatePermittedAccounts([account]); this.validatePermittedAccounts([account]);
const oldPermittedAccounts = this._getPermittedAccounts(origin); const oldPermittedAccounts = this._getPermittedAccounts(origin);
if (!oldPermittedAccounts) { if (oldPermittedAccounts.length === 0) {
throw new Error(`Origin does not have 'eth_accounts' permission`); throw new Error(`Origin does not have 'eth_accounts' permission`);
} else if (!oldPermittedAccounts.includes(account)) { } else if (!oldPermittedAccounts.includes(account)) {
throw new Error('Account is not permitted for origin'); throw new Error('Account is not permitted for origin');
@ -612,7 +612,7 @@ export class PermissionsController {
* Get current set of permitted accounts for the given origin * Get current set of permitted accounts for the given origin
* *
* @param {string} origin - The origin to obtain permitted accounts for * @param {string} origin - The origin to obtain permitted accounts for
* @returns {Array<string>|null} The list of permitted accounts * @returns {Array<string>} The list of permitted accounts
*/ */
_getPermittedAccounts(origin) { _getPermittedAccounts(origin) {
const permittedAccounts = this.permissions const permittedAccounts = this.permissions
@ -620,7 +620,7 @@ export class PermissionsController {
?.caveats?.find((caveat) => caveat.name === CAVEAT_NAMES.exposedAccounts) ?.caveats?.find((caveat) => caveat.name === CAVEAT_NAMES.exposedAccounts)
?.value; ?.value;
return permittedAccounts || null; return permittedAccounts || [];
} }
/** /**

Loading…
Cancel
Save