1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

devicemeuni while one of devices is in bootloader/not-initialized mode

This commit is contained in:
Szymon Lesisz 2018-09-21 10:37:19 +02:00 committed by Vasek Mlejnsky
parent 41ced76a48
commit cde9206f08
5 changed files with 28 additions and 21 deletions

View File

@ -43,7 +43,15 @@ const getStatusName = (deviceStatus) => {
const isWebUSB = transport => !!((transport && transport.version.indexOf('webusb') >= 0));
const isDisabled = (selectedDevice, devices, transport) => (devices.length < 1 && !isWebUSB(transport)) || (devices.length === 1 && !selectedDevice.features && !isWebUSB(transport));
const isDisabled = (selectedDevice, devices, transport) => {
if (isWebUSB(transport)) return false; // always enabled if webusb
if (devices.length < 1) return true; // no devices
if (devices.length === 1) {
if (!selectedDevice.features) return true; // unacquired, unreadable
if (selectedDevice.features.bootloader_mode || !selectedDevice.features.initialized) return true; // bootlader, not initialized
}
return false; // default
}
const getVersion = (device) => {
let version;

View File

@ -21,7 +21,6 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
connect: state.connect,
accounts: state.accounts,
router: state.router,
deviceDropdownOpened: state.wallet.dropdownOpened,
fiat: state.fiat,
localStorage: state.localStorage,
discovery: state.discovery,

View File

@ -41,6 +41,11 @@ class MenuItems extends Component {
}
}
showDeviceMenu() {
const device = this.props.device;
return device && device.features && !device.features.bootloader_mode && device.features.initialized;
}
showClone() {
return this.props.device && this.props.device.features.passphrase_protection && this.props.device.connected && this.props.device.available;
}
@ -50,6 +55,7 @@ class MenuItems extends Component {
}
render() {
if (!this.showDeviceMenu()) return null;
return (
<Wrapper>
<Item onClick={() => this.onDeviceMenuClick('settings', this.props.device)}>

View File

@ -8,7 +8,6 @@ export type StateProps = {
connect: $ElementType<State, 'connect'>,
accounts: $ElementType<State, 'accounts'>,
router: $ElementType<State, 'router'>,
deviceDropdownOpened: boolean,
fiat: $ElementType<State, 'fiat'>,
localStorage: $ElementType<State, 'localStorage'>,
discovery: $ElementType<State, 'discovery'>,

View File

@ -111,27 +111,22 @@ class LeftNavigation extends React.PureComponent<Props, State> {
});
}
componentWillReceiveProps(nextProps: Props) {
const { deviceDropdownOpened } = nextProps;
const { selectedDevice } = nextProps.wallet;
const hasNetwork = nextProps.router.location.state && nextProps.router.location.state.network;
const deviceReady = selectedDevice && selectedDevice.features && !selectedDevice.features.bootloader_mode && selectedDevice.features.initialized;
if (deviceDropdownOpened) {
componentWillReceiveProps(nextProps) {
const { dropdownOpened, selectedDevice } = nextProps.wallet;
const hasNetwork = nextProps.location.state && nextProps.location.state.network;
const hasFeatures = selectedDevice && selectedDevice.features;
const deviceReady = hasFeatures && !selectedDevice.features.bootloader_mode && selectedDevice.features.initialized;
if (dropdownOpened) {
this.setState({ shouldRenderDeviceSelection: true });
} else if (hasNetwork) {
this.setState({
shouldRenderDeviceSelection: false,
animationType: 'slide-left',
});
} else if (deviceReady) {
this.setState({
shouldRenderDeviceSelection: false,
animationType: 'slide-right',
});
} else if (selectedDevice.features.bootloader_mode) {
} else {
this.setState({
shouldRenderDeviceSelection: false,
animationType: deviceReady ? 'slide-right' : null,
});
}
}
@ -148,7 +143,7 @@ class LeftNavigation extends React.PureComponent<Props, State> {
}
handleOpen() {
this.props.toggleDeviceDropdown(!this.props.deviceDropdownOpened);
this.props.toggleDeviceDropdown(!this.props.wallet.dropdownOpened);
}
shouldRenderCoins() {
@ -174,15 +169,15 @@ class LeftNavigation extends React.PureComponent<Props, State> {
return (
<StickyContainer
location={this.props.router.location.pathname}
deviceSelection={this.props.deviceDropdownOpened}
location={this.props.location.pathname}
deviceSelection={this.props.wallet.dropdownOpened}
>
<Header
onClickWrapper={() => this.handleOpen()}
device={this.props.wallet.selectedDevice}
transport={this.props.connect.transport}
devices={this.props.devices}
isOpen={this.props.deviceDropdownOpened}
isOpen={this.props.wallet.dropdownOpened}
{...this.props}
/>
<Body>
@ -209,7 +204,6 @@ LeftNavigation.propTypes = {
connect: PropTypes.object,
accounts: PropTypes.array,
router: PropTypes.object,
deviceDropdownOpened: PropTypes.bool,
fiat: PropTypes.array,
localStorage: PropTypes.object,
discovery: PropTypes.array,
@ -218,6 +212,7 @@ LeftNavigation.propTypes = {
pending: PropTypes.array,
toggleDeviceDropdown: PropTypes.func,
selectedDevice: PropTypes.object,
};