From 32c8a3c7ec8b8ea6911c35a237391dfc869f64fc Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Wed, 5 Feb 2025 22:09:36 +0100 Subject: [PATCH] wip: https://github.com/trezor/trezor-suite/issues/13550 --- packages/transport/src/api/usb.ts | 53 ++++++++++--------- .../src/discovery/discoveryThunks.ts | 13 ++++- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/packages/transport/src/api/usb.ts b/packages/transport/src/api/usb.ts index 43e7183bf84..bcc31697e07 100644 --- a/packages/transport/src/api/usb.ts +++ b/packages/transport/src/api/usb.ts @@ -308,33 +308,34 @@ export class UsbApi extends AbstractApi { }); } - if (first) { - try { - this.logger?.debug(`usb: device.selectConfiguration ${CONFIGURATION_ID}`); - await this.abortableMethod(() => device.selectConfiguration(CONFIGURATION_ID), { - signal, - }); - this.logger?.debug(`usb: device.selectConfiguration done: ${CONFIGURATION_ID}.`); - } catch (err) { - this.logger?.error( - `usb: device.selectConfiguration error ${err}. device: ${this.formatDeviceForLog(device)}`, - ); - } - try { - // reset fails on ChromeOS and windows - this.logger?.debug('usb: device.reset'); - await this.abortableMethod( - () => this.synchronizeDeviceReset(() => device?.reset()), - { signal }, - ); - this.logger?.debug(`usb: device.reset done.`); - } catch (err) { - this.logger?.error( - `usb: device.reset error ${err}. device: ${this.formatDeviceForLog(device)}`, - ); - // empty - } + // commenting out first fixes https://github.com/trezor/trezor-suite/issues/13550#issuecomment-2637659335 + // if (first) { + try { + this.logger?.debug(`usb: device.selectConfiguration ${CONFIGURATION_ID}`); + await this.abortableMethod(() => device.selectConfiguration(CONFIGURATION_ID), { + signal, + }); + this.logger?.debug(`usb: device.selectConfiguration done: ${CONFIGURATION_ID}.`); + } catch (err) { + this.logger?.error( + `usb: device.selectConfiguration error ${err}. device: ${this.formatDeviceForLog(device)}`, + ); + } + try { + // reset fails on ChromeOS and windows + this.logger?.debug('usb: device.reset'); + await this.abortableMethod(() => this.synchronizeDeviceReset(() => device?.reset()), { + signal, + }); + this.logger?.debug(`usb: device.reset done.`); + } catch (err) { + this.logger?.error( + `usb: device.reset error ${err}. device: ${this.formatDeviceForLog(device)}`, + ); + // empty } + // } + try { const interfaceId = this.debugLink ? DEBUGLINK_INTERFACE_ID : INTERFACE_ID; this.logger?.debug(`usb: device.claimInterface: ${interfaceId}`); diff --git a/suite-common/wallet-core/src/discovery/discoveryThunks.ts b/suite-common/wallet-core/src/discovery/discoveryThunks.ts index 623da079c85..9df70a63487 100644 --- a/suite-common/wallet-core/src/discovery/discoveryThunks.ts +++ b/suite-common/wallet-core/src/discovery/discoveryThunks.ts @@ -421,7 +421,7 @@ export const startDiscoveryThunk = createThunk( thunks: { initMetadata, fetchAndSaveMetadata }, actions: { requestAuthConfirm }, } = extra; - const device = selectDevice(getState()); + let device = selectDevice(getState()); const metadata = selectMetadata(getState()); const discovery = selectDeviceDiscovery(getState()); @@ -469,9 +469,16 @@ export const startDiscoveryThunk = createThunk( // metadata are enabled in settings but metadata master key does not exist for this device // try to generate device metadata master key if passphrase is not used if (!authConfirm && metadataEnabled) { + console.log('discovery: initMetadata'); await dispatch(initMetadata(false)); + console.log('discovery: initMetadata done'); } + device = selectDevice(getState()); + if (device?.status !== 'available') { + console.log('device is not available anymore'); + return; + } dispatch( startDiscovery({ ...discovery, @@ -566,6 +573,7 @@ export const startDiscoveryThunk = createThunk( }; TrezorConnect.on(UI.BUNDLE_PROGRESS, onBundleProgress); + console.log('startDiscoveryThunk: TrezorConnect.getAccountInfo'); const result = await TrezorConnect.getAccountInfo({ device, bundle, @@ -598,6 +606,8 @@ export const startDiscoveryThunk = createThunk( }), ); // try to generate device metadata master key + // todo: why is it here again? + console.log('init metadata 2'); await dispatch(initMetadata(false)); } if (currentDiscovery.status === DiscoveryStatus.RUNNING) { @@ -661,6 +671,7 @@ export const startDiscoveryThunk = createThunk( } } + // todo: isn't it better to reload device from state and check its properties such as status and connected instead of error codes? if ( result.payload.error && device.connected &&