Ensure proper transport type is set before attempting to connect ledger wallet (#12594)

* Ensure proper transport type is set before attempting to connect ledger wallet

* Fix unit tests
feature/default_network_editable
Dan J Miller 3 years ago committed by ryanml
parent ac0f70b858
commit e740f7a436
  1. 10
      app/scripts/metamask-controller.js
  2. 4
      ui/store/actions.js
  3. 4
      ui/store/actions.test.js

@ -849,6 +849,10 @@ export default class MetamaskController extends EventEmitter {
this.attemptLedgerTransportCreation,
this,
),
establishLedgerTransportPreference: nodeify(
this.establishLedgerTransportPreference,
this,
),
// mobile
fetchInfoToSync: nodeify(this.fetchInfoToSync, this),
@ -1252,6 +1256,7 @@ export default class MetamaskController extends EventEmitter {
this.preferencesController.setAddresses(addresses);
this.selectFirstIdentity();
}
return vault;
} finally {
releaseLock();
@ -1565,6 +1570,11 @@ export default class MetamaskController extends EventEmitter {
return await keyring.attemptMakeApp();
}
async establishLedgerTransportPreference() {
const transportPreference = this.preferencesController.getLedgerTransportPreference();
return await this.setLedgerTransportPreference(transportPreference);
}
/**
* Fetch account list from a trezor device.
*

@ -409,6 +409,10 @@ export function connectHardware(deviceName, page, hdPath, t) {
let accounts;
try {
const { ledgerTransportType } = getState().metamask;
if (deviceName === 'ledger') {
await promisifiedBackground.establishLedgerTransportPreference();
}
if (
deviceName === 'ledger' &&
ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID

@ -548,6 +548,8 @@ describe('Actions', () => {
(_, __, ___, cb) => cb(),
);
background.establishLedgerTransportPreference.callsFake((cb) => cb());
actions._setBackgroundConnection(background);
await store.dispatch(
@ -563,6 +565,8 @@ describe('Actions', () => {
cb(new Error('error')),
);
background.establishLedgerTransportPreference.callsFake((cb) => cb());
actions._setBackgroundConnection(background);
const expectedActions = [

Loading…
Cancel
Save