Skip to content

Commit

Permalink
Merge branch 'develop' into 19692-reduce-gas-limit-fallback-from-95-t…
Browse files Browse the repository at this point in the history
…o-35-of-the-block-gas-limit-to-improve-how-we-handle-failed-gas-limit-estimations
  • Loading branch information
OGPoyraz authored Oct 21, 2024
2 parents a930a84 + 29e1c5b commit db2473b
Show file tree
Hide file tree
Showing 48 changed files with 1,094 additions and 242 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ jobs:
command: ./development/shellcheck.sh

test-lint-lockfile:
executor: node-browsers-medium
executor: node-browsers-medium-plus
steps:
- run: *shallow-git-clone-and-enable-vnc
- run: sudo corepack enable
Expand Down
5 changes: 4 additions & 1 deletion app/scripts/lib/offscreen-bridge/trezor-offscreen-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
export class TrezorOffscreenBridge implements TrezorBridge {
model: string | undefined;

minorVersion: number | undefined;

init(
settings: {
manifest: Manifest;
Expand All @@ -40,7 +42,8 @@ export class TrezorOffscreenBridge implements TrezorBridge {
msg.target === OffscreenCommunicationTarget.extension &&
msg.event === OffscreenCommunicationEvents.trezorDeviceConnect
) {
this.model = msg.payload;
this.model = msg.payload.model;
this.minorVersion = msg.payload.minorVersion;
}
});

Expand Down
31 changes: 29 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import {
NotificationServicesPushController,
NotificationServicesController,
} from '@metamask/notification-services-controller';
import { isProduction } from '../../shared/modules/environment';
import { methodsRequiringNetworkSwitch } from '../../shared/constants/methods-tags';

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
Expand Down Expand Up @@ -386,6 +387,9 @@ export const METAMASK_CONTROLLER_EVENTS = {
// stream channels
const PHISHING_SAFELIST = 'metamask-phishing-safelist';

// OneKey devices can connect to Metamask using Trezor USB transport. They use a specific device minor version (99) to differentiate between genuine Trezor and OneKey devices.
export const ONE_KEY_VIA_TREZOR_MINOR_VERSION = 99;

export default class MetamaskController extends EventEmitter {
/**
* @param {object} opts
Expand Down Expand Up @@ -1561,7 +1565,7 @@ export default class MetamaskController extends EventEmitter {
},
},
env: {
isAccountSyncingEnabled: isManifestV3,
isAccountSyncingEnabled: !isProduction() && isManifestV3,
},
messenger: this.controllerMessenger.getRestricted({
name: 'UserStorageController',
Expand Down Expand Up @@ -3399,6 +3403,7 @@ export default class MetamaskController extends EventEmitter {
connectHardware: this.connectHardware.bind(this),
forgetDevice: this.forgetDevice.bind(this),
checkHardwareStatus: this.checkHardwareStatus.bind(this),
getDeviceNameForMetric: this.getDeviceNameForMetric.bind(this),
unlockHardwareWalletAccount: this.unlockHardwareWalletAccount.bind(this),
attemptLedgerTransportCreation:
this.attemptLedgerTransportCreation.bind(this),
Expand Down Expand Up @@ -4683,6 +4688,26 @@ export default class MetamaskController extends EventEmitter {
return keyring.isUnlocked();
}

/**
* Get hardware device name for metric logging.
*
* @param deviceName - HardwareDeviceNames
* @param hdPath - string
* @returns {Promise<string>}
*/
async getDeviceNameForMetric(deviceName, hdPath) {
if (deviceName === HardwareDeviceNames.trezor) {
const keyring = await this.getKeyringForDevice(deviceName, hdPath);
const { minorVersion } = keyring.bridge;
// Specific case for OneKey devices, see `ONE_KEY_VIA_TREZOR_MINOR_VERSION` for further details.
if (minorVersion && minorVersion === ONE_KEY_VIA_TREZOR_MINOR_VERSION) {
return HardwareDeviceNames.oneKeyViaTrezor;
}
}

return deviceName;
}

/**
* Clear
*
Expand Down Expand Up @@ -4755,9 +4780,11 @@ export default class MetamaskController extends EventEmitter {
/**
* get hardware account label
*
* @param name
* @param index
* @param hdPathDescription
* @returns string label
*/

getAccountLabel(name, index, hdPathDescription) {
return `${name[0].toUpperCase()}${name.slice(1)} ${
parseInt(index, 10) + 1
Expand Down
71 changes: 70 additions & 1 deletion app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import {
} from './lib/accounts/BalancesController';
import { BalancesTracker as MultichainBalancesTracker } from './lib/accounts/BalancesTracker';
import { deferredPromise } from './lib/util';
import MetaMaskController from './metamask-controller';
import MetaMaskController, {
ONE_KEY_VIA_TREZOR_MINOR_VERSION,
} from './metamask-controller';

const { Ganache } = require('../../test/e2e/seeder/ganache');

Expand Down Expand Up @@ -894,6 +896,73 @@ describe('MetaMaskController', () => {
);
});

describe('getHardwareDeviceName', () => {
const hdPath = "m/44'/60'/0'/0/0";

it('should return the correct device name for Ledger', async () => {
const deviceName = 'ledger';

const result = await metamaskController.getDeviceNameForMetric(
deviceName,
hdPath,
);
expect(result).toBe('ledger');
});

it('should return the correct device name for Lattice', async () => {
const deviceName = 'lattice';

const result = await metamaskController.getDeviceNameForMetric(
deviceName,
hdPath,
);
expect(result).toBe('lattice');
});

it('should return the correct device name for Trezor', async () => {
const deviceName = 'trezor';
jest
.spyOn(metamaskController, 'getKeyringForDevice')
.mockResolvedValue({
bridge: {
minorVersion: 1,
model: 'T',
},
});
const result = await metamaskController.getDeviceNameForMetric(
deviceName,
hdPath,
);
expect(result).toBe('trezor');
});

it('should return undefined for unknown device name', async () => {
const deviceName = 'unknown';
const result = await metamaskController.getDeviceNameForMetric(
deviceName,
hdPath,
);
expect(result).toBe(deviceName);
});

it('should handle special case for OneKeyDevice via Trezor', async () => {
const deviceName = 'trezor';
jest
.spyOn(metamaskController, 'getKeyringForDevice')
.mockResolvedValue({
bridge: {
model: 'T',
minorVersion: ONE_KEY_VIA_TREZOR_MINOR_VERSION,
},
});
const result = await metamaskController.getDeviceNameForMetric(
deviceName,
hdPath,
);
expect(result).toBe('OneKey via Trezor');
});
});

describe('forgetDevice', () => {
it('should throw if it receives an unknown device name', async () => {
const result = metamaskController.forgetDevice(
Expand Down
Loading

0 comments on commit db2473b

Please sign in to comment.