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

Convert TokenRatesController from BaseControllerV1 to BaseControllerV2 #4076

Closed
desi opened this issue Mar 18, 2024 · 1 comment · Fixed by #4314
Closed

Convert TokenRatesController from BaseControllerV1 to BaseControllerV2 #4076

desi opened this issue Mar 18, 2024 · 1 comment · Fixed by #4314
Assignees

Comments

@desi
Copy link
Contributor

desi commented Mar 18, 2024

Considering that converting TokenDetectionController to BaseController v2 took longer than expected due to unforeseen changes, we want to be more conscientious about converting TokenRatesController.

Figure out all of the changes we would want to make in upgrading this controller, outline those changes here and create new tickets if appropriate.

@desi desi changed the title (assets-controllers) TokenRatesController Convert TokenRatesController from BaseControllerV1 to BaseControllerV2 Mar 18, 2024
@mikesposito
Copy link
Member

  • The TokenRatesController class can extend the StaticIntervalPollingController “mixin” type, which extends BaseControllerV2.
  • StaticIntervalPollingController will accept type parameters needed for BaseControllerV2 (name, state and messenger types)
    • We can rename TokenRatesConfig to TokenRatesControllerConfig
    • We can rename TokenRatesState to TokenRatesControllerState
    • We should add types for actions and events needed by the TokenRatesController messengers
      • It would be useful for external clients to have access to a start and a stop action to toggle the polling
  • Since we can now use the messenger, we can remove these constructor options in favour of messenger events or actions:
    • getNetworkClientById
    • onPreferencesStateChange
    • onTokensStateChange
    • onNetworkStateChange
  • Tests should be refactored to support the new controller version
    • In addition to that, we can create a withController helper to make tests more readable and easier to be maintained

@kanthesha kanthesha self-assigned this Apr 29, 2024
@github-project-automation github-project-automation bot moved this to Needs dev review in PR review queue May 24, 2024
kanthesha added a commit that referenced this issue Jun 8, 2024
## Explanation

<!--
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?
-->

In this, the TokenRatesController has been upgraded to BaseControllerV2.
The upgrade includes TokenRatesController inheriting BaseController v2
instead of BaseController v1. This affects the constructor and the also
the way state is updated inside the controller, but it also prompts
other changes:

This also includes the changes to the unit tests, so that all the tests
uses `withController` pattern.

## References

<!--
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
-->
Fixes #4076 

## 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/assets-controller`
### Added

- New types for `TokenRatesController `messenger actions 
  - `TokenRatesControllerGetStateAction`
- New types for `TokenRatesController` messenger events
  - `TokenRatesControllerStateChangeEvent`

### Changed

- **BREAKING:** Changed superclass of `TokenRatesController` from
BaseController v1 to BaseController v2
- **BREAKING:** Renamed `TokenRatesState` to `TokenRatesControllerState`

### Removed

- **BREAKING:** Removed `TokenRatesConfig` type

## 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
@github-project-automation github-project-automation bot moved this from Needs dev review to Merged, Closed or Archived in PR review queue Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Merged, Closed or Archived
Development

Successfully merging a pull request may close this issue.

3 participants