Skip to content

Commit

Permalink
Merge pull request #26842 from MetaMask/v12.2.0-sync-v12.1.1
Browse files Browse the repository at this point in the history
v12.2.0 sync v12.1.1
  • Loading branch information
Gudahtt authored Sep 3, 2024
2 parents 7a5acb3 + fa444cf commit 8fa9cc0
Show file tree
Hide file tree
Showing 59 changed files with 3,989 additions and 1,477 deletions.
33 changes: 33 additions & 0 deletions .yarn/patches/@trezor-connect-web-npm-9.3.0-040ab10d9a.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/lib/impl/core-in-iframe.js b/lib/impl/core-in-iframe.js
index c47cf3bff860d6b1855341c00b80fc6c40f9d6d5..275eb0f312ff396819fa406c154a3562842db49d 100644
--- a/lib/impl/core-in-iframe.js
+++ b/lib/impl/core-in-iframe.js
@@ -116,7 +116,9 @@ class CoreInIframe {
this._log.enabled = !!this._settings.debug;
window.addEventListener('message', this.boundHandleMessage);
window.addEventListener('unload', this.boundDispose);
- await iframe.init(this._settings);
+ const modifiedSettings = Object.assign({}, this.settings);
+ modifiedSettings.env = 'webextension';
+ await iframe.init(modifiedSettings);
if (this._settings.sharedLogger !== false) {
iframe.initIframeLogger();
}
diff --git a/lib/popup/index.js b/lib/popup/index.js
index 9b13c370a5ac8b4e4fc0315ed40cdf615d0bb0cb..4dbd97fc28df49beb73379451974ec48a8a42ea7 100644
--- a/lib/popup/index.js
+++ b/lib/popup/index.js
@@ -229,10 +229,12 @@ class PopupManager extends events_1.default {
}
else if (message.type === events_2.POPUP.LOADED) {
this.handleMessage(message);
+ const modifiedSettings = Object.assign({}, this.settings);
+ modifiedSettings.env = 'webextension';
this.channel.postMessage({
type: events_2.POPUP.INIT,
payload: {
- settings: this.settings,
+ settings: modifiedSettings,
useCore: true,
},
});
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [12.2.0]

## [12.1.1]
### Changed
- Update Polygon from MATIC to POL ([#26671](https://github.com/MetaMask/metamask-extension/pull/26671))

### Fixed
- Fix signature confirmation UI crash ([#26143](https://github.com/MetaMask/metamask-extension/pull/26143))
- Update current selected account when selected account is removed ([#26573](https://github.com/MetaMask/metamask-extension/pull/26573), [#26742](https://github.com/MetaMask/metamask-extension/pull/26742), [#26773](https://github.com/MetaMask/metamask-extension/pull/26773))
- This also includes a migration to reset the selected account if it's currently invalid
- Prevent pending confirmations from being inaccessible after attempting to add currently selected chain ([#26726](https://github.com/MetaMask/metamask-extension/pull/26726))

## [12.1.0]
### Added
- Launched a feature displaying the percentage increase or decrease for tokens within the UI ([#24223](https://github.com/MetaMask/metamask-extension/pull/24223))
Expand Down Expand Up @@ -4999,7 +5009,8 @@ Update styles and spacing on the critical error page ([#20350](https://github.c


[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.2.0...HEAD
[12.2.0]: https://github.com/MetaMask/metamask-extension/compare/v12.1.0...v12.2.0
[12.2.0]: https://github.com/MetaMask/metamask-extension/compare/v12.1.1...v12.2.0
[12.1.1]: https://github.com/MetaMask/metamask-extension/compare/v12.1.0...v12.1.1
[12.1.0]: https://github.com/MetaMask/metamask-extension/compare/v12.0.6...v12.1.0
[12.0.6]: https://github.com/MetaMask/metamask-extension/compare/v12.0.5...v12.0.6
[12.0.5]: https://github.com/MetaMask/metamask-extension/compare/v12.0.4...v12.0.5
Expand Down
Binary file removed app/images/matic-token.png
Binary file not shown.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const CHAIN_SYMBOLS = {
[NOTIFICATION_CHAINS.ETHEREUM]: 'ETH',
[NOTIFICATION_CHAINS.OPTIMISM]: 'ETH',
[NOTIFICATION_CHAINS.BSC]: 'BNB',
[NOTIFICATION_CHAINS.POLYGON]: 'MATIC',
[NOTIFICATION_CHAINS.POLYGON]: 'POL',
[NOTIFICATION_CHAINS.ARBITRUM]: 'ETH',
[NOTIFICATION_CHAINS.AVALANCHE]: 'AVAX',
[NOTIFICATION_CHAINS.LINEA]: 'ETH',
Expand Down
25 changes: 14 additions & 11 deletions app/scripts/lib/accounts/BalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ export class BalancesController extends BaseController<
* @param accountId - The account ID.
*/
#getAccount(accountId: string): InternalAccount {
const account: InternalAccount = this.#listMultichainAccounts().find(
(multichainAccount) => multichainAccount.id === accountId,
);
const account: InternalAccount | undefined =
this.#listMultichainAccounts().find(
(multichainAccount) => multichainAccount.id === accountId,
);

if (!account) {
throw new Error(`Unknown account: ${accountId}`);
Expand All @@ -247,13 +248,15 @@ export class BalancesController extends BaseController<
const account = this.#getAccount(accountId);
const partialState: BalancesControllerState = { balances: {} };

partialState.balances[account.id] = await this.#getBalances(
account.id,
account.metadata.snap.id,
isBtcMainnetAddress(account.address)
? BTC_MAINNET_ASSETS
: BTC_TESTNET_ASSETS,
);
if (account.metadata.snap) {
partialState.balances[account.id] = await this.#getBalances(
account.id,
account.metadata.snap.id,
isBtcMainnetAddress(account.address)
? BTC_MAINNET_ASSETS
: BTC_TESTNET_ASSETS,
);
}

this.update((state: Draft<BalancesControllerState>) => ({
...state,
Expand Down Expand Up @@ -292,7 +295,7 @@ export class BalancesController extends BaseController<
return (
!isEvmAccountType(account.type) &&
// Non-EVM accounts are backed by a Snap for now
account.metadata.snap
account.metadata.snap !== undefined
);
}

Expand Down
27 changes: 17 additions & 10 deletions app/scripts/lib/createDupeReqFilterStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import OurReadableStream from 'readable-stream';
import ReadableStream2 from 'readable-stream-2';
import ReadableStream3 from 'readable-stream-3';

import type { JsonRpcRequest } from '@metamask/utils';
import type { JsonRpcNotification, JsonRpcRequest } from '@metamask/utils';
import createDupeReqFilterStream, {
THREE_MINUTES,
} from './createDupeReqFilterStream';
Expand All @@ -26,7 +26,7 @@ function createTestStream(output: JsonRpcRequest[] = [], S = Transform) {
}

function runStreamTest(
requests: JsonRpcRequest[] = [],
requests: (JsonRpcRequest | JsonRpcNotification)[] = [],
advanceTimersTime = 10,
S = Transform,
) {
Expand Down Expand Up @@ -54,12 +54,12 @@ describe('createDupeReqFilterStream', () => {
const requests = [
{ id: 1, method: 'foo' },
{ id: 2, method: 'bar' },
];
].map((request) => ({ ...request, jsonrpc: '2.0' as const }));

const expectedOutput = [
{ id: 1, method: 'foo' },
{ id: 2, method: 'bar' },
];
].map((output) => ({ ...output, jsonrpc: '2.0' }));

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
Expand All @@ -69,18 +69,25 @@ describe('createDupeReqFilterStream', () => {
const requests = [
{ id: 1, method: 'foo' },
{ id: 1, method: 'foo' }, // duplicate
];
].map((request) => ({ ...request, jsonrpc: '2.0' as const }));

const expectedOutput = [{ id: 1, method: 'foo' }];
const expectedOutput = [{ id: 1, method: 'foo' }].map((output) => ({
...output,
jsonrpc: '2.0',
}));

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
});

it("lets through requests if they don't have an id", async () => {
const requests = [{ method: 'notify1' }, { method: 'notify2' }];
const requests = [{ method: 'notify1' }, { method: 'notify2' }].map(
(request) => ({ ...request, jsonrpc: '2.0' as const }),
);

const expectedOutput = [{ method: 'notify1' }, { method: 'notify2' }];
const expectedOutput = [{ method: 'notify1' }, { method: 'notify2' }].map(
(output) => ({ ...output, jsonrpc: '2.0' }),
);

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
Expand All @@ -95,15 +102,15 @@ describe('createDupeReqFilterStream', () => {
{ method: 'notify2' },
{ id: 2, method: 'bar' },
{ id: 3, method: 'baz' },
];
].map((request) => ({ ...request, jsonrpc: '2.0' as const }));

const expectedOutput = [
{ id: 1, method: 'foo' },
{ method: 'notify1' },
{ id: 2, method: 'bar' },
{ method: 'notify2' },
{ id: 3, method: 'baz' },
];
].map((output) => ({ ...output, jsonrpc: '2.0' }));

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/lib/createDupeReqFilterStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const THREE_MINUTES = MINUTE * 3;
* @returns The expiry set.
*/
const makeExpirySet = () => {
const map: Map<string | number, number> = new Map();
const map: Map<string | number | null, number> = new Map();

setInterval(() => {
const cutoffTime = Date.now() - THREE_MINUTES;
Expand All @@ -32,7 +32,7 @@ const makeExpirySet = () => {
* @param value - The value to add.
* @returns `true` if the value was added, and `false` if it already existed.
*/
add(value: string | number) {
add(value: string | number | null) {
if (!map.has(value)) {
map.set(value, Date.now());
return true;
Expand Down
47 changes: 24 additions & 23 deletions app/scripts/lib/ppom/ppom-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
type Hex,
JsonRpcRequestStruct,
JsonRpcResponseStruct,
} from '@metamask/utils';
import { type Hex, JsonRpcResponseStruct } from '@metamask/utils';
import * as ControllerUtils from '@metamask/controller-utils';

import { CHAIN_IDS } from '../../../../shared/constants/network';

import {
BlockaidReason,
BlockaidResultType,
} from '../../../../shared/constants/security-provider';
import { flushPromises } from '../../../../test/lib/timer-helpers';
import { createPPOMMiddleware } from './ppom-middleware';
import { createPPOMMiddleware, PPOMMiddlewareRequest } from './ppom-middleware';
import {
generateSecurityAlertId,
handlePPOMError,
Expand All @@ -30,6 +25,12 @@ const SECURITY_ALERT_RESPONSE_MOCK: SecurityAlertResponse = {
reason: BlockaidReason.permitFarming,
};

const REQUEST_MOCK = {
params: [],
id: '',
jsonrpc: '2.0' as const,
};

const createMiddleware = (
options: {
chainId?: Hex;
Expand Down Expand Up @@ -107,14 +108,14 @@ describe('PPOMMiddleware', () => {
});

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand All @@ -131,20 +132,20 @@ describe('PPOMMiddleware', () => {
it('adds loading response to confirmation requests while validation is in progress', async () => {
const middlewareFunction = createMiddleware();

const req = {
...JsonRpcRequestStruct,
const req: PPOMMiddlewareRequest<(string | { to: string })[]> = {
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

expect(req.securityAlertResponse.reason).toBe(BlockaidReason.inProgress);
expect(req.securityAlertResponse.result_type).toBe(
expect(req.securityAlertResponse?.reason).toBe(BlockaidReason.inProgress);
expect(req.securityAlertResponse?.result_type).toBe(
BlockaidResultType.Loading,
);
});
Expand All @@ -155,7 +156,7 @@ describe('PPOMMiddleware', () => {
});

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};
Expand All @@ -172,14 +173,14 @@ describe('PPOMMiddleware', () => {
});

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand All @@ -191,14 +192,14 @@ describe('PPOMMiddleware', () => {
const middlewareFunction = createMiddleware();

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_someRequest',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand Down Expand Up @@ -256,8 +257,8 @@ describe('PPOMMiddleware', () => {
const nextMock = jest.fn();

await middlewareFunction(
{ ...JsonRpcRequestStruct, method: 'eth_sendTransaction' },
{ ...JsonRpcResponseStruct },
{ ...REQUEST_MOCK, method: 'eth_sendTransaction' },
{ ...JsonRpcResponseStruct.TYPE },
nextMock,
);

Expand All @@ -273,12 +274,12 @@ describe('PPOMMiddleware', () => {
const middlewareFunction = createMiddleware({ error });

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(req, { ...JsonRpcResponseStruct }, nextMock);
await middlewareFunction(req, { ...JsonRpcResponseStruct.TYPE }, nextMock);

expect(req.securityAlertResponse).toStrictEqual(
SECURITY_ALERT_RESPONSE_MOCK,
Expand Down
10 changes: 8 additions & 2 deletions app/scripts/lib/ppom/ppom-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const CONFIRMATION_METHODS = Object.freeze([
...SIGNING_METHODS,
]);

export type PPOMMiddlewareRequest<
Params extends JsonRpcParams = JsonRpcParams,
> = Required<JsonRpcRequest<Params>> & {
securityAlertResponse?: SecurityAlertResponse | undefined;
};

/**
* Middleware function that handles JSON RPC requests.
* This function will be called for every JSON RPC request.
Expand All @@ -45,7 +51,7 @@ const CONFIRMATION_METHODS = Object.freeze([
* @returns PPOMMiddleware function.
*/
export function createPPOMMiddleware<
Params extends JsonRpcParams,
Params extends (string | { to: string })[],
Result extends Json,
>(
ppomController: PPOMController,
Expand All @@ -59,7 +65,7 @@ export function createPPOMMiddleware<
) => void,
) {
return async (
req: JsonRpcRequest<Params>,
req: PPOMMiddlewareRequest<Params>,
_res: JsonRpcResponse<Result>,
next: () => void,
) => {
Expand Down
Loading

0 comments on commit 8fa9cc0

Please sign in to comment.