2019-01-15 18:02:49 -08:00
|
|
|
// @flow
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2019-02-10 08:49:24 -08:00
|
|
|
import React, { PureComponent } from 'react';
|
2019-02-18 10:04:41 -08:00
|
|
|
import styled, { withTheme } from 'styled-components';
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-04 19:16:25 -08:00
|
|
|
import { ColumnComponent } from './column';
|
2019-02-18 15:40:15 -08:00
|
|
|
import { TextComponent } from './text';
|
2019-01-15 18:02:49 -08:00
|
|
|
import { QRCode } from './qrcode';
|
2019-02-18 15:40:15 -08:00
|
|
|
import { CopyToClipboard } from './copy-to-clipboard';
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-18 10:04:41 -08:00
|
|
|
import CopyIconDark from '../assets/images/copy_icon_dark.svg';
|
|
|
|
import CopyIconLight from '../assets/images/copy_icon_light.svg';
|
|
|
|
import ScanIconDark from '../assets/images/scan_icon_dark.svg';
|
|
|
|
import ScanIconLight from '../assets/images/scan_icon_light.svg';
|
|
|
|
import { DARK } from '../constants/themes';
|
2019-01-17 12:26:46 -08:00
|
|
|
|
2019-01-15 18:02:49 -08:00
|
|
|
const AddressWrapper = styled.div`
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
2019-02-17 19:56:50 -08:00
|
|
|
border-radius: ${props => props.theme.boxBorderRadius};
|
2019-02-16 19:34:12 -08:00
|
|
|
padding: 0 13px 0 0;
|
2019-02-11 05:37:50 -08:00
|
|
|
margin-bottom: 10px;
|
2019-01-15 18:02:49 -08:00
|
|
|
width: 100%;
|
2019-02-17 19:56:50 -08:00
|
|
|
background: ${props => props.theme.colors.walletAddressBg};
|
|
|
|
border: 1px solid ${props => props.theme.colors.walletAddressBorder};
|
2019-01-15 18:02:49 -08:00
|
|
|
`;
|
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
const Address = styled(TextComponent)`
|
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-15 18:59:05 -08:00
|
|
|
background-color: ${props => props.theme.colors.inputBg};
|
2019-01-15 18:02:49 -08:00
|
|
|
padding: 15px;
|
2019-02-18 15:40:15 -08:00
|
|
|
width: 92%;
|
2019-01-15 18:02:49 -08:00
|
|
|
outline: none;
|
2019-02-07 08:31:59 -08:00
|
|
|
font-family: ${props => props.theme.fontFamily};
|
2019-02-18 10:04:41 -08:00
|
|
|
font-size: 13px;
|
2019-02-18 15:40:15 -08:00
|
|
|
color: ${props => props.theme.colors.walletAddressInput};
|
2019-02-18 10:04:41 -08:00
|
|
|
line-height: 1;
|
2019-02-18 15:40:15 -08:00
|
|
|
letter-spacing: 0.5px;
|
|
|
|
overflow-x: scroll;
|
2019-02-18 10:04:41 -08:00
|
|
|
cursor: pointer;
|
2019-02-18 15:40:15 -08:00
|
|
|
user-select: text;
|
|
|
|
|
|
|
|
::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
2019-02-18 10:04:41 -08:00
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
/* // todo: make this theme supported */
|
2019-02-18 10:04:41 -08:00
|
|
|
${AddressWrapper}:hover & {
|
2019-02-18 15:40:15 -08:00
|
|
|
color: ${props => props.theme.colors.walletAddressInputHovered};
|
2019-02-18 10:04:41 -08:00
|
|
|
}
|
2019-01-15 18:02:49 -08:00
|
|
|
|
|
|
|
::placeholder {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
const QRCodeContainer = styled.div`
|
2019-01-15 18:02:49 -08:00
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
2019-02-15 18:59:05 -08:00
|
|
|
background-color: ${props => props.theme.colors.qrCodeWrapperBg}
|
2019-02-18 10:04:41 -08:00
|
|
|
border: 1px solid ${props => props.theme.colors.qrCodeWrapperBorder}
|
|
|
|
border-radius: 3px;
|
2019-01-15 18:02:49 -08:00
|
|
|
padding: 20px;
|
2019-02-11 05:37:50 -08:00
|
|
|
margin-bottom: 10px;
|
2019-01-15 18:02:49 -08:00
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
const QRCodeWrapper = styled.div`
|
2019-02-19 08:06:34 -08:00
|
|
|
background-color: #ffffff;
|
2019-02-18 15:40:15 -08:00
|
|
|
padding: 10px;
|
|
|
|
`;
|
|
|
|
|
2019-02-10 08:49:24 -08:00
|
|
|
const IconButton = styled.button`
|
|
|
|
background: transparent;
|
|
|
|
cursor: pointer;
|
|
|
|
outline: none;
|
2019-02-18 10:04:41 -08:00
|
|
|
border: none;
|
|
|
|
display: flex;
|
|
|
|
width: 28px;
|
|
|
|
margin-left: 3px;
|
2019-02-18 15:40:15 -08:00
|
|
|
position: relative;
|
|
|
|
`;
|
2019-02-18 10:04:41 -08:00
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
const IconImage = styled.img`
|
|
|
|
max-width: 23px;
|
|
|
|
opacity: 0.4;
|
|
|
|
|
|
|
|
${IconButton}:hover & {
|
2019-02-18 10:04:41 -08:00
|
|
|
opacity: 1;
|
|
|
|
}
|
2019-02-10 08:49:24 -08:00
|
|
|
`;
|
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
const CopyTooltip = styled.div`
|
|
|
|
background: ${props => props.theme.colors.walletAddressTooltipBg};
|
|
|
|
position: absolute;
|
|
|
|
top: -27px;
|
|
|
|
left: -8px;
|
|
|
|
padding: 6px 10px;
|
|
|
|
border-radius: 3px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TooltipText = styled(TextComponent)`
|
|
|
|
color: ${props => props.theme.colors.walletAddressTooltip};
|
|
|
|
font-size: 10px;
|
|
|
|
font-weight: 700;
|
2019-02-10 08:49:24 -08:00
|
|
|
`;
|
|
|
|
|
2019-01-15 18:02:49 -08:00
|
|
|
type Props = {
|
|
|
|
address: string,
|
2019-02-18 10:04:41 -08:00
|
|
|
theme: AppTheme,
|
2019-01-15 18:02:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
2019-02-18 15:40:15 -08:00
|
|
|
showCopiedTooltip: boolean,
|
2019-02-10 08:49:24 -08:00
|
|
|
showQRCode: boolean,
|
2019-01-15 18:02:49 -08:00
|
|
|
};
|
|
|
|
|
2019-02-18 10:04:41 -08:00
|
|
|
class Component extends PureComponent<Props, State> {
|
2019-02-04 19:16:25 -08:00
|
|
|
state = {
|
2019-02-10 08:49:24 -08:00
|
|
|
showQRCode: false,
|
2019-02-18 15:40:15 -08:00
|
|
|
showCopiedTooltip: false,
|
2019-01-28 05:03:11 -08:00
|
|
|
};
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
showMoreInfo = () => this.setState(() => ({ showQRCode: true }));
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-18 15:40:15 -08:00
|
|
|
toggleMoreInfo = () => this.setState(prevState => ({
|
|
|
|
showQRCode: !prevState.showQRCode,
|
|
|
|
}));
|
|
|
|
|
|
|
|
hideTooltip = () => this.setState(() => ({ showCopiedTooltip: false }));
|
|
|
|
|
|
|
|
copyAddress = () => this.setState(
|
|
|
|
() => ({ showCopiedTooltip: true }),
|
|
|
|
() => setTimeout(() => this.hideTooltip(), 1500),
|
|
|
|
);
|
2019-01-15 18:02:49 -08:00
|
|
|
|
|
|
|
render() {
|
2019-02-18 10:04:41 -08:00
|
|
|
const { address, theme } = this.props;
|
2019-02-18 15:40:15 -08:00
|
|
|
const { showQRCode, showCopiedTooltip } = this.state;
|
2019-01-15 18:02:49 -08:00
|
|
|
|
2019-02-19 08:06:34 -08:00
|
|
|
const qrCodeIcon = theme.mode === DARK ? ScanIconDark : ScanIconLight;
|
2019-02-18 10:04:41 -08:00
|
|
|
|
2019-02-19 08:06:34 -08:00
|
|
|
const copyIcon = theme.mode === DARK ? CopyIconDark : CopyIconLight;
|
2019-02-18 10:04:41 -08:00
|
|
|
|
2019-01-15 18:02:49 -08:00
|
|
|
return (
|
|
|
|
<ColumnComponent width='100%'>
|
|
|
|
<AddressWrapper>
|
2019-02-18 15:40:15 -08:00
|
|
|
<Address
|
2019-02-10 08:49:24 -08:00
|
|
|
value={address}
|
2019-02-18 15:40:15 -08:00
|
|
|
onClick={this.toggleMoreInfo}
|
|
|
|
onDoubleClick={this.showMoreInfo}
|
2019-01-15 18:02:49 -08:00
|
|
|
/>
|
2019-02-19 08:06:34 -08:00
|
|
|
<CopyToClipboard text={address} onCopy={this.copyAddress}>
|
2019-02-18 15:40:15 -08:00
|
|
|
<IconButton onClick={() => {}}>
|
|
|
|
{!showCopiedTooltip ? null : (
|
|
|
|
<CopyTooltip>
|
|
|
|
<TooltipText value='Copied!' />
|
|
|
|
</CopyTooltip>
|
|
|
|
)}
|
2019-02-19 08:06:34 -08:00
|
|
|
<IconImage src={copyIcon} alt='Copy Address' />
|
2019-02-18 15:40:15 -08:00
|
|
|
</IconButton>
|
|
|
|
</CopyToClipboard>
|
|
|
|
<IconButton onClick={this.toggleMoreInfo}>
|
2019-02-19 08:06:34 -08:00
|
|
|
<IconImage src={qrCodeIcon} alt='See QRCode' />
|
2019-02-10 08:49:24 -08:00
|
|
|
</IconButton>
|
2019-01-15 18:02:49 -08:00
|
|
|
</AddressWrapper>
|
2019-02-10 08:49:24 -08:00
|
|
|
{!showQRCode ? null : (
|
2019-02-18 15:40:15 -08:00
|
|
|
<QRCodeContainer>
|
|
|
|
<QRCodeWrapper>
|
|
|
|
<QRCode value={address} />
|
|
|
|
</QRCodeWrapper>
|
|
|
|
</QRCodeContainer>
|
2019-02-04 20:41:45 -08:00
|
|
|
)}
|
2019-02-04 19:16:25 -08:00
|
|
|
</ColumnComponent>
|
2019-01-15 18:02:49 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-02-18 10:04:41 -08:00
|
|
|
|
|
|
|
export const WalletAddress = withTheme(Component);
|