MetaMask / MetaMask/metamask-extension
[Unflattening #3] Construct exhaustive state object for `metamask` slice with default values for all nested properties.
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
In the Extension, our background state object gets “flattened” before being sent to the UI, instead, we want to leave our state grouped by controller.
This task is for creating an exhaustive state object, which
- Maintains the controller structure (not flattening)
- Includes default values for all nested properties
- Ensures type safety and completeness
- Documents the shape of the state
Here's a conceptual example of what we want to create:
```
interface MetaMaskState {
NetworkController: {
networkId: number;
chainId: string;
provider: {
type: string;
rpcUrl?: string;
};
// ... other network properties with defaults
};
PreferencesController: {
selectedAddress: string | null;
tokens: Token[];
// ... other preferences properties with defaults
};
// ... other controllers
}
export const defaultState: MetaMaskState = {
NetworkController: {
network: {
networkId: 1,
chainId: '0x1',
provider: {
type: 'mainnet',
rpcUrl: null,
chainId: '0x1',
ticker: 'ETH',
nickname: null,
},
},
},
PreferencesController: {
selectedAddress: null,
tokens: [],
},
// ... other controllers
};
```
Contributor guide
Assessment
This issue has not been assessed yet.