2018-03-26 23:32:43 +02:00
// @flow
2018-12-19 06:44:53 +01:00
import * as icons from 'constants/icons' ;
2017-12-21 22:08:54 +01:00
import React from 'react' ;
2018-03-26 23:32:43 +02:00
import Button from 'component/button' ;
2019-01-22 21:36:28 +01:00
import CopyableText from 'component/copyableText' ;
2018-06-12 15:22:53 +02:00
import QRCode from 'component/common/qr-code' ;
2017-05-11 02:59:47 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
checkAddressIsMine : string => void ,
receiveAddress : string ,
getNewAddress : ( ) => void ,
gettingNewAddress : boolean ,
} ;
2018-10-28 19:32:52 +01:00
type State = {
showQR : boolean ,
} ;
class WalletAddress extends React . PureComponent < Props , State > {
2018-06-12 15:22:53 +02:00
constructor ( props : Props ) {
super ( props ) ;
this . state = {
showQR : false ,
} ;
2018-10-28 19:32:52 +01:00
this . toggleQR = this . toggleQR . bind ( this ) ;
2018-06-12 15:22:53 +02:00
}
2017-05-11 02:59:47 +02:00
componentWillMount ( ) {
2018-04-19 01:02:24 +02:00
const { checkAddressIsMine , receiveAddress , getNewAddress } = this . props ;
if ( ! receiveAddress ) {
getNewAddress ( ) ;
} else {
checkAddressIsMine ( receiveAddress ) ;
}
2017-05-11 02:59:47 +02:00
}
2018-10-28 19:32:52 +01:00
toggleQR : Function ;
toggleQR ( ) {
this . setState ( {
showQR : ! this . state . showQR ,
} ) ;
}
2017-05-11 02:59:47 +02:00
render ( ) {
2017-06-06 23:19:12 +02:00
const { receiveAddress , getNewAddress , gettingNewAddress } = this . props ;
2018-06-12 15:22:53 +02:00
const { showQR } = this . state ;
2017-05-11 02:59:47 +02:00
return (
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Receive Credits' ) } < / h2 >
< p className = "card__subtitle" >
{ _ _ ( 'Use this wallet address to receive credits sent by another user (or yourself).' ) }
< / p >
< / header >
2018-03-26 23:32:43 +02:00
2017-05-11 02:59:47 +02:00
< div className = "card__content" >
2019-01-22 21:36:28 +01:00
< CopyableText copyable = { receiveAddress } snackMessage = { _ _ ( 'Address copied.' ) } / >
2017-05-11 02:59:47 +02:00
< / div >
2018-03-26 23:32:43 +02:00
2018-12-19 06:44:53 +01:00
< div className = "card__content" >
< div className = "card__actions" >
< Button
button = "primary"
label = { _ _ ( 'Get New Address' ) }
icon = { icons . REFRESH }
onClick = { getNewAddress }
disabled = { gettingNewAddress }
/ >
< Button
button = "link"
label = { showQR ? _ _ ( 'Hide QR code' ) : _ _ ( 'Show QR code' ) }
onClick = { this . toggleQR }
/ >
< / div >
< p className = "help" >
{ _ _ (
'You can generate a new address at any time, and any previous addresses will continue to work. Using multiple addresses can be helpful for keeping track of incoming payments from multiple sources.'
) }
< / p >
2017-05-11 02:59:47 +02:00
< / div >
2018-06-12 15:22:53 +02:00
2018-06-20 23:56:42 +02:00
{ showQR && (
< div className = "card__content" >
< QRCode value = { receiveAddress } paddingTop / >
< / div >
) }
2017-05-11 02:59:47 +02:00
< / section >
) ;
}
}
2017-06-06 06:21:55 +02:00
export default WalletAddress ;