Skip to content

Commit

Permalink
Merge branch 'develop' into rekmarks/reorder-permission-middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed May 28, 2024
2 parents 91dc4ea + 70b2258 commit 8f971bf
Show file tree
Hide file tree
Showing 333 changed files with 12,749 additions and 3,930 deletions.
45 changes: 45 additions & 0 deletions .yarn/patches/nock-npm-13.5.4-2c4f77b249.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
diff --git a/lib/common.js b/lib/common.js
index 336bc4d376d07306d6adf79b8e73cffd4dfff4f7..271d50d42a5a370440fd93de00072ddfdd2fcf4b 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -1,7 +1,17 @@
'use strict'

const debug = require('debug')('nock.common')
-const timers = require('timers')
+/**
+ * PATCH NOTES:
+ *
+ * Replace Node.js `timers` module with global timers, because Jest/Sinon fake timers do not work
+ * with the Node.js timers module in the version we are using.
+ *
+ * This is resolved in `@sinon/fake-timers@11`, which is introduced in the upcoming `jest@30`
+ * release.
+ *
+ * TODO: Remove this patch after updating to `jest@30`.
+ */
const url = require('url')
const util = require('util')

@@ -598,16 +608,16 @@ const intervals = []
const immediates = []

const wrapTimer =
- (timer, ids) =>
+ (timerName, ids) =>
(...args) => {
- const id = timer(...args)
+ const id = globalThis[timerName](...args)
ids.push(id)
return id
}

-const setTimeout = wrapTimer(timers.setTimeout, timeouts)
-const setInterval = wrapTimer(timers.setInterval, intervals)
-const setImmediate = wrapTimer(timers.setImmediate, immediates)
+const setTimeout = wrapTimer('setTimeout', timeouts)
+const setInterval = wrapTimer('setInterval', intervals)
+const setImmediate = wrapTimer('setImmediate', immediates)

