mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
|
|
import { createSelector } from 'reselect'
|
|
import {
|
|
CAVEAT_NAMES,
|
|
} from '../../../app/scripts/controllers/permissions/enums'
|
|
|
|
const permissionsSelector = (state, origin) => {
|
|
return origin && state.metamask.domains && state.metamask.domains[origin]
|
|
}
|
|
|
|
// all permissions for the origin probably too expensive for deep equality check
|
|
const accountsPermissionSelector = createSelector(
|
|
permissionsSelector,
|
|
(domain = {}) => {
|
|
|
|
return (
|
|
Array.isArray(domain.permissions)
|
|
? domain.permissions.find(
|
|
(perm) => perm.parentCapability === 'eth_accounts'
|
|
)
|
|
: {}
|
|
)
|
|
}
|
|
)
|
|
|
|
/**
|
|
* Selects the permitted accounts from an eth_accounts permission.
|
|
* Expects input from accountsPermissionsSelector.
|
|
* @returns - An empty array or an array of accounts.
|
|
*/
|
|
export const getPermittedAccounts = createSelector(
|
|
accountsPermissionSelector, // deep equal check performed on this output
|
|
(accountsPermission = {}) => {
|
|
|
|
const accountsCaveat = (
|
|
Array.isArray(accountsPermission.caveats) &&
|
|
accountsPermission.caveats.find(
|
|
(c) => c.name === CAVEAT_NAMES.exposedAccounts
|
|
)
|
|
)
|
|
|
|
return (
|
|
accountsCaveat && Array.isArray(accountsCaveat.value)
|
|
? accountsCaveat.value
|
|
: []
|
|
)
|
|
}
|
|
)
|