mirror of https://github.com/trezor/trezor-wallet
parent
50a877eac2
commit
80fcd15558
@ -0,0 +1,125 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import PropTypes from 'prop-types';
|
||||
import Icon from 'components/Icon';
|
||||
import icons from 'config/icons';
|
||||
import { getStatusColor } from 'utils/device';
|
||||
import TrezorImage from 'components/TrezorImage';
|
||||
|
||||
import colors from 'config/colors';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
position: relative;
|
||||
height: 64px;
|
||||
width: 320px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
`;
|
||||
|
||||
const ImageWrapper = styled.div`
|
||||
`;
|
||||
|
||||
const Dot = styled.div`
|
||||
border: 2px solid @color_white;
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
background: red;
|
||||
`;
|
||||
|
||||
const ClickWrapper = styled.div`
|
||||
width: 100%;
|
||||
display: flex;
|
||||
padding-left: 22px;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
||||
const LabelWrapper = styled.div`
|
||||
flex: 1;
|
||||
padding-left: 18px;
|
||||
`;
|
||||
|
||||
const Name = styled.div`
|
||||
display: block;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
color: ${colors.TEXT_PRIMARY};
|
||||
`;
|
||||
|
||||
const Status = styled.div`
|
||||
display: block;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
font-size: 12px;
|
||||
color: ${colors.TEXT_SECONDARY};
|
||||
`;
|
||||
|
||||
const Counter = styled.div`
|
||||
border: 1px solid ${colors.DIVIDER};
|
||||
border-radius: 50%;
|
||||
color: ${colors.TEXT_SECONDARY};
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
line-height: 22px;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
margin-right: 8px;
|
||||
`;
|
||||
|
||||
const IconWrapper = styled.div`
|
||||
padding-right: 25px;
|
||||
display: flex;
|
||||
`;
|
||||
|
||||
const StyledIcon = styled(Icon)`
|
||||
transform: rotate(180deg);
|
||||
`;
|
||||
|
||||
const DeviceHeader = ({
|
||||
disabled = false,
|
||||
handleOpen,
|
||||
status,
|
||||
label,
|
||||
deviceCount,
|
||||
isOpen = false,
|
||||
trezorModel,
|
||||
}) => (
|
||||
<Wrapper>
|
||||
<ClickWrapper onClick={!disabled ? handleOpen : null}>
|
||||
<ImageWrapper>
|
||||
<Dot color={getStatusColor('device')} />
|
||||
<TrezorImage model={trezorModel} />
|
||||
</ImageWrapper>
|
||||
<LabelWrapper>
|
||||
<Name>{label}</Name>
|
||||
<Status>{status}</Status>
|
||||
</LabelWrapper>
|
||||
<IconWrapper>
|
||||
{deviceCount > 1 ? <Counter>{deviceCount}</Counter> : null}
|
||||
<StyledIcon
|
||||
isOpen={isOpen}
|
||||
size={25}
|
||||
color={colors.TEXT_SECONDARY}
|
||||
icon={icons.ARROW_DOWN}
|
||||
/>
|
||||
</IconWrapper>
|
||||
</ClickWrapper>
|
||||
</Wrapper>
|
||||
);
|
||||
|
||||
DeviceHeader.propTypes = {
|
||||
deviceCount: PropTypes.number,
|
||||
disabled: PropTypes.bool,
|
||||
isOpen: PropTypes.bool,
|
||||
trezorModel: PropTypes.string.isRequired,
|
||||
handleOpen: PropTypes.func.isRequired,
|
||||
status: PropTypes.string.isRequired,
|
||||
label: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default DeviceHeader;
|
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 3.6 KiB |
@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
width: 20px;
|
||||
`;
|
||||
|
||||
const Img = styled.img`
|
||||
width: ${props => (props.model === 'T' ? '17px' : '13px')};
|
||||
`;
|
||||
|
||||
const TrezorImage = ({ model }) => (
|
||||
<Wrapper>
|
||||
<Img
|
||||
model={model}
|
||||
src={model === 'T' ? './images/trezor-T.png' : './images/trezor-1.png'}
|
||||
/>
|
||||
</Wrapper>
|
||||
);
|
||||
|
||||
TrezorImage.propTypes = {
|
||||
model: PropTypes.string,
|
||||
};
|
||||
|
||||
export default TrezorImage;
|
@ -0,0 +1,56 @@
|
||||
const getStatus = (device) => {
|
||||
let deviceStatus = '';
|
||||
if (device.type === 'unacquired' || (device.features && device.status === 'occupied')) {
|
||||
deviceStatus = 'used-in-other-window';
|
||||
} else if (device.type === 'unreadable') {
|
||||
deviceStatus = 'connected';
|
||||
} else if (!device.connected) {
|
||||
deviceStatus = 'disconnected';
|
||||
} else if (!device.available) {
|
||||
deviceStatus = 'unavailable';
|
||||
}
|
||||
|
||||
return deviceStatus;
|
||||
};
|
||||
|
||||
const getStatusName = (device) => {
|
||||
const status = getStatus(device);
|
||||
const unknownStatusName = 'Status unknown';
|
||||
let statusName;
|
||||
switch (status) {
|
||||
case 'used-in-other-window':
|
||||
statusName = 'Used in other window';
|
||||
break;
|
||||
case 'connected':
|
||||
statusName = 'Connected';
|
||||
break;
|
||||
case 'disconnected':
|
||||
statusName = 'Disconnected';
|
||||
break;
|
||||
case 'unavailable':
|
||||
statusName = 'Unavailable';
|
||||
break;
|
||||
default:
|
||||
statusName = unknownStatusName;
|
||||
}
|
||||
|
||||
return statusName;
|
||||
};
|
||||
|
||||
const getVersion = (device) => {
|
||||
let version = null;
|
||||
if (device.features && device.features.major_version > 1) {
|
||||
version = 'T';
|
||||
} else {
|
||||
version = '1';
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
const getStatusColor = device => 'red';
|
||||
|
||||
export {
|
||||
getStatusName,
|
||||
getVersion,
|
||||
getStatusColor,
|
||||
};
|
Loading…
Reference in new issue