mirror of
https://github.com/trezor/trezor-wallet
synced 2025-07-24 07:28:35 +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:
parent
4307978069
commit
250141236b
@ -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;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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<Props> {
|
||||
if (selected.features) {
|
||||
const deviceMenuItems: Array<DeviceMenuItem> = [];
|
||||
|
||||
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<Props> {
|
||||
|
||||
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) {
|
||||
|
@ -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<TrezorDevice>): 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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user