mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
Device in bootloader mode is not selectable
This commit is contained in:
parent
cde9206f08
commit
cfda758ecb
@ -1,12 +1,9 @@
|
|||||||
import React, { Component } from 'react';
|
import React from 'react';
|
||||||
import styled, { css } from 'styled-components';
|
import styled, { css } from 'styled-components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Icon from 'components/Icon';
|
|
||||||
import icons from 'config/icons';
|
|
||||||
import {
|
import {
|
||||||
getStatusColor,
|
getStatusColor,
|
||||||
getStatusName,
|
getStatusName,
|
||||||
isDisabled,
|
|
||||||
getStatus,
|
getStatus,
|
||||||
getVersion,
|
getVersion,
|
||||||
} from 'utils/device';
|
} from 'utils/device';
|
||||||
@ -19,11 +16,13 @@ const Wrapper = styled.div`
|
|||||||
width: 320px;
|
width: 320px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: ${colors.WHITE};
|
background: ${props => (props.disabled ? colors.GRAY_LIGHT : 'transparent')};
|
||||||
border-radius: 4px 0 0 0;
|
background: ${props => (props.isSelected ? colors.WHITE : 'transparent')};
|
||||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.04);
|
|
||||||
|
|
||||||
${props => props.isOpen && css`
|
border-radius: 4px 0 0 0;
|
||||||
|
box-shadow: ${props => (props.disabled ? 'none' : '0 3px 8px rgba(0, 0, 0, 0.04)')};
|
||||||
|
|
||||||
|
${props => (props.isOpen || !props.isSelected) && css`
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
`}
|
`}
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ const ClickWrapper = styled.div`
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
${props => props.disabled && css`
|
${props => props.disabled && css`
|
||||||
cursor: initial;
|
cursor: not-allowed;
|
||||||
`}
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -71,18 +70,6 @@ const Status = styled.div`
|
|||||||
color: ${colors.TEXT_SECONDARY};
|
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`
|
const IconWrapper = styled.div`
|
||||||
padding-right: 25px;
|
padding-right: 25px;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -104,72 +91,42 @@ const Dot = styled.div`
|
|||||||
height: 10px;
|
height: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
class DeviceHeader extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
clicked: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
isDisabled(device, devices, transport) {
|
const DeviceHeader = ({
|
||||||
return isDisabled(device, devices, transport);
|
isOpen, icon, device, isHoverable = true, onClickWrapper, disabled = false, isSelected = false,
|
||||||
}
|
}) => {
|
||||||
|
const status = getStatus(device);
|
||||||
handleClickWrapper() {
|
return (
|
||||||
this.setState({ clicked: true });
|
<Wrapper
|
||||||
if (!this.props.disabled) {
|
isSelected={isSelected}
|
||||||
this.props.onClickWrapper();
|
isOpen={isOpen}
|
||||||
}
|
isHoverable={isHoverable}
|
||||||
}
|
disabled={disabled}
|
||||||
|
>
|
||||||
render() {
|
<ClickWrapper disabled={disabled} onClick={onClickWrapper}>
|
||||||
const {
|
<ImageWrapper>
|
||||||
isOpen, icon, device, devices, transport, isHoverable,
|
<Dot color={getStatusColor(status)} />
|
||||||
} = this.props;
|
<TrezorImage model={getVersion(device)} />
|
||||||
const status = getStatus(device);
|
</ImageWrapper>
|
||||||
const disabled = isDisabled(device, devices, transport);
|
<LabelWrapper>
|
||||||
const deviceCount = devices.length;
|
<Name>{device.instanceLabel}</Name>
|
||||||
|
<Status>{getStatusName(status)}</Status>
|
||||||
return (
|
</LabelWrapper>
|
||||||
<Wrapper isOpen={isOpen} isHoverable={isHoverable}>
|
<IconWrapper>
|
||||||
<ClickWrapper disabled={disabled} onClick={() => this.handleClickWrapper()}>
|
{icon && !disabled && icon}
|
||||||
<ImageWrapper>
|
</IconWrapper>
|
||||||
<Dot color={getStatusColor(status)} />
|
</ClickWrapper>
|
||||||
<TrezorImage model={getVersion(device)} />
|
</Wrapper>
|
||||||
</ImageWrapper>
|
);
|
||||||
<LabelWrapper>
|
};
|
||||||
<Name>{device.instanceLabel}</Name>
|
|
||||||
<Status>{getStatusName(status)}</Status>
|
|
||||||
</LabelWrapper>
|
|
||||||
<IconWrapper>
|
|
||||||
{icon && icon}
|
|
||||||
{!icon && deviceCount > 1 && <Counter>{deviceCount}</Counter>}
|
|
||||||
{!icon && !disabled && (
|
|
||||||
<Icon
|
|
||||||
canAnimate={this.state.clicked === true}
|
|
||||||
isActive={isOpen}
|
|
||||||
size={25}
|
|
||||||
color={colors.TEXT_SECONDARY}
|
|
||||||
icon={icons.ARROW_DOWN}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</IconWrapper>
|
|
||||||
</ClickWrapper>
|
|
||||||
</Wrapper>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceHeader.propTypes = {
|
DeviceHeader.propTypes = {
|
||||||
device: PropTypes.object,
|
device: PropTypes.object,
|
||||||
devices: PropTypes.array,
|
|
||||||
transport: PropTypes.object,
|
|
||||||
icon: PropTypes.element,
|
icon: PropTypes.element,
|
||||||
isHoverable: PropTypes.bool,
|
isHoverable: PropTypes.bool,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
isOpen: PropTypes.bool,
|
isOpen: PropTypes.bool,
|
||||||
|
isSelected: PropTypes.bool,
|
||||||
onClickWrapper: PropTypes.func.isRequired,
|
onClickWrapper: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,22 +23,30 @@ class DeviceList extends Component {
|
|||||||
.map(device => (
|
.map(device => (
|
||||||
device !== selectedDevice && (
|
device !== selectedDevice && (
|
||||||
<DeviceHeader
|
<DeviceHeader
|
||||||
key={`${device.instanceLabel}`}
|
key={device.state || device.path}
|
||||||
onClickWrapper={() => onSelectDevice(device)}
|
disabled={device.features && device.features.bootloader_mode}
|
||||||
|
onClickWrapper={() => {
|
||||||
|
if (device.features
|
||||||
|
&& !device.features.bootloader_mode) {
|
||||||
|
onSelectDevice(device);
|
||||||
|
}
|
||||||
|
}}
|
||||||
onClickIcon={() => this.onDeviceMenuClick({ type: 'forget', label: '' }, device)}
|
onClickIcon={() => this.onDeviceMenuClick({ type: 'forget', label: '' }, device)}
|
||||||
icon={(
|
icon={(
|
||||||
<IconClick onClick={(event) => {
|
<React.Fragment>
|
||||||
event.stopPropagation();
|
<IconClick onClick={(event) => {
|
||||||
event.preventDefault();
|
event.stopPropagation();
|
||||||
this.onDeviceMenuClick({ type: 'forget', label: '' }, device);
|
event.preventDefault();
|
||||||
}}
|
this.onDeviceMenuClick({ type: 'forget', label: '' }, device);
|
||||||
>
|
}}
|
||||||
<Icon
|
>
|
||||||
icon={icons.EJECT}
|
<Icon
|
||||||
size={25}
|
icon={icons.EJECT}
|
||||||
color={colors.TEXT_SECONDARY}
|
size={25}
|
||||||
/>
|
color={colors.TEXT_SECONDARY}
|
||||||
</IconClick>
|
/>
|
||||||
|
</IconClick>
|
||||||
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
device={device}
|
device={device}
|
||||||
devices={devices}
|
devices={devices}
|
||||||
|
@ -16,6 +16,18 @@ import type { Props } from './components/common';
|
|||||||
|
|
||||||
const Header = styled(DeviceHeader)``;
|
const Header = styled(DeviceHeader)``;
|
||||||
|
|
||||||
|
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 TransitionGroupWrapper = styled(TransitionGroup)`
|
const TransitionGroupWrapper = styled(TransitionGroup)`
|
||||||
width: 640px;
|
width: 640px;
|
||||||
`;
|
`;
|
||||||
@ -101,6 +113,7 @@ class LeftNavigation extends React.PureComponent<Props, State> {
|
|||||||
this.state = {
|
this.state = {
|
||||||
animationType: null,
|
animationType: null,
|
||||||
shouldRenderDeviceSelection: false,
|
shouldRenderDeviceSelection: false,
|
||||||
|
clicked: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +156,7 @@ class LeftNavigation extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleOpen() {
|
handleOpen() {
|
||||||
|
this.setState({ clicked: true });
|
||||||
this.props.toggleDeviceDropdown(!this.props.wallet.dropdownOpened);
|
this.props.toggleDeviceDropdown(!this.props.wallet.dropdownOpened);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,11 +187,26 @@ class LeftNavigation extends React.PureComponent<Props, State> {
|
|||||||
deviceSelection={this.props.wallet.dropdownOpened}
|
deviceSelection={this.props.wallet.dropdownOpened}
|
||||||
>
|
>
|
||||||
<Header
|
<Header
|
||||||
|
isSelected
|
||||||
onClickWrapper={() => this.handleOpen()}
|
onClickWrapper={() => this.handleOpen()}
|
||||||
device={this.props.wallet.selectedDevice}
|
device={this.props.wallet.selectedDevice}
|
||||||
transport={this.props.connect.transport}
|
transport={this.props.connect.transport}
|
||||||
devices={this.props.devices}
|
devices={this.props.devices}
|
||||||
isOpen={this.props.wallet.dropdownOpened}
|
isOpen={this.props.wallet.dropdownOpened}
|
||||||
|
icon={(
|
||||||
|
<React.Fragment>
|
||||||
|
{this.props.devices.length > 1 && (
|
||||||
|
<Counter>{this.props.devices.length}</Counter>
|
||||||
|
)}
|
||||||
|
<Icon
|
||||||
|
canAnimate={this.state.clicked === true}
|
||||||
|
isActive={this.props.wallet.dropdownOpened}
|
||||||
|
size={25}
|
||||||
|
color={colors.TEXT_SECONDARY}
|
||||||
|
icon={icons.ARROW_DOWN}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
{...this.props}
|
{...this.props}
|
||||||
/>
|
/>
|
||||||
<Body>
|
<Body>
|
||||||
|
Loading…
Reference in New Issue
Block a user