From cde9206f0852d6aefcc7df81284560873e068785 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 21 Sep 2018 10:37:19 +0200 Subject: [PATCH] devicemeuni while one of devices is in bootloader/not-initialized mode --- src/utils/device.js | 10 +++++- .../components/LeftNavigation/Container.js | 1 - .../DeviceMenu/components/MenuItems/index.js | 6 ++++ .../LeftNavigation/components/common.js | 1 - .../Wallet/components/LeftNavigation/index.js | 31 ++++++++----------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/utils/device.js b/src/utils/device.js index de04d66f..6a3c2e4f 100644 --- a/src/utils/device.js +++ b/src/utils/device.js @@ -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; diff --git a/src/views/Wallet/components/LeftNavigation/Container.js b/src/views/Wallet/components/LeftNavigation/Container.js index e297c59c..f5dd762f 100644 --- a/src/views/Wallet/components/LeftNavigation/Container.js +++ b/src/views/Wallet/components/LeftNavigation/Container.js @@ -21,7 +21,6 @@ const mapStateToProps: MapStateToProps = (state: St connect: state.connect, accounts: state.accounts, router: state.router, - deviceDropdownOpened: state.wallet.dropdownOpened, fiat: state.fiat, localStorage: state.localStorage, discovery: state.discovery, diff --git a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js index 5c0b9d15..7ca2c305 100644 --- a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js +++ b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.js @@ -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 ( this.onDeviceMenuClick('settings', this.props.device)}> diff --git a/src/views/Wallet/components/LeftNavigation/components/common.js b/src/views/Wallet/components/LeftNavigation/components/common.js index ee7f1d37..0e3a66c4 100644 --- a/src/views/Wallet/components/LeftNavigation/components/common.js +++ b/src/views/Wallet/components/LeftNavigation/components/common.js @@ -8,7 +8,6 @@ export type StateProps = { connect: $ElementType, accounts: $ElementType, router: $ElementType, - deviceDropdownOpened: boolean, fiat: $ElementType, localStorage: $ElementType, discovery: $ElementType, diff --git a/src/views/Wallet/components/LeftNavigation/index.js b/src/views/Wallet/components/LeftNavigation/index.js index 0a6edb9c..18ff81eb 100644 --- a/src/views/Wallet/components/LeftNavigation/index.js +++ b/src/views/Wallet/components/LeftNavigation/index.js @@ -111,27 +111,22 @@ class LeftNavigation extends React.PureComponent { }); } - 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 { } handleOpen() { - this.props.toggleDeviceDropdown(!this.props.deviceDropdownOpened); + this.props.toggleDeviceDropdown(!this.props.wallet.dropdownOpened); } shouldRenderCoins() { @@ -174,15 +169,15 @@ class LeftNavigation extends React.PureComponent { return (
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} /> @@ -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, };