Skip to content

Commit

Permalink
add togglable QR code to wallet address component
Browse files Browse the repository at this point in the history
  • Loading branch information
daovist committed Jun 12, 2018
1 parent feffa76 commit 4107022
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/renderer/component/common/qr-code.jsx
Expand Up @@ -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>
);
}
Expand Down
26 changes: 26 additions & 0 deletions src/renderer/component/walletAddress/view.jsx
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -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">
Expand All @@ -43,7 +59,17 @@ class WalletAddress extends React.PureComponent<Props> {
onClick={getNewAddress}
disabled={gettingNewAddress}
/>
<Button
button="alt"
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>
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/scss/_gui.scss
Expand Up @@ -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;
}
}

0 comments on commit 4107022

Please sign in to comment.