From ce2f5ad120c8da46bf3ca634c4f40afdcda27b9b Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Sat, 3 Apr 2021 22:17:56 -0700 Subject: [PATCH] Fix _getPermittedAccounts type safety --- app/scripts/controllers/permissions/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/controllers/permissions/index.js b/app/scripts/controllers/permissions/index.js index c4b6eae79f06..281c4e8a3ee9 100644 --- a/app/scripts/controllers/permissions/index.js +++ b/app/scripts/controllers/permissions/index.js @@ -297,7 +297,7 @@ export class PermissionsController { this.validatePermittedAccounts([account]); const oldPermittedAccounts = this._getPermittedAccounts(origin); - if (!oldPermittedAccounts) { + if (oldPermittedAccounts.length === 0) { throw new Error(`Origin does not have 'eth_accounts' permission`); } else if (oldPermittedAccounts.includes(account)) { throw new Error('Account is already permitted for origin'); @@ -335,7 +335,7 @@ export class PermissionsController { this.validatePermittedAccounts([account]); const oldPermittedAccounts = this._getPermittedAccounts(origin); - if (!oldPermittedAccounts) { + if (oldPermittedAccounts.length === 0) { throw new Error(`Origin does not have 'eth_accounts' permission`); } else if (!oldPermittedAccounts.includes(account)) { 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 * * @param {string} origin - The origin to obtain permitted accounts for - * @returns {Array|null} The list of permitted accounts + * @returns {Array} The list of permitted accounts */ _getPermittedAccounts(origin) { const permittedAccounts = this.permissions @@ -620,7 +620,7 @@ export class PermissionsController { ?.caveats?.find((caveat) => caveat.name === CAVEAT_NAMES.exposedAccounts) ?.value; - return permittedAccounts || null; + return permittedAccounts || []; } /**