@ -1,16 +1,29 @@
import React , { Component } from 'react'
import React , { Pure Component } from 'react'
import PropTypes from 'prop-types'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import Identicon from '../identicon'
import Identicon from '../identicon'
import Tooltip from '../tooltip-v2'
import Tooltip from '../tooltip-v2'
import copyToClipboard from 'copy-to-clipboard'
import copyToClipboard from 'copy-to-clipboard'
import { DEFAULT _VARIANT , CARDS _VARIANT } from './sender-to-recipient.constants'
export default class SenderToRecipient extends Component {
const variantHash = {
[ DEFAULT _VARIANT ] : 'sender-to-recipient--default' ,
[ CARDS _VARIANT ] : 'sender-to-recipient--cards' ,
}
export default class SenderToRecipient extends PureComponent {
static propTypes = {
static propTypes = {
senderName : PropTypes . string ,
senderName : PropTypes . string ,
senderAddress : PropTypes . string ,
senderAddress : PropTypes . string ,
recipientName : PropTypes . string ,
recipientName : PropTypes . string ,
recipientAddress : PropTypes . string ,
recipientAddress : PropTypes . string ,
t : PropTypes . func ,
t : PropTypes . func ,
variant : PropTypes . oneOf ( [ DEFAULT _VARIANT , CARDS _VARIANT ] ) ,
addressOnly : PropTypes . bool ,
}
static defaultProps = {
variant : DEFAULT _VARIANT ,
}
}
static contextTypes = {
static contextTypes = {
@ -22,24 +35,62 @@ export default class SenderToRecipient extends Component {
recipientAddressCopied : false ,
recipientAddressCopied : false ,
}
}
renderSenderIdenticon ( ) {
return ! this . props . addressOnly && (
< div className = "sender-to-recipient__sender-icon" >
< Identicon
address = { this . props . senderAddress }
diameter = { 24 }
/ >
< / d i v >
)
}
renderSenderAddress ( ) {
const { t } = this . context
const { senderName , senderAddress , addressOnly } = this . props
return (
< Tooltip
position = "bottom"
title = { this . state . senderAddressCopied ? t ( 'copiedExclamation' ) : t ( 'copyAddress' ) }
wrapperClassName = "sender-to-recipient__tooltip-wrapper"
containerClassName = "sender-to-recipient__tooltip-container"
onHidden = { ( ) => this . setState ( { senderAddressCopied : false } ) }
>
< div className = "sender-to-recipient__name" >
{ addressOnly ? ` ${ t ( 'from' ) } : ${ senderAddress } ` : senderName }
< / d i v >
< / T o o l t i p >
)
}
renderRecipientIdenticon ( ) {
const { recipientAddress } = this . props
return ! this . props . addressOnly && (
< div className = "sender-to-recipient__sender-icon" >
< Identicon
address = { recipientAddress }
diameter = { 24 }
/ >
< / d i v >
)
}
renderRecipientWithAddress ( ) {
renderRecipientWithAddress ( ) {
const { t } = this . context
const { t } = this . context
const { recipientName , recipientAddress } = this . props
const { recipientName , recipientAddress , addressOnly } = this . props
return (
return (
< div
< div
className = "sender-to-recipient__recipient sender-to-recipient__recipient--with-address"
className = "sender-to-recipient__party sender-to-recipient__party-- recipient sender-to-recipient__party-- recipient-with-address"
onClick = { ( ) => {
onClick = { ( ) => {
this . setState ( { recipientAddressCopied : true } )
this . setState ( { recipientAddressCopied : true } )
copyToClipboard ( recipientAddress )
copyToClipboard ( recipientAddress )
} }
} }
>
>
< div className = "sender-to-recipient__sender-icon" >
{ this . renderRecipientIdenticon ( ) }
< Identicon
address = { recipientAddress }
diameter = { 24 }
/ >
< / d i v >
< Tooltip
< Tooltip
position = "bottom"
position = "bottom"
title = { this . state . recipientAddressCopied ? t ( 'copiedExclamation' ) : t ( 'copyAddress' ) }
title = { this . state . recipientAddressCopied ? t ( 'copiedExclamation' ) : t ( 'copyAddress' ) }
@ -47,8 +98,12 @@ export default class SenderToRecipient extends Component {
containerClassName = "sender-to-recipient__tooltip-container"
containerClassName = "sender-to-recipient__tooltip-container"
onHidden = { ( ) => this . setState ( { recipientAddressCopied : false } ) }
onHidden = { ( ) => this . setState ( { recipientAddressCopied : false } ) }
>
>
< div className = "sender-to-recipient__name sender-to-recipient__recipient-name" >
< div className = "sender-to-recipient__name" >
{ recipientName || this . context . t ( 'newContract' ) }
{
addressOnly
? ` ${ t ( 'to' ) } : ${ recipientAddress } `
: ( recipientName || this . context . t ( 'newContract' ) )
}
< / d i v >
< / d i v >
< / T o o l t i p >
< / T o o l t i p >
< / d i v >
< / d i v >
@ -57,46 +112,25 @@ export default class SenderToRecipient extends Component {
renderRecipientWithoutAddress ( ) {
renderRecipientWithoutAddress ( ) {
return (
return (
< div className = "sender-to-recipient__recipient" >
< div className = "sender-to-recipient__party sender-to-recipient__party-- recipient" >
< i className = "fa fa-file-text-o" / >
< i className = "fa fa-file-text-o" / >
< div className = "sender-to-recipient__name sender-to-recipient__recipient-name " >
< div className = "sender-to-recipient__name" >
{ this . context . t ( 'newContract' ) }
{ this . context . t ( 'newContract' ) }
< / d i v >
< / d i v >
< / d i v >
< / d i v >
)
)
}
}
render ( ) {
renderArrow ( ) {
const { t } = this . context
return this . props . variant === CARDS _VARIANT
const { senderName , senderAddress , recipientAddress } = this . props
? (
< div className = "sender-to-recipient__arrow-container" >
return (
< img
< div className = "sender-to-recipient__container" >
height = { 20 }
< div
src = "./images/caret-right.svg"
className = "sender-to-recipient__sender"
/ >
onClick = { ( ) => {
this . setState ( { senderAddressCopied : true } )
copyToClipboard ( senderAddress )
} }
>
< div className = "sender-to-recipient__sender-icon" >
< Identicon
address = { senderAddress }
diameter = { 24 }
/ >
< / d i v >
< Tooltip
position = "bottom"
title = { this . state . senderAddressCopied ? t ( 'copiedExclamation' ) : t ( 'copyAddress' ) }
wrapperClassName = "sender-to-recipient__tooltip-wrapper"
containerClassName = "sender-to-recipient__tooltip-container"
onHidden = { ( ) => this . setState ( { senderAddressCopied : false } ) }
>
< div className = "sender-to-recipient__name sender-to-recipient__sender-name" >
{ senderName }
< / d i v >
< / T o o l t i p >
< / d i v >
< / d i v >
) : (
< div className = "sender-to-recipient__arrow-container" >
< div className = "sender-to-recipient__arrow-container" >
< div className = "sender-to-recipient__arrow-circle" >
< div className = "sender-to-recipient__arrow-circle" >
< img
< img
@ -106,6 +140,25 @@ export default class SenderToRecipient extends Component {
/ >
/ >
< / d i v >
< / d i v >
< / d i v >
< / d i v >
)
}
render ( ) {
const { senderAddress , recipientAddress , variant } = this . props
return (
< div className = { classnames ( variantHash [ variant ] ) } >
< div
className = { classnames ( 'sender-to-recipient__party sender-to-recipient__party--sender' ) }
onClick = { ( ) => {
this . setState ( { senderAddressCopied : true } )
copyToClipboard ( senderAddress )
} }
>
{ this . renderSenderIdenticon ( ) }
{ this . renderSenderAddress ( ) }
< / d i v >
{ this . renderArrow ( ) }
{
{
recipientAddress
recipientAddress
? this . renderRecipientWithAddress ( )
? this . renderRecipientWithAddress ( )