Skip to content

Commit d0895c7

Browse files
marekrjpolakmroz22
authored andcommitted
fix(connect): correctly return used status for device
1 parent 22cb397 commit d0895c7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/connect/src/device/Device.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
147147
return this._features;
148148
}
149149

150-
private _featuresNeedsReload = false;
150+
private wasUsedElsewhere = false;
151151

152152
// variables used in one workflow: acquire -> transportSession -> commands -> run -> keepTransportSession -> release
153153
private acquirePromise?: ReturnType<Transport['acquire']>;
@@ -272,6 +272,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
272272
.then(result => this.waitAndCompareSession(result, sessionPromise))
273273
.then(result => {
274274
if (result.success) {
275+
this.wasUsedElsewhere = false;
275276
this.sessionAcquired = result.payload;
276277
this.currentSession = new DeviceCurrentSession(
277278
this,
@@ -446,6 +447,8 @@ export class Device extends TypedEmitter<DeviceEvents> {
446447
}
447448

448449
private usedElsewhere() {
450+
this.wasUsedElsewhere = true;
451+
449452
// only makes sense to continue when device held by this instance
450453
if (!this.sessionAcquired) {
451454
return;
@@ -457,8 +460,6 @@ export class Device extends TypedEmitter<DeviceEvents> {
457460
this.transport.releaseDevice(this.sessionAcquired);
458461
this.sessionAcquired = null;
459462

460-
this._featuresNeedsReload = true;
461-
462463
_log.debug('interruptionFromOutside');
463464

464465
this.runAbort?.abort(ERRORS.TypedError('Device_UsedElsewhere'));
@@ -944,7 +945,6 @@ export class Device extends TypedEmitter<DeviceEvents> {
944945
}
945946

946947
this._features = feat;
947-
this._featuresNeedsReload = false;
948948

949949
// Vendor headers have been changed in 2.6.3.
950950
if (feat.fw_vendor === 'Trezor Bitcoin-only') {
@@ -1137,8 +1137,9 @@ export class Device extends TypedEmitter<DeviceEvents> {
11371137
const defaultLabel = 'My Trezor';
11381138
const label =
11391139
this.features.label === '' || !this.features.label ? defaultLabel : this.features.label;
1140-
let status: DeviceStatus = this.isUsedElsewhere() ? 'occupied' : 'available';
1141-
if (this._featuresNeedsReload) status = 'used';
1140+
const status: DeviceStatus = this.isUsedElsewhere()
1141+
? 'occupied'
1142+
: (this.wasUsedElsewhere && 'used') || 'available';
11421143

11431144
return {
11441145
...base,

0 commit comments

Comments
 (0)