Minor permissions selector refactor (#8495)

* refactor selectors
feature/default_network_editable
Erik Marks 5 years ago committed by GitHub
parent 748d5e680c
commit ca135a4342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      ui/app/selectors/permissions.js
  2. 6
      ui/app/selectors/selectors.js

@ -1,5 +1,3 @@
import { createSelector } from 'reselect'
import { import {
CAVEAT_NAMES, CAVEAT_NAMES,
} from '../../../app/scripts/controllers/permissions/enums' } from '../../../app/scripts/controllers/permissions/enums'
@ -26,20 +24,18 @@ export function getPermittedAccounts (state, origin) {
* @param {Object} state - The current state. * @param {Object} state - The current state.
* @returns {Object} Permitted accounts by origin. * @returns {Object} Permitted accounts by origin.
*/ */
export const getPermittedAccountsMap = createSelector( export function getPermittedAccountsByOrigin (state) {
allDomainsSelector, const domains = allDomainsSelector(state)
(domains = {}) => { return Object.keys(domains).reduce((acc, domainKey) => {
return Object.keys(domains).reduce((acc, domainKey) => { const accounts = getAccountsFromPermission(
const accounts = getAccountsFromPermission( getAccountsPermissionFromDomain(domains[domainKey])
getAccountsPermissionFromDomain(domains[domainKey]) )
) if (accounts.length > 0) {
if (accounts.length > 0) { acc[domainKey] = accounts
acc[domainKey] = accounts }
} return acc
return acc }, {})
}, {}) }
}
)
// selector helpers // selector helpers
@ -72,7 +68,7 @@ function getAccountsCaveatFromPermission (accountsPermission = {}) {
} }
function allDomainsSelector (state) { function allDomainsSelector (state) {
return state.metamask.domains return state.metamask.domains || {}
} }
function domainSelector (state, origin) { function domainSelector (state, origin) {

@ -12,7 +12,7 @@ import {
getAccountByAddress, getAccountByAddress,
} from '../helpers/utils/util' } from '../helpers/utils/util'
import { getPermittedAccountsMap } from './permissions' import { getPermittedAccountsByOrigin } from './permissions'
export { getPermittedAccounts } from './permissions' export { getPermittedAccounts } from './permissions'
@ -440,7 +440,7 @@ export function getAddressConnectedDomainMap (state) {
domainMetadata, domainMetadata,
} = state.metamask } = state.metamask
const accountsMap = getPermittedAccountsMap(state) const accountsMap = getPermittedAccountsByOrigin(state)
const addressConnectedIconMap = {} const addressConnectedIconMap = {}
Object.keys(accountsMap).forEach((domainKey) => { Object.keys(accountsMap).forEach((domainKey) => {
@ -457,7 +457,7 @@ export function getAddressConnectedDomainMap (state) {
} }
export function getPermittedAccountsForCurrentTab (state) { export function getPermittedAccountsForCurrentTab (state) {
const permittedAccountsMap = getPermittedAccountsMap(state) const permittedAccountsMap = getPermittedAccountsByOrigin(state)
const originOfCurrentTab = getOriginOfCurrentTab(state) const originOfCurrentTab = getOriginOfCurrentTab(state)
return permittedAccountsMap[originOfCurrentTab] || [] return permittedAccountsMap[originOfCurrentTab] || []
} }

Loading…
Cancel
Save