Skip to content

Commit

Permalink
feat: add new default networks
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Oct 21, 2024
1 parent 71ce22f commit ca47c0e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ import OptionsSheet from '../../UI/SelectOptionSheet/OptionsSheet';
import FoxLoader from '../../../components/UI/FoxLoader';
import { AppStateEventProcessor } from '../../../core/AppStateEventListener';
import MultiRpcModal from '../../../components/Views/MultiRpcModal/MultiRpcModal';
import Engine from '../../../core/Engine';
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { PopularList } from '../../../util/networks/customNetworks';
import { RpcEndpointType } from '@metamask/network-controller';

const clearStackNavigatorOptions = {
headerShown: false,
Expand Down Expand Up @@ -528,6 +532,47 @@ const App = (props) => {
useEffect(() => {
async function startApp() {
const existingUser = await StorageWrapper.getItem(EXISTING_USER);
if (!existingUser) {
// List of chainIds to add (as hex strings)
const chainIdsToAdd = [
CHAIN_IDS.ARBITRUM,
CHAIN_IDS.BASE,
CHAIN_IDS.BSC,
CHAIN_IDS.OPTIMISM,
CHAIN_IDS.POLYGON,
];

// Filter the PopularList to get only the specified networks based on chainId
const selectedNetworks = PopularList.filter((network) =>
chainIdsToAdd.includes(network.chainId),
);
const { NetworkController } = Engine.context;

// Loop through each selected network and call NetworkController.addNetwork
for (const network of selectedNetworks) {
try {
await NetworkController.addNetwork({
chainId: network.chainId,
blockExplorerUrls: [network.rpcPrefs.blockExplorerUrl],
defaultRpcEndpointIndex: 0,
defaultBlockExplorerUrlIndex: 0,
name: network.nickname,
nativeCurrency: network.ticker,
rpcEndpoints: [
{
url: network.rpcUrl,
name: network.nickname,
type: RpcEndpointType.Custom,
},
],
});
console.log(`Successfully added network: ${network.nickname}`);

Check failure on line 569 in app/components/Nav/App/index.js

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected console statement
} catch (error) {
Logger.error(error);
}
}
}

try {
const currentVersion = getVersion();
const savedVersion = await StorageWrapper.getItem(CURRENT_APP_VERSION);
Expand Down

0 comments on commit ca47c0e

Please sign in to comment.