2020-06-01 19:54:32 +02:00
|
|
|
import React, { useContext, useState } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import { I18nContext } from '../../../contexts/i18n'
|
|
|
|
import { Menu, MenuItem } from '../../../components/ui/menu'
|
|
|
|
|
|
|
|
const TokenOptions = ({ onRemove, onViewEtherscan, tokenSymbol }) => {
|
|
|
|
const t = useContext(I18nContext)
|
2020-11-03 00:41:28 +01:00
|
|
|
const [tokenOptionsButtonElement, setTokenOptionsButtonElement] = useState(
|
|
|
|
null,
|
|
|
|
)
|
2020-06-01 19:54:32 +02:00
|
|
|
const [tokenOptionsOpen, setTokenOptionsOpen] = useState(false)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
className="fas fa-ellipsis-v token-options__button"
|
|
|
|
data-testid="token-options__button"
|
|
|
|
onClick={() => setTokenOptionsOpen(true)}
|
|
|
|
ref={setTokenOptionsButtonElement}
|
|
|
|
title={t('tokenOptions')}
|
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
{tokenOptionsOpen ? (
|
|
|
|
<Menu
|
|
|
|
anchorElement={tokenOptionsButtonElement}
|
|
|
|
onHide={() => setTokenOptionsOpen(false)}
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
iconClassName="fas fa-external-link-alt token-options__icon"
|
|
|
|
data-testid="token-options__etherscan"
|
|
|
|
onClick={() => {
|
|
|
|
setTokenOptionsOpen(false)
|
|
|
|
onViewEtherscan()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('viewOnEtherscan')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
iconClassName="fas fa-trash-alt token-options__icon"
|
|
|
|
data-testid="token-options__hide"
|
|
|
|
onClick={() => {
|
|
|
|
setTokenOptionsOpen(false)
|
|
|
|
onRemove()
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('hideTokenSymbol', [tokenSymbol])}
|
|
|
|
</MenuItem>
|
|
|
|
</Menu>
|
|
|
|
) : null}
|
2020-06-01 19:54:32 +02:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenOptions.propTypes = {
|
|
|
|
onRemove: PropTypes.func.isRequired,
|
|
|
|
onViewEtherscan: PropTypes.func.isRequired,
|
|
|
|
tokenSymbol: PropTypes.string.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TokenOptions
|