lbry-desktop/ui/component/walletAddress/view.jsx

87 lines
2.2 KiB
React
Raw Normal View History

2018-03-26 14:32:43 -07:00
// @flow
import React from 'react';
2018-03-26 14:32:43 -07:00
import Button from 'component/button';
2019-01-22 15:36:28 -05:00
import CopyableText from 'component/copyableText';
import QRCode from 'component/common/qr-code';
2019-09-26 12:07:11 -04:00
import Card from 'component/common/card';
2018-03-26 14:32:43 -07:00
type Props = {
2021-03-10 14:06:59 +08:00
checkAddressIsMine: (string) => void,
2018-03-26 14:32:43 -07:00
receiveAddress: string,
getNewAddress: () => void,
gettingNewAddress: boolean,
};
type State = {
showQR: boolean,
};
class WalletAddress extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
showQR: false,
};
2019-03-05 12:54:11 -05:00
(this: any).toggleQR = this.toggleQR.bind(this);
}
2019-06-17 16:32:38 -04:00
componentDidMount() {
const { checkAddressIsMine, receiveAddress, getNewAddress } = this.props;
if (!receiveAddress) {
getNewAddress();
} else {
checkAddressIsMine(receiveAddress);
}
}
toggleQR() {
this.setState({
showQR: !this.state.showQR,
});
}
render() {
2019-11-22 16:13:00 -05:00
const { receiveAddress, getNewAddress, gettingNewAddress } = this.props;
const { showQR } = this.state;
return (
2019-09-26 12:07:11 -04:00
<Card
2021-03-10 14:06:59 +08:00
title={__('Receive Credits')}
2020-09-02 16:08:37 -04:00
subtitle={__('Use this address to receive LBRY Credits.')}
2019-09-26 12:07:11 -04:00
actions={
<React.Fragment>
2019-11-22 16:13:00 -05:00
<CopyableText
primaryButton
label={__('Your Address')}
copyable={receiveAddress}
snackMessage={__('Address copied.')}
/>
2018-03-26 14:32:43 -07:00
2019-09-26 12:07:11 -04:00
<div className="card__actions">
{!IS_WEB && (
<Button
2019-11-22 16:13:00 -05:00
button="secondary"
2019-09-26 12:07:11 -04:00
label={__('Get New Address')}
onClick={getNewAddress}
disabled={gettingNewAddress}
/>
)}
<Button button="link" label={showQR ? __('Hide QR code') : __('Show QR code')} onClick={this.toggleQR} />
</div>
2019-09-30 17:48:30 -04:00
<p className="help">
2019-11-01 13:27:01 -04:00
{!IS_WEB &&
__('You can generate a new address at any time, and any previous addresses will continue to work.')}
2019-09-30 17:48:30 -04:00
</p>
2018-03-26 14:32:43 -07:00
2019-09-26 12:07:11 -04:00
{showQR && <QRCode value={receiveAddress} paddingTop />}
</React.Fragment>
}
/>
);
}
}
2017-06-05 21:21:55 -07:00
export default WalletAddress;