mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
Functions refactored, device list refactored 2
This commit is contained in:
parent
80fcd15558
commit
250aa217a2
@ -3,7 +3,7 @@ import styled from 'styled-components';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import icons from 'config/icons';
|
import icons from 'config/icons';
|
||||||
import { getStatusColor } from 'utils/device';
|
import { getStatusColor, getStatusName } from 'utils/device';
|
||||||
import TrezorImage from 'components/TrezorImage';
|
import TrezorImage from 'components/TrezorImage';
|
||||||
|
|
||||||
import colors from 'config/colors';
|
import colors from 'config/colors';
|
||||||
@ -92,11 +92,11 @@ const DeviceHeader = ({
|
|||||||
<Wrapper>
|
<Wrapper>
|
||||||
<ClickWrapper onClick={!disabled ? handleOpen : null}>
|
<ClickWrapper onClick={!disabled ? handleOpen : null}>
|
||||||
<ImageWrapper>
|
<ImageWrapper>
|
||||||
<Dot color={getStatusColor('device')} />
|
<Dot color={getStatusColor(status)} />
|
||||||
<TrezorImage model={trezorModel} />
|
<TrezorImage model={trezorModel} />
|
||||||
</ImageWrapper>
|
</ImageWrapper>
|
||||||
<LabelWrapper>
|
<LabelWrapper>
|
||||||
<Name>{label}</Name>
|
<Name>{getStatusName(status)}</Name>
|
||||||
<Status>{status}</Status>
|
<Status>{status}</Status>
|
||||||
</LabelWrapper>
|
</LabelWrapper>
|
||||||
<IconWrapper>
|
<IconWrapper>
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import colors from 'js/config/colors';
|
||||||
|
|
||||||
const getStatus = (device) => {
|
const getStatus = (device) => {
|
||||||
let deviceStatus = '';
|
let deviceStatus = '';
|
||||||
if (device.type === 'unacquired' || (device.features && device.status === 'occupied')) {
|
if (device.type === 'unacquired' || (device.features && device.status === 'occupied')) {
|
||||||
@ -14,10 +16,10 @@ const getStatus = (device) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getStatusName = (device) => {
|
const getStatusName = (device) => {
|
||||||
const status = getStatus(device);
|
const deviceStatus = getStatus(device);
|
||||||
const unknownStatusName = 'Status unknown';
|
const unknownStatusName = 'Status unknown';
|
||||||
let statusName;
|
let statusName;
|
||||||
switch (status) {
|
switch (deviceStatus) {
|
||||||
case 'used-in-other-window':
|
case 'used-in-other-window':
|
||||||
statusName = 'Used in other window';
|
statusName = 'Used in other window';
|
||||||
break;
|
break;
|
||||||
@ -37,6 +39,10 @@ const getStatusName = (device) => {
|
|||||||
return statusName;
|
return statusName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isWebUSB = transport => !!((transport && transport.version.indexOf('webusb') >= 0));
|
||||||
|
|
||||||
|
const isDisabled = (devices, transport) => (devices.length < 1 && !isWebUSB(transport)) || (devices.length === 1 && !selected.features && !webusb);
|
||||||
|
|
||||||
const getVersion = (device) => {
|
const getVersion = (device) => {
|
||||||
let version = null;
|
let version = null;
|
||||||
if (device.features && device.features.major_version > 1) {
|
if (device.features && device.features.major_version > 1) {
|
||||||
@ -47,9 +53,32 @@ const getVersion = (device) => {
|
|||||||
return version;
|
return version;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = device => 'red';
|
const getStatusColor = (device) => {
|
||||||
|
const deviceStatus = getStatus(device);
|
||||||
|
let color = null;
|
||||||
|
|
||||||
|
switch (deviceStatus) {
|
||||||
|
case 'used-in-other-window':
|
||||||
|
color = colors.WARNING_PRIMARY;
|
||||||
|
break;
|
||||||
|
case 'connected':
|
||||||
|
color = colors.GREEN_PRIMARY;
|
||||||
|
break;
|
||||||
|
case 'disconnected':
|
||||||
|
color = colors.ERROR_PRIMARY;
|
||||||
|
break;
|
||||||
|
case 'unavailable':
|
||||||
|
color = colors.ERROR_PRIMARY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
color = colors.ERROR_PRIMARY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
isDisabled,
|
||||||
getStatusName,
|
getStatusName,
|
||||||
getVersion,
|
getVersion,
|
||||||
getStatusColor,
|
getStatusColor,
|
||||||
|
@ -63,7 +63,7 @@ export const DeviceSelect = (props: Props) => {
|
|||||||
<DeviceHeader
|
<DeviceHeader
|
||||||
handleOpen={handleOpen}
|
handleOpen={handleOpen}
|
||||||
label={selected.instanceLabel}
|
label={selected.instanceLabel}
|
||||||
status={deviceStatus}
|
status={getStatus(selected)}
|
||||||
deviceCount={deviceCount}
|
deviceCount={deviceCount}
|
||||||
isOpen={props.deviceDropdownOpened}
|
isOpen={props.deviceDropdownOpened}
|
||||||
trezorModel={getVersion(selected)}
|
trezorModel={getVersion(selected)}
|
||||||
|
Loading…
Reference in New Issue
Block a user