1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Minor permissions selector refactor (#8495)

* refactor selectors
This commit is contained in:
Erik Marks 2020-05-01 16:48:32 -07:00 committed by GitHub
parent 748d5e680c
commit ca135a4342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 20 deletions

View File

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

View File

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