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.
69 lines
2.1 KiB
69 lines
2.1 KiB
4 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { useSelector } from 'react-redux';
|
||
|
import { findKey } from 'lodash';
|
||
4 years ago
|
import {
|
||
|
STATUS_CONNECTED,
|
||
|
STATUS_CONNECTED_TO_ANOTHER_ACCOUNT,
|
||
|
STATUS_NOT_CONNECTED,
|
||
4 years ago
|
} from '../../../helpers/constants/connected-sites';
|
||
|
import ColorIndicator from '../../ui/color-indicator';
|
||
|
import { COLORS } from '../../../helpers/constants/design-system';
|
||
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||
4 years ago
|
import {
|
||
|
getAddressConnectedDomainMap,
|
||
|
getOriginOfCurrentTab,
|
||
|
getSelectedAddress,
|
||
4 years ago
|
} from '../../../selectors';
|
||
4 years ago
|
|
||
|
export default function ConnectedStatusIndicator({ onClick }) {
|
||
4 years ago
|
const t = useI18nContext();
|
||
4 years ago
|
|
||
4 years ago
|
const selectedAddress = useSelector(getSelectedAddress);
|
||
|
const addressConnectedDomainMap = useSelector(getAddressConnectedDomainMap);
|
||
|
const originOfCurrentTab = useSelector(getOriginOfCurrentTab);
|
||
4 years ago
|
|
||
4 years ago
|
const selectedAddressDomainMap = addressConnectedDomainMap[selectedAddress];
|
||
4 years ago
|
const currentTabIsConnectedToSelectedAddress = Boolean(
|
||
|
selectedAddressDomainMap && selectedAddressDomainMap[originOfCurrentTab],
|
||
4 years ago
|
);
|
||
|
let status;
|
||
4 years ago
|
if (currentTabIsConnectedToSelectedAddress) {
|
||
4 years ago
|
status = STATUS_CONNECTED;
|
||
4 years ago
|
} else if (findKey(addressConnectedDomainMap, originOfCurrentTab)) {
|
||
4 years ago
|
status = STATUS_CONNECTED_TO_ANOTHER_ACCOUNT;
|
||
4 years ago
|
} else {
|
||
4 years ago
|
status = STATUS_NOT_CONNECTED;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
let indicatorType = ColorIndicator.TYPES.OUTLINE;
|
||
|
let indicatorColor = COLORS.UI4;
|
||
4 years ago
|
|
||
|
if (status === STATUS_CONNECTED) {
|
||
4 years ago
|
indicatorColor = COLORS.SUCCESS1;
|
||
|
indicatorType = ColorIndicator.TYPES.PARTIAL;
|
||
4 years ago
|
} else if (status === STATUS_CONNECTED_TO_ANOTHER_ACCOUNT) {
|
||
4 years ago
|
indicatorColor = COLORS.ALERT1;
|
||
4 years ago
|
}
|
||
|
|
||
|
const text =
|
||
4 years ago
|
status === STATUS_CONNECTED
|
||
|
? t('statusConnected')
|
||
|
: t('statusNotConnected');
|
||
4 years ago
|
|
||
|
return (
|
||
|
<button className="connected-status-indicator" onClick={onClick}>
|
||
|
<ColorIndicator color={indicatorColor} type={indicatorType} />
|
||
|
<div className="connected-status-indicator__text">{text}</div>
|
||
|
</button>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
|
|
||
|
ConnectedStatusIndicator.defaultProps = {
|
||
|
onClick: undefined,
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
|
ConnectedStatusIndicator.propTypes = {
|
||
|
onClick: PropTypes.func,
|
||
4 years ago
|
};
|