Skip to content

Commit

Permalink
wip: #13550
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Feb 10, 2025
1 parent b686a3e commit 32c8a3c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
53 changes: 27 additions & 26 deletions packages/transport/src/api/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
13 changes: 12 additions & 1 deletion suite-common/wallet-core/src/discovery/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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');

Check failure on line 472 in suite-common/wallet-core/src/discovery/discoveryThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
await dispatch(initMetadata(false));
console.log('discovery: initMetadata done');

Check failure on line 474 in suite-common/wallet-core/src/discovery/discoveryThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
}

device = selectDevice(getState());
if (device?.status !== 'available') {
console.log('device is not available anymore');

Check failure on line 479 in suite-common/wallet-core/src/discovery/discoveryThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
return;

Check failure on line 480 in suite-common/wallet-core/src/discovery/discoveryThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Expected blank line before this statement
}
dispatch(
startDiscovery({
...discovery,
Expand Down Expand Up @@ -566,6 +573,7 @@ export const startDiscoveryThunk = createThunk(
};

TrezorConnect.on<AccountInfo | null>(UI.BUNDLE_PROGRESS, onBundleProgress);
console.log('startDiscoveryThunk: TrezorConnect.getAccountInfo');

Check failure on line 576 in suite-common/wallet-core/src/discovery/discoveryThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
const result = await TrezorConnect.getAccountInfo({
device,
bundle,
Expand Down Expand Up @@ -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');

Check failure on line 610 in suite-common/wallet-core/src/discovery/discoveryThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
await dispatch(initMetadata(false));
}
if (currentDiscovery.status === DiscoveryStatus.RUNNING) {
Expand Down Expand Up @@ -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 &&
Expand Down

0 comments on commit 32c8a3c

Please sign in to comment.