mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 11:01:41 +01:00
63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
|
import { connect } from 'react-redux'
|
||
|
import ConnectedSites from './connected-sites.component'
|
||
|
import { getOpenMetamaskTabsIds, legacyExposeAccounts, removePermissionsFor } from '../../store/actions'
|
||
|
import {
|
||
|
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)
|
||
|
|
||
|
let tabToConnect
|
||
|
if (url && permittedAccounts.length === 0 && !openMetaMaskTabs[id]) {
|
||
|
tabToConnect = {
|
||
|
title,
|
||
|
origin: getOriginFromUrl(url),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
accountLabel: getCurrentAccountWithSendEtherInfo(state).name,
|
||
|
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)
|