import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import Identicon from '../identicon'
import Tooltip from '../tooltip-v2'
import copyToClipboard from 'copy-to-clipboard'
import { DEFAULT_VARIANT, CARDS_VARIANT } from './sender-to-recipient.constants'
const variantHash = {
[DEFAULT_VARIANT]: 'sender-to-recipient--default',
[CARDS_VARIANT]: 'sender-to-recipient--cards',
}
export default class SenderToRecipient extends PureComponent {
static propTypes = {
senderName: PropTypes.string,
senderAddress: PropTypes.string,
recipientName: PropTypes.string,
recipientAddress: PropTypes.string,
t: PropTypes.func,
variant: PropTypes.oneOf([DEFAULT_VARIANT, CARDS_VARIANT]),
addressOnly: PropTypes.bool,
assetImage: PropTypes.string,
}
static defaultProps = {
variant: DEFAULT_VARIANT,
}
static contextTypes = {
t: PropTypes.func,
}
state = {
senderAddressCopied: false,
recipientAddressCopied: false,
}
renderSenderIdenticon () {
return !this.props.addressOnly && (
)
}
renderSenderAddress () {
const { t } = this.context
const { senderName, senderAddress, addressOnly } = this.props
return (
this.setState({ senderAddressCopied: false })}
>
{ addressOnly ? `${t('from')}: ${senderAddress}` : senderName }
)
}
renderRecipientIdenticon () {
const { recipientAddress, assetImage } = this.props
return !this.props.addressOnly && (
)
}
renderRecipientWithAddress () {
const { t } = this.context
const { recipientName, recipientAddress, addressOnly } = this.props
return (
{
this.setState({ recipientAddressCopied: true })
copyToClipboard(recipientAddress)
}}
>
{ this.renderRecipientIdenticon() }
this.setState({ recipientAddressCopied: false })}
>
{
addressOnly
? `${t('to')}: ${recipientAddress}`
: (recipientName || this.context.t('newContract'))
}
)
}
renderRecipientWithoutAddress () {
return (
{ this.context.t('newContract') }
)
}
renderArrow () {
return this.props.variant === CARDS_VARIANT
? (
) : (
)
}
render () {
const { senderAddress, recipientAddress, variant } = this.props
return (
{
this.setState({ senderAddressCopied: true })
copyToClipboard(senderAddress)
}}
>
{ this.renderSenderIdenticon() }
{ this.renderSenderAddress() }
{ this.renderArrow() }
{
recipientAddress
? this.renderRecipientWithAddress()
: this.renderRecipientWithoutAddress()
}
)
}
}