MetaMask / MetaMask/metamask-extension
UI <=> Background - Isolate selectors that interact with background state
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
### **Epic: Define deeper boundaries between background and redux state**
https://github.com/MetaMask/metamask-extension/issues/18054
### **Tasks:**
- Create `selectors.ts` files in each of the controller folders located in `ui/background` (will be done in https://github.com/MetaMask/metamask-extension/issues/18072)
- Relocate all of the selectors from the selectors folder that interact with background state. There are also places throughout the code that use intermediary selectors or state directly to access the metamask subkey (where background state is stored). We would ideally have all selectors that interact with the background state in the background folder. Here are some selectors we can move out:
```
export const currentCurrencySelector = (state) =>
state.metamask.currentCurrency;
export const conversionRateSelector = (state) => state.metamask.conversionRate;
```
```
export function getSafeLowEstimate(state) {
const gasFeeEstimates = getGasFeeEstimates(state);
const gasEstimateType = getGasEstimateType(state);
return gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.legacy
? gasFeeEstimates?.low
: null;
}
```
```
export const selectFragmentBySuccessEvent = createSelector(
selectFragments,
(_, fragmentOptions) => fragmentOptions,
(fragments, fragmentOptions) => {
if (fragmentOptions.persist) {
return Object.values(fragments).find(
(fragment) => fragment.successEvent === fragmentOptions.successEvent,
);
}
return undefined;
},
);
```
Contributor guide
Research direction
Review the controller folders under ui/background, the existing selectors folder, and issue 18072 for the selectors.ts prerequisite. Identify selectors that read background state such as state.metamask, then relocate them into the relevant background controller folders; done means those selectors no longer remain in the shared selectors folder.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- redux, typescript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100