MetaMask / MetaMask/metamask-extension
[`MetamaskController` A.1] Extract `token-resolution`
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
**Sub-epic:** [#41736 — `MetamaskController` decomposition: `wallet-services` completion](https://github.com/MetaMask/metamask-extension/issues/41736)
**Files:**
- `app/scripts/lib/wallet-services/token-resolution/index.ts` (new)
- `app/scripts/lib/wallet-services/token-resolution/token-resolution.test.ts` (new)
- `app/scripts/metamask-controller.js`
**Size:** S
## Problem
Token resolution logic lives inline on `MetamaskController`: the methods that call `AssetsContractController:getTokenStandardAndDetails` and `AssetsContractController:getBalancesInSingleCall` sit alongside unrelated wallet concerns, with no dedicated module or test surface. Extract them into `wallet-services/token-resolution/` so the responsibility is named, independently testable, and usable from a cross-client seam.
Both actions are already registered messenger actions — see [`app/scripts/controller-init/messengers/assets/assets-contract-controller-messenger.ts`](https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/controller-init/messengers/assets/assets-contract-controller-messenger.ts) — so this extraction is purely a move, not a messenger-wiring reconciliation.
## Solution
1. Create `app/scripts/lib/wallet-services/token-resolution/` with `index.ts` exporting a structural `TokenResolutionMessenger` type and the extracted function bodies.
2. Move the corresponding method bodies out of `app/scripts/metamask-controller.js` into the new module.
3. Export a `TOKEN_RESOLUTION_ACTIONS` constant and a `registerActions(messenger)` helper that wires the module into the root messenger.
4. Add structural unit tests: construct a fake messenger that satisfies `TokenResolutionMessenger` only (no `RootMessenger` import, no real controller imports), and assert the `call` arguments directly.
5. Delete the moved method bodies from `metamask-controller.js`.
6. Update `MetamaskController#getApi()` entries for token resolution to delegate via messenger.
## Acceptance criteria
- [ ] `app/scripts/lib/wallet-services/token-resolution/index.ts` exists and owns the extracted logic
- [ ] `yarn test app/scripts/lib/wallet-services/token-resolution` passes
- [ ] Tests contain no `RootMessenger` or real controller imports
- [ ] Moved method bodies are removed from `app/scripts/metamask-controller.js`
- [ ] `getApi()` entries rewritten to call `messenger.call('Module:action', ...)` directly — no forwarding stub remains in `MetamaskController`
- [ ] `yarn test` green, `tsc` green, extension dev build boots
## Dependencies
None.
Contributor guide
Assessment
This issue has not been assessed yet.