Skip to content

Commit 14cfe12

Browse files
authored
Merge branch 'main' into mikesposito/update-keyring-controller
2 parents 9126053 + 2fa2606 commit 14cfe12

File tree

58 files changed

+1202
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1202
-313
lines changed

.github/workflows/run-e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
RUN_ID: ${{ github.run_id }}
7575
PR_NUMBER: ${{ github.event.pull_request.number || '' }}
7676
TEST_SUITE_NAME: ${{ inputs.test-suite-name }}
77+
IS_SIDEPANEL: true
7778
steps:
7879
- name: Checkout and setup environment
7980
uses: MetaMask/action-checkout-and-setup@v1

app/manifest/v3/_base.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@
8888
"webRequest",
8989
"offscreen",
9090
"identity",
91-
"sidePanel",
92-
"contextMenus"
91+
"sidePanel"
9392
],
9493
"sandbox": {
9594
"pages": ["snaps/index.html"]

app/scripts/background.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import {
5555
CorruptionHandler,
5656
hasVault,
5757
} from './lib/state-corruption/state-corruption-recovery';
58-
import { initSidePanelContextMenu } from './lib/sidepanel-context-menu';
5958
import {
6059
backedUpStateKeys,
6160
PersistenceManager,
@@ -183,7 +182,6 @@ const PHISHING_WARNING_PAGE_TIMEOUT = ONE_SECOND_IN_MILLISECONDS;
183182

184183
lazyListener.once('runtime', 'onInstalled').then((details) => {
185184
handleOnInstalled(details);
186-
handleSidePanelContextMenu();
187185
});
188186

189187
/**
@@ -1663,15 +1661,6 @@ function onInstall() {
16631661
}
16641662
}
16651663

1666-
/**
1667-
* Handles the onInstalled event for sidepanel context menu creation.
1668-
* This is registered via lazyListener to catch the event at module load time.
1669-
*/
1670-
async function handleSidePanelContextMenu() {
1671-
await isInitialized;
1672-
await initSidePanelContextMenu(controller);
1673-
}
1674-
16751664
/**
16761665
* Trigger actions that should happen only when an update is available
16771666
*/
@@ -1749,18 +1738,6 @@ const initSidePanelBehavior = async () => {
17491738
openPanelOnActionClick: useSidePanelAsDefault,
17501739
});
17511740
}
1752-
1753-
// Setup remote feature flag listener to update sidepanel preferences
1754-
controller?.controllerMessenger?.subscribe(
1755-
'RemoteFeatureFlagController:stateChange',
1756-
(state) => {
1757-
const extensionUxSidepanel =
1758-
state?.remoteFeatureFlags?.extensionUxSidepanel;
1759-
if (extensionUxSidepanel === false) {
1760-
controller?.preferencesController?.setUseSidePanelAsDefault(false);
1761-
}
1762-
},
1763-
);
17641741
} catch (error) {
17651742
console.error('Error setting side panel behavior:', error);
17661743
}

app/scripts/lib/dapp-swap/dapp-swap-middleware.test.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
12
import { JsonRpcResponseStruct } from '@metamask/utils';
23

