1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/pages/connected-sites/connected-sites.container.js
Erik Marks a84eedb7da
Permissions: Do not display HTTP/HTTPS URL schemes for unique hosts (#8768)
* only show URL.host in connected-accounts component

* strip scheme from URL for unique hosts

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-06-09 13:56:24 -07:00

110 lines
3.3 KiB
JavaScript

import { connect } from 'react-redux'
import ConnectedSites from './connected-sites.component'
import {
getOpenMetamaskTabsIds,
requestAccountsPermission,
removePermissionsFor,
removePermittedAccount,
} from '../../store/actions'
import {
getConnectedDomainsForSelectedAddress,
getCurrentAccountWithSendEtherInfo,
getOriginOfCurrentTab,
getPermissionDomains,
getPermissionsMetadataHostCounts,
getPermittedAccountsByOrigin,
getSelectedAddress,
} from '../../selectors'
import { CONNECT_ROUTE } from '../../helpers/constants/routes'
import { getMostRecentOverviewPage } from '../../ducks/history/history'
const mapStateToProps = (state) => {
const { openMetaMaskTabs } = state.appState
const { id } = state.activeTab
const connectedDomains = getConnectedDomainsForSelectedAddress(state)
const originOfCurrentTab = getOriginOfCurrentTab(state)
const permittedAccountsByOrigin = getPermittedAccountsByOrigin(state)
const selectedAddress = getSelectedAddress(state)
const currentTabHasNoAccounts = !permittedAccountsByOrigin[
originOfCurrentTab
]?.length
let tabToConnect
if (originOfCurrentTab && currentTabHasNoAccounts && !openMetaMaskTabs[id]) {
tabToConnect = {
origin: originOfCurrentTab,
}
}
return {
accountLabel: getCurrentAccountWithSendEtherInfo(state).name,
connectedDomains,
domains: getPermissionDomains(state),
domainHostCount: getPermissionsMetadataHostCounts(state),
mostRecentOverviewPage: getMostRecentOverviewPage(state),
permittedAccountsByOrigin,
selectedAddress,
tabToConnect,
}
}
const mapDispatchToProps = (dispatch) => {
return {
getOpenMetamaskTabsIds: () => dispatch(getOpenMetamaskTabsIds()),
disconnectAccount: (domainKey, address) => {
dispatch(removePermittedAccount(domainKey, address))
},
disconnectAllAccounts: (domainKey, domain) => {
const permissionMethodNames = domain.permissions.map(({ parentCapability }) => parentCapability)
dispatch(removePermissionsFor({
[domainKey]: permissionMethodNames,
}))
},
requestAccountsPermission: (origin) => dispatch(requestAccountsPermission(origin)),
}
}
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const {
connectedDomains,
domains,
mostRecentOverviewPage,
selectedAddress,
tabToConnect,
} = stateProps
const {
disconnectAccount,
disconnectAllAccounts,
requestAccountsPermission: dispatchRequestAccountsPermission,
} = dispatchProps
const { history } = ownProps
const closePopover = () => history.push(mostRecentOverviewPage)
return {
...ownProps,
...stateProps,
...dispatchProps,
closePopover,
disconnectAccount: (domainKey) => {
disconnectAccount(domainKey, selectedAddress)
if (connectedDomains.length === 1) {
closePopover()
}
},
disconnectAllAccounts: (domainKey) => {
disconnectAllAccounts(domainKey, domains[domainKey])
if (connectedDomains.length === 1) {
closePopover()
}
},
requestAccountsPermission: async () => {
const id = await dispatchRequestAccountsPermission(tabToConnect.origin)
history.push(`${CONNECT_ROUTE}/${id}`)
},
}
}
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ConnectedSites)