feat: retrieve global provider and block tracker dynamically
[!NOTE] This PR is a commandeer of @matthewwalsh0's https://github.com/MetaMask/core/pull/4004.
This PR has been deprioritized. We are coordinating with the multichain team to figure out the best time to address it.
Explanation (by @matthewwalsh0)
Currently the global provider and blockTracker instances are required as constructor options in the TransactionController.
This means the clients must have the global provider available when the controller instance is created, usually on startup.
In order to support construction of the TransactionController before these are available, to facilitate use cases such as disabling provider access until onboarding is complete, this PR does the following:
- Removes the
providerandblockTrackerconstructor options. - Adds the
getGlobalProviderAndBlockTrackercallback option. - Updates all usages of the global network to retrieve the network client dynamically when required.
- Updates all relevant public methods and helper classes to either gracefully ignore a missing network client, or throw an error.
- Replace the
blockTracker,getEthQueryandchainIdconstructor options in the helper classes with a singlegetNetworkClientoption since all the previous values are either all available or all unavailable, meaning the associated validation becomes much simpler. - Dynamically create the global
nonceTrackerwhen first used since it is an alternate package and still requires aproviderargument. - Dynamically create the
MethodRegistryinstance since it is also an alternate package and requires aproviderargument. - Move the
onBootCleanuplogic into the public methodinitApprovedTransactionsso it can be called by the client explicitly when suitable. - Fix logger used by
MultichainTrackingHelper.
Note that any additional complexity or logic surrounding the global network specifically is temporary and can be removed once the clients enable the multichain flag, at which point all network clients and helpers will be dynamically synchronised with the NetworkController state.
Changelog
@metamask/transaction-controller
[PENDING]
Checklist
- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category above as appropriate
Looking at the existing tests, the existing set up with the block tracker and multiple providers looks s bit weird.
- #4345
@dbrans Any progress or blockers here?
- Closing this PR in favor on #4004