diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 3711866477b4..e86ce2a5fa77 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3970,11 +3970,16 @@ export default class MetamaskController extends EventEmitter { await this.keyringController.addNewAccount(count)); } + const { completedOnboarding } = + this.onboardingController.store.getState(); + // This must be set as soon as possible to communicate to the // keyring's iframe and have the setting initialized properly // Optimistically called to not block MetaMask login due to // Ledger Keyring GitHub downtime - this.setLedgerTransportPreference(); + if (completedOnboarding) { + this.setLedgerTransportPreference(); + } return vault; } finally { @@ -4043,6 +4048,7 @@ export default class MetamaskController extends EventEmitter { * @param {string} password - The user's password */ async submitPassword(password) { + const { completedOnboarding } = this.onboardingController.store.getState(); await this.keyringController.submitPassword(password); ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) @@ -4061,7 +4067,9 @@ export default class MetamaskController extends EventEmitter { // keyring's iframe and have the setting initialized properly // Optimistically called to not block MetaMask login due to // Ledger Keyring GitHub downtime - this.setLedgerTransportPreference(); + if (completedOnboarding) { + this.setLedgerTransportPreference(); + } } async _loginUser(password) { @@ -4221,6 +4229,10 @@ export default class MetamaskController extends EventEmitter { async connectHardware(deviceName, page, hdPath) { const keyring = await this.getKeyringForDevice(deviceName, hdPath); + if (deviceName === HardwareDeviceNames.ledger) { + await this.setLedgerTransportPreference(keyring); + } + let accounts = []; switch (page) { case -1: @@ -5879,14 +5891,16 @@ export default class MetamaskController extends EventEmitter { /** * Sets the Ledger Live preference to use for Ledger hardware wallet support * + * @param _keyring * @deprecated This method is deprecated and will be removed in the future. * Only webhid connections are supported in chrome and u2f in firefox. */ - async setLedgerTransportPreference() { + async setLedgerTransportPreference(_keyring) { const transportType = window.navigator.hid ? LedgerTransportTypes.webhid : LedgerTransportTypes.u2f; - const keyring = await this.getKeyringForDevice(HardwareDeviceNames.ledger); + const keyring = + _keyring || (await this.getKeyringForDevice(HardwareDeviceNames.ledger)); if (keyring?.updateTransportMethod) { return keyring.updateTransportMethod(transportType).catch((e) => { throw e;