mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 11:01:41 +01:00
d131014b5e
This change replaces `getRenderablePermissionsDomains` with a new selector `getConnectedDomainsForSelectedAddress` that works better. The data returned from this selector is used to populated the _Connected Sites_ modal, which (as of #8262) didn't use most of the data returned from the old selector. The old selector only looked at the first address that was exposed, making it not work for anything other than the first account connected to a particular origin.
66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
import { connect } from 'react-redux'
|
|
import ConnectedSites from './connected-sites.component'
|
|
import { getOpenMetamaskTabsIds, legacyExposeAccounts, removePermissionsFor } from '../../store/actions'
|
|
import {
|
|
getConnectedDomainsForSelectedAddress,
|
|
getCurrentAccountWithSendEtherInfo,
|
|
getPermissionsDomains,
|
|
getPermittedAccountsForCurrentTab,
|
|
getSelectedAddress,
|
|
} from '../../selectors/selectors'
|
|
import { getOriginFromUrl } from '../../helpers/utils/util'
|
|
|
|
const mapStateToProps = (state) => {
|
|
const { openMetaMaskTabs } = state.appState
|
|
const { title, url, id } = state.activeTab
|
|
const permittedAccounts = getPermittedAccountsForCurrentTab(state)
|
|
const connectedDomains = getConnectedDomainsForSelectedAddress(state)
|
|
|
|
let tabToConnect
|
|
if (url && permittedAccounts.length === 0 && !openMetaMaskTabs[id]) {
|
|
tabToConnect = {
|
|
title,
|
|
origin: getOriginFromUrl(url),
|
|
}
|
|
}
|
|
|
|
return {
|
|
accountLabel: getCurrentAccountWithSendEtherInfo(state).name,
|
|
connectedDomains,
|
|
domains: getPermissionsDomains(state),
|
|
selectedAddress: getSelectedAddress(state),
|
|
tabToConnect,
|
|
}
|
|
}
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
getOpenMetamaskTabsIds: () => dispatch(getOpenMetamaskTabsIds()),
|
|
disconnectAccount: (domainKey, domain) => {
|
|
const permissionMethodNames = domain.permissions.map(({ parentCapability }) => parentCapability)
|
|
dispatch(removePermissionsFor({
|
|
[domainKey]: permissionMethodNames,
|
|
}))
|
|
},
|
|
legacyExposeAccounts: (origin, account) => dispatch(legacyExposeAccounts(origin, [account])),
|
|
}
|
|
}
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|
const { domains, selectedAddress, tabToConnect } = stateProps
|
|
const {
|
|
disconnectAccount,
|
|
legacyExposeAccounts: dispatchLegacyExposeAccounts,
|
|
} = dispatchProps
|
|
|
|
return {
|
|
...ownProps,
|
|
...stateProps,
|
|
...dispatchProps,
|
|
disconnectAccount: (domainKey) => disconnectAccount(domainKey, domains[domainKey]),
|
|
legacyExposeAccount: () => dispatchLegacyExposeAccounts(tabToConnect.origin, selectedAddress),
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ConnectedSites)
|