add togglable QR code to wallet address component

This commit is contained in:
Travis Eden 2018-06-12 09:22:53 -04:00
parent 7e7b8d770b
commit a2a12ef6cd
3 changed files with 36 additions and 2 deletions

View file

@ -6,22 +6,27 @@ import classnames from 'classnames';
type Props = {
value: string,
paddingRight?: boolean,
paddingTop?: boolean,
size?: number,
};
class QRCode extends React.Component<Props> {
static defaultProps = {
paddingRight: false,
paddingTop: false,
size: 128,
};
render() {
const { value, paddingRight } = this.props;
const { value, paddingRight, paddingTop, size } = this.props;
return (
<div
className={classnames('qr-code', {
'qr-code--right-padding': paddingRight,
'qr-code--top-padding': paddingTop,
})}
>
<QRCodeElement value={value} />
<QRCodeElement value={value} size={size} />
</div>
);
}

View file

@ -2,6 +2,7 @@
import React from 'react';
import Button from 'component/button';
import Address from 'component/address';
import QRCode from 'component/common/qr-code';
import * as icons from 'constants/icons';
type Props = {
@ -12,6 +13,20 @@ type Props = {
};
class WalletAddress extends React.PureComponent<Props> {
constructor(props: Props) {
super(props);
this.state = {
showQR: false,
};
}
toggleQR() {
this.setState({
showQR: !this.state.showQR,
});
}
componentWillMount() {
const { checkAddressIsMine, receiveAddress, getNewAddress } = this.props;
if (!receiveAddress) {
@ -23,6 +38,7 @@ class WalletAddress extends React.PureComponent<Props> {
render() {
const { receiveAddress, getNewAddress, gettingNewAddress } = this.props;
const { showQR } = this.state;
return (
<section className="card card--section">
@ -43,7 +59,17 @@ class WalletAddress extends React.PureComponent<Props> {
onClick={getNewAddress}
disabled={gettingNewAddress}
/>
<Button
button="link"
label={showQR ? __('Hide QR code') : __('Show QR code')}
onClick={this.toggleQR.bind(this)}
/>
</div>
<div className="card__content">
{showQR && <QRCode value={receiveAddress} paddingTop size={256} />}
</div>
<div className="card__content">
<div className="help">
<p>

View file

@ -359,4 +359,7 @@ p {
&.qr-code--right-padding {
padding-right: $spacing-vertical * 2/3;
}
&.qr-code--top-padding {
padding-top: $spacing-vertical * 2/3;
}
}