From e740f7a43685109d0d8f0c359ae768ceff10b926 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 5 Nov 2021 13:43:29 -0230 Subject: [PATCH] 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 --- app/scripts/metamask-controller.js | 10 ++++++++++ ui/store/actions.js | 4 ++++ ui/store/actions.test.js | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 40832c0bc..106317bdd 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.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. * diff --git a/ui/store/actions.js b/ui/store/actions.js index aeca70147..546b2733a 100644 --- a/ui/store/actions.js +++ b/ui/store/actions.js @@ -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 diff --git a/ui/store/actions.test.js b/ui/store/actions.test.js index 7e803c284..90f524895 100644 --- a/ui/store/actions.test.js +++ b/ui/store/actions.test.js @@ -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 = [