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

Use networkClientId in AssetsContractController #1638

Merged
merged 14 commits into from
Sep 13, 2023

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Aug 28, 2023

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.

References

Changelog

@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

  • 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

@jiexi jiexi requested a review from a team as a code owner August 28, 2023 22:48
@jiexi jiexi marked this pull request as draft August 28, 2023 22:49
@jiexi jiexi marked this pull request as ready for review August 29, 2023 17:00
@jiexi jiexi requested review from mcmire and BelfordZ August 29, 2023 17:01
@jiexi jiexi changed the title Jl/mmp 1021/multichain v1 assets contract controller Use networkClientId in AssetsContractController Sep 7, 2023
@@ -93,6 +94,7 @@ export class AssetsContractController extends BaseController<
chainId: initialChainId,
onPreferencesStateChange,
onNetworkStateChange,
getNetworkClientById,
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

@jiexi jiexi Sep 11, 2023

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

adonesky1
adonesky1 previously approved these changes Sep 12, 2023
Copy link
Contributor

@adonesky1 adonesky1 left a 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

Copy link
Contributor

@BelfordZ BelfordZ left a comment

Choose a reason for hiding this comment

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

good stuff! LGTM

@adonesky1 adonesky1 merged commit f39b18b into main Sep 13, 2023
99 checks passed
@adonesky1 adonesky1 deleted the jl/mmp-1021/multichain-v1-assets-contract-controller branch September 13, 2023 18:41
@Gudahtt Gudahtt mentioned this pull request Sep 21, 2023
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
## 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>
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
## 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>
tommasini added a commit that referenced this pull request Mar 20, 2024
…Preferences Controller of the controllers 77 version for being able to build, also change tsconfigbuild json to only build assets controllers
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.

4 participants