Commit d219a72
committed
fix(assets-controller): fix snap-backed multichain balance delivery
Fixes three related bugs that caused snap chain balances (Tron, Bitcoin,
Solana, etc.) to never appear in AssetsController state.
**Bug 1 — Chain discovery ignored `endowment:keyring` chainIds caveat**
`#discoverKeyringSnaps` only read `chainIds` from `endowment:assets`.
Snaps that declare supported chains solely on `endowment:keyring` (e.g.
many wallet snaps) produced an empty `activeChains` after discovery.
Fix: `#getChainIdsFromSnapPermissions` now prefers `endowment:assets` and
falls back to `endowment:keyring` when the assets caveat is absent.
**Bug 2 — Snap subscriptions never created (activeSubscriptions always 0)**
`#subscribeAssetsBalance` in AssetsController passed only `#enabledChains`
(EVM networks from NetworkController) to `#buildChainToAccountsMap`. Snap
chains (`bip122:*`, `solana:*`, `tron:*`) were never in that set, so
`remainingChains` had no overlap with SnapDataSource's `activeChains` →
`assignedChains.length === 0` every call → SnapDataSource was immediately
unsubscribed → `activeSubscriptions` stayed 0 and every push balance event
was dispatched into nothing.
Fix: augment the chain set with `snapDataSource.getActiveChainsSync()` so
snap chains enter the assignment loop and are routed to SnapDataSource.
**Bug 3 — Snaps with no `chainIds` caveat silently dropped (e.g. Tron)**
When a snap has `endowment:keyring` but no `chainIds` caveat on either
permission, discovery returns `null` and skips the snap. Tron balances
arrived with `chainAllowed=false` and were discarded on every event.
Fix: `#handleSnapBalancesUpdated` now detects a non-EVM chain that arrived
after discovery completed but isn't registered, adds it to `activeChains`
via `updateActiveChains`, and triggers `onActiveChainsUpdated` to
re-subscribe AssetsController. EVM chains are explicitly excluded from
this path — they belong to RpcDataSource.
**Additional fixes**
- Retry discovery in `#handleSnapBalancesUpdated` when a balance push
arrives before `SnapController`/`PermissionController` are ready.
- Fail-open in `subscribe` when discovery has not completed: register
the subscription using requested chains so push events can be delivered
once discovery finishes.
- Subscribe to `PermissionController:stateChanged` (correct BaseController
v2 event) instead of the deprecated `stateChange`.1 parent 558518d commit d219a72
4 files changed
Lines changed: 313 additions & 46 deletions
File tree
- packages/assets-controller
- src
- data-sources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 40 | + | |
44 | 41 | | |
45 | 42 | | |
46 | 43 | | |
| |||
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
82 | | - | |
| 79 | + | |
83 | 80 | | |
84 | 81 | | |
85 | 82 | | |
| |||
335 | 332 | | |
336 | 333 | | |
337 | 334 | | |
338 | | - | |
339 | | - | |
| 335 | + | |
340 | 336 | | |
341 | 337 | | |
342 | 338 | | |
| |||
2565 | 2561 | | |
2566 | 2562 | | |
2567 | 2563 | | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
2568 | 2568 | | |
2569 | 2569 | | |
2570 | | - | |
| 2570 | + | |
2571 | 2571 | | |
2572 | 2572 | | |
2573 | 2573 | | |
| |||
Lines changed: 218 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
149 | 174 | | |
150 | 175 | | |
151 | 176 | | |
| |||
171 | 196 | | |
172 | 197 | | |
173 | 198 | | |
174 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
175 | 207 | | |
176 | 208 | | |
177 | 209 | | |
| 210 | + | |
178 | 211 | | |
179 | 212 | | |
180 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
181 | 219 | | |
182 | 220 | | |
183 | 221 | | |
| |||
200 | 238 | | |
201 | 239 | | |
202 | 240 | | |
203 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
204 | 245 | | |
205 | 246 | | |
206 | 247 | | |
| |||
218 | 259 | | |
219 | 260 | | |
220 | 261 | | |
221 | | - | |
222 | | - | |
223 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
224 | 268 | | |
225 | 269 | | |
226 | 270 | | |
| |||
236 | 280 | | |
237 | 281 | | |
238 | 282 | | |
239 | | - | |
| 283 | + | |
240 | 284 | | |
241 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
242 | 289 | | |
243 | 290 | | |
244 | 291 | | |
| |||
409 | 456 | | |
410 | 457 | | |
411 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
412 | 619 | | |
413 | 620 | | |
414 | 621 | | |
| |||
922 | 1129 | | |
923 | 1130 | | |
924 | 1131 | | |
925 | | - | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
926 | 1136 | | |
927 | 1137 | | |
928 | 1138 | | |
| |||
0 commit comments