diff --git a/src/flowtype/index.js b/src/flowtype/index.js index a66b4135..7de58c39 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -53,11 +53,13 @@ export type TrezorDevice = { instanceLabel: string; instanceName: ?string; features?: Features; - unacquired?: boolean; - isUsedElsewhere?: boolean; + // unacquired?: boolean; // device.type === 'unacquired' && device.type !== 'unreadable' + // isUsedElsewhere?: boolean; // device.status === 'occupied' + type: 'acquired' | 'unacquired' | 'unreadable'; + status: 'available' | 'occupied' | 'used'; featuresNeedsReload?: boolean; ts: number; -} +}; export type RouterLocationState = LocationState; diff --git a/src/js/actions/TrezorConnectActions.js b/src/js/actions/TrezorConnectActions.js index 28c35b8d..eb7c64b6 100644 --- a/src/js/actions/TrezorConnectActions.js +++ b/src/js/actions/TrezorConnectActions.js @@ -169,7 +169,7 @@ export const postInit = (): ThunkAction => (dispatch: Dispatch, getState: GetSta } else { if (devices.length > 0) { - const unacquired: ?TrezorDevice = devices.find(d => d.unacquired); + const unacquired: ?TrezorDevice = devices.find(d => d.type === 'unacquired'); if (unacquired) { dispatch( onSelectDevice(unacquired) ); } else { @@ -260,7 +260,7 @@ export const switchToFirstAvailableDevice = (): AsyncAction => async (dispatch: // 1. First Unacquired // 2. First connected // 3. Saved with latest timestamp - const unacquired = devices.find(d => d.unacquired); + const unacquired = devices.find(d => d.type === 'unacquired'); if (unacquired) { dispatch(initConnectedDevice(unacquired)); } else { diff --git a/src/js/components/wallet/aside/DeviceSelection.js b/src/js/components/wallet/aside/DeviceSelection.js index 443e37dc..eeae1b90 100644 --- a/src/js/components/wallet/aside/DeviceSelection.js +++ b/src/js/components/wallet/aside/DeviceSelection.js @@ -26,11 +26,11 @@ export const DeviceSelect = (props: Props) => { css += ' unavailable'; deviceStatus = 'Unavailable'; } else { - if (selected.unacquired) { + if (selected.type === 'unacquired') { css += ' unacquired'; deviceStatus = 'Used in other window'; } - if (selected.isUsedElsewhere) { + if (selected.status === 'occupied') { css += ' used-elsewhere'; deviceStatus = 'Used in other window'; } else if (selected.featuresNeedsReload) { @@ -147,7 +147,7 @@ export class DeviceDropdown extends Component { if (selected.features) { const deviceMenuItems: Array = []; - if (selected.isUsedElsewhere) { + if (selected.status === 'occupied') { deviceMenuItems.push({ type: 'reload', label: 'Renew session' }); } else if (selected.featuresNeedsReload) { deviceMenuItems.push({ type: 'reload', label: 'Renew session' }); @@ -177,7 +177,7 @@ export class DeviceDropdown extends Component { let deviceStatus: string = 'Connected'; let css: string = 'device item'; - if (dev.unacquired || dev.isUsedElsewhere) { + if (dev.type === 'unacquired' || dev.status === 'occupied') { deviceStatus = 'Used in other window'; css += ' unacquired'; } else if (!dev.connected) { diff --git a/src/js/reducers/DevicesReducer.js b/src/js/reducers/DevicesReducer.js index a3d0f672..d96ffc67 100644 --- a/src/js/reducers/DevicesReducer.js +++ b/src/js/reducers/DevicesReducer.js @@ -44,8 +44,8 @@ const mergeDevices = (current: TrezorDevice, upcoming: Device | TrezorDevice): T }; // corner-case: trying to merge unacquired device with acquired // make sure that sensitive fields will not be changed and device will remain acquired - if (upcoming.unacquired && current.state) { - dev.unacquired = false; + if (upcoming.type === 'unacquired' && current.state) { + dev.type = 'unacquired'; dev.features = current.features; dev.label = current.label; } @@ -184,7 +184,8 @@ const devicesFromStorage = (devices: Array): State => devices.map( path: '', acquiring: false, featuresNeedsReload: false, - isUsedElsewhere: false, + //isUsedElsewhere: false, + status: 'available', })); // 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); 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) => { d.connected = false; d.available = false; - d.isUsedElsewhere = false; + d.status = 'used'; d.featuresNeedsReload = false; d.path = ''; return d; diff --git a/src/js/reducers/utils/index.js b/src/js/reducers/utils/index.js index 26fb3761..11b5020d 100644 --- a/src/js/reducers/utils/index.js +++ b/src/js/reducers/utils/index.js @@ -30,7 +30,7 @@ export const getSelectedDevice = (state: State): ?TrezorDevice => { const instance: ?number = locationState.deviceInstance ? parseInt(locationState.deviceInstance) : undefined; return state.devices.find((d) => { - if (d.unacquired && d.path === locationState.device) { + if (d.type === 'unacquired' && d.path === locationState.device) { return true; } if (d.features && d.features.bootloader_mode && d.path === locationState.device) { return true;