MetaMask / MetaMask/metamask-extension

UI <=> Background - Pass unflattened state from background to UI

Open
#18,092 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

**Epic: Allow the UI to read state from the storage system**
https://github.com/MetaMask/metamask-extension/issues/18054

Currently UI receives flattened background state under `metamask` key, which is causing confusion of where is the state coming from. The first step is to **temporarily** keep the flattened state on the `metamask` key, while also sending the unflattened state next to it so that we can incrementally adopt this and not have to do the entire application in one change.

**Tasks:**

1. Pass unflattened state inside `metamask` key `metamaskState`, which comes from `getFlatState` inside `app/scripts/lib/ComposableObservableStore.js`

Screenshot 2023-03-10 at 03 05 37

2. Adopt gradually in UI to use such unflattened state, for example, to get `unapprovedDecryptMsgCount` from `DecryptMessageManager`

```
// Before:
const unapprovedMsgCountSelector = (state) => state.metamask.unapprovedMsgCount;
// After:
const unapprovedMsgCountSelector = (state) => state.metamask.DecryptMessageManager.unapprovedDecryptMsgCount
```

3. Finally, remove flattened state
4. You can also check fixtures in e2e test and validate the refactor

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/lib/ComposableObservableStore.js and the getFlatState path described in the issue. Then inspect the DecryptMessageManager state usage in the UI and the e2e fixtures mentioned. Done means the UI can adopt the unflattened state incrementally, validation covers the refactor, and the flattened state can eventually be removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, frontend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.