Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure network request to ledger bridge is not made during onboarding #24890

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
Loading