function clearTimer(clear, ids) {
while (ids.length) {
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ If you are using VS Code and are unable to make commits from the source control

To start a development build (e.g. with logging and file watching) run `yarn start`.

Alternatively, one can skip wallet onboarding and preload the vault state with a specific SRP by adding `TEST_SRP='<insert SRP here>'` and `PASSWORD='<insert wallet password here>'` to the `.metamaskrc` file and running `yarn start:skip-onboarding`.


#### React and Redux DevTools

To start the [React DevTools](https://github.com/facebook/react-devtools), run `yarn devtools:react` with a development build installed in a browser. This will open in a separate window; no browser extension is required.
Expand Down
55 changes: 47 additions & 8 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions app/images/product-announcement-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { checkForLastErrorAndLog } from '../../shared/modules/browser-runtime.utils';
import { isManifestV3 } from '../../shared/modules/mv3.utils';
import { maskObject } from '../../shared/modules/object.utils';
import { FIXTURE_STATE_METADATA_VERSION } from '../../test/e2e/default-fixture';
import migrations from './migrations';
import Migrator from './lib/migrator';
import ExtensionPlatform from './platforms/extension';
Expand All @@ -66,6 +67,7 @@ import {
getPlatform,
shouldEmitDappViewedEvent,
} from './lib/util';
import { generateSkipOnboardingState } from './skip-onboarding';

/* eslint-enable import/first */

Expand All @@ -86,7 +88,7 @@ global.stateHooks.getMostRecentPersistedState = () =>
localStore.mostRecentRetrievedState;

const { sentry } = global;
const firstTimeState = { ...rawFirstTimeState };
let firstTimeState = { ...rawFirstTimeState };

const metamaskInternalProcessHash = {
[ENVIRONMENT_TYPE_POPUP]: true,
Expand Down Expand Up @@ -279,6 +281,7 @@ function saveTimestamp() {
async function initialize() {
try {
const initData = await loadStateFromPersistence();

const initState = initData.data;
const initLangCode = await getFirstPreferredLangCode();

Expand Down Expand Up @@ -404,9 +407,19 @@ async function loadPhishingWarningPage() {
*/
export async function loadStateFromPersistence() {
// migrations
const migrator = new Migrator({ migrations });
const migrator = new Migrator({
migrations,
defaultVersion: process.env.SKIP_ONBOARDING
? FIXTURE_STATE_METADATA_VERSION
: null,
});
migrator.on('error', console.warn);

if (process.env.SKIP_ONBOARDING) {
const skipOnboardingStateOverrides = await generateSkipOnboardingState();
firstTimeState = { ...firstTimeState, ...skipOnboardingStateOverrides };
}

// read from disk
// first from preferred, async API:
versionedData =
Expand Down
16 changes: 8 additions & 8 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WindowPostMessageStream } from '@metamask/post-message-stream';
import PortStream from 'extension-port-stream';
import ObjectMultiplex from 'obj-multiplex';
import ObjectMultiplex from '@metamask/object-multiplex';
import pump from 'pump';
import { obj as createThoughStream } from 'through2';
import browser from 'webextension-polyfill';
Expand Down Expand Up @@ -94,8 +94,8 @@ const setupPhishingExtStreams = () => {
{
target: PHISHING_WARNING_PAGE, // the post-message-stream "target"
data: {
// this object gets passed to obj-multiplex
name: PHISHING_SAFELIST, // the obj-multiplex channel name
// this object gets passed to @metamask/object-multiplex
name: PHISHING_SAFELIST, // the @metamask/object-multiplex channel name
data: {
jsonrpc: '2.0',
method: 'METAMASK_STREAM_FAILURE',
Expand Down Expand Up @@ -456,8 +456,8 @@ function extensionStreamMessageListener(msg) {
{
target: INPAGE, // the post-message-stream "target"
data: {
// this object gets passed to obj-multiplex
name: PROVIDER, // the obj-multiplex channel name
// this object gets passed to @metamask/object-multiplex
name: PROVIDER, // the @metamask/object-multiplex channel name
data: {
jsonrpc: '2.0',
method: 'METAMASK_EXTENSION_CONNECT_CAN_RETRY',
Expand All @@ -472,15 +472,15 @@ function extensionStreamMessageListener(msg) {
/**
* This function must ONLY be called in pump destruction/close callbacks.
* Notifies the inpage context that streams have failed, via window.postMessage.
* Relies on obj-multiplex and post-message-stream implementation details.
* Relies on @metamask/object-multiplex and post-message-stream implementation details.
*/
function notifyInpageOfStreamFailure() {
window.postMessage(
{
target: INPAGE, // the post-message-stream "target"
data: {
// this object gets passed to obj-multiplex
name: PROVIDER, // the obj-multiplex channel name
// this object gets passed to @metamask/object-multiplex
name: PROVIDER, // the @metamask/object-multiplex channel name
data: {
jsonrpc: '2.0',
method: 'METAMASK_STREAM_FAILURE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ describe('metamask-notifications - constructor()', () => {
expect(mockDelete).not.toBeCalled();
});

test('Keying Change Event with new triggers', async () => {
test('Keyring Change Event with new triggers will update triggers correctly', async () => {
const { messenger, globalMessenger, mockListAccounts } = arrangeMocks();

// initialize controller with 1 address
mockListAccounts.mockResolvedValueOnce(['addr1']);
const controller = new MetamaskNotificationsController({
messenger,
state: { isMetamaskNotificationsEnabled: true },
state: {
isMetamaskNotificationsEnabled: true,
subscriptionAccountsSeen: ['addr1'],
},
});

const mockUpdate = jest
Expand All @@ -120,27 +122,28 @@ describe('metamask-notifications - constructor()', () => {
mockDelete.mockClear();
}

await act(['addr2'], () => {
expect(mockUpdate).toBeCalled();
expect(mockDelete).toBeCalled();
// Act - if list accounts has been seen, then will not update
await act(['addr1'], () => {
expect(mockUpdate).not.toBeCalled();
expect(mockDelete).not.toBeCalled();
});

// Act - new accounts were added
// Act - if a new address in list, then will update
await act(['addr1', 'addr2'], () => {
expect(mockUpdate).toBeCalled();
expect(mockDelete).not.toBeCalled();
});

// Act - an account was removed
await act(['addr1'], () => {
// Act - if the list doesn't have an address, then we need to delete
await act(['addr2'], () => {
expect(mockUpdate).not.toBeCalled();
expect(mockDelete).toBeCalled();
});

// Act - an account was added and removed
await act(['addr2'], () => {
expect(mockUpdate).toBeCalled();
expect(mockDelete).toBeCalled();
// If the address is added back to the list, because it is seen we won't update
await act(['addr1', 'addr2'], () => {
expect(mockUpdate).not.toBeCalled();
expect(mockDelete).not.toBeCalled();
});
});

Expand Down
Loading

0 comments on commit 8f971bf

Please sign in to comment.