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

Conversation

salimtb
Copy link
Contributor

@salimtb salimtb commented Oct 21, 2024

Description

This PR ensures that a predefined list of popular networks (Arbitrum, BSC, Base, Optimism, and Polygon) is automatically added for new users only during the app startup process. The networks are added using NetworkController.addNetwork within the useEffect hook inside the app's initialization flow.

Related issues

Fixes:

Manual testing steps

  1. Do a new fresh install app
  2. Import/create your wallet
  3. check the list of added networks

Screenshots/Recordings

Before

Screenshot 2024-10-21 at 20 02 38

After

Screenshot 2024-10-21 at 19 56 59

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@salimtb salimtb added team-assets needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. labels Oct 21, 2024
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@salimtb salimtb changed the title Salim/add new default networks feat: add new default networks Oct 21, 2024
@salimtb salimtb force-pushed the salim/add-new-default-networks branch from ca47c0e to cdf1c3d Compare October 21, 2024 17:46
@salimtb salimtb force-pushed the salim/add-new-default-networks branch from cdf1c3d to 644a541 Compare October 21, 2024 17:51
@salimtb salimtb added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 21, 2024
@MetaMask MetaMask deleted a comment from github-actions bot Oct 22, 2024
@salimtb salimtb added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 22, 2024
Copy link
Contributor

github-actions bot commented Oct 22, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: d124a74
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/568ed606-1ae5-4bca-8752-d50787757d8b

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@salimtb salimtb marked this pull request as ready for review October 22, 2024 13:42
@salimtb salimtb requested a review from a team as a code owner October 22, 2024 13:42
@salimtb
Copy link
Contributor Author

salimtb commented Oct 23, 2024

gambinish
gambinish previously approved these changes Oct 23, 2024
Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

Same question about Promise.all here, but code lgtm. Also pulled down and behavior is as expected ✅

@salimtb
Copy link
Contributor Author

salimtb commented Oct 24, 2024

Same question about Promise.all here, but code lgtm. Also pulled down and behavior is as expected ✅

hey @gambinish , regarding the use of promise all, it's possible on extension since he networkSorting is managed by sortedNetworks , but for mobile , we don't have this and we want to add the networks on a certain order.
so i'm going to do it just for extension

Copy link

sonarcloud bot commented Oct 24, 2024

Comment on lines +780 to +807
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);
}
}
}
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);
}
}
}

Copy link
Contributor

@tommasini tommasini left a comment

Choose a reason for hiding this comment

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

It looks good to me!

I wonder if there is a plan to deprecate this code and add this to all the users?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. Run Smoke E2E Triggers smoke e2e on Bitrise team-assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants