Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new default networks #11926

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 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 @@ -753,6 +757,46 @@ 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,
},
],
});
} catch (error) {
Logger.error(error);
}
}
}
Comment on lines +780 to +807
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if networksToAdd is more accurate, because the networks are not really selected, wdyt?

Suggested change
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,
},
],
});
} catch (error) {
Logger.error(error);
}
}
}
const networksToAdd = PopularList.filter((network) =>
chainIdsToAdd.includes(network.chainId),
);
const { NetworkController } = Engine.context;
// Loop through each selected network and call NetworkController.addNetwork
for (const network of networksToAdd) {
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,
},
],
});
} catch (error) {
Logger.error(error);
}
}
}


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