34
import { flushPromises } from '../../../../test/lib/timer-helpers';
@@ -20,15 +21,23 @@ const getNetworkConfigurationByNetworkClientId = jest.fn();
2021
const createMiddleware = (
2122
args: {
2223
// eslint-disable-next-line @typescript-eslint/naming-convention
23-
dappSwapMetricsFlag?: { enabled: boolean; bridge_quote_fees: number };
24+
dappSwapMetricsFlag?: {
25+
enabled: boolean;
26+
bridge_quote_fees: number;
27+
origins: string[];
28+
};
2429
} = {},
2530
) => {
2631
const middlewareFunction = createDappSwapMiddleware({
2732
fetchQuotes,
2833
setDappSwapComparisonData,
2934
getNetworkConfigurationByNetworkClientId,
3035
// eslint-disable-next-line @typescript-eslint/naming-convention
31-
dappSwapMetricsFlag: { enabled: true, bridge_quote_fees: 250 },
36+
dappSwapMetricsFlag: {
37+
enabled: true,
38+
bridge_quote_fees: 250,
39+
origins: ['https://metamask.github.io'],
40+
},
3241
...args,
3342
});
3443
return { middlewareFunction };
@@ -60,7 +69,11 @@ describe('DappSwapMiddleware', () => {
6069
fetchQuotes.mockReturnValueOnce(mockBridgeQuotes);
6170
const { middlewareFunction } = createMiddleware({
6271
// eslint-disable-next-line @typescript-eslint/naming-convention
63-
dappSwapMetricsFlag: { enabled: false, bridge_quote_fees: 250 },
72+
dappSwapMetricsFlag: {
73+
enabled: false,
74+
bridge_quote_fees: 250,
75+
origins: ['https://metamask.github.io'],
76+
},
6477
});
6578

6679
const req = {
@@ -221,4 +234,44 @@ describe('DappSwapMiddleware', () => {
221234
'Error fetching bridge quotes: Error: Error getting data from swap: invalid batch transaction, invalid command',
222235
});
223236
});
237+
238+
it('does not fetch quotes if origin is not in the list of allowed origins', async () => {
239+
fetchQuotes.mockReturnValueOnce(mockBridgeQuotes);
240+
const { middlewareFunction } = createMiddleware({
241+
// eslint-disable-next-line @typescript-eslint/naming-convention
242+
dappSwapMetricsFlag: {
243+
enabled: true,
244+
bridge_quote_fees: 250,
245+
origins: ['https://metamask.github.io'],
246+
},
247+
});
248+
249+
const req = {
250+
...REQUEST_MOCK,
251+
method: 'eth_sendTransaction',
252+
origin: 'https://test.com',
253+
securityAlertResponse: {
254+
securityAlertId: '123',
255+
},
256+
params: [
257+
{
258+
data: '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000068f0dd1b0000000000000000000000000000000000000000000000000000000000000003100604000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003070b0e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000007ffc3dbf3b2b50ff3a1d5523bc24bb5043837b1400000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000178239802520a9c99dcbd791f81326b70298d62900000000000000000000000000000000000000000000000000000000000601470c',
259+
from: '0x12312312312312',
260+
chainId: '1',
261+
calls: [],
262+
},
263+
],
264+
networkClientId: 'networkClientId',
265+
};
266+
267+
await middlewareFunction(
268+
req as unknown as DappSwapMiddlewareRequest<(string | { to: string })[]>,
269+
{ ...JsonRpcResponseStruct.TYPE },
270+
() => undefined,
271+
);
272+
273+
await flushPromises();
274+
275+
expect(fetchQuotes).not.toHaveBeenCalled();
276+
});
224277
});

app/scripts/lib/dapp-swap/dapp-swap-middleware.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ export function createDappSwapMiddleware<
3131
getNetworkConfigurationByNetworkClientId: (
3232
networkClientId: NetworkClientId,
3333
) => NetworkConfiguration | undefined;
34-
// eslint-disable-next-line @typescript-eslint/naming-convention
35-
dappSwapMetricsFlag: { enabled: boolean; bridge_quote_fees: number };
34+
dappSwapMetricsFlag: {
35+
enabled: boolean;
36+
// eslint-disable-next-line @typescript-eslint/naming-convention
37+
bridge_quote_fees: number;
38+
origins: string[];
39+
};
3640
}) {
3741
return async (
3842
req: DappSwapMiddlewareRequest<Params>,

app/scripts/lib/dapp-swap/dapp-swap-util.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export type DappSwapMiddlewareRequest<
3434
};
3535

3636
const FOUR_BYTE_EXECUTE_SWAP_CONTRACT = '0x3593564c';
37-
const DAPP_SWAP_COMPARISON_ORIGIN = 'https://app.uniswap.org';
38-
const TEST_DAPP_ORIGIN = 'https://metamask.github.io';
3937

4038
const getSwapDetails = (params: DappSwapMiddlewareRequest['params']) => {
4139
if (!params?.length) {
@@ -79,20 +77,27 @@ export function getQuotesForConfirmation({
7977
getNetworkConfigurationByNetworkClientId: (
8078
networkClientId: NetworkClientId,
8179
) => NetworkConfiguration | undefined;
82-
// eslint-disable-next-line @typescript-eslint/naming-convention
83-
dappSwapMetricsFlag: { enabled: boolean; bridge_quote_fees: number };
80+
dappSwapMetricsFlag: {
81+
enabled: boolean;
82+
// eslint-disable-next-line @typescript-eslint/naming-convention
83+
bridge_quote_fees: number;
84+
origins: string[];
85+
};
8486
securityAlertId?: string;
8587
}) {
8688
let commands = '';
8789
try {
88-
// eslint-disable-next-line @typescript-eslint/naming-convention
89-
const { enabled: dappSwapEnabled, bridge_quote_fees: bridgeQuoteFees } =
90-
dappSwapMetricsFlag;
90+
const {
91+
enabled: dappSwapEnabled,
92+
// eslint-disable-next-line @typescript-eslint/naming-convention
93+
bridge_quote_fees: bridgeQuoteFees,
94+
origins,
95+
} = dappSwapMetricsFlag;
9196
if (!dappSwapEnabled || !securityAlertId) {
9297
return;
9398
}
9499
const { params, origin } = req;
95-
if (origin === DAPP_SWAP_COMPARISON_ORIGIN || origin === TEST_DAPP_ORIGIN) {
100+
if (origin && origins.includes(origin)) {
96101
const { chainId } =
97102
getNetworkConfigurationByNetworkClientId(req.networkClientId) ?? {};
98103
const { data, from } = getSwapDetails(params);

app/scripts/lib/sidepanel-context-menu.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)