2023-03-31 19:23:27 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import {
|
|
|
|
STATUS_CONNECTED_TO_ANOTHER_ACCOUNT,
|
|
|
|
STATUS_NOT_CONNECTED,
|
|
|
|
} from '../../../helpers/constants/connected-sites';
|
|
|
|
import {
|
2023-05-05 07:21:10 +02:00
|
|
|
AlignItems,
|
2023-03-31 19:23:27 +02:00
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
|
|
|
BorderRadius,
|
2023-06-28 17:03:50 +02:00
|
|
|
Display,
|
2023-03-31 19:23:27 +02:00
|
|
|
IconColor,
|
2023-05-05 07:21:10 +02:00
|
|
|
JustifyContent,
|
2023-03-31 19:23:27 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-05-05 07:21:10 +02:00
|
|
|
import {
|
|
|
|
BadgeWrapper,
|
|
|
|
Icon,
|
|
|
|
IconName,
|
|
|
|
IconSize,
|
2023-07-04 14:00:09 +02:00
|
|
|
Box,
|
2023-05-05 07:21:10 +02:00
|
|
|
} from '../../component-library';
|
2023-03-31 19:23:27 +02:00
|
|
|
import { getSelectedIdentity } from '../../../selectors';
|
|
|
|
import Tooltip from '../../ui/tooltip';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
export const ConnectedSiteMenu = ({
|
2023-03-31 19:23:27 +02:00
|
|
|
className,
|
|
|
|
globalMenuColor,
|
|
|
|
status,
|
|
|
|
text,
|
2023-05-05 07:21:10 +02:00
|
|
|
onClick,
|
2023-03-31 19:23:27 +02:00
|
|
|
}) => {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const selectedAccount = useSelector(getSelectedIdentity);
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className={classNames('multichain-connected-site-menu', className)}
|
|
|
|
data-testid="connection-menu"
|
2023-05-05 07:21:10 +02:00
|
|
|
as="button"
|
|
|
|
onClick={onClick}
|
2023-06-28 17:03:50 +02:00
|
|
|
display={Display.Flex}
|
2023-05-05 07:21:10 +02:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.center}
|
2023-07-07 15:22:23 +02:00
|
|
|
backgroundColor={BackgroundColor.backgroundDefault}
|
2023-03-31 19:23:27 +02:00
|
|
|
>
|
|
|
|
<Tooltip
|
|
|
|
title={
|
|
|
|
status === STATUS_NOT_CONNECTED
|
|
|
|
? t('statusNotConnectedAccount')
|
|
|
|
: `${selectedAccount?.name} ${text}`
|
|
|
|
}
|
|
|
|
data-testid="multichain-connected-site-menu__tooltip"
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
<BadgeWrapper
|
|
|
|
positionObj={
|
|
|
|
status === STATUS_CONNECTED_TO_ANOTHER_ACCOUNT
|
|
|
|
? { bottom: 4, right: -1, zIndex: 1 }
|
|
|
|
: { bottom: 2, right: -4, zIndex: 1 }
|
|
|
|
}
|
|
|
|
badge={
|
|
|
|
<Box
|
|
|
|
backgroundColor={globalMenuColor}
|
|
|
|
className={`multichain-connected-site-menu__badge ${
|
|
|
|
status === STATUS_CONNECTED_TO_ANOTHER_ACCOUNT
|
|
|
|
? 'not-connected'
|
|
|
|
: ''
|
|
|
|
}`}
|
|
|
|
borderRadius={BorderRadius.full}
|
|
|
|
borderColor={
|
|
|
|
status === STATUS_CONNECTED_TO_ANOTHER_ACCOUNT
|
|
|
|
? BorderColor.successDefault
|
|
|
|
: BackgroundColor.backgroundDefault
|
|
|
|
}
|
|
|
|
borderWidth={
|
|
|
|
status === STATUS_CONNECTED_TO_ANOTHER_ACCOUNT ? 2 : 3
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Icon
|
2023-04-14 00:24:47 +02:00
|
|
|
name={IconName.Global}
|
2023-05-05 07:21:10 +02:00
|
|
|
size={IconSize.Sm}
|
2023-03-31 19:23:27 +02:00
|
|
|
color={IconColor.iconDefault}
|
|
|
|
/>
|
|
|
|
</BadgeWrapper>
|
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
ConnectedSiteMenu.propTypes = {
|
2023-03-31 19:23:27 +02:00
|
|
|
/**
|
2023-06-14 17:51:19 +02:00
|
|
|
* Additional classNames to be added to the ConnectedSiteMenu
|
2023-03-31 19:23:27 +02:00
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Background color based on the connection status
|
|
|
|
*/
|
|
|
|
globalMenuColor: PropTypes.string.isRequired,
|
|
|
|
/**
|
|
|
|
* Connection status string
|
|
|
|
*/
|
|
|
|
status: PropTypes.string.isRequired,
|
|
|
|
/**
|
|
|
|
* Connection status message
|
|
|
|
*/
|
|
|
|
text: PropTypes.string,
|
2023-05-05 07:21:10 +02:00
|
|
|
/**
|
|
|
|
* onClick handler to be passed
|
|
|
|
*/
|
|
|
|
onClick: PropTypes.func,
|
2023-03-31 19:23:27 +02:00
|
|
|
};
|