Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _getPermittedAccounts type safety #10819

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/scripts/controllers/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -612,15 +612,15 @@ 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<string>|null} The list of permitted accounts
* @returns {Array<string>} The list of permitted accounts
*/
_getPermittedAccounts(origin) {
const permittedAccounts = this.permissions
.getPermission(origin, 'eth_accounts')
?.caveats?.find((caveat) => caveat.name === CAVEAT_NAMES.exposedAccounts)
?.value;

return permittedAccounts || null;
return permittedAccounts || [];
}

/**
Expand Down