From 8331348ed603968a633a8beea368630dad533a3f Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Mon, 27 Aug 2018 12:17:27 +0200 Subject: [PATCH] Refactor device header --- .../components/AccountMenu/index.js | 9 ++++-- .../components/DeviceHeader/index.js | 31 +++++++++++++++---- .../components/DeviceMenu/index.js | 22 +++++-------- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/js/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js b/src/js/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js index 0339240f..ed245279 100644 --- a/src/js/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js +++ b/src/js/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js @@ -38,13 +38,16 @@ const RowAccountWrapper = styled.div` font-size: ${FONT_SIZE.SMALL}; color: ${colors.TEXT_PRIMARY}; border-left: ${BORDER_WIDTH.SELECTED} solid transparent; - ${props => props.borderTop && css` - border-top: 1px solid ${colors.DIVIDER}; - `} border-bottom: 1px solid ${colors.DIVIDER}; + &:hover { background-color: ${colors.GRAY_LIGHT}; } + + ${props => props.borderTop && css` + border-top: 1px solid ${colors.DIVIDER}; + `} + ${props => props.isSelected && css` border-left: ${BORDER_WIDTH.SELECTED} solid ${colors.GREEN_PRIMARY}; background: ${colors.WHITE}; diff --git a/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/DeviceHeader/index.js b/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/DeviceHeader/index.js index 414554bb..654f0b53 100644 --- a/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/DeviceHeader/index.js +++ b/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/DeviceHeader/index.js @@ -3,9 +3,14 @@ import styled, { css } from 'styled-components'; import PropTypes from 'prop-types'; import Icon from 'components/Icon'; import icons from 'config/icons'; -import { getStatusColor, getStatusName } from 'utils/device'; +import { + getStatusColor, + getStatusName, + isDisabled, + getStatus, + getVersion, +} from 'utils/device'; import TrezorImage from 'components/TrezorImage'; - import colors from 'config/colors'; const Wrapper = styled.div` @@ -21,6 +26,12 @@ const Wrapper = styled.div` ${props => props.isOpen && css` box-shadow: none; `} + + ${props => props.isHoverable && css` + &:hover { + background: ${colors.GRAY_LIGHT}; + } + `} `; const ClickWrapper = styled.div` @@ -101,6 +112,10 @@ class DeviceHeader extends Component { }; } + isDisabled(device, devices, transport) { + return isDisabled(device, devices, transport); + } + handleClickWrapper() { this.setState({ clicked: true }); if (!this.props.disabled) { @@ -110,17 +125,21 @@ class DeviceHeader extends Component { render() { const { - status, label, deviceCount, isOpen, trezorModel, disabled, icon, + isOpen, icon, device, devices, transport, isHoverable, } = this.props; + const status = getStatus(device); + const disabled = isDisabled(device, devices, transport); + const deviceCount = devices.length; + return ( - + this.handleClickWrapper()}> - + - {label} + {device.instanceLabel} {getStatusName(status)} diff --git a/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.js b/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.js index 48e1c071..4cbad644 100644 --- a/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.js +++ b/src/js/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.js @@ -6,7 +6,6 @@ import colors from 'config/colors'; import Icon from 'components/Icon'; import TrezorConnect from 'trezor-connect'; import type { TrezorDevice } from 'flowtype'; -import { getStatus, getVersion, isDisabled } from 'utils/device'; import DeviceHeader from './components/DeviceHeader'; @@ -19,11 +18,6 @@ const Wrapper = styled.div``; const IconClick = styled.div``; export const DeviceSelect = (props: Props) => { - const { devices } = props; - const { transport } = props.connect; - const { selectedDevice } = props.wallet; - const disabled = isDisabled(selectedDevice, devices, transport); - const handleOpen = () => { props.toggleDeviceDropdown(!props.deviceDropdownOpened); }; @@ -31,12 +25,10 @@ export const DeviceSelect = (props: Props) => { return ( ); }; @@ -152,7 +144,7 @@ export class DeviceDropdown extends Component { }; const deviceList = devices.sort(sortByInstance) - .map((dev, index) => { + .map((dev) => { if (dev === selected) return null; return ( { /> )} - label={dev.instanceLabel} - status={getStatus(dev)} - trezorModel={getVersion(dev)} + device={dev} + devices={devices} + isHoverable /> ); });