1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-05 22:58:12 +00:00
trezor-wallet/src/js/utils/device.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

import colors from 'js/config/colors';
2018-08-21 15:56:30 +00:00
const getDeviceSelectStatus = (device) => {
let status = 'connected';
if (!device.connected) {
status = 'disconnected';
} else if (!device.available) {
2018-08-21 15:56:30 +00:00
status = 'unavailable';
} else if (device.type === 'acquired') {
if (device.status === 'occupied') {
status = 'used-in-other-window';
}
} else if (device.type === 'unacquired') {
status = 'unacquired';
}
2018-08-21 15:56:30 +00:00
return status;
};
2018-08-21 15:56:30 +00:00
const getStatusName = (deviceStatus) => {
const unknownStatusName = 'Status unknown';
let statusName;
switch (deviceStatus) {
case 'used-in-other-window':
statusName = 'Used in other window';
break;
case 'connected':
statusName = 'Connected';
break;
case 'disconnected':
statusName = 'Disconnected';
break;
case 'unavailable':
statusName = 'Unavailable';
break;
default:
statusName = unknownStatusName;
}
return statusName;
};
const isWebUSB = transport => !!((transport && transport.version.indexOf('webusb') >= 0));
2018-08-21 15:56:30 +00:00
const isDisabled = (selectedDevice, devices, transport) => (devices.length < 1 && !isWebUSB(transport)) || (devices.length === 1 && !selectedDevice.features && !isWebUSB(transport));
const getVersion = (device) => {
let version = null;
if (device.features && device.features.major_version > 1) {
version = 'T';
} else {
version = '1';
}
return version;
};
2018-08-21 15:56:30 +00:00
const getStatusColor = (deviceStatus) => {
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;
}
2018-08-21 15:56:30 +00:00
console.log('color', color);
return color;
};
export {
2018-08-21 15:56:30 +00:00
getDeviceSelectStatus,
isDisabled,
getStatusName,
getVersion,
getStatusColor,
};