Skip to content

Commit 80d560b

Browse files
authored
Merge branch 'main' into chore/upgrade-assets-controllers
2 parents ea422ed + 1997e26 commit 80d560b

File tree

14 files changed

+502
-212
lines changed

14 files changed

+502
-212
lines changed

app/scripts/metamask-controller.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ import { createEngineStream } from '@metamask/json-rpc-middleware-stream';
1414
import { ObservableStore } from '@metamask/obs-store';
1515
import { storeAsStream } from '@metamask/obs-store/dist/asStream';
1616
import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware';
17-
import {
18-
debounce,
19-
throttle,
20-
memoize,
21-
wrap,
22-
pick,
23-
cloneDeep,
24-
uniq,
25-
} from 'lodash';
17+
import { debounce, throttle, memoize, wrap, pick, uniq } from 'lodash';
2618
import {
2719
KeyringController,
2820
KeyringTypes,
@@ -92,6 +84,7 @@ import {
9284
ERC20,
9385
ERC721,
9486
BlockExplorerUrl,
87+
ChainId,
9588
} from '@metamask/controller-utils';
9689

9790
import { AccountsController } from '@metamask/accounts-controller';
@@ -189,8 +182,6 @@ import {
189182
CHAIN_SPEC_URL,
190183
NETWORK_TYPES,
191184
NetworkStatus,
192-
MAINNET_DISPLAY_NAME,
193-
DEFAULT_CUSTOM_TESTNET_MAP,
194185
UNSUPPORTED_RPC_METHODS,
195186
} from '../../shared/constants/network';
196187
import { getAllowedSmartTransactionsChainIds } from '../../shared/constants/smartTransactions';
@@ -582,22 +573,10 @@ export default class MetamaskController extends EventEmitter {
582573
const networks =
583574
initialNetworkControllerState.networkConfigurationsByChainId;
584575

585-
// Note: Consider changing `getDefaultNetworkControllerState`
586-
// on the controller side to include some of these tweaks.
587-
networks[CHAIN_IDS.MAINNET].name = MAINNET_DISPLAY_NAME;
588-
delete networks[CHAIN_IDS.GOERLI];
589-
delete networks[CHAIN_IDS.LINEA_GOERLI];
590-
591-
// Due to the MegaETH Testnet not being included in getDefaultNetworkControllerState().
592-
// and it is not using Infura as a provider, we need to add it manually.
593-
networks[CHAIN_IDS.MEGAETH_TESTNET] = cloneDeep(
594-
DEFAULT_CUSTOM_TESTNET_MAP[CHAIN_IDS.MEGAETH_TESTNET],
595-
);
596-
576+
// TODO: It should be done on NetworkController level
597577
Object.values(networks).forEach((network) => {
598578
const id = network.rpcEndpoints[0].networkClientId;
599579
// Process only if the default network has a corresponding networkClientId in BlockExplorerUrl.
600-
// Note: The MegaETH Testnet is currently the only network that is not included.
601580
if (hasProperty(BlockExplorerUrl, id)) {
602581
network.blockExplorerUrls = [BlockExplorerUrl[id]];
603582
}
@@ -642,6 +621,7 @@ export default class MetamaskController extends EventEmitter {
642621
fetch: globalThis.fetch.bind(globalThis),
643622
btoa: globalThis.btoa.bind(globalThis),
644623
}),
624+
additionalDefaultNetworks: [ChainId['megaeth-testnet']],
645625
});
646626
this.networkController.initializeProvider();
647627

app/scripts/migrations/146.test.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
import { cloneDeep } from 'lodash';
2-
import {
3-
CHAIN_IDS,
4-
DEFAULT_CUSTOM_TESTNET_MAP,
5-
} from '../../../shared/constants/network';
1+
import { ChainId } from '@metamask/controller-utils';
2+
63
import { migrate, version } from './146';
74

85
const oldVersion = 145;
6+
const megaEthChainId = ChainId['megaeth-testnet'];
7+
8+
/**
9+
* Get the MegaETH testnet network configuration object as snapshot.
10+
*
11+
* @returns The MegaETH testnet network configuration object.
12+
*/
13+
const getMegaEthTestnetConfiguration = () => ({
14+
chainId: megaEthChainId,
15+
name: 'Mega Testnet',
16+
nativeCurrency: 'MegaETH',
17+
blockExplorerUrls: ['https://megaexplorer.xyz'],
18+
defaultRpcEndpointIndex: 0,
19+
defaultBlockExplorerUrlIndex: 0,
20+
rpcEndpoints: [
21+
{
22+
networkClientId: 'megaeth-testnet',
23+
url: 'https://carrot.megaeth.com/rpc',
24+
type: 'custom',
25+
},
26+
],
27+
});
928

1029
describe(`migration #${version}`, () => {
1130
it('updates the version metadata', async () => {
@@ -129,9 +148,7 @@ describe(`migration #${version}`, () => {
129148
...oldState.data.NetworkController,
130149
networkConfigurationsByChainId: {
131150
...oldState.data.NetworkController.networkConfigurationsByChainId,
132-
[CHAIN_IDS.MEGAETH_TESTNET]: cloneDeep(
133-
DEFAULT_CUSTOM_TESTNET_MAP[CHAIN_IDS.MEGAETH_TESTNET],
134-
),
151+
[megaEthChainId]: getMegaEthTestnetConfiguration(),
135152
},
136153
},
137154
};
@@ -148,10 +165,8 @@ describe(`migration #${version}`, () => {
148165
selectedNetworkClientId: 'mainnet',
149166
networksMetadata: {},
150167
networkConfigurationsByChainId: {
151-
[CHAIN_IDS.MEGAETH_TESTNET]: {
152-
...cloneDeep(
153-
DEFAULT_CUSTOM_TESTNET_MAP[CHAIN_IDS.MEGAETH_TESTNET],
154-
),
168+
[megaEthChainId]: {
169+
...getMegaEthTestnetConfiguration(),
155170
name: 'Some other name',
156171
},
157172
},
@@ -164,9 +179,7 @@ describe(`migration #${version}`, () => {
164179
...oldStorage.data.NetworkController,
165180
networkConfigurationsByChainId: {
166181
...oldStorage.data.NetworkController.networkConfigurationsByChainId,
167-
[CHAIN_IDS.MEGAETH_TESTNET]: cloneDeep(
168-
DEFAULT_CUSTOM_TESTNET_MAP[CHAIN_IDS.MEGAETH_TESTNET],
169-
),
182+
[megaEthChainId]: getMegaEthTestnetConfiguration(),
170183
},
171184
},
172185
};

app/scripts/migrations/146.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { hasProperty, isObject } from '@metamask/utils';
2-
import { cloneDeep } from 'lodash';
32
import {
4-
CHAIN_IDS,
5-
DEFAULT_CUSTOM_TESTNET_MAP,
6-
} from '../../../shared/constants/network';
3+
NetworkConfiguration,
4+
RpcEndpointType,
5+
} from '@metamask/network-controller';
6+
import {
7+
BlockExplorerUrl,
8+
BUILT_IN_CUSTOM_NETWORKS_RPC,
9+
ChainId,
10+
NetworkNickname,
11+
NetworksTicker,
12+
} from '@metamask/controller-utils';
13+
import { cloneDeep } from 'lodash';
714

815
type VersionedData = {
916
meta: { version: number };
@@ -33,9 +40,27 @@ function transformState(state: Record<string, unknown>) {
3340
isObject(state.NetworkController) &&
3441
isObject(state.NetworkController.networkConfigurationsByChainId)
3542
) {
43+
const megaethTestnet = 'megaeth-testnet';
44+
const megaethTestnetChainId = ChainId[megaethTestnet];
45+
const megaethTestnetConfiguration: NetworkConfiguration = {
46+
chainId: megaethTestnetChainId,
47+
name: NetworkNickname[megaethTestnet],
48+
nativeCurrency: NetworksTicker[megaethTestnet],
49+
blockExplorerUrls: [BlockExplorerUrl[megaethTestnet]],
50+
defaultRpcEndpointIndex: 0,
51+
defaultBlockExplorerUrlIndex: 0,
52+
rpcEndpoints: [
53+
{
54+
networkClientId: megaethTestnet,
55+
type: RpcEndpointType.Custom,
56+
url: BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET,
57+
},
58+
],
59+
};
60+
3661
state.NetworkController.networkConfigurationsByChainId[
37-
CHAIN_IDS.MEGAETH_TESTNET
38-
] = cloneDeep(DEFAULT_CUSTOM_TESTNET_MAP[CHAIN_IDS.MEGAETH_TESTNET]);
62+
megaethTestnetChainId
63+
] = megaethTestnetConfiguration;
3964
}
4065
return state;
4166
}

shared/constants/network.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import type {
2-
AddNetworkFields,
3-
NetworkConfiguration,
4-
} from '@metamask/network-controller';
1+
import type { AddNetworkFields } from '@metamask/network-controller';
52
import { RpcEndpointType } from '@metamask/network-controller';
63
import { capitalize, pick } from 'lodash';
74
import { Hex, hexToNumber } from '@metamask/utils';
@@ -1249,27 +1246,6 @@ export const FEATURED_NETWORK_CHAIN_IDS = [
12491246
...FEATURED_RPCS.map((rpc) => rpc.chainId),
12501247
];
12511248

1252-
/**
1253-
* A mapping for the default custom testnets.
1254-
*/
1255-
export const DEFAULT_CUSTOM_TESTNET_MAP: Record<Hex, NetworkConfiguration> = {
1256-
[CHAIN_IDS.MEGAETH_TESTNET]: {
1257-
chainId: CHAIN_IDS.MEGAETH_TESTNET,
1258-
name: MEGAETH_TESTNET_DISPLAY_NAME,
1259-
nativeCurrency: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.MEGAETH_TESTNET],
1260-
blockExplorerUrls: ['https://megaexplorer.xyz'],
1261-
defaultRpcEndpointIndex: 0,
1262-
defaultBlockExplorerUrlIndex: 0,
1263-
rpcEndpoints: [
1264-
{
1265-
networkClientId: 'megaeth-testnet',
1266-
url: 'https://carrot.megaeth.com/rpc',
1267-
type: RpcEndpointType.Custom,
1268-
},
1269-
],
1270-
},
1271-
};
1272-
12731249
export const infuraChainIdsTestNets: string[] = [
12741250
CHAIN_IDS.SEPOLIA,
12751251
CHAIN_IDS.HOLESKY,

test/e2e/mock-e2e.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -676,20 +676,6 @@ async function setupMocking(
676676
};
677677
});
678678

679-
await server
680-
.forGet('https://min-api.cryptocompare.com/data/pricemulti')
681-
.withQuery({ fsyms: 'ETH,MegaETH', tsyms: 'usd' })
682-
.thenCallback(() => {
683-
return {
684-
statusCode: 200,
685-
json: {
686-
ETH: {
687-
USD: ethConversionInUsd,
688-
},
689-
},
690-
};
691-
});
692-
693679
const PPOM_VERSION = fs.readFileSync(PPOM_VERSION_PATH);
694680
const PPOM_VERSION_HEADERS = fs.readFileSync(PPOM_VERSION_HEADERS_PATH);
695681
const CDN_CONFIG = fs.readFileSync(CDN_CONFIG_PATH);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { InternalAccount } from '@metamask/keyring-internal-api';
2+
import { isRemoteModeSupported } from './remote-mode';
3+
4+
describe('Remote Mode Utils', () => {
5+
describe('isRemoteModeSupported', () => {
6+
it('returns true for supported hardware wallet types', () => {
7+
const ledgerAccount: InternalAccount = {
8+
address: '0x12C7e...q135f',
9+
type: 'eip155:eoa',
10+
id: '1',
11+
options: {},
12+
metadata: {
13+
name: 'Ledger Hardware',
14+
importTime: 1717334400,
15+
keyring: {
16+
type: 'Ledger Hardware',
17+
},
18+
},
19+
scopes: [],
20+
methods: [],
21+
};
22+
23+
const latticeAccount: InternalAccount = {
24+
address: '0x12C7e...q135f',
25+
type: 'eip155:eoa',
26+
id: '2',
27+
options: {},
28+
metadata: {
29+
name: 'Lattice Hardware',
30+
importTime: 1717334400,
31+
keyring: {
32+
type: 'Lattice Hardware',
33+
},
34+
},
35+
scopes: [],
36+
methods: [],
37+
};
38+
39+
expect(isRemoteModeSupported(ledgerAccount)).toBe(true);
40+
expect(isRemoteModeSupported(latticeAccount)).toBe(true);
41+
});
42+
43+
it('returns false for unsupported hardware wallet types', () => {
44+
const unsupportedAccount: InternalAccount = {
45+
address: '0x12C7e...q135f',
46+
type: 'eip155:eoa',
47+
id: '3',
48+
options: {},
49+
metadata: {
50+
name: 'Some Other Wallet',
51+
importTime: 1717334400,
52+
keyring: {
53+
type: 'eip155',
54+
},
55+
},
56+
scopes: [],
57+
methods: [],
58+
};
59+
60+
expect(isRemoteModeSupported(unsupportedAccount)).toBe(false);
61+
});
62+
});
63+
});

ui/helpers/utils/remote-mode.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { InternalAccount } from '@metamask/keyring-internal-api';
2+
3+
const SUPPORTED_HARDWARE_WALLET_TYPES = ['Ledger Hardware', 'Lattice Hardware'];
4+
5+
export function isRemoteModeSupported(account: InternalAccount) {
6+
// todo: add check that account also implements signEip7702Authorization()
7+
return SUPPORTED_HARDWARE_WALLET_TYPES.includes(
8+
account.metadata.keyring.type,
9+
);
10+
}

ui/pages/pages.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@import 'snaps/snaps-list/index';
2222
@import 'snaps/snap-view/index';
2323
@import 'create-snap-account/index';
24+
@import 'remote-mode/setup/setup-swaps/index';
2425
@import 'remove-snap-account/index';
2526
@import 'swaps/index';
2627
@import 'bridge/index';

0 commit comments

Comments
 (0)