Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 300
chore(assets-controllers): add isDeprecated to TokenDetectionController#9362
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
Merged
Prithpal-Sooriya
merged 8 commits into
main
from
cursor/deprecate-token-detection-controller-553eJul 21, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad39f1b
chore(assets-controllers): add isDeprecated to TokenDetectionController
cursoragent 4eeb735
docs(assets-controllers): link changelog entry to PR #9362
cursoragent 4d7b9b6
style(assets-controllers): fix oxfmt formatting in TokenDetectionCont…
cursoragent 97ddaa4
Merge branch 'main' into cursor/deprecate-token-detection-controller-…
cursoragent e905f2d
docs(assets-controllers): shorten isDeprecated JSDoc per review
cursoragent 059517e
fix(assets-controllers): reset state in TokenDetectionController enfo…
cursoragent 20b5667
fix(assets-controllers): keep polling when TokenDetectionController i…
cursoragent 45e2a28
Merge branch 'main' into cursor/deprecate-token-detection-controller-…
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
270 changes: 270 additions & 0 deletions
270 packages/assets-controllers/src/TokenDetectionController.test.ts
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37 packages/assets-controllers/src/TokenDetectionController.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -204,6 +204,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| readonly #useExternalServices: () => boolean; | ||
| readonly #isDeprecated: () => boolean; | ||
| readonly #getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall']; | ||
| readonly #trackMetaMetricsEvent: (options: { | ||
| @@ -230,6 +232,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| * @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking. | ||
| * @param options.useTokenDetection - Feature Switch for using token detection (default: true) | ||
| * @param options.useExternalServices - Feature Switch for using external services (default: false) | ||
| * @param options.isDeprecated - Optional callback that disables token detection when it returns true. | ||
| */ | ||
| constructor({ | ||
| interval = DEFAULT_INTERVAL, | ||
| @@ -240,6 +243,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| tokenListService, | ||
| useTokenDetection = (): boolean => true, | ||
| useExternalServices = (): boolean => true, | ||
| isDeprecated = (): boolean => false, | ||
| }: { | ||
| interval?: number; | ||
| disabled?: boolean; | ||
| @@ -259,6 +263,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| tokenListService: TokenListService; | ||
| useTokenDetection?: () => boolean; | ||
| useExternalServices?: () => boolean; | ||
| isDeprecated?: () => boolean; | ||
| }) { | ||
| super({ | ||
| name: controllerName, | ||
| @@ -290,10 +295,22 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| this.#useTokenDetection = useTokenDetection; | ||
| this.#useExternalServices = useExternalServices; | ||
| this.#isDeprecated = isDeprecated; | ||
| if (this.#isDeprecated()) { | ||
| this.#enforceDisabledState(); | ||
| } | ||
| this.#registerEventListeners(); | ||
| } | ||
| #enforceDisabledState(): void { | ||
| if (Object.keys(this.state).length === 0) { | ||
| return; | ||
| } | ||
| this.update(() => ({})); | ||
| } | ||
| /** | ||
| * Constructor helper for registering this controller's messenger subscriptions to controller events. | ||
| */ | ||
| @@ -390,6 +407,10 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| * Start polling for detected tokens. | ||
| */ | ||
| async start(): Promise<void> { | ||
| if (this.#isDeprecated()) { | ||
| this.#enforceDisabledState(); | ||
| return; | ||
| } | ||
Prithpal-Sooriya marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| this.enable(); | ||
| await this.#startPolling(); | ||
| } | ||
| @@ -459,6 +480,10 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| chainIds, | ||
| address, | ||
| }: TokenDetectionPollingInput): Promise<void> { | ||
| if (this.#isDeprecated()) { | ||
| this.#enforceDisabledState(); | ||
| return; | ||
| } | ||
| if (!this.isActive) { | ||
| return; | ||
| } | ||
| @@ -574,6 +599,10 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| selectedAddress?: string; | ||
| forceRpc?: boolean; | ||
| } = {}): Promise<void> { | ||
| if (this.#isDeprecated()) { | ||
| this.#enforceDisabledState(); | ||
| return; | ||
| } | ||
| if (!this.isActive) { | ||
| return; | ||
| } | ||
| @@ -886,6 +915,10 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| tokensSlice: string[]; | ||
| chainId: Hex; | ||
| }): Promise<void> { | ||
| if (this.#isDeprecated()) { | ||
| this.#enforceDisabledState(); | ||
| return; | ||
| } | ||
| // Check if token detection is enabled via preferences | ||
| if (!this.#useTokenDetection()) { | ||
| return; | ||
| @@ -992,6 +1025,10 @@ export class TokenDetectionController extends StaticIntervalPollingController<To | ||
| tokensSlice: string[]; | ||
| chainId: Hex; | ||
| }): Promise<void> { | ||
| if (this.#isDeprecated()) { | ||
| this.#enforceDisabledState(); | ||
| return; | ||
| } | ||
| // Check if token detection is enabled via preferences | ||
| if (!this.#useTokenDetection()) { | ||
| return; | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.