-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Upgrade TokenDetectionController
to extend BaseControllerV2
, StaticIntervalPollingController
#3609
Merged
MajorLift
merged 95 commits into
main
from
231201-token-detection-controller-basecontrollerv2-migration
Dec 22, 2023
Merged
Changes from 84 commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
d595d0f
Define types for BaseControllerV2 migration
MajorLift 56ca692
Upgrade `TokenDetectionController` to extend from `PollingController`
MajorLift 25ae501
Replace event handlers with controller-messenger pattern
MajorLift d42cc0f
[token-list-controller] Export `TokenListControllerMessenger` and def…
MajorLift 0a66c50
Explicitly enumerate package-level exports
MajorLift 1b5b635
Move `TokenDetectionConfig` properties to private class fields in `To…
MajorLift 94448cd
Define `controllerName`, `TokenDetectionState` as empty object, remov…
MajorLift bcfa0a1
Fix: unregister internal `getState` action handler in constructor as …
MajorLift b8dcf32
Fix `sliceOfTokensToDetect` logic to handle arbitrary number of `toke…
MajorLift a5ef650
Various fixes for controller upgrade
MajorLift 72b3618
Adapt tests to align with upgraded `TokenDetectionController` API
MajorLift 2f74472
Fix test to avoid using deprecated aurora network
MajorLift 720dc69
Assume that `getTokensState` never returns `undefined`
MajorLift 74f74ba
Remove unnecessary cleanup function calls
MajorLift 7b3d4e4
Add jsdoc for test utility functions
MajorLift 2bef9b8
Fix unnecessary `await`
MajorLift 9c8491a
Use new network-controller action/event
MajorLift 05ed86b
Fix tests
MajorLift 8964e0d
Move `unregisterActionhandler` calls for `TokenDetectionController:ge…
MajorLift 26509c1
Remove `disabled` class field entirely
MajorLift cb2bd08
Remove unnecessary `tokenDetect.start()` calls from tests
MajorLift 9244803
Record CHANGELOG entries
MajorLift 1274137
Reorder constructor assignments
MajorLift 0c0476c
Await all `detectTokens()` calls
MajorLift 8dc1fcd
Test fixes
MajorLift bb43ebb
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift fdb70d9
Add `deferPollingStart` property
MajorLift 98e8d17
Fix test
MajorLift 8ad12b5
Fix test to avoid implicitly calling `detectTokens()`
MajorLift 5e94d13
Fix `#getCorrectChainId` and polygon network test to pull network con…
MajorLift a5ebc52
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift a2007f6
Update jest coverage thresholds
MajorLift 3532bbc
Remove `deferPollingStart` constructor option
MajorLift 6601dcc
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 322d074
Add controller types to package-level exports
MajorLift b60ada5
Update CHANGELOG records
MajorLift 599da4d
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 6c22a3a
Update jest coverage thresholds
MajorLift a26d568
Mock action handler return value instead of registering multiple hand…
MajorLift 85e3f10
Remove unregister action handler call in constructor and define `befo…
MajorLift e1a061a
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift b9cbcba
Revert "Fix `sliceOfTokensToDetect` logic to handle arbitrary number …
MajorLift 4322102
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift fb7cbe2
set polygon network as rpc in test
MajorLift 5d602a3
Fix test so that `preferencesStateChangeListener` triggers `detectTok…
MajorLift a41a218
Add `#networkClientId` class field and update using `seletedNetworkCl…
MajorLift 7e52c7c
Update CHANGELOG to reflect 'Revert "Fix `sliceOfTokensToDetect` logi…
MajorLift e7dac31
Update jsdoc for class fields
MajorLift 15f8922
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 15ea19c
Fix mistaken assignment of chainId to networkClientId property
MajorLift 3e1416d
Revert "Add `#networkClientId` class field and update using `seletedN…
MajorLift 123aff5
Revert "Fix test so that `preferencesStateChangeListener` triggers `d…
MajorLift 7f2e58b
Fix test so that `preferencesStateChangeListener` triggers `detectTok…
MajorLift d32cdf4
Add `#networkClientId` class field and update using `seletedNetworkCl…
MajorLift 9167cac
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 71d9967
Fix test by publishing `networkDidChange` event in `changeNetwork` he…
MajorLift 0dda603
Add `#disabled` class field to ensure that passive token detection is…
MajorLift c5eec25
Adjust jest coverage thresholds
MajorLift 1337d19
Update packages/assets-controllers/src/TokenDetectionController.test.ts
MajorLift 41f85a1
Update packages/assets-controllers/CHANGELOG.md
MajorLift 8c331fa
Edit test descriptions so that `getBalancesInSingleMock` is subject
MajorLift d40247e
Fix incorrect package-level export
MajorLift 757ab04
[tokens-controller] Add actions `getState`, `addDetectedTokens` and e…
MajorLift 44e92cb
Replace `getTokensState`, `addDetectedTokens` callbacks with messenge…
MajorLift 4b0bda3
Make `detectTokens` take empty options object as default argument
MajorLift a007d15
Remove assignment to `#chainId` in `#getCorrectChainId`
MajorLift f5e6611
Edit test description
MajorLift b2a5af5
Update changelog
MajorLift eadf3ba
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift aa9e3ba
Adjust jest coverage thresholds
MajorLift f636e25
Revert "Fix incorrect package-level export"
MajorLift 173168f
Use `getNetworkClientById` action in `#getCorrectChainId` method
MajorLift d81c23d
Replace `chainId` with `networkClientId` in constructor options.
MajorLift d9bd4b1
Remove `getNetworkConfigurationByClientId` handler from tests
MajorLift fefc64b
test: adjust `getNetworkClientById` handler to return polygon chainId
MajorLift 73eccbf
test: remove unnecessary `.start()` calls
MajorLift 5fe7674
Add `disabled` as constructor option and set it to block `#startPolli…
MajorLift 116a227
Adjust jest coverage thresholds
MajorLift acd022f
Remove unused comment
MajorLift ee2154d
test: Restore publishes for `networkDidChange` event, mock polygon ne…
MajorLift cfbd787
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 21f9b8c
Adjust jest coverage thresholds
MajorLift de94761
Revert "[tokens-controller] Add actions `getState`, `addDetectedToken…
MajorLift 4b6c1d2
test: Apply 'Revert "[tokens-controller] Add actions `getState`, `add…
MajorLift a951492
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 541f8f4
Adjust jest coverage threshold
MajorLift 798bb09
Use `getNetworkConfigurationByNetworkClientId` to replace `getNetwork…
MajorLift 1552041
Remove throw error in `_executePoll`
MajorLift 2451982
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift 6d020bc
Adjust jest coverage threshold
MajorLift 05cf2bd
Set `disabled` to true by default and add `enable`, `disable` methods
MajorLift d8ced01
Revert "test: remove unnecessary `.start()` calls"
MajorLift 16e8bad
test: Adjust tests to `disabled` being true by default
MajorLift f67bead
Update changelog
MajorLift 8e1cdf5
Merge branch 'main' into 231201-token-detection-controller-basecontro…
MajorLift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Which option was this?
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.
Ah, I used "polling" here to include passively calling
detectTokens
(i.e.executePoll
), which is definitely confusing. Also, the disabled option was previously true by default, which makes the current API a breaking change. Thoughts on the following?I guess whether to keep this change would depend on the expected behavior of polling controllers upon initialization. If we're going to use a dedicated service for network calls and let it handle blocking outgoing requests, perhaps it makes sense to enable passive updates in the polling controller itself?
But if this is disruptive to the current implementation I can revert the default value for
disabled
. It will require some changes in the tests, probably including restoring thesestart
calls: 73eccbf.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'd prefer that we keep the current default, and consider changing this independently even if we do want to. Better to minimize scope of we can.
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.
One issue with doing that is that the new
startPollingByNetworkClientId
method is now blocked by default in this controller, and requires thedisabled
flag to be flipped before it can work.#disabled
class field public or adding a setter method seems unsafe and not in keeping with the idea of having this be controlled by a network service,disabled: false
prior to makingstartPollingByNetworkClientId
calls seems like overkill and bad design,start
to be called beforestartPollingByNetworkClientId
calls seems redundant and unintuitive,disabled
property, so lifting the disabled property itself toStaticIntervalPollingController
would require more changes that are out of scope.I'm not sure how to proceed with this off the top of my head. I'll give it some more thought.
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 see what you mean, this is a bit tricky. I guess this dilemma was introduced with these new polling functions, but made worse with this change because runtime config modification is no longer possible.
For the
CurrencyRateController
, the DevEx team decided to deal with this by callingstopAllPolling
when the UI closes. So they didn't need to use the disabled state for the newer polling API. But this is problematic because now those polls won't be going anymore when the UI re-opens, even if they might still be needed.The easiest solution would be to make it possible to update
disabled
at runtime. I don't know what you meant about that seeming unsafe, nor do I understand what you're referring to by "not in keeping with the idea of having this be controlled by a network service".Longer-term I'd like us to take these services out of the controller altogether, so that there is never a need to disable the controller. @mcmire and I have also discussed adding a "pause" method to the polling controller, so that they can be paused and unpaused without being deregistered (this idea was from before the service refactor was discussed, I am unsure if we still need this). But both of those ideas seem fairly substantial, I am guessing that we'd be better off trying to land this first, now that this work is already done.
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 referring to the longer-term solution you mentioned, but I can see that trying to anticipate those changes is premature at this point.
I added a
disable
andenable
method for now: 05cf2bd. Does this seem like a good approach?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.
Looks reasonable to me!
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.
Could use additional tests for those two new methods though