MetaMask / MetaMask/metamask-extension

[State Sync Redesign 3.3a] Remove flat state from `controller-init` smart transaction helpers

Open
#40,181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

INVALID-ISSUE-TEMPLATE team-extension-platform
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

`transaction-controller-init.ts` destructures `getFlatState` from the controller init request and passes it to smart transaction selectors (`getIsSmartTransaction`, `getSmartTransactionCommonParams`) and hooks (`publishHook`, `publishBatchHook`). These consume the full flat `ControllerFlatState` type.

With the flat state removal in the PoC (`jongsun/poc/sync-state-redesign`), these call sites are stubbed with `{} as ControllerFlatState`. They need refactoring to read from controllers directly via the messenger.

## Steps

1. Identify which controller properties `publishHook`, `publishBatchHook`, and `isEIP7702GasFeeTokensEnabled` read from flat state
2. Replace `getFlatState()` calls with direct controller state reads via `initMessenger` (e.g., `NetworkController:getState`, `PreferencesController:getState`)
3. Refactor `getSmartTransactionCommonParams` and `getIsSmartTransaction` to accept controller-keyed state or individual controller states instead of `ControllerFlatState`
4. Remove `getFlatState` from the `ControllerInitRequest` type in `controller-init/types.ts` (already done in PoC)
5. Remove `ControllerFlatState` type from `controller-list.ts` if no remaining consumers

## Files

- `app/scripts/controller-init/confirmations/transaction-controller-init.ts`
- `app/scripts/controller-init/types.ts`
- `app/scripts/controller-init/controller-list.ts`
- `shared/modules/selectors/smart-transactions.ts`

## Risk

Medium — smart transaction logic is sensitive. Must validate with E2E swap tests.

## Dependencies

Issue 3.3 (simplify `getState()` to controller-keyed)

## Context

Part of [State Sync Redesign — Epic 3: Background cleanup]. Gap identified during PoC branch `jongsun/poc/sync-state-redesign`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with app/scripts/controller-init/confirmations/transaction-controller-init.ts and trace the flat-state reads into shared/modules/selectors/smart-transactions.ts. Review controller-init/types.ts and controller-list.ts, then inspect the PoC's controller-keyed state approach and the dependency on Issue 3.3. Done means the listed consumers read through initMessenger without ControllerFlatState, unused types are removed, and E2E swap tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.