Skip to content

upgrade NetworkController to V20#395

Merged
kanthesha merged 5 commits intomainfrom
feat/network-controller-upgrade-to-v20
Jul 30, 2024
Merged

upgrade NetworkController to V20#395
kanthesha merged 5 commits intomainfrom
feat/network-controller-upgrade-to-v20

Conversation

@kanthesha
Copy link
Copy Markdown
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.

@socket-security
Copy link
Copy Markdown

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/network-controller@20.0.0 environment 0 410 kB metamaskbot
npm/loglevel@1.9.1 None 0 639 kB pimterry

🚮 Removed packages: npm/@metamask/network-controller@19.0.0

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 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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