2019-01-15 18:02:49 -08:00
|
|
|
// @flow
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2019-02-04 19:16:25 -08:00
|
|
|
import React, { Component } from 'react';
|
2019-01-15 18:02:49 -08:00
|
|
|
import styled from 'styled-components';
|
|
|
|
|
2019-02-04 19:16:25 -08:00
|
|
|
import { ColumnComponent } from './column';
|
2019-01-15 18:02:49 -08:00
|
|
|
import { Button } from './button';
|
|
|
|
import { QRCode } from './qrcode';
|
|
|
|
|
2019-01-29 07:36:13 -08:00
|
|
|
import { truncateAddress } from '../utils/truncate-address';
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-01-17 12:26:46 -08:00
|
|
|
import eyeIcon from '../assets/images/eye.png';
|
|
|
|
|
2019-01-15 18:02:49 -08:00
|
|
|
const AddressWrapper = styled.div`
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
|
|
|
background-color: #000;
|
|
|
|
border-radius: 6px;
|
|
|
|
padding: 7px 13px;
|
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Input = styled.input`
|
2019-02-07 08:31:59 -08:00
|
|
|
border-radius: ${props => props.theme.boxBorderRadius};
|
2019-01-15 18:02:49 -08:00
|
|
|
border: none;
|
2019-02-07 08:31:59 -08:00
|
|
|
background-color: ${props => props.theme.colors.inputBackground};
|
|
|
|
color: ${props => props.theme.colors.text};
|
2019-01-15 18:02:49 -08:00
|
|
|
padding: 15px;
|
|
|
|
width: 100%;
|
|
|
|
outline: none;
|
2019-02-07 08:31:59 -08:00
|
|
|
font-family: ${props => props.theme.fontFamily};
|
2019-01-15 18:02:49 -08:00
|
|
|
|
|
|
|
::placeholder {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const QRCodeWrapper = styled.div`
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
|
|
|
background-color: #000;
|
|
|
|
border-radius: 6px;
|
|
|
|
padding: 20px;
|
2019-02-04 19:16:25 -08:00
|
|
|
margin-top: 10px;
|
2019-01-15 18:02:49 -08:00
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
address: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
isVisible: boolean,
|
|
|
|
};
|
|
|
|
|
2019-02-04 19:16:25 -08:00
|
|
|
export class WalletAddress extends Component<Props, State> {
|
|
|
|
state = {
|
2019-01-15 18:02:49 -08:00
|
|
|
isVisible: false,
|
2019-01-28 05:03:11 -08:00
|
|
|
};
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-04 20:41:45 -08:00
|
|
|
show = () => this.setState(() => ({ isVisible: true }));
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-04 20:41:45 -08:00
|
|
|
hide = () => this.setState(() => ({ isVisible: false }));
|
2019-01-15 18:02:49 -08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { address } = this.props;
|
|
|
|
const { isVisible } = this.state;
|
|
|
|
const toggleVisibility = isVisible ? this.hide : this.show;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ColumnComponent width='100%'>
|
|
|
|
<AddressWrapper>
|
|
|
|
<Input
|
|
|
|
value={isVisible ? address : truncateAddress(address)}
|
2019-02-06 19:06:48 -08:00
|
|
|
onChange={() => {}}
|
2019-01-15 18:02:49 -08:00
|
|
|
onFocus={event => event.currentTarget.select()}
|
|
|
|
/>
|
2019-02-04 19:16:25 -08:00
|
|
|
<Button
|
2019-01-17 12:26:46 -08:00
|
|
|
icon={eyeIcon}
|
2019-02-04 19:16:25 -08:00
|
|
|
label={`${isVisible ? 'Hide' : 'Show'} full address and QR Code`}
|
2019-01-15 18:02:49 -08:00
|
|
|
onClick={toggleVisibility}
|
|
|
|
variant='secondary'
|
|
|
|
/>
|
|
|
|
</AddressWrapper>
|
2019-02-04 20:41:45 -08:00
|
|
|
{!isVisible ? null : (
|
|
|
|
<QRCodeWrapper>
|
|
|
|
<QRCode value={address} />
|
|
|
|
</QRCodeWrapper>
|
|
|
|
)}
|
2019-02-04 19:16:25 -08:00
|
|
|
</ColumnComponent>
|
2019-01-15 18:02:49 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|