Skip to content

Commit

Permalink
Merge branch 'develop' into cryptodev2s/bump-user-operatin-controller…
Browse files Browse the repository at this point in the history
…-19.0.0
  • Loading branch information
cryptodev-2s authored Nov 28, 2024
2 parents c9178ad + a902677 commit dccd430
Show file tree
Hide file tree
Showing 67 changed files with 1,916 additions and 2,008 deletions.
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [12.7.2]
### Fixed
- Fix message signatures for Gridplus lattice hardware wallets ([#28694](https://github.com/MetaMask/metamask-extension/pull/28694))

## [12.7.1]
### Fixed
- Fix bug that could prevent security warnings from being shown on token transfer confirmations in some cases ([#28487](https://github.com/MetaMask/metamask-extension/pull/28487))
- Fix balance display, so that it correctly shows ETH and fiat values, when the "Show balane and token price checker" toggle is off ([#28569](https://github.com/MetaMask/metamask-extension/pull/28569))

## [12.7.0]
### Added
- Added Token Network Filter UI, allowing users to filter tokens by network (behind a feature flag) ([#27884](https://github.com/MetaMask/metamask-extension/pull/27884))
Expand Down Expand Up @@ -42,6 +51,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved handling of network switching and adding networks to prevent issues with queued transactions ([#28090](https://github.com/MetaMask/metamask-extension/pull/28090))
- Prevented redirect after adding a network in Onboarding Settings ([#28165](https://github.com/MetaMask/metamask-extension/pull/28165))

## [12.6.2]
### Fixed
- Prevent QR code scanning from setting incorrect recipient addresses during the send flow by restricting the QR scanner feature to only handle simple sends, and fail on QR codes that encode more complex transaction types ([#28521](https://github.com/MetaMask/metamask-extension/pull/28521))

## [12.6.1]
### Fixed
- Fixed gas limit estimation on Base and BNB chains ([#28327](https://github.com/MetaMask/metamask-extension/pull/28327))
Expand Down Expand Up @@ -5343,8 +5356,11 @@ Update styles and spacing on the critical error page ([#20350](https://github.c
- Added the ability to restore accounts from seed words.


[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.7.0...HEAD
[12.7.0]: https://github.com/MetaMask/metamask-extension/compare/v12.6.1...v12.7.0
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.7.2...HEAD
[12.7.2]: https://github.com/MetaMask/metamask-extension/compare/v12.7.1...v12.7.2
[12.7.1]: https://github.com/MetaMask/metamask-extension/compare/v12.7.0...v12.7.1
[12.7.0]: https://github.com/MetaMask/metamask-extension/compare/v12.6.2...v12.7.0
[12.6.2]: https://github.com/MetaMask/metamask-extension/compare/v12.6.1...v12.6.2
[12.6.1]: https://github.com/MetaMask/metamask-extension/compare/v12.6.0...v12.6.1
[12.6.0]: https://github.com/MetaMask/metamask-extension/compare/v12.5.1...v12.6.0
[12.5.1]: https://github.com/MetaMask/metamask-extension/compare/v12.5.0...v12.5.1
Expand Down
7 changes: 5 additions & 2 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,27 @@ function maybeDetectPhishing(theController) {

// Determine the block reason based on the type
let blockReason;
let blockedUrl = hostname;
if (phishingTestResponse?.result && blockedRequestResponse.result) {
blockReason = `${phishingTestResponse.type} and ${blockedRequestResponse.type}`;
} else if (phishingTestResponse?.result) {
blockReason = phishingTestResponse.type;
} else {
blockReason = blockedRequestResponse.type;
blockedUrl = details.initiator;
}

theController.metaMetricsController.trackEvent({
// should we differentiate between background redirection and content script redirection?
event: MetaMetricsEventName.PhishingPageDisplayed,
category: MetaMetricsEventCategory.Phishing,
properties: {
url: hostname,
url: blockedUrl,
referrer: {
url: hostname,
url: blockedUrl,
},
reason: blockReason,
requestDomain: blockedRequestResponse.result ? hostname : undefined,
},
});
const querystring = new URLSearchParams({ hostname, href });
Expand Down
197 changes: 125 additions & 72 deletions app/scripts/controllers/app-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import AppMetadataController from './app-metadata';

const EXPECTED_DEFAULT_STATE = {
currentAppVersion: '',
previousAppVersion: '',
previousMigrationVersion: 0,
currentMigrationVersion: 0,
};
import { ControllerMessenger } from '@metamask/base-controller';
import AppMetadataController, {
getDefaultAppMetadataControllerState,
type AppMetadataControllerOptions,
} from './app-metadata';

describe('AppMetadataController', () => {
describe('constructor', () => {
Expand All @@ -16,86 +13,142 @@ describe('AppMetadataController', () => {
previousMigrationVersion: 1,
currentMigrationVersion: 1,
};
const appMetadataController = new AppMetadataController({
state: initState,
currentMigrationVersion: 1,
currentAppVersion: '1',
});
expect(appMetadataController.store.getState()).toStrictEqual(initState);
withController(
{
state: initState,
currentMigrationVersion: 1,
currentAppVersion: '1',
},
({ controller }) => {
expect(controller.state).toStrictEqual(initState);
},
);
});

it('sets default state and does not modify it', async () => {
const appMetadataController = new AppMetadataController({
state: {},
it('sets default state and does not modify it', () => {
withController({ state: {} }, ({ controller }) => {
expect(controller.state).toStrictEqual(
getDefaultAppMetadataControllerState(),
);
});
expect(appMetadataController.store.getState()).toStrictEqual(
EXPECTED_DEFAULT_STATE,
);
});

it('sets default state and does not modify it if options version parameters match respective default values', async () => {
const appMetadataController = new AppMetadataController({
state: {},
currentMigrationVersion: 0,
currentAppVersion: '',
});
expect(appMetadataController.store.getState()).toStrictEqual(
EXPECTED_DEFAULT_STATE,
it('sets default state and does not modify it if options version parameters match respective default values', () => {
withController(
{
state: {},
currentMigrationVersion: 0,
currentAppVersion: '',
},
({ controller }) => {
expect(controller.state).toStrictEqual(
getDefaultAppMetadataControllerState(),
);
},
);
});

it('updates the currentAppVersion state property if options.currentAppVersion does not match the default value', async () => {
const appMetadataController = new AppMetadataController({
state: {},
currentMigrationVersion: 0,
currentAppVersion: '1',
});
expect(appMetadataController.store.getState()).toStrictEqual({
...EXPECTED_DEFAULT_STATE,
currentAppVersion: '1',
});
it('updates the currentAppVersion state property if options.currentAppVersion does not match the default value', () => {
withController(
{
state: {},
currentMigrationVersion: 0,
currentAppVersion: '1',
},
({ controller }) => {
expect(controller.state).toStrictEqual({
...getDefaultAppMetadataControllerState(),
currentAppVersion: '1',
});
},
);
});

it('updates the currentAppVersion and previousAppVersion state properties if options.currentAppVersion, currentAppVersion and previousAppVersion are all different', async () => {
const appMetadataController = new AppMetadataController({
state: {
currentAppVersion: '2',
previousAppVersion: '1',
it('updates the currentAppVersion and previousAppVersion state properties if options.currentAppVersion, currentAppVersion and previousAppVersion are all different', () => {
withController(
{
state: {
currentAppVersion: '2',
previousAppVersion: '1',
},
currentAppVersion: '3',
currentMigrationVersion: 0,
},
currentAppVersion: '3',
currentMigrationVersion: 0,
});
expect(appMetadataController.store.getState()).toStrictEqual({
...EXPECTED_DEFAULT_STATE,
currentAppVersion: '3',
previousAppVersion: '2',
});
({ controller }) => {
expect(controller.state).toStrictEqual({
...getDefaultAppMetadataControllerState(),
currentAppVersion: '3',
previousAppVersion: '2',
});
},
);
});

it('updates the currentMigrationVersion state property if the currentMigrationVersion param does not match the default value', async () => {
const appMetadataController = new AppMetadataController({
state: {},
currentMigrationVersion: 1,
});
expect(appMetadataController.store.getState()).toStrictEqual({
...EXPECTED_DEFAULT_STATE,
currentMigrationVersion: 1,
});
it('updates the currentMigrationVersion state property if the currentMigrationVersion param does not match the default value', () => {
withController(
{
state: {},
currentMigrationVersion: 1,
},
({ controller }) => {
expect(controller.state).toStrictEqual({
...getDefaultAppMetadataControllerState(),
currentMigrationVersion: 1,
});
},
);
});

it('updates the currentMigrationVersion and previousMigrationVersion state properties if the currentMigrationVersion param, the currentMigrationVersion state property and the previousMigrationVersion state property are all different', async () => {
const appMetadataController = new AppMetadataController({
state: {
currentMigrationVersion: 2,
previousMigrationVersion: 1,
it('updates the currentMigrationVersion and previousMigrationVersion state properties if the currentMigrationVersion param, the currentMigrationVersion state property and the previousMigrationVersion state property are all different', () => {
withController(
{
state: {
currentMigrationVersion: 2,
previousMigrationVersion: 1,
},
currentMigrationVersion: 3,
},
currentMigrationVersion: 3,
});
expect(appMetadataController.store.getState()).toStrictEqual({
...EXPECTED_DEFAULT_STATE,
currentMigrationVersion: 3,
previousMigrationVersion: 2,
});
({ controller }) => {
expect(controller.state).toStrictEqual({
...getDefaultAppMetadataControllerState(),
currentMigrationVersion: 3,
previousMigrationVersion: 2,
});
},
);
});
});
});

type WithControllerOptions = Partial<AppMetadataControllerOptions>;

type WithControllerCallback<ReturnValue> = ({
controller,
}: {
controller: AppMetadataController;
}) => ReturnValue;

type WithControllerArgs<ReturnValue> =
| [WithControllerCallback<ReturnValue>]
| [WithControllerOptions, WithControllerCallback<ReturnValue>];

function withController<ReturnValue>(
...args: WithControllerArgs<ReturnValue>
): ReturnValue {
const [options = {}, fn] = args.length === 2 ? args : [{}, args[0]];

const controllerMessenger = new ControllerMessenger<never, never>();

const messenger = controllerMessenger.getRestricted({
name: 'AppMetadataController',
allowedActions: [],
allowedEvents: [],
});

return fn({
controller: new AppMetadataController({
messenger,
...options,
}),
});
}
Loading

0 comments on commit dccd430

Please sign in to comment.