mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
parent
748d5e680c
commit
ca135a4342
@ -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…
x
Reference in New Issue
Block a user