You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
import { findKey } from 'lodash'
|
|
import { connect } from 'react-redux'
|
|
import ConnectedStatusIndicator from './connected-status-indicator.component'
|
|
import {
|
|
STATUS_CONNECTED,
|
|
STATUS_CONNECTED_TO_ANOTHER_ACCOUNT,
|
|
STATUS_NOT_CONNECTED,
|
|
} from '../../../helpers/constants/connected-sites'
|
|
import {
|
|
getAddressConnectedDomainMap,
|
|
getOriginOfCurrentTab,
|
|
getSelectedAddress,
|
|
} from '../../../selectors'
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
const selectedAddress = getSelectedAddress(state)
|
|
const addressConnectedDomainMap = getAddressConnectedDomainMap(state)
|
|
const originOfCurrentTab = getOriginOfCurrentTab(state)
|
|
|
|
const selectedAddressDomainMap = addressConnectedDomainMap[selectedAddress]
|
|
const currentTabIsConnectedToSelectedAddress = Boolean(selectedAddressDomainMap && selectedAddressDomainMap[originOfCurrentTab])
|
|
|
|
let status
|
|
if (currentTabIsConnectedToSelectedAddress) {
|
|
status = STATUS_CONNECTED
|
|
} else if (findKey(addressConnectedDomainMap, originOfCurrentTab)) {
|
|
status = STATUS_CONNECTED_TO_ANOTHER_ACCOUNT
|
|
} else {
|
|
status = STATUS_NOT_CONNECTED
|
|
}
|
|
|
|
return {
|
|
status,
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps)(ConnectedStatusIndicator)
|
|
|