2023-02-15 15:39:46 +01:00
|
|
|
import React, { useContext, useRef, useState } from 'react';
|
2021-12-14 00:41:10 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
|
|
|
import { Menu, MenuItem } from '../../ui/menu';
|
2023-02-15 15:39:46 +01:00
|
|
|
import { ButtonIcon, ICON_NAMES } from '../../component-library';
|
|
|
|
import { Color } from '../../../helpers/constants/design-system';
|
2021-12-14 00:41:10 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const NftOptions = ({ onRemove, onViewOnOpensea }) => {
|
2021-12-14 00:41:10 +01:00
|
|
|
const t = useContext(I18nContext);
|
2023-02-16 20:23:29 +01:00
|
|
|
const [nftOptionsOpen, setNftOptionsOpen] = useState(false);
|
2023-02-15 15:39:46 +01:00
|
|
|
const ref = useRef(false);
|
2021-12-14 00:41:10 +01:00
|
|
|
|
|
|
|
return (
|
2023-02-15 15:39:46 +01:00
|
|
|
<div ref={ref}>
|
|
|
|
<ButtonIcon
|
|
|
|
iconName={ICON_NAMES.MORE_VERTICAL}
|
2023-02-16 20:23:29 +01:00
|
|
|
className="nft-options__button"
|
|
|
|
data-testid="nft-options__button"
|
|
|
|
onClick={() => setNftOptionsOpen(true)}
|
2023-02-15 15:39:46 +01:00
|
|
|
color={Color.textDefault}
|
|
|
|
ariaLabel={t('nftOptions')}
|
2021-12-14 00:41:10 +01:00
|
|
|
/>
|
2023-02-15 15:39:46 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
{nftOptionsOpen ? (
|
2021-12-14 00:41:10 +01:00
|
|
|
<Menu
|
2023-02-16 20:23:29 +01:00
|
|
|
data-testid="close-nft-options-menu"
|
2023-02-15 15:39:46 +01:00
|
|
|
anchorElement={ref.current}
|
2023-02-16 20:23:29 +01:00
|
|
|
onHide={() => setNftOptionsOpen(false)}
|
2021-12-14 00:41:10 +01:00
|
|
|
>
|
|
|
|
{onViewOnOpensea ? (
|
|
|
|
<MenuItem
|
2023-01-27 15:32:03 +01:00
|
|
|
iconName={ICON_NAMES.EXPORT}
|
2023-02-16 20:23:29 +01:00
|
|
|
data-testid="nft-options__view-on-opensea"
|
2021-12-14 00:41:10 +01:00
|
|
|
onClick={() => {
|
2023-02-16 20:23:29 +01:00
|
|
|
setNftOptionsOpen(false);
|
2021-12-14 00:41:10 +01:00
|
|
|
onViewOnOpensea();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('viewOnOpensea')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
|
|
|
<MenuItem
|
2023-01-27 15:32:03 +01:00
|
|
|
iconName={ICON_NAMES.TRASH}
|
2023-02-16 20:23:29 +01:00
|
|
|
data-testid="nft-item-remove"
|
2021-12-14 00:41:10 +01:00
|
|
|
onClick={() => {
|
2023-02-16 20:23:29 +01:00
|
|
|
setNftOptionsOpen(false);
|
2021-12-14 00:41:10 +01:00
|
|
|
onRemove();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('removeNFT')}
|
|
|
|
</MenuItem>
|
|
|
|
</Menu>
|
|
|
|
) : null}
|
2023-02-15 15:39:46 +01:00
|
|
|
</div>
|
2021-12-14 00:41:10 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
NftOptions.propTypes = {
|
2021-12-14 00:41:10 +01:00
|
|
|
onRemove: PropTypes.func.isRequired,
|
2023-02-07 19:06:37 +01:00
|
|
|
onViewOnOpensea: PropTypes.func,
|
2021-12-14 00:41:10 +01:00
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
export default NftOptions;
|