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

upgrade NetworkController to V20 #395

Merged
merged 5 commits into from
Jul 30, 2024

Conversation

kanthesha
Copy link
Contributor

Upgrade the @metamask/network-controller to v20. @metamask/network-controller 20.0.0 removed providerConfig from state, which means that we now need to use selectedNetworkClientId to access the chain ID for the currently selected network. And we no longer need to take provider, instead get this from the network client object.

Copy link

socket-security bot commented Jul 29, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] environment 0 410 kB metamaskbot
npm/[email protected] None 0 639 kB pimterry

🚮 Removed packages: npm/@metamask/[email protected]

View full report↗︎

@kanthesha kanthesha marked this pull request as ready for review July 29, 2024 15:18
@kanthesha kanthesha requested a review from a team as a code owner July 29, 2024 15:18
Comment on lines 192 to 204
onNetworkStateChange((networkState) => {
const { selectedNetworkClientId } = networkState;
const networkClient = this.getNetworkClientById(selectedNetworkClientId);
const { chainId } = networkClient.configuration;
const isNewChainId = chainId !== this.config.chainId;
this.configure({ chainId });
this.initializeSmartTransactionsForChainId();
if (isNewChainId) {
this.#ensureUniqueSmartTransactions();
}
this.checkPoll(this.state);
this.ethQuery = new EthQuery(provider);
this.ethQuery = new EthQuery(networkClient.provider);
});
Copy link
Contributor

@cryptodev-2s cryptodev-2s Jul 29, 2024

Choose a reason for hiding this comment

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

Nit: Could we do it this way instead? The only difference is fewer rows and earlier deconstruction ?

Suggested change
onNetworkStateChange((networkState) => {
const { selectedNetworkClientId } = networkState;
const networkClient = this.getNetworkClientById(selectedNetworkClientId);
const { chainId } = networkClient.configuration;
const isNewChainId = chainId !== this.config.chainId;
this.configure({ chainId });
this.initializeSmartTransactionsForChainId();
if (isNewChainId) {
this.#ensureUniqueSmartTransactions();
}
this.checkPoll(this.state);
this.ethQuery = new EthQuery(provider);
this.ethQuery = new EthQuery(networkClient.provider);
});
onNetworkStateChange(({ selectedNetworkClientId }) => {
const {
configuration: { chainId },
provider,
} = this.getNetworkClientById(selectedNetworkClientId);
const isNewChainId = chainId !== this.config.chainId;
this.configure({ chainId });
this.initializeSmartTransactionsForChainId();
if (isNewChainId) {
this.#ensureUniqueSmartTransactions();
}
this.checkPoll(this.state);
this.ethQuery = new EthQuery(provider);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

Looks good to me, there's just one minor change proposed

Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

LGTM!

@kanthesha kanthesha merged commit b55fa2d into main Jul 30, 2024
16 checks passed
@kanthesha kanthesha deleted the feat/network-controller-upgrade-to-v20 branch July 30, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade @metamask/network-controller from v19 to v20
2 participants