1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-07-25 16:08:37 +00:00

Update TrezorDevice's isUsedElsewhere & unacquired properties

- both properties are now deprecated
- following properties are now used instead (matching trezor-connect):
 - `type` with possible values `acquired` | `unacquired` | `unreadable`
 - `status` with possible values `available` | `occupied` | `used`
This commit is contained in:
Vasek Mlejnsky 2018-08-02 11:44:52 +02:00
parent 4307978069
commit 250141236b
5 changed files with 18 additions and 15 deletions

View File

@ -53,11 +53,13 @@ export type TrezorDevice = {
instanceLabel: string; instanceLabel: string;
instanceName: ?string; instanceName: ?string;
features?: Features; features?: Features;
unacquired?: boolean; // unacquired?: boolean; // device.type === 'unacquired' && device.type !== 'unreadable'
isUsedElsewhere?: boolean; // isUsedElsewhere?: boolean; // device.status === 'occupied'
type: 'acquired' | 'unacquired' | 'unreadable';
status: 'available' | 'occupied' | 'used';
featuresNeedsReload?: boolean; featuresNeedsReload?: boolean;
ts: number; ts: number;
} };
export type RouterLocationState = LocationState; export type RouterLocationState = LocationState;

View File

@ -169,7 +169,7 @@ export const postInit = (): ThunkAction => (dispatch: Dispatch, getState: GetSta
} else { } else {
if (devices.length > 0) { if (devices.length > 0) {
const unacquired: ?TrezorDevice = devices.find(d => d.unacquired); const unacquired: ?TrezorDevice = devices.find(d => d.type === 'unacquired');
if (unacquired) { if (unacquired) {
dispatch( onSelectDevice(unacquired) ); dispatch( onSelectDevice(unacquired) );
} else { } else {
@ -260,7 +260,7 @@ export const switchToFirstAvailableDevice = (): AsyncAction => async (dispatch:
// 1. First Unacquired // 1. First Unacquired
// 2. First connected // 2. First connected
// 3. Saved with latest timestamp // 3. Saved with latest timestamp
const unacquired = devices.find(d => d.unacquired); const unacquired = devices.find(d => d.type === 'unacquired');
if (unacquired) { if (unacquired) {
dispatch(initConnectedDevice(unacquired)); dispatch(initConnectedDevice(unacquired));
} else { } else {

View File

@ -26,11 +26,11 @@ export const DeviceSelect = (props: Props) => {
css += ' unavailable'; css += ' unavailable';
deviceStatus = 'Unavailable'; deviceStatus = 'Unavailable';
} else { } else {
if (selected.unacquired) { if (selected.type === 'unacquired') {
css += ' unacquired'; css += ' unacquired';
deviceStatus = 'Used in other window'; deviceStatus = 'Used in other window';
} }
if (selected.isUsedElsewhere) { if (selected.status === 'occupied') {
css += ' used-elsewhere'; css += ' used-elsewhere';
deviceStatus = 'Used in other window'; deviceStatus = 'Used in other window';
} else if (selected.featuresNeedsReload) { } else if (selected.featuresNeedsReload) {
@ -147,7 +147,7 @@ export class DeviceDropdown extends Component<Props> {
if (selected.features) { if (selected.features) {
const deviceMenuItems: Array<DeviceMenuItem> = []; const deviceMenuItems: Array<DeviceMenuItem> = [];
if (selected.isUsedElsewhere) { if (selected.status === 'occupied') {
deviceMenuItems.push({ type: 'reload', label: 'Renew session' }); deviceMenuItems.push({ type: 'reload', label: 'Renew session' });
} else if (selected.featuresNeedsReload) { } else if (selected.featuresNeedsReload) {
deviceMenuItems.push({ type: 'reload', label: 'Renew session' }); deviceMenuItems.push({ type: 'reload', label: 'Renew session' });
@ -177,7 +177,7 @@ export class DeviceDropdown extends Component<Props> {
let deviceStatus: string = 'Connected'; let deviceStatus: string = 'Connected';
let css: string = 'device item'; let css: string = 'device item';
if (dev.unacquired || dev.isUsedElsewhere) { if (dev.type === 'unacquired' || dev.status === 'occupied') {
deviceStatus = 'Used in other window'; deviceStatus = 'Used in other window';
css += ' unacquired'; css += ' unacquired';
} else if (!dev.connected) { } else if (!dev.connected) {

View File

@ -44,8 +44,8 @@ const mergeDevices = (current: TrezorDevice, upcoming: Device | TrezorDevice): T
}; };
// corner-case: trying to merge unacquired device with acquired // corner-case: trying to merge unacquired device with acquired
// make sure that sensitive fields will not be changed and device will remain acquired // make sure that sensitive fields will not be changed and device will remain acquired
if (upcoming.unacquired && current.state) { if (upcoming.type === 'unacquired' && current.state) {
dev.unacquired = false; dev.type = 'unacquired';
dev.features = current.features; dev.features = current.features;
dev.label = current.label; dev.label = current.label;
} }
@ -184,7 +184,8 @@ const devicesFromStorage = (devices: Array<TrezorDevice>): State => devices.map(
path: '', path: '',
acquiring: false, acquiring: false,
featuresNeedsReload: false, featuresNeedsReload: false,
isUsedElsewhere: false, //isUsedElsewhere: false,
status: 'available',
})); }));
// Remove all device reference from State // Remove all device reference from State
@ -204,11 +205,11 @@ const disconnectDevice = (state: State, device: Device): State => {
const otherDevices: State = state.filter(d => affectedDevices.indexOf(d) === -1); const otherDevices: State = state.filter(d => affectedDevices.indexOf(d) === -1);
if (affectedDevices.length > 0) { if (affectedDevices.length > 0) {
const acquiredDevices = affectedDevices.filter(d => !d.unacquired && d.state); const acquiredDevices = affectedDevices.filter(d => d.type !== 'unacquired' && d.type !== 'unreadable' && d.state);
return otherDevices.concat(acquiredDevices.map((d) => { return otherDevices.concat(acquiredDevices.map((d) => {
d.connected = false; d.connected = false;
d.available = false; d.available = false;
d.isUsedElsewhere = false; d.status = 'used';
d.featuresNeedsReload = false; d.featuresNeedsReload = false;
d.path = ''; d.path = '';
return d; return d;

View File

@ -30,7 +30,7 @@ export const getSelectedDevice = (state: State): ?TrezorDevice => {
const instance: ?number = locationState.deviceInstance ? parseInt(locationState.deviceInstance) : undefined; const instance: ?number = locationState.deviceInstance ? parseInt(locationState.deviceInstance) : undefined;
return state.devices.find((d) => { return state.devices.find((d) => {
if (d.unacquired && d.path === locationState.device) { if (d.type === 'unacquired' && d.path === locationState.device) {
return true; return true;
} if (d.features && d.features.bootloader_mode && d.path === locationState.device) { } if (d.features && d.features.bootloader_mode && d.path === locationState.device) {
return true; return true;