-
-
Notifications
You must be signed in to change notification settings - Fork 267
feat(AssetController): add hiddenAssets state #7777
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
base: main
Are you sure you want to change the base?
Conversation
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.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
| this.state.hiddenAssets[accountId]?.includes(normalizedAssetId) ?? false | ||
| ); | ||
| } | ||
|
|
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.
getAssets does not filter out hidden assets
High Severity
The hideAsset method's JSDoc states "Hidden assets are excluded from the asset list returned by getAssets", but #getAssetsFromState doesn't actually filter hidden assets. The method iterates through accountBalances and filters by chain, metadata, and asset type, but never checks this.state.hiddenAssets[account.id] to skip hidden assets. Users who hide assets will still see them returned by getAssets(), completely defeating the feature's purpose.
Additional Locations (1)
| return ( | ||
| this.state.hiddenAssets[accountId]?.includes(normalizedAssetId) ?? false | ||
| ); | ||
| } |
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.
Method isAssetHidden is defined but never used
Low Severity
The isAssetHidden() method is defined but never used anywhere in the codebase. Unlike the other hidden asset methods (hideAsset, unhideAsset, getHiddenAssets), this method has no corresponding action type defined and is not registered as a messenger action handler. It cannot be called via the messenger pattern and is never called internally. This appears to be dead code that was added but never integrated.
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.
not a huge deal, we can add some tests to cover this.
| if (hiddenAssets.has(assetId)) { | ||
| continue; | ||
| } |
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.
Hmm does this mean we don't fetch and update balances for hidden assets?
Might be problematic for the swaps flow (you could be trying to swap a hidden asset, where the balance is outdated?)
High level, my initial thoughts are that "Hidden Assets" are a UI lever/control, we should still be performing data fetching if there are places that do show this asset.
| allIgnoredTokens: Record<string, Record<string, string[]>>; | ||
| assetsMetadata: Record<Caip19AssetId, AssetMetadata>; | ||
| assetsBalance: Record<string, Record<string, { amount: string }>>; | ||
| hiddenAssets: Record<string, string[]>; |
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.
nit (not a blocker) - I wonder if we add the JSDOC like we did for packages/assets-controller/src/data-sources/evm-rpc-services/types/state.ts, it helped readability on what this Record<string, string[]> is.
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.
(optional, needs discussion), the Accounts team export a type alias, that could assist with readability
export type AccountId = string;...Hesitant since it doesn't actually provide any additional type safety... maybe JSDOC is better?
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.
Actually I actually much more prefer the approach you used below in packages/assets-controller/src/AssetsController.ts
type Foo = { [accountId: string]: string[] };I think this is easier to read/understand then Record<string, string[]>
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.
Can we add some tests on the new exposed methods from this controller?
Prithpal-Sooriya
left a comment
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.
Initial pass looks good. Lemme know when this PR is out of draft 😄
Explanation
This PR adds support for hidden assets in the
AssetsController, similar to howallIgnoredAssetsworks inMultichainAssetsController.Current State:
Users currently have no way to hide assets they don't want to see or track in the new AssetsController architecture. The
MultichainAssetsControlleralready has this capability viaallIgnoredAssets, but the new unifiedAssetsControllerwas missing this feature.Solution:
Added a
hiddenAssetsfield to theAssetsControllerstate that stores hidden assets per account (CAIP-19 asset IDs). This allows users to hide assets they don't want to track and/or see.Changes:
hiddenAssets: { [accountId: string]: string[] }toAssetsControllerStatehideAsset(),unhideAsset(),getHiddenAssets(), andisAssetHidden()methodsAssetsControllerHideAssetAction,AssetsControllerUnhideAssetAction,AssetsControllerGetHiddenAssetsAction) and registered handlersaddCustomAsset(), it's automatically unhidden if it was previously hidden (matching the behavior ofMultichainAssetsController.addAssets())RpcDataSourceandBalanceFetcherto filter out hidden assets from balance polling, so hidden assets won't be tracked or updatedType Updates:
hiddenAssetstoAssetsControllerStatehiddenAssetstoAssetsControllerStateInternalhiddenAssetstoAssetsBalanceStatein evm-rpc-services typesReferences
allIgnoredAssetsinMultichainAssetsControllerChecklist
Note
Medium Risk
Medium risk: introduces new persisted controller state and new messenger actions that change balance polling behavior by filtering out hidden assets, which could impact what assets are tracked/displayed if misapplied.
Overview
Adds a persisted
hiddenAssetsmap toAssetsControllerstate and exports new messenger actions tohideAsset,unhideAsset, andgetHiddenAssets(plus anisAssetHiddenhelper).Updates
addCustomAssetto automatically unhide an asset when it’s re-added, wireshiddenAssetsthroughRpcDataSource→BalanceFetcher, and filters hidden asset IDs out of token balance polling. Tests and shared types are updated to include the new state shape.Written by Cursor Bugbot for commit ea074cb. This will update automatically on new commits. Configure here.