Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Migrate store to TypeScript #7110

Merged
merged 1 commit into from
Sep 2, 2023
Merged

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 1, 2023

Development & PR Process

  1. Follow MetaMask Mobile Coding Standards
  2. Add release-xx label to identify the PR slated for a upcoming release (will be used in release discussion)
  3. Add needs-dev-review label when work is completed
  4. Add the appropiate QA label when dev review is completed
    • needs-qa: PR requires manual QA.
    • No QA/E2E only: PR does not require any manual QA effort. Prior to merging, ensure that you have successful end-to-end test runs in Bitrise.
    • Spot check on release build: PR does not require feature QA but needs non-automated verification. In the description section, provide test scenarios. Add screenshots, and or recordings of what was tested.
  5. Add QA Passed label when QA has signed off (Only required if the PR was labeled with needs-qa)
  6. Add your team's label, i.e. label starting with team- (or external-contributor label if your not a MetaMask employee)

Description

The Redux store module and the root reducer have been migrated to TypeScript. We now have the start of a root state object for the Redux state. Most of the reducers still aren't typed, or there are type errors, but it's a start. The missing pieces are typed as any for now.

The TypeScript conversion introduced some lint errors caused by the pattern of using destructuring to omit object properties. The rule has been updated to allow this pattern (it's already allowed on the latest shared ESLint config).

The store type changes required updates to the selectors as well. The types they had been using only included a subset of the root state. They have been updated to use the real root state type instead.

Issue

This relates to https://github.com/MetaMask/mobile-planning/issues/1226

Checklist

  • There is a related GitHub issue
  • Tests are included if applicable
  • Any added code is fully documented

@Gudahtt Gudahtt force-pushed the migrate-store-to-typescript branch 2 times, most recently from a12d254 to 7d3a46d Compare September 1, 2023 21:13
Base automatically changed from fix-additional-engine-type-errors to main September 1, 2023 21:23
@Gudahtt Gudahtt marked this pull request as ready for review September 1, 2023 21:24
@Gudahtt Gudahtt requested a review from a team as a code owner September 1, 2023 21:24
@Gudahtt Gudahtt added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) team-mobile-platform labels Sep 1, 2023
@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: -0.01% ⚠️

Comparison is base (96c0b56) 32.86% compared to head (300ca07) 32.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7110      +/-   ##
==========================================
- Coverage   32.86%   32.85%   -0.01%     
==========================================
  Files        1001     1001              
  Lines       26757    26756       -1     
  Branches     2109     2113       +4     
==========================================
- Hits         8794     8792       -2     
  Misses      17540    17540              
- Partials      423      424       +1     
Files Changed Coverage Δ
...component-library/components/Checkbox/Checkbox.tsx 100.00% <ø> (ø)
...ct/MultiSelect/MultiSelectItem/MultiSelectItem.tsx 100.00% <ø> (ø)
...components/Select/Select/SelectItem/SelectItem.tsx 100.00% <ø> (ø)
app/core/Engine.ts 55.71% <ø> (-0.21%) ⬇️
app/core/EngineService/EngineService.ts 83.78% <ø> (ø)
app/reducers/fiatOrders/index.ts 100.00% <ø> (ø)
app/reducers/fiatOrders/types.ts 100.00% <ø> (ø)
app/store/migrations.js 11.90% <ø> (ø)
app/store/index.ts 34.09% <25.00%> (ø)
app/reducers/index.ts 100.00% <100.00%> (ø)
... and 10 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Cal-L Cal-L added No QA Needed/E2E Only Apply this label when your PR does not need any QA effort. and removed needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Sep 1, 2023
The Redux store module and the root reducer have been migrated to
TypeScript. We now have the start of a root state object for the Redux
state. Most of the reducers still aren't typed, or there are type
errors, but it's a start. The missing pieces are typed as `any` for
now.

The TypeScript conversion introduced some lint errors caused by the
pattern of using destructuring to omit object properties. The rule has
been updated to allow this pattern (it's already allowed on the latest
shared ESLint config).

The store type changes required updates to the selectors as well. The
types they had been using only included a subset of the root state.
They have been updated to use the real root state type instead.

This relates to MetaMask/mobile-planning#1226
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 2, 2023

@sonarcloud
Copy link

sonarcloud bot commented Sep 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

44.4% 44.4% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.20) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@Gudahtt Gudahtt merged commit 5aca039 into main Sep 2, 2023
12 checks passed
@Gudahtt Gudahtt deleted the migrate-store-to-typescript branch September 2, 2023 01:14
@github-actions github-actions bot locked and limited conversation to collaborators Sep 2, 2023
@metamaskbot metamaskbot added the release-7.8.0 Issue or pull request that will be included in release 7.8.0 label Sep 2, 2023
// Source: https://redux.js.org/tutorials/typescript-quick-start
// Infer the `RootState` and `AppDispatch` types from the store itself
// @ts-expect-error Type errors in store
export type RootState = ReturnType<typeof store.getState>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke this import:

import { RootState } from '../../../../reducers/fiatOrders/types';

Fix is to change

import { RootState } from '../../../../reducers/fiatOrders/types';

to

import { RootState } from '../../../../reducers';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will fix this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here: #7147

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
No QA Needed/E2E Only Apply this label when your PR does not need any QA effort. release-7.8.0 Issue or pull request that will be included in release 7.8.0 team-mobile-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants