Skip to content

Commit

Permalink
Merge branch 'feat/websocket-support' of https://github.com/MetaMask/…
Browse files Browse the repository at this point in the history
…metamask-extension into feat/websocket-support
  • Loading branch information
AugmentedMode committed Nov 27, 2024
2 parents 6f1da54 + 60a3ac7 commit d2c7f78
Show file tree
Hide file tree
Showing 196 changed files with 3,949 additions and 2,749 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ version: 2.1
executors:
node-browsers-small:
docker:
- image: cimg/node:20.17-browsers
- image: cimg/node:20.18-browsers
resource_class: small
environment:
NODE_OPTIONS: --max_old_space_size=2048
node-browsers-medium:
docker:
- image: cimg/node:20.17-browsers
- image: cimg/node:20.18-browsers
resource_class: medium
environment:
NODE_OPTIONS: --max_old_space_size=3072
Expand All @@ -21,7 +21,7 @@ executors:
NODE_OPTIONS: --max_old_space_size=6144
node-browsers-medium-plus:
docker:
- image: cimg/node:20.17-browsers
- image: cimg/node:20.18-browsers
resource_class: medium+
environment:
NODE_OPTIONS: --max_old_space_size=4096
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.17
v20.18
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"shellcheck",
"SIWE",
"sourcemaps",
"Sourcify",
"sprintf",
"testcase",
"TESTFILES",
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions app/_locales/en/messages.json

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

23 changes: 12 additions & 11 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ import {
FakeLedgerBridge,
FakeTrezorBridge,
} from '../../test/stub/keyring-bridge';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { getCurrentChainId } from '../../ui/selectors';
import { getCurrentChainId } from '../../shared/modules/selectors/networks';
import { addNonceToCsp } from '../../shared/modules/add-nonce-to-csp';
import { checkURLForProviderInjection } from '../../shared/modules/provider-injection';
import migrations from './migrations';
Expand Down Expand Up @@ -1048,11 +1046,6 @@ export function setupController(
updateBadge,
);

controller.controllerMessenger.subscribe(
METAMASK_CONTROLLER_EVENTS.NOTIFICATIONS_STATE_CHANGE,
updateBadge,
);

/**
* Formats a count for display as a badge label.
*
Expand Down Expand Up @@ -1121,8 +1114,14 @@ export function setupController(
controller.notificationServicesController.state;

const snapNotificationCount = Object.values(
controller.notificationController.state.notifications,
).filter((notification) => notification.readDate === null).length;
controller.notificationServicesController.state
.metamaskNotificationsList,
).filter(
(notification) =>
notification.type ===
NotificationServicesController.Constants.TRIGGER_TYPES.SNAP &&
notification.readDate === null,
).length;

const featureAnnouncementCount = isFeatureAnnouncementsEnabled
? controller.notificationServicesController.state.metamaskNotificationsList.filter(
Expand All @@ -1140,7 +1139,9 @@ export function setupController(
!notification.isRead &&
notification.type !==
NotificationServicesController.Constants.TRIGGER_TYPES
.FEATURES_ANNOUNCEMENT,
.FEATURES_ANNOUNCEMENT &&
notification.type !==
NotificationServicesController.Constants.TRIGGER_TYPES.SNAP,
).length
: 0;

Expand Down
3 changes: 0 additions & 3 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ export const SENTRY_BACKGROUND_STATE = {
allNfts: false,
ignoredNfts: false,
},
NotificationController: {
notifications: false,
},
OnboardingController: {
completedOnboarding: true,
firstTimeFlowType: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ const executePollingWithPendingStatus = async () => {
const bridgeStatusController = new BridgeStatusController({
messenger: getMessengerMock(),
});
const startPollingByNetworkClientIdSpy = jest.spyOn(
bridgeStatusController,
'startPollingByNetworkClientId',
);
const startPollingSpy = jest.spyOn(bridgeStatusController, 'startPolling');
const fetchBridgeTxStatusSpy = jest.spyOn(
bridgeStatusUtils,
'fetchBridgeTxStatus',
Expand All @@ -319,7 +316,7 @@ const executePollingWithPendingStatus = async () => {

return {
bridgeStatusController,
startPollingByNetworkClientIdSpy,
startPollingSpy,
fetchBridgeTxStatusSpy,
};
};
Expand Down Expand Up @@ -398,12 +395,12 @@ describe('BridgeStatusController', () => {
it('starts polling and updates the tx history when the status response is received', async () => {
const {
bridgeStatusController,
startPollingByNetworkClientIdSpy,
startPollingSpy,
fetchBridgeTxStatusSpy,
} = await executePollingWithPendingStatus();

// Assertions
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledTimes(1);
expect(startPollingSpy).toHaveBeenCalledTimes(1);
expect(fetchBridgeTxStatusSpy).toHaveBeenCalled();
expect(bridgeStatusController.state.bridgeStatusState.txHistory).toEqual(
MockTxHistory.getPending(),
Expand Down
35 changes: 21 additions & 14 deletions app/scripts/controllers/bridge-status/bridge-status-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StateMetadata } from '@metamask/base-controller';
import type { NetworkClientId } from '@metamask/network-controller';
import { StaticIntervalPollingController } from '@metamask/polling-controller';
import { Hex } from '@metamask/utils';
// eslint-disable-next-line import/no-restricted-paths
Expand Down Expand Up @@ -28,11 +29,17 @@ const metadata: StateMetadata<{
},
};

/** The input to start polling for the {@link BridgeStatusController} */
type BridgeStatusPollingInput = {
networkClientId: NetworkClientId;
statusRequest: StatusRequest;
};

type SrcTxHash = string;
export type FetchBridgeTxStatusArgs = {
statusRequest: StatusRequest;
};
export default class BridgeStatusController extends StaticIntervalPollingController<
export default class BridgeStatusController extends StaticIntervalPollingController<BridgeStatusPollingInput>()<
typeof BRIDGE_STATUS_CONTROLLER_NAME,
{ bridgeStatusState: BridgeStatusControllerState },
BridgeStatusControllerMessenger
Expand Down Expand Up @@ -149,11 +156,10 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
hexSourceChainId,
);

// We manually call startPollingByNetworkClientId() here rather than go through startPollingForBridgeTxStatus()
// We manually call startPolling() here rather than go through startPollingForBridgeTxStatus()
// because we don't want to overwrite the existing historyItem in state
const options: FetchBridgeTxStatusArgs = { statusRequest };
this.#pollingTokensBySrcTxHash[statusRequest.srcTxHash] =
this.startPollingByNetworkClientId(networkClientId, options);
this.startPolling({ networkClientId, statusRequest });
});
};

Expand Down Expand Up @@ -209,24 +215,25 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
'NetworkController:findNetworkClientIdByChainId',
hexSourceChainId,
);
this.#pollingTokensBySrcTxHash[statusRequest.srcTxHash] =
this.startPollingByNetworkClientId(networkClientId, { statusRequest });
this.#pollingTokensBySrcTxHash[statusRequest.srcTxHash] = this.startPolling(
{ networkClientId, statusRequest },
);
};

// This will be called after you call this.startPollingByNetworkClientId()
// The args passed in are the args you passed in to startPollingByNetworkClientId()
_executePoll = async (
_networkClientId: string,
fetchBridgeTxStatusArgs: FetchBridgeTxStatusArgs,
) => {
await this.#fetchBridgeTxStatus(fetchBridgeTxStatusArgs);
// This will be called after you call this.startPolling()
// The args passed in are the args you passed in to startPolling()
_executePoll = async (pollingInput: BridgeStatusPollingInput) => {
await this.#fetchBridgeTxStatus(pollingInput);
};

#getSelectedAccount() {
return this.messagingSystem.call('AccountsController:getSelectedAccount');
}

