diff --git a/src/components/CopyButton/index.tsx b/src/components/CopyButton/index.tsx new file mode 100644 index 000000000..bc0d8f21d --- /dev/null +++ b/src/components/CopyButton/index.tsx @@ -0,0 +1,72 @@ +import { useState } from 'react' +import { CopyIcon, SvgProps } from '@pancakeswap/uikit' +import { copyText } from 'utils/copyText' +import styled from 'styled-components' + +const Tooltip = styled.div<{ + isTooltipDisplayed: boolean + tooltipTop: number + tooltipRight: number + tooltipFontSize?: number +}>` + display: ${({ isTooltipDisplayed }) => (isTooltipDisplayed ? 'inline' : 'none')}; + position: absolute; + padding: 8px; + top: ${({ tooltipTop }) => `${tooltipTop}px`}; + right: ${({ tooltipRight }) => (tooltipRight ? `${tooltipRight}px` : 0)}; + text-align: center; + font-size: ${({ tooltipFontSize }) => `${tooltipFontSize}px` ?? '100%'}; + background-color: ${({ theme }) => theme.colors.contrast}; + color: ${({ theme }) => theme.colors.invertedContrast}; + border-radius: 16px; + opacity: 0.7; + width: max-content; +` + +interface CopyButtonProps extends SvgProps { + text: string + tooltipMessage: string + tooltipTop: number + tooltipRight?: number + tooltipFontSize?: number + buttonColor?: string +} + +export const CopyButton: React.FC = ({ + text, + tooltipMessage, + width, + tooltipTop, + tooltipRight, + tooltipFontSize, + buttonColor = 'primary', + ...props +}) => { + const [isTooltipDisplayed, setIsTooltipDisplayed] = useState(false) + + const displayTooltip = () => { + setIsTooltipDisplayed(true) + setTimeout(() => { + setIsTooltipDisplayed(false) + }, 1000) + } + return ( + <> + copyText(text, displayTooltip)} + {...props} + /> + + {tooltipMessage} + + + ) +} diff --git a/src/components/CurrencyInputPanel/index.tsx b/src/components/CurrencyInputPanel/index.tsx index 6e428074c..3298c4994 100644 --- a/src/components/CurrencyInputPanel/index.tsx +++ b/src/components/CurrencyInputPanel/index.tsx @@ -11,6 +11,7 @@ import { CurrencyLogo, DoubleCurrencyLogo } from '../Logo' import { RowBetween } from '../Layout/Row' import { Input as NumericalInput } from './NumericalInput' +import { CopyButton } from '../CopyButton' const InputRow = styled.div<{ selected: boolean }>` display: flex; @@ -93,57 +94,69 @@ export default function CurrencyInputPanel({ />, ) return ( - + - { - if (!disableCurrencySelect) { - onPresentCurrencyModal() - } - }} - > - - {pair ? ( - - ) : currency ? ( - - ) : null} - {pair ? ( - - {pair?.token0.symbol}:{pair?.token1.symbol} - - ) : ( - - {(currency && currency.symbol && currency.symbol.length > 20 - ? `${currency.symbol.slice(0, 4)}...${currency.symbol.slice( - currency.symbol.length - 5, - currency.symbol.length, - )}` - : currency?.symbol) || t('Select a currency')} - - )} - {!disableCurrencySelect && } - - - - {token && tokenAddress && library?.provider?.isMetaMask && ( - registerToken(tokenAddress, token.symbol, token.decimals)} - /> - )} - {account && ( - - {!hideBalance && !!currency - ? t('Balance: %balance%', { balance: selectedCurrencyBalance?.toSignificant(6) ?? t('Loading') }) - : ' -'} - - )} + + { + if (!disableCurrencySelect) { + onPresentCurrencyModal() + } + }} + > + + {pair ? ( + + ) : currency ? ( + + ) : null} + {pair ? ( + + {pair?.token0.symbol}:{pair?.token1.symbol} + + ) : ( + + {(currency && currency.symbol && currency.symbol.length > 20 + ? `${currency.symbol.slice(0, 4)}...${currency.symbol.slice( + currency.symbol.length - 5, + currency.symbol.length, + )}` + : currency?.symbol) || t('Select a currency')} + + )} + {!disableCurrencySelect && } + + + {token && tokenAddress ? ( + + + {library?.provider?.isMetaMask && ( + registerToken(tokenAddress, token.symbol, token.decimals)} + /> + )} + + ) : null} + {account && ( + + {!hideBalance && !!currency + ? t('Balance: %balance%', { balance: selectedCurrencyBalance?.toSignificant(6) ?? t('Loading') }) + : ' -'} + + )} diff --git a/src/components/Menu/UserMenu/CopyAddress.tsx b/src/components/Menu/UserMenu/CopyAddress.tsx index 25df6fe1e..7092170b5 100644 --- a/src/components/Menu/UserMenu/CopyAddress.tsx +++ b/src/components/Menu/UserMenu/CopyAddress.tsx @@ -1,8 +1,7 @@ -import { useState } from 'react' -import { Box, CopyIcon, Flex, FlexProps, IconButton } from '@pancakeswap/uikit' +import { Box, Flex, FlexProps } from '@pancakeswap/uikit' import styled from 'styled-components' import { useTranslation } from 'contexts/Localization' -import { copyText } from 'utils/copyText' +import { CopyButton } from '../../CopyButton' interface CopyAddressProps extends FlexProps { account: string @@ -51,46 +50,18 @@ const Address = styled.div` } ` -const Tooltip = styled.div<{ isTooltipDisplayed: boolean }>` - display: ${({ isTooltipDisplayed }) => (isTooltipDisplayed ? 'inline-block' : 'none')}; - position: absolute; - padding: 8px; - top: -38px; - right: 0; - text-align: center; - background-color: ${({ theme }) => theme.colors.contrast}; - color: ${({ theme }) => theme.colors.invertedContrast}; - border-radius: 16px; - opacity: 0.7; - width: 100px; -` - const CopyAddress: React.FC = ({ account, ...props }) => { - const [isTooltipDisplayed, setIsTooltipDisplayed] = useState(false) const { t } = useTranslation() - - const copyAddress = () => { - copyText(account, displayTooltip) - } - - function displayTooltip() { - setIsTooltipDisplayed(true) - setTimeout(() => { - setIsTooltipDisplayed(false) - }, 1000) - } - return (
- - - + + +
- {t('Copied')}
) }