2019-01-15 18:02:49 -08:00
|
|
|
// @flow
|
2019-01-23 21:08:20 -08:00
|
|
|
import React, { PureComponent } from 'react';
|
2019-01-15 18:02:49 -08:00
|
|
|
import styled from 'styled-components';
|
2019-01-23 21:08:20 -08:00
|
|
|
import { Transition, animated } from 'react-spring';
|
2019-01-15 18:02:49 -08:00
|
|
|
|
|
|
|
import { ColumnComponent } from './column';
|
|
|
|
import { Button } from './button';
|
|
|
|
import { QRCode } from './qrcode';
|
|
|
|
|
|
|
|
import truncateAddress from '../utils/truncateAddress';
|
|
|
|
|
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`
|
|
|
|
border-radius: ${props => props.theme.boxBorderRadius};
|
|
|
|
border: none;
|
|
|
|
background-color: ${props => props.theme.colors.inputBackground};
|
|
|
|
color: ${props => props.theme.colors.text};
|
|
|
|
padding: 15px;
|
|
|
|
width: 100%;
|
|
|
|
outline: none;
|
|
|
|
font-family: ${props => props.theme.fontFamily};
|
|
|
|
|
|
|
|
::placeholder {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-01-23 13:00:42 -08:00
|
|
|
const Btn = styled(Button)`
|
|
|
|
border-width: 1px;
|
2019-01-23 21:08:20 -08:00
|
|
|
font-weight: ${props => props.theme.fontWeight.regular};
|
2019-01-23 13:00:42 -08:00
|
|
|
border-color: ${props => (props.isVisible
|
|
|
|
? props.theme.colors.primary : props.theme.colors.buttonBorderColor
|
|
|
|
)};
|
2019-01-23 21:08:20 -08:00
|
|
|
padding: 8px 10px;
|
|
|
|
min-width: 260px;
|
2019-01-23 13:00:42 -08:00
|
|
|
|
|
|
|
img {
|
|
|
|
height: 12px;
|
2019-01-23 21:08:20 -08:00
|
|
|
width: 20px;
|
2019-01-23 13:00:42 -08:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-01-15 18:02:49 -08:00
|
|
|
const QRCodeWrapper = styled.div`
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
|
|
|
background-color: #000;
|
|
|
|
border-radius: 6px;
|
|
|
|
padding: 20px;
|
|
|
|
margin-top: 10px;
|
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
2019-01-23 21:08:20 -08:00
|
|
|
const RevealsMain = styled.div`
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
& > div {
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-01-15 18:02:49 -08:00
|
|
|
type Props = {
|
|
|
|
address: string,
|
2019-01-23 21:08:20 -08:00
|
|
|
isVisible?: boolean,
|
2019-01-15 18:02:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
isVisible: boolean,
|
|
|
|
};
|
|
|
|
|
2019-01-23 21:08:20 -08:00
|
|
|
export class WalletAddress extends PureComponent<Props, State> {
|
|
|
|
static defaultProps = {
|
2019-01-15 18:02:49 -08:00
|
|
|
isVisible: false,
|
2019-01-23 21:08:20 -08:00
|
|
|
}
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-01-23 21:08:20 -08:00
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-01-23 21:08:20 -08:00
|
|
|
this.state = { isVisible: props.isVisible };
|
|
|
|
}
|
|
|
|
|
|
|
|
show = () => this.setState(() => ({ isVisible: true }));
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-01-23 21:08:20 -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;
|
2019-01-23 21:08:20 -08:00
|
|
|
const buttonLabel = `${isVisible ? 'Hide' : 'Show'} details and QR Code`;
|
2019-01-15 18:02:49 -08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ColumnComponent width='100%'>
|
|
|
|
<AddressWrapper>
|
|
|
|
<Input
|
|
|
|
value={isVisible ? address : truncateAddress(address)}
|
|
|
|
onChange={() => {}}
|
|
|
|
onFocus={event => event.currentTarget.select()}
|
|
|
|
/>
|
2019-01-23 13:00:42 -08:00
|
|
|
<Btn
|
2019-01-17 12:26:46 -08:00
|
|
|
icon={eyeIcon}
|
2019-01-23 21:08:20 -08:00
|
|
|
label={buttonLabel}
|
2019-01-15 18:02:49 -08:00
|
|
|
onClick={toggleVisibility}
|
|
|
|
variant='secondary'
|
2019-01-23 13:00:42 -08:00
|
|
|
isVisible={isVisible}
|
2019-01-15 18:02:49 -08:00
|
|
|
/>
|
|
|
|
</AddressWrapper>
|
2019-01-23 21:08:20 -08:00
|
|
|
<RevealsMain>
|
|
|
|
<Transition
|
|
|
|
native
|
|
|
|
items={isVisible}
|
|
|
|
enter={[{ height: 'auto' }]}
|
|
|
|
leave={{ height: 0 }}
|
|
|
|
from={{
|
|
|
|
// TODO: fix this
|
|
|
|
// position: 'absolute',
|
|
|
|
// overflow: 'hidden',
|
|
|
|
// height: 0,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{show => show && (props => (
|
|
|
|
<animated.div style={props}>
|
|
|
|
<QRCodeWrapper>
|
|
|
|
<QRCode value={address} />
|
|
|
|
</QRCodeWrapper>
|
|
|
|
</animated.div>
|
|
|
|
))}
|
|
|
|
</Transition>
|
|
|
|
</RevealsMain>
|
2019-01-15 18:02:49 -08:00
|
|
|
</ColumnComponent>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|