mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
Finalized status dot
This commit is contained in:
parent
250aa217a2
commit
d7e067616f
@ -16,16 +16,6 @@ const Wrapper = styled.div`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ImageWrapper = styled.div`
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Dot = styled.div`
|
|
||||||
border: 2px solid @color_white;
|
|
||||||
border-radius: 50%;
|
|
||||||
position: absolute;
|
|
||||||
background: red;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ClickWrapper = styled.div`
|
const ClickWrapper = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -91,13 +81,13 @@ const DeviceHeader = ({
|
|||||||
}) => (
|
}) => (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<ClickWrapper onClick={!disabled ? handleOpen : null}>
|
<ClickWrapper onClick={!disabled ? handleOpen : null}>
|
||||||
<ImageWrapper>
|
<TrezorImage
|
||||||
<Dot color={getStatusColor(status)} />
|
status={status}
|
||||||
<TrezorImage model={trezorModel} />
|
model={trezorModel}
|
||||||
</ImageWrapper>
|
/>
|
||||||
<LabelWrapper>
|
<LabelWrapper>
|
||||||
<Name>{getStatusName(status)}</Name>
|
<Name>{label}</Name>
|
||||||
<Status>{status}</Status>
|
<Status>{getStatusName(status)}</Status>
|
||||||
</LabelWrapper>
|
</LabelWrapper>
|
||||||
<IconWrapper>
|
<IconWrapper>
|
||||||
{deviceCount > 1 ? <Counter>{deviceCount}</Counter> : null}
|
{deviceCount > 1 ? <Counter>{deviceCount}</Counter> : null}
|
||||||
|
@ -1,17 +1,32 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import colors from 'config/colors';
|
||||||
|
import { getStatusColor } from 'utils/device';
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
width: 20px;
|
width: 20px;
|
||||||
|
position: relative;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Dot = styled.div`
|
||||||
|
border: 2px solid ${colors.WHITE};
|
||||||
|
border-radius: 50%;
|
||||||
|
position: absolute;
|
||||||
|
background: ${props => props.color};
|
||||||
|
top: -5px;
|
||||||
|
right: 0px;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Img = styled.img`
|
const Img = styled.img`
|
||||||
width: ${props => (props.model === 'T' ? '17px' : '13px')};
|
width: ${props => (props.model === 'T' ? '17px' : '13px')};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const TrezorImage = ({ model }) => (
|
const TrezorImage = ({ model, status }) => (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
|
{status && <Dot color={getStatusColor(status)} />}
|
||||||
<Img
|
<Img
|
||||||
model={model}
|
model={model}
|
||||||
src={model === 'T' ? './images/trezor-T.png' : './images/trezor-1.png'}
|
src={model === 'T' ? './images/trezor-T.png' : './images/trezor-1.png'}
|
||||||
@ -21,6 +36,7 @@ const TrezorImage = ({ model }) => (
|
|||||||
|
|
||||||
TrezorImage.propTypes = {
|
TrezorImage.propTypes = {
|
||||||
model: PropTypes.string,
|
model: PropTypes.string,
|
||||||
|
status: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TrezorImage;
|
export default TrezorImage;
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
import colors from 'js/config/colors';
|
import colors from 'js/config/colors';
|
||||||
|
|
||||||
const getStatus = (device) => {
|
const getDeviceSelectStatus = (device) => {
|
||||||
let deviceStatus = '';
|
let status = 'connected';
|
||||||
if (device.type === 'unacquired' || (device.features && device.status === 'occupied')) {
|
if (!device.connected) {
|
||||||
deviceStatus = 'used-in-other-window';
|
status = 'disconnected';
|
||||||
} else if (device.type === 'unreadable') {
|
|
||||||
deviceStatus = 'connected';
|
|
||||||
} else if (!device.connected) {
|
|
||||||
deviceStatus = 'disconnected';
|
|
||||||
} else if (!device.available) {
|
} else if (!device.available) {
|
||||||
deviceStatus = 'unavailable';
|
status = 'unavailable';
|
||||||
|
} else if (device.type === 'acquired') {
|
||||||
|
if (device.status === 'occupied') {
|
||||||
|
status = 'used-in-other-window';
|
||||||
|
}
|
||||||
|
} else if (device.type === 'unacquired') {
|
||||||
|
status = 'unacquired';
|
||||||
}
|
}
|
||||||
|
|
||||||
return deviceStatus;
|
return status;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusName = (device) => {
|
const getStatusName = (deviceStatus) => {
|
||||||
const deviceStatus = getStatus(device);
|
|
||||||
const unknownStatusName = 'Status unknown';
|
const unknownStatusName = 'Status unknown';
|
||||||
let statusName;
|
let statusName;
|
||||||
switch (deviceStatus) {
|
switch (deviceStatus) {
|
||||||
@ -41,7 +42,7 @@ const getStatusName = (device) => {
|
|||||||
|
|
||||||
const isWebUSB = transport => !!((transport && transport.version.indexOf('webusb') >= 0));
|
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 isDisabled = (selectedDevice, devices, transport) => (devices.length < 1 && !isWebUSB(transport)) || (devices.length === 1 && !selectedDevice.features && !isWebUSB(transport));
|
||||||
|
|
||||||
const getVersion = (device) => {
|
const getVersion = (device) => {
|
||||||
let version = null;
|
let version = null;
|
||||||
@ -53,8 +54,7 @@ const getVersion = (device) => {
|
|||||||
return version;
|
return version;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = (device) => {
|
const getStatusColor = (deviceStatus) => {
|
||||||
const deviceStatus = getStatus(device);
|
|
||||||
let color = null;
|
let color = null;
|
||||||
|
|
||||||
switch (deviceStatus) {
|
switch (deviceStatus) {
|
||||||
@ -74,10 +74,13 @@ const getStatusColor = (device) => {
|
|||||||
color = colors.ERROR_PRIMARY;
|
color = colors.ERROR_PRIMARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('color', color);
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
getDeviceSelectStatus,
|
||||||
isDisabled,
|
isDisabled,
|
||||||
getStatusName,
|
getStatusName,
|
||||||
getVersion,
|
getVersion,
|
||||||
|
@ -4,7 +4,7 @@ import styled from 'styled-components';
|
|||||||
import TrezorConnect from 'trezor-connect';
|
import TrezorConnect from 'trezor-connect';
|
||||||
import type { TrezorDevice } from 'flowtype';
|
import type { TrezorDevice } from 'flowtype';
|
||||||
import DeviceHeader from 'components/DeviceHeader';
|
import DeviceHeader from 'components/DeviceHeader';
|
||||||
import { getStatus, getVersion } from 'utils/device';
|
import { getDeviceSelectStatus, getVersion } from 'utils/device';
|
||||||
|
|
||||||
// import DeviceList from './components/DeviceList';
|
// import DeviceList from './components/DeviceList';
|
||||||
import type { Props } from '../common';
|
import type { Props } from '../common';
|
||||||
@ -63,7 +63,7 @@ export const DeviceSelect = (props: Props) => {
|
|||||||
<DeviceHeader
|
<DeviceHeader
|
||||||
handleOpen={handleOpen}
|
handleOpen={handleOpen}
|
||||||
label={selected.instanceLabel}
|
label={selected.instanceLabel}
|
||||||
status={getStatus(selected)}
|
status={getDeviceSelectStatus(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