Commit 372d21e
authored
feat(AssetController): add hiddenAssets state (#7777)
## Explanation
This PR adds support for hidden assets in the `AssetsController`,
similar to how `allIgnoredAssets` works in `MultichainAssetsController`.
**Current State:**
Users currently have no way to hide assets they don't want to see or
track in the new AssetsController architecture. The
`MultichainAssetsController` already has this capability via
`allIgnoredAssets`, but the new unified `AssetsController` was missing
this feature.
**Solution:**
Added a `hiddenAssets` field to the `AssetsController` state 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:**
1. **State**: Added `hiddenAssets: { [accountId: string]: string[] }` to
`AssetsControllerState`
2. **Methods**: Added `hideAsset()`, `unhideAsset()`,
`getHiddenAssets()`, and `isAssetHidden()` methods
3. **Actions**: Added corresponding action types
(`AssetsControllerHideAssetAction`, `AssetsControllerUnhideAssetAction`,
`AssetsControllerGetHiddenAssetsAction`) and registered handlers
4. **Custom Assets Integration**: When a custom asset is added via
`addCustomAsset()`, it's automatically unhidden if it was previously
hidden (matching the behavior of
`MultichainAssetsController.addAssets()`)
5. **RPC Tracking**: Updated `RpcDataSource` and `BalanceFetcher` to
filter out hidden assets from balance polling, so hidden assets won't be
tracked or updated
**Type Updates:**
- Added `hiddenAssets` to `AssetsControllerState`
- Added `hiddenAssets` to `AssetsControllerStateInternal`
- Added `hiddenAssets` to `AssetsBalanceState` in evm-rpc-services types
## References
- Related to the Hide Token feature for the new unified AssetsController
architecture
- Pattern follows `allIgnoredAssets` in `MultichainAssetsController`
## 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
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Adds a new persisted `assetPreferences` state slice and changes
`getAssets` to filter hidden assets, which can affect UI output and
downstream consumers relying on prior state shape/types.
>
> **Overview**
> Adds a new persisted `assetPreferences` state (with
`AssetPreferences`) to store per-asset UI flags like `hidden`, and
introduces `hideAsset`/`unhideAsset` actions to manage this globally.
>
> Updates `getAssets` to exclude hidden assets from returned results
(while leaving balance/price tracking intact), and ensures
`addCustomAsset` automatically unhides an asset if it was previously
hidden.
>
> Tightens `AssetsControllerState` typing from generic `Json`/`string[]`
to semantic types (`AssetMetadata`, `AssetBalance`, `AssetPrice`,
`Caip19AssetId[]`), and adjusts `RpcDataSource`/tests to match the
narrowed `AssetsController:getState` expectations.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
a661f7e. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent df7c506 commit 372d21e
File tree
7 files changed
+152
-40
lines changed- packages/assets-controller
- src
- data-sources
7 files changed
+152
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| 217 | + | |
216 | 218 | | |
217 | 219 | | |
218 | 220 | | |
| |||
291 | 293 | | |
292 | 294 | | |
293 | 295 | | |
| 296 | + | |
294 | 297 | | |
295 | 298 | | |
296 | 299 | | |
| |||
311 | 314 | | |
312 | 315 | | |
313 | 316 | | |
| 317 | + | |
314 | 318 | | |
315 | 319 | | |
316 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 78 | + | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
86 | | - | |
| 85 | + | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | | - | |
| 89 | + | |
91 | 90 | | |
92 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
| |||
160 | 162 | | |
161 | 163 | | |
162 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
163 | 175 | | |
164 | 176 | | |
165 | 177 | | |
| |||
170 | 182 | | |
171 | 183 | | |
172 | 184 | | |
173 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
174 | 188 | | |
175 | 189 | | |
176 | 190 | | |
| |||
292 | 306 | | |
293 | 307 | | |
294 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
295 | 315 | | |
296 | 316 | | |
297 | 317 | | |
| |||
627 | 647 | | |
628 | 648 | | |
629 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
630 | 660 | | |
631 | 661 | | |
632 | 662 | | |
| |||
872 | 902 | | |
873 | 903 | | |
874 | 904 | | |
| 905 | + | |
875 | 906 | | |
876 | 907 | | |
877 | 908 | | |
| |||
894 | 925 | | |
895 | 926 | | |
896 | 927 | | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
897 | 937 | | |
898 | 938 | | |
899 | 939 | | |
| |||
919 | 959 | | |
920 | 960 | | |
921 | 961 | | |
922 | | - | |
923 | | - | |
924 | | - | |
| 962 | + | |
| 963 | + | |
925 | 964 | | |
926 | 965 | | |
927 | 966 | | |
928 | 967 | | |
929 | | - | |
930 | | - | |
| 968 | + | |
| 969 | + | |
931 | 970 | | |
932 | 971 | | |
933 | 972 | | |
| |||
940 | 979 | | |
941 | 980 | | |
942 | 981 | | |
943 | | - | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
944 | 1028 | | |
945 | 1029 | | |
946 | 1030 | | |
| |||
1083 | 1167 | | |
1084 | 1168 | | |
1085 | 1169 | | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1092 | 1173 | | |
1093 | | - | |
| 1174 | + | |
1094 | 1175 | | |
1095 | | - | |
| 1176 | + | |
1096 | 1177 | | |
1097 | 1178 | | |
1098 | 1179 | | |
| |||
1247 | 1328 | | |
1248 | 1329 | | |
1249 | 1330 | | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | 1331 | | |
1256 | 1332 | | |
1257 | 1333 | | |
| |||
1260 | 1336 | | |
1261 | 1337 | | |
1262 | 1338 | | |
1263 | | - | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
1264 | 1352 | | |
1265 | 1353 | | |
1266 | 1354 | | |
1267 | 1355 | | |
1268 | 1356 | | |
1269 | 1357 | | |
1270 | 1358 | | |
1271 | | - | |
1272 | | - | |
| 1359 | + | |
| 1360 | + | |
1273 | 1361 | | |
1274 | 1362 | | |
1275 | 1363 | | |
| |||
1783 | 1871 | | |
1784 | 1872 | | |
1785 | 1873 | | |
| 1874 | + | |
| 1875 | + | |
1786 | 1876 | | |
1787 | 1877 | | |
Lines changed: 0 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 190 | | |
194 | 191 | | |
195 | 192 | | |
| |||
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | 177 | | |
181 | 178 | | |
182 | 179 | | |
| |||
1304 | 1301 | | |
1305 | 1302 | | |
1306 | 1303 | | |
1307 | | - | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
1308 | 1307 | | |
1309 | 1308 | | |
1310 | 1309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
0 commit comments