#fetchBridgeTxStatus = async ({ statusRequest }: FetchBridgeTxStatusArgs) => {
#fetchBridgeTxStatus = async ({
networkClientId: _networkClientId,
statusRequest,
}: BridgeStatusPollingInput) => {
const { bridgeStatusState } = this.state;

try {
Expand Down
52 changes: 20 additions & 32 deletions app/scripts/controllers/bridge/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ describe('BridgeController', function () {
it('updateBridgeQuoteRequestParams should trigger quote polling if request is valid', async function () {
jest.useFakeTimers();
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
const startPollingByNetworkClientIdSpy = jest.spyOn(
bridgeController,
'startPollingByNetworkClientId',
);
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
const hasSufficientBalanceSpy = jest
.spyOn(balanceUtils, 'hasSufficientBalance')
.mockResolvedValue(true);
Expand Down Expand Up @@ -328,15 +325,15 @@ describe('BridgeController', function () {
await bridgeController.updateBridgeQuoteRequestParams(quoteParams);

expect(stopAllPollingSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledTimes(1);
expect(startPollingSpy).toHaveBeenCalledTimes(1);
expect(hasSufficientBalanceSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledWith(
expect.anything(),
{
expect(startPollingSpy).toHaveBeenCalledWith({
networkClientId: expect.anything(),
updatedQuoteRequest: {
...quoteRequest,
insufficientBal: false,
},
);
});

expect(bridgeController.state.bridgeState).toStrictEqual(
expect.objectContaining({
Expand Down Expand Up @@ -430,10 +427,7 @@ describe('BridgeController', function () {
it('updateBridgeQuoteRequestParams should only poll once if insufficientBal=true', async function () {
jest.useFakeTimers();
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
const startPollingByNetworkClientIdSpy = jest.spyOn(
bridgeController,
'startPollingByNetworkClientId',
);
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
const hasSufficientBalanceSpy = jest
.spyOn(balanceUtils, 'hasSufficientBalance')
.mockResolvedValue(false);
Expand Down Expand Up @@ -478,15 +472,15 @@ describe('BridgeController', function () {
await bridgeController.updateBridgeQuoteRequestParams(quoteParams);

expect(stopAllPollingSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledTimes(1);
expect(startPollingSpy).toHaveBeenCalledTimes(1);
expect(hasSufficientBalanceSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledWith(
expect.anything(),
{
expect(startPollingSpy).toHaveBeenCalledWith({
networkClientId: expect.anything(),
updatedQuoteRequest: {
...quoteRequest,
insufficientBal: true,
},
);
});

expect(bridgeController.state.bridgeState).toStrictEqual(
expect.objectContaining({
Expand Down Expand Up @@ -556,10 +550,7 @@ describe('BridgeController', function () {

it('updateBridgeQuoteRequestParams should not trigger quote polling if request is invalid', function () {
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
const startPollingByNetworkClientIdSpy = jest.spyOn(
bridgeController,
'startPollingByNetworkClientId',
);
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
messengerMock.call.mockReturnValue({
address: '0x123',
provider: jest.fn(),
Expand All @@ -573,7 +564,7 @@ describe('BridgeController', function () {
});

expect(stopAllPollingSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).not.toHaveBeenCalled();
expect(startPollingSpy).not.toHaveBeenCalled();

expect(bridgeController.state.bridgeState).toStrictEqual(
expect.objectContaining({
Expand Down Expand Up @@ -638,10 +629,7 @@ describe('BridgeController', function () {
) => {
jest.useFakeTimers();
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
const startPollingByNetworkClientIdSpy = jest.spyOn(
bridgeController,
'startPollingByNetworkClientId',
);
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
const hasSufficientBalanceSpy = jest
.spyOn(balanceUtils, 'hasSufficientBalance')
.mockResolvedValue(false);
Expand Down Expand Up @@ -676,15 +664,15 @@ describe('BridgeController', function () {
await bridgeController.updateBridgeQuoteRequestParams(quoteParams);

expect(stopAllPollingSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledTimes(1);
expect(startPollingSpy).toHaveBeenCalledTimes(1);
expect(hasSufficientBalanceSpy).toHaveBeenCalledTimes(1);
expect(startPollingByNetworkClientIdSpy).toHaveBeenCalledWith(
expect.anything(),
{
expect(startPollingSpy).toHaveBeenCalledWith({
networkClientId: expect.anything(),
updatedQuoteRequest: {
...quoteRequest,
insufficientBal: true,
},
);
});

expect(bridgeController.state.bridgeState).toStrictEqual(
expect.objectContaining({
Expand Down
Loading

0 comments on commit d2c7f78

Please sign in to comment.