1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/selectors/permissions.js
Erik Marks b75f812953
Improve LoginPerSite UX/devX and permissions logging (#7649)
Update accounts permission history on accountsChanged
Create PermissionsLogController
Fix permissions activity log pruning
Add selectors, background hooks for better UX
Make selected account the first account returned
Use enums for store keys in log controller
Add last selected address history to PreferencesController
2020-01-27 14:42:03 -08:00

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
: []
)
}
)