Skip to content

Commit

Permalink
Merge pull request #27733 from MetaMask/Version-v12.4.1
Browse files Browse the repository at this point in the history
Version v12.4.1 RC
  • Loading branch information
danjm authored Oct 10, 2024
2 parents 73ad771 + ac46289 commit ccb9706
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [12.4.1]
### Fixed
- Fix crash on swaps review page ([#27708](https://github.com/MetaMask/metamask-extension/pull/27708))
- Fix bug that could prevent the phishing detection feature from having the most up to date info on which web pages to block ([#27743](https://github.com/MetaMask/metamask-extension/pull/27743))

## [12.4.0]
### Added
- Added a receive button to the home screen, allowing users to easily get their address or QR-code for receiving cryptocurrency ([#26148](https://github.com/MetaMask/metamask-extension/pull/26148))
Expand Down Expand Up @@ -5139,7 +5144,8 @@ 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.4.0...HEAD
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.4.1...HEAD
[12.4.1]: https://github.com/MetaMask/metamask-extension/compare/v12.4.0...v12.4.1
[12.4.0]: https://github.com/MetaMask/metamask-extension/compare/v12.3.1...v12.4.0
[12.3.1]: https://github.com/MetaMask/metamask-extension/compare/v12.3.0...v12.3.1
[12.3.0]: https://github.com/MetaMask/metamask-extension/compare/v12.2.4...v12.3.0
Expand Down
142 changes: 142 additions & 0 deletions app/scripts/migrations/126.1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { migrate, version } from './126.1';

const oldVersion = 126.1;

const mockPhishingListMetaMask = {
allowlist: [],
blocklist: ['malicious1.com'],
c2DomainBlocklist: ['malicious2.com'],
fuzzylist: [],
tolerance: 0,
version: 1,
lastUpdated: Date.now(),
name: 'MetaMask',
};

const mockPhishingListPhishfort = {
allowlist: [],
blocklist: ['phishfort1.com'],
c2DomainBlocklist: ['phishfort2.com'],
fuzzylist: [],
tolerance: 0,
version: 1,
lastUpdated: Date.now(),
name: 'Phishfort',
};

describe(`migration #${version}`, () => {
it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {},
};

const newStorage = await migrate(oldStorage);

expect(newStorage.meta).toStrictEqual({ version });
});

it('keeps only the MetaMask phishing list in PhishingControllerState', async () => {
const oldState = {
PhishingController: {
phishingLists: [mockPhishingListMetaMask, mockPhishingListPhishfort],
whitelist: [],
hotlistLastFetched: 0,
stalelistLastFetched: 0,
c2DomainBlocklistLastFetched: 0,
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
});

const updatedPhishingController = transformedState.data
.PhishingController as Record<string, unknown>;

expect(updatedPhishingController.phishingLists).toStrictEqual([
mockPhishingListMetaMask,
]);
});

it('removes all phishing lists if MetaMask is not present', async () => {
const oldState = {
PhishingController: {
phishingLists: [mockPhishingListPhishfort],
whitelist: [],
hotlistLastFetched: 0,
stalelistLastFetched: 0,
c2DomainBlocklistLastFetched: 0,
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
});

const updatedPhishingController = transformedState.data
.PhishingController as Record<string, unknown>;

expect(updatedPhishingController.phishingLists).toStrictEqual([]);
});

it('does nothing if PhishingControllerState is empty', async () => {
const oldState = {
PhishingController: {
phishingLists: [],
whitelist: [],
hotlistLastFetched: 0,
stalelistLastFetched: 0,
c2DomainBlocklistLastFetched: 0,
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
});

const updatedPhishingController = transformedState.data
.PhishingController as Record<string, unknown>;

expect(updatedPhishingController.phishingLists).toStrictEqual([]);
});

it('does nothing if PhishingController is not in the state', async () => {
const oldState = {
NetworkController: {
providerConfig: {
chainId: '0x1',
},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
});

expect(transformedState.data).toStrictEqual(oldState);
});

it('does nothing if phishingLists is not an array (null)', async () => {
const oldState: Record<string, unknown> = {
PhishingController: {
phishingLists: null,
whitelist: [],
hotlistLastFetched: 0,
stalelistLastFetched: 0,
c2DomainBlocklistLastFetched: 0,
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: oldState,
});

expect(transformedState.data).toStrictEqual(oldState);
});
});
54 changes: 54 additions & 0 deletions app/scripts/migrations/126.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { hasProperty, isObject } from '@metamask/utils';
import { cloneDeep } from 'lodash';

type VersionedData = {
meta: { version: number };
data: Record<string, unknown>;
};

export const version = 126.1;

/**
* This migration removes `providerConfig` from the network controller state.
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
* @param originalVersionedData.meta - State metadata.
* @param originalVersionedData.meta.version - The current state version.
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
* @returns Updated versioned MetaMask extension state.
*/
export async function migrate(
originalVersionedData: VersionedData,
): Promise<VersionedData> {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
transformState(versionedData.data);
return versionedData;
}

function transformState(
state: Record<string, unknown>,
): Record<string, unknown> {
if (
hasProperty(state, 'PhishingController') &&
isObject(state.PhishingController) &&
hasProperty(state.PhishingController, 'phishingLists')
) {
const phishingController = state.PhishingController;

if (!Array.isArray(phishingController.phishingLists)) {
console.error(
`Migration ${version}: Invalid PhishingController.phishingLists state`,
);
return state;
}

phishingController.phishingLists = phishingController.phishingLists.filter(
(list) => list.name === 'MetaMask',
);

state.PhishingController = phishingController;
}

return state;
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const migrations = [
require('./125'),
require('./125.1'),
require('./126'),
require('./126.1'),
];

export default migrations;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamask-crx",
"version": "12.4.0",
"version": "12.4.1",
"private": true,
"repository": {
"type": "git",
Expand Down
4 changes: 3 additions & 1 deletion ui/pages/swaps/prepare-swap-page/prepare-swap-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
getTransactionSettingsOpened,
setTransactionSettingsOpened,
getLatestAddedTokenTo,
getUsedQuote,
} from '../../../ducks/swaps/swaps';
import {
getSwapsDefaultToken,
Expand Down Expand Up @@ -190,9 +191,10 @@ export default function PrepareSwapPage({
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual);
const tokenList = useSelector(getTokenList, isEqual);
const quotes = useSelector(getQuotes, isEqual);
const usedQuote = useSelector(getUsedQuote, isEqual);
const latestAddedTokenTo = useSelector(getLatestAddedTokenTo, isEqual);
const numberOfQuotes = Object.keys(quotes).length;
const areQuotesPresent = numberOfQuotes > 0;
const areQuotesPresent = numberOfQuotes > 0 && usedQuote;
const swapsErrorKey = useSelector(getSwapsErrorKey);
const aggregatorMetadata = useSelector(getAggregatorMetadata, shallowEqual);
const transactionSettingsOpened = useSelector(
Expand Down

0 comments on commit ccb9706

Please sign in to comment.