Skip to content

Commit 7ec5325

Browse files
committed
Merge branch 'main' into mikesposito/deps/smart-transaction-controller
2 parents 9724c1b + 49cc847 commit 7ec5325

File tree

59 files changed

+1529
-269
lines changed

Some content is hidden

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

59 files changed

+1529
-269
lines changed

.github/workflows/add-team-label.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ on:
88
jobs:
99
add-team-label:
1010
if: ${{ !github.event.pull_request.head.repo.fork }}
11-
uses: metamask/github-tools/.github/workflows/add-team-label.yml@18af6e4b56a18230d1792480e249ebc50b324927
11+
uses: metamask/github-tools/.github/workflows/add-team-label.yml@7fe185fdb0e60981c898e88d82e44ff33f604daa
1212
secrets:
1313
TEAM_LABEL_TOKEN: ${{ secrets.TEAM_LABEL_TOKEN }}

.github/workflows/update-lavamoat-policies.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ on:
44
issue_comment:
55
types: created
66

7-
concurrency:
8-
group: ${{ github.workflow }}-${{ github.ref_name }}
9-
cancel-in-progress: ${{ !contains(github.ref_name, 'release/')}}
10-
117
jobs:
128
is-fork-pull-request:
139
name: Determine whether this issue comment was on a pull request from a fork

app/_locales/en/messages.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/_locales/en_GB/messages.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/images/lukso-native.svg

Lines changed: 3 additions & 0 deletions
Loading

app/images/lukso.svg

Lines changed: 3 additions & 0 deletions
Loading

app/scripts/controller-init/assets/network-enablement-controller-init.test.ts

Lines changed: 126 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
AccountTreeControllerGetAccountsFromSelectedAccountGroupAction,
77
AccountTreeControllerSelectedAccountGroupChangeEvent,
88
} from '@metamask/account-tree-controller';
9+
import { KnownCaipNamespace } from '@metamask/utils';
10+
import { CHAIN_IDS } from '../../../../shared/constants/network';
911
import { ControllerInitRequest } from '../types';
1012
import { buildControllerInitRequestMock } from '../test/utils';
1113
import {
@@ -37,15 +39,23 @@ function getInitRequestMock(
3739
if (controllerName === 'MultichainNetworkController') {
3840
return {
3941
state: {
40-
multichainNetworkConfigurationsByChainId: {},
42+
multichainNetworkConfigurationsByChainId: {
43+
[SolScope.Mainnet]: {},
44+
[BtcScope.Mainnet]: {},
45+
},
4146
},
4247
};
4348
}
4449

4550
if (controllerName === 'NetworkController') {
4651
return {
4752
state: {
48-
networkConfigurationsByChainId: {},
53+
networkConfigurationsByChainId: {
54+
[CHAIN_IDS.MAINNET]: {},
55+
[CHAIN_IDS.POLYGON]: {},
56+
[CHAIN_IDS.SEPOLIA]: {},
57+
[CHAIN_IDS.LOCALHOST]: {},
58+
},
4959
},
5060
};
5161
}
@@ -63,22 +73,6 @@ describe('NetworkEnablementControllerInit', () => {
6373
expect(controller).toBeInstanceOf(NetworkEnablementController);
6474
});
6575

66-
it('passes the proper arguments to the controller', () => {
67-
NetworkEnablementControllerInit(getInitRequestMock());
68-
69-
const controllerMock = jest.mocked(NetworkEnablementController);
70-
expect(controllerMock).toHaveBeenCalledWith({
71-
messenger: expect.any(Object),
72-
state: {
73-
enabledNetworkMap: {
74-
bitcoin: {},
75-
eip155: {},
76-
solana: {},
77-
},
78-
},
79-
});
80-
});
81-
8276
it('enables the Solana network when `AccountsController:selectedAccountChange` is emitted', () => {
8377
const messenger = new Messenger<
8478
never,
@@ -225,4 +219,118 @@ describe('NetworkEnablementControllerInit', () => {
225219

226220
expect(controller.enableNetwork).not.toHaveBeenCalled();
227221
});
222+
223+
it('initialises the controller with the correct networks for prod environment', () => {
224+
process.env.METAMASK_DEBUG = '';
225+
process.env.METAMASK_ENVIRONMENT = 'production';
226+
process.env.IN_TEST = '';
227+
228+
NetworkEnablementControllerInit(getInitRequestMock());
229+
230+
const controllerMock = jest.mocked(NetworkEnablementController);
231+
expect(controllerMock).toHaveBeenCalledWith({
232+
messenger: expect.any(Object),
233+
state: {
234+
enabledNetworkMap: {
235+
[KnownCaipNamespace.Eip155]: {
236+
[CHAIN_IDS.MAINNET]: true,
237+
[CHAIN_IDS.POLYGON]: true,
238+
[CHAIN_IDS.SEPOLIA]: false,
239+
[CHAIN_IDS.LOCALHOST]: false,
240+
},
241+
[KnownCaipNamespace.Solana]: {
242+
[SolScope.Mainnet]: true,
243+
},
244+
[KnownCaipNamespace.Bip122]: {
245+
[BtcScope.Mainnet]: true,
246+
},
247+
},
248+
},
249+
});
250+
});
251+
252+
it('initialises the controller with the correct networks for IN_TEST environment', () => {
253+
process.env.IN_TEST = 'true';
254+
255+
NetworkEnablementControllerInit(getInitRequestMock());
256+
257+
const controllerMock = jest.mocked(NetworkEnablementController);
258+
expect(controllerMock).toHaveBeenCalledWith({
259+
messenger: expect.any(Object),
260+
state: {
261+
enabledNetworkMap: {
262+
[KnownCaipNamespace.Eip155]: {
263+
[CHAIN_IDS.MAINNET]: false,
264+
[CHAIN_IDS.POLYGON]: false,
265+
[CHAIN_IDS.SEPOLIA]: false,
266+
[CHAIN_IDS.LOCALHOST]: true,
267+
},
268+
[KnownCaipNamespace.Solana]: {
269+
[SolScope.Mainnet]: false,
270+
},
271+
[KnownCaipNamespace.Bip122]: {
272+
[BtcScope.Mainnet]: false,
273+
},
274+
},
275+
},
276+
});
277+
});
278+
279+
it('initialises the controller with the correct networks for DEBUG environment', () => {
280+
process.env.METAMASK_DEBUG = 'true';
281+
process.env.METAMASK_ENVIRONMENT = 'production';
282+
process.env.IN_TEST = '';
283+
284+
NetworkEnablementControllerInit(getInitRequestMock());
285+
286+
const controllerMock = jest.mocked(NetworkEnablementController);
287+
expect(controllerMock).toHaveBeenCalledWith({
288+
messenger: expect.any(Object),
289+
state: {
290+
enabledNetworkMap: {
291+
[KnownCaipNamespace.Eip155]: {
292+
[CHAIN_IDS.MAINNET]: false,
293+
[CHAIN_IDS.POLYGON]: false,
294+
[CHAIN_IDS.SEPOLIA]: true,
295+
[CHAIN_IDS.LOCALHOST]: false,
296+
},
297+
[KnownCaipNamespace.Solana]: {
298+
[SolScope.Mainnet]: false,
299+
},
300+
[KnownCaipNamespace.Bip122]: {
301+
[BtcScope.Mainnet]: false,
302+
},
303+
},
304+
},
305+
});
306+
});
307+
308+
it('initialises the controller with the correct networks for test environment', () => {
309+
process.env.METAMASK_DEBUG = '';
310+
process.env.METAMASK_ENVIRONMENT = 'test';
311+
process.env.IN_TEST = '';
312+
313+
NetworkEnablementControllerInit(getInitRequestMock());
314+
315+
const controllerMock = jest.mocked(NetworkEnablementController);
316+
expect(controllerMock).toHaveBeenCalledWith({
317+
messenger: expect.any(Object),
318+
state: {
319+
enabledNetworkMap: {
320+
[KnownCaipNamespace.Eip155]: {
321+
[CHAIN_IDS.MAINNET]: false,
322+
[CHAIN_IDS.POLYGON]: false,
323+
[CHAIN_IDS.SEPOLIA]: true,
324+
[CHAIN_IDS.LOCALHOST]: false,
325+
},
326+
[KnownCaipNamespace.Solana]: {
327+
[SolScope.Mainnet]: false,
328+
},
329+
[KnownCaipNamespace.Bip122]: {
330+
[BtcScope.Mainnet]: false,
331+
},
332+
},
333+
},
334+
});
335+
});
228336
});

app/scripts/controller-init/assets/network-enablement-controller-init.ts

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import {
1111
SolAccountType,
1212
SolScope,
1313
} from '@metamask/keyring-api';
14-
import { KnownCaipNamespace } from '@metamask/utils';
14+
import {
15+
CaipChainId,
16+
CaipNamespace,
17+
Hex,
18+
KnownCaipNamespace,
19+
parseCaipChainId,
20+
} from '@metamask/utils';
1521
import {
1622
NetworkEnablementControllerMessenger,
1723
NetworkEnablementControllerInitMessenger,
@@ -32,12 +38,14 @@ import {
3238
const generateEVMNetworkMap = (
3339
networkConfigurationsByChainId: NetworkState['networkConfigurationsByChainId'],
3440
enabledChainIds: string[],
35-
): Record<string, boolean> => {
36-
const networkMap: Record<string, boolean> = {};
41+
): Record<KnownCaipNamespace.Eip155, Record<Hex, boolean>> => {
42+
const networkMap: Record<KnownCaipNamespace.Eip155, Record<Hex, boolean>> = {
43+
[KnownCaipNamespace.Eip155]: {},
44+
};
3745

38-
// Add all available EVM networks from NetworkController with default disabled status
39-
Object.keys(networkConfigurationsByChainId).forEach((chainId) => {
40-
networkMap[chainId] = enabledChainIds.includes(chainId);
46+
(Object.keys(networkConfigurationsByChainId) as Hex[]).forEach((chainId) => {
47+
networkMap[KnownCaipNamespace.Eip155][chainId] =
48+
enabledChainIds.includes(chainId);
4149
});
4250

4351
return networkMap;
@@ -53,22 +61,16 @@ const generateEVMNetworkMap = (
5361
const generateMultichainNetworkMaps = (
5462
multichainNetworkConfigurationsByChainId: MultichainNetworkControllerState['multichainNetworkConfigurationsByChainId'],
5563
enabledNetworks: string[] = [],
56-
): Record<string, Record<string, boolean>> => {
57-
const networkMaps: Record<string, Record<string, boolean>> = {
58-
solana: {},
59-
bitcoin: {},
60-
};
64+
): Record<CaipNamespace, Record<CaipChainId, boolean>> => {
65+
const networkMaps: Record<CaipNamespace, Record<CaipChainId, boolean>> = {};
6166

62-
// Organize multichain networks by their prefix/type
63-
Object.keys(multichainNetworkConfigurationsByChainId).forEach((chainId) => {
67+
(
68+
Object.keys(multichainNetworkConfigurationsByChainId) as CaipChainId[]
69+
).forEach((chainId) => {
6470
const isEnabled = enabledNetworks.includes(chainId);
71+
const { namespace } = parseCaipChainId(chainId);
6572

66-
if (chainId.startsWith('solana:')) {
67-
networkMaps.solana[chainId] = isEnabled;
68-
} else if (chainId.startsWith('bip122:')) {
69-
networkMaps.bitcoin[chainId] = isEnabled;
70-
}
71-
// Add other network types as needed
73+
(networkMaps[namespace] ??= {})[chainId] = isEnabled;
7274
});
7375

7476
return networkMaps;
@@ -82,19 +84,16 @@ const generateDefaultNetworkEnablementControllerState = (
8284
const { multichainNetworkConfigurationsByChainId } =
8385
multichainNetworkControllerState;
8486

85-
// Generate multichain network maps (always empty for all environments currently)
86-
const multichainMaps = generateMultichainNetworkMaps(
87-
multichainNetworkConfigurationsByChainId,
88-
[],
89-
);
90-
9187
if (process.env.IN_TEST) {
9288
return {
9389
enabledNetworkMap: {
94-
eip155: generateEVMNetworkMap(networkConfigurationsByChainId, [
90+
...generateEVMNetworkMap(networkConfigurationsByChainId, [
9591
CHAIN_IDS.LOCALHOST,
9692
]),
97-
...multichainMaps,
93+
...generateMultichainNetworkMaps(
94+
multichainNetworkConfigurationsByChainId,
95+
[],
96+
),
9897
},
9998
};
10099
} else if (
@@ -103,21 +102,33 @@ const generateDefaultNetworkEnablementControllerState = (
103102
) {
104103
return {
105104
enabledNetworkMap: {
106-
eip155: generateEVMNetworkMap(networkConfigurationsByChainId, [
105+
...generateEVMNetworkMap(networkConfigurationsByChainId, [
107106
CHAIN_IDS.SEPOLIA,
108107
]),
109-
...multichainMaps,
108+
...generateMultichainNetworkMaps(
109+
multichainNetworkConfigurationsByChainId,
110+
[],
111+
),
110112
},
111113
};
112114
}
113115

116+
const enabledMultichainNetworks: string[] = [SolScope.Mainnet];
117+
118+
///: BEGIN:ONLY_INCLUDE_IF(bitcoin)
119+
enabledMultichainNetworks.push(BtcScope.Mainnet);
120+
///: END:ONLY_INCLUDE_IF
121+
114122
return {
115123
enabledNetworkMap: {
116-
eip155: generateEVMNetworkMap(
124+
...generateEVMNetworkMap(
117125
networkConfigurationsByChainId,
118126
FEATURED_NETWORK_CHAIN_IDS,
119127
),
120-
...multichainMaps,
128+
...generateMultichainNetworkMaps(
129+
multichainNetworkConfigurationsByChainId,
130+
enabledMultichainNetworks,
131+
),
121132
},
122133
};
123134
};

app/scripts/controller-init/messengers/shield/shield-controller-messenger.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export function getShieldControllerMessenger(
3636
return messenger.getRestricted({
3737
name: 'ShieldController',
3838
allowedActions: [],
39-
allowedEvents: ['TransactionController:stateChange'],
39+
allowedEvents: [
40+
'SignatureController:stateChange',
41+
'TransactionController:stateChange',
42+
],
4043
});
4144
}
4245

0 commit comments

Comments
 (0)