-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Use networkClientId in AssetsContractController #1638
Use networkClientId in AssetsContractController #1638
Conversation
@@ -93,6 +94,7 @@ export class AssetsContractController extends BaseController< | |||
chainId: initialChainId, | |||
onPreferencesStateChange, | |||
onNetworkStateChange, | |||
getNetworkClientById, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about how many controllers will need to do this, maybe we should expose this method over the controller messenger so that the order of creation of the controllers doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to apply this pattern to the other controllers in core? If so, can we address this in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do as part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssetsContractController is V1 BaseController. So will have to follow this dependency injection pattern for now still
EDIT: exposing getNetworkClientById
action from NetworkController in this PR
packages/assets-controllers/src/AssetsContractController.test.ts
Outdated
Show resolved
Hide resolved
packages/assets-controllers/src/AssetsContractControllerWithNetworkClientId.test.ts
Show resolved
Hide resolved
packages/assets-controllers/src/AssetsContractControllerWithNetworkClientId.test.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits but nothing blocking. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good stuff! LGTM
## Explanation `AssetsContractController` currently relies on the proxied provider and `onNetworkStateChange` listener to ensure it is performing checks against the correct network. As part of multichain efforts, we want to decouple this controller from the notion of a single active network. We do this by adding an optional `networkClientId` argument to each of the external facing methods. This arg is used to resolve to a `NetworkClient` from the `NetworkController` when set. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References * Fixes [mmp-1021](MetaMask/MetaMask-planning#1021) <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? For example: * Fixes #12345 * Related to #67890 --> ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/network-controller` - **ADDED**: `NetworkController` exposes `getNetworkClientById()` in a `NetworkController:getNetworkClientById` action ### `@metamask/assets-controllers` - **ADDED**: `AssetsContractController` constructor options requires `getNetworkClientById` - **CHANGED**: `AssetsContractController.getERC20BalanceOf()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC20TokenDecimals()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC20TokenName()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721NftTokenId()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getTokenStandardAndDetails()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721TokenURI()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721AssetName()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721AssetSymbol()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721OwnerOf()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC1155TokenURI()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC1155BalanceOf()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.transferSingleERC1155()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getBalancesInSingleCall()` accepts optional `networkClientId` ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate --------- Co-authored-by: Alex Donesky <adonesky@gmail.com>
## Explanation `AssetsContractController` currently relies on the proxied provider and `onNetworkStateChange` listener to ensure it is performing checks against the correct network. As part of multichain efforts, we want to decouple this controller from the notion of a single active network. We do this by adding an optional `networkClientId` argument to each of the external facing methods. This arg is used to resolve to a `NetworkClient` from the `NetworkController` when set. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References * Fixes [mmp-1021](MetaMask/MetaMask-planning#1021) <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? For example: * Fixes #12345 * Related to #67890 --> ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/network-controller` - **ADDED**: `NetworkController` exposes `getNetworkClientById()` in a `NetworkController:getNetworkClientById` action ### `@metamask/assets-controllers` - **ADDED**: `AssetsContractController` constructor options requires `getNetworkClientById` - **CHANGED**: `AssetsContractController.getERC20BalanceOf()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC20TokenDecimals()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC20TokenName()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721NftTokenId()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getTokenStandardAndDetails()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721TokenURI()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721AssetName()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721AssetSymbol()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC721OwnerOf()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC1155TokenURI()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getERC1155BalanceOf()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.transferSingleERC1155()` accepts optional `networkClientId` - **CHANGED**: `AssetsContractController.getBalancesInSingleCall()` accepts optional `networkClientId` ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate --------- Co-authored-by: Alex Donesky <adonesky@gmail.com>
…Preferences Controller of the controllers 77 version for being able to build, also change tsconfigbuild json to only build assets controllers
Explanation
AssetsContractController
currently relies on the proxied provider andonNetworkStateChange
listener to ensure it is performing checks against the correct network. As part of multichain efforts, we want to decouple this controller from the notion of a single active network. We do this by adding an optionalnetworkClientId
argument to each of the external facing methods. This arg is used to resolve to aNetworkClient
from theNetworkController
when set.References
Changelog
@metamask/network-controller
NetworkController
exposesgetNetworkClientById()
in aNetworkController:getNetworkClientById
action@metamask/assets-controllers
AssetsContractController
constructor options requiresgetNetworkClientById
AssetsContractController.getERC20BalanceOf()
accepts optionalnetworkClientId
AssetsContractController.getERC20TokenDecimals()
accepts optionalnetworkClientId
AssetsContractController.getERC20TokenName()
accepts optionalnetworkClientId
AssetsContractController.getERC721NftTokenId()
accepts optionalnetworkClientId
AssetsContractController.getTokenStandardAndDetails()
accepts optionalnetworkClientId
AssetsContractController.getERC721TokenURI()
accepts optionalnetworkClientId
AssetsContractController.getERC721AssetName()
accepts optionalnetworkClientId
AssetsContractController.getERC721AssetSymbol()
accepts optionalnetworkClientId
AssetsContractController.getERC721OwnerOf()
accepts optionalnetworkClientId
AssetsContractController.getERC1155TokenURI()
accepts optionalnetworkClientId
AssetsContractController.getERC1155BalanceOf()
accepts optionalnetworkClientId
AssetsContractController.transferSingleERC1155()
accepts optionalnetworkClientId
AssetsContractController.getBalancesInSingleCall()
accepts optionalnetworkClientId
Checklist