Skip to content

Commit

Permalink
Merge pull request #3278 from Emurgo/fix/YOEXT-756/trezor-no-device-e…
Browse files Browse the repository at this point in the history
…vent

Handle TrezorConnect not firing device event
  • Loading branch information
vsubhuman authored Sep 7, 2023
2 parents 37dbb2e + 0af09df commit acdd2b2
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions packages/yoroi-extension/app/stores/ada/TrezorConnectStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ export default class TrezorConnectStore
this._onTrezorUIEvent,
);

if (this.trezorEventDevice == null) {
throw new Error(`${nameof(this._checkAndStoreHWDeviceInfo)} no ${nameof(this.trezorEventDevice)}`);
}
const trezorEventDevice = this.trezorEventDevice;

/** Converts a valid hardware wallet response to a common storable format
Expand Down Expand Up @@ -231,29 +228,25 @@ export default class TrezorConnectStore

const { trezorResp, trezorEventDevice } = resp;

/** This check already done in _validateHWResponse but flow needs this */
const device = trezorEventDevice.payload;
const { features } = device;
if (features == null) {
throw new Error('Trezor device hardware info not valid');
}
const device = trezorEventDevice?.payload;
const features = device?.features;

return {
publicMasterKey: trezorResp.payload.publicKey,
hwFeatures: {
Vendor: features.vendor ?? Config.wallets.hardwareWallet.trezorT.VENDOR,
Model: features.model,
DeviceId: features.device_id || '',
Vendor: features?.vendor ?? Config.wallets.hardwareWallet.trezorT.VENDOR,
Model: features?.model ?? Config.wallets.hardwareWallet.trezorT.MODEL,
DeviceId: features?.device_id || '',
},
defaultName: device.label || '',
defaultName: device?.label || '',
};
}

/** Validates the compatibility of data which we have received from Trezor device */
_validateHWResponse: TrezorConnectionResponse => boolean = (
resp,
) => {
const { trezorResp, trezorEventDevice } = resp;
const { trezorResp } = resp;

if (trezorResp && !trezorResp.success) {
switch (trezorResp.payload.error) {
Expand All @@ -276,13 +269,6 @@ export default class TrezorConnectStore
throw new Error('Invalid public key received from Trezor device');
}

if (trezorEventDevice == null
|| trezorEventDevice.payload == null
|| trezorEventDevice.payload.type !== 'acquired'
|| trezorEventDevice.payload.features == null) {
throw new Error('Invalid trezor device event');
}

return true;
};

Expand Down

0 comments on commit acdd2b2

Please sign in to comment.