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

Initialize asset controllers with the current network #1361

Merged
merged 2 commits into from
May 11, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented May 10, 2023

Description

Certain controllers in @metamask/assets-controllers would default to assuming the current selected network was Ethereum Mainnet, or they'd default with an empty string as the chainId (causing errors if any methods were called). Instead they now all get initialized with the current chain ID, passed in as a new constructor parameter.

Affected controllers are:

  • AssetsContractController
  • NftController
  • NftDetectionController
  • TokenRatesController
  • TokensController

Changes

  • BREAKING: The following controllers now have a new chainId required constructor parameter:
    • AssetsContractController
    • NftController
    • NftDetectionController
    • TokenRatesController
    • TokensController

References

Relates to #1209

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation for new or updated code as appropriate (note: this will usually be JSDoc)
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@Gudahtt

This comment was marked as resolved.

@Gudahtt Gudahtt force-pushed the support-custom-rpc-mainnet-nft-detection branch 2 times, most recently from 1e825b7 to be06843 Compare May 10, 2023 18:12
Base automatically changed from support-custom-rpc-mainnet-nft-detection to main May 10, 2023 18:15
@Gudahtt Gudahtt force-pushed the initialize-asset-controllers-with-current-network branch from 04b418e to 76a0b37 Compare May 10, 2023 18:15
@Gudahtt Gudahtt marked this pull request as ready for review May 10, 2023 18:16
@Gudahtt Gudahtt requested a review from a team as a code owner May 10, 2023 18:16
@@ -122,7 +122,7 @@ export interface ApiNftCreator {
*/
export interface NftDetectionConfig extends BaseConfig {
interval: number;
chainId: `0x${string}` | `${number}` | number;
chainId: string;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is only ever set via the network controller provider config, so it has been updated to be just string, which is what the type is at the moment in the network controller. This will get more specific in an upcoming PR.

@Gudahtt Gudahtt force-pushed the initialize-asset-controllers-with-current-network branch from 76a0b37 to f9683e5 Compare May 10, 2023 19:16
@legobeat
Copy link
Contributor

Thank you for doing this, well-needed!

I note that each controller still inlines the default chainid. Do you think it would make sense to introduce a constant DEFAULT_CHAIN_ID in assets-controller that they can all use?

@Gudahtt
Copy link
Member Author

Gudahtt commented May 10, 2023

I note that each controller still inlines the default chainid

Hmm, I'm not aware of any examples of this. Maybe I missed some cases. They are intended to have no default chain ID.

mcmire
mcmire previously approved these changes May 10, 2023
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Makes sense!

Certain controllers in `@metamask/assets-controllers` would default to
assuming the current selected network was Ethereum Mainnet, or they'd
default with an empty string as the `chainId` (causing errors if any
methods were called). Instead they now all get initialized with the
current chain ID, passed in as a new constructor parameter.

Affected controllers are:
* `AssetsContractController`
* `NftController`
* `NftDetectionController`
* `TokenRatesController`
* `TokensController`

Relates to #1209
@Gudahtt Gudahtt force-pushed the initialize-asset-controllers-with-current-network branch from 9820305 to d11e953 Compare May 11, 2023 20:43
@Gudahtt Gudahtt merged commit c2ee6a2 into main May 11, 2023
@Gudahtt Gudahtt deleted the initialize-asset-controllers-with-current-network branch May 11, 2023 21:01
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Initialize asset controllers with the current network

Certain controllers in `@metamask/assets-controllers` would default to
assuming the current selected network was Ethereum Mainnet, or they'd
default with an empty string as the `chainId` (causing errors if any
methods were called). Instead they now all get initialized with the
current chain ID, passed in as a new constructor parameter.

Affected controllers are:
* `AssetsContractController`
* `NftController`
* `NftDetectionController`
* `TokenRatesController`
* `TokensController`

Relates to #1209

* Fix more tests
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Initialize asset controllers with the current network

Certain controllers in `@metamask/assets-controllers` would default to
assuming the current selected network was Ethereum Mainnet, or they'd
default with an empty string as the `chainId` (causing errors if any
methods were called). Instead they now all get initialized with the
current chain ID, passed in as a new constructor parameter.

Affected controllers are:
* `AssetsContractController`
* `NftController`
* `NftDetectionController`
* `TokenRatesController`
* `TokensController`

Relates to #1209

* Fix more tests
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.

3 participants