2020-05-15 20:53:52 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import ConnectedAccounts from './connected-accounts.component'
|
|
|
|
import {
|
|
|
|
getAccountToConnectToActiveTab,
|
|
|
|
getOrderedConnectedAccountsForActiveTab,
|
|
|
|
getPermissionsForActiveTab,
|
|
|
|
getSelectedAddress,
|
|
|
|
} from '../../selectors'
|
|
|
|
import { addPermittedAccount, removePermittedAccount, setSelectedAddress } from '../../store/actions'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-05-29 19:12:14 +02:00
|
|
|
const EXT_PROTOCOLS = ['chrome-extension:', 'moz-extension:']
|
|
|
|
|
2020-05-15 20:53:52 +02:00
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
const { activeTab } = state
|
|
|
|
const accountToConnect = getAccountToConnectToActiveTab(state)
|
|
|
|
const connectedAccounts = getOrderedConnectedAccountsForActiveTab(state)
|
|
|
|
const permissions = getPermissionsForActiveTab(state)
|
|
|
|
const selectedAddress = getSelectedAddress(state)
|
|
|
|
|
2020-05-29 19:12:14 +02:00
|
|
|
const isActiveTabExtension = EXT_PROTOCOLS.includes(activeTab.protocol)
|
2020-05-15 20:53:52 +02:00
|
|
|
return {
|
|
|
|
accountToConnect,
|
2020-05-29 19:12:14 +02:00
|
|
|
isActiveTabExtension,
|
2020-05-15 20:53:52 +02:00
|
|
|
activeTabOrigin: activeTab.origin,
|
|
|
|
connectedAccounts,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2020-05-15 20:53:52 +02:00
|
|
|
permissions,
|
|
|
|
selectedAddress,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
return {
|
|
|
|
addPermittedAccount: (origin, address) => dispatch(addPermittedAccount(origin, address)),
|
|
|
|
removePermittedAccount: (origin, address) => dispatch(removePermittedAccount(origin, address)),
|
|
|
|
setSelectedAddress: (address) => dispatch(setSelectedAddress(address)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|
|
|
const { activeTabOrigin: origin } = stateProps
|
|
|
|
|
|
|
|
return {
|
|
|
|
...ownProps,
|
|
|
|
...stateProps,
|
|
|
|
...dispatchProps,
|
|
|
|
addPermittedAccount: (address) => dispatchProps.addPermittedAccount(origin, address),
|
|
|
|
removePermittedAccount: (address) => dispatchProps.removePermittedAccount(origin, address),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ConnectedAccounts)
|