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

Let's Fix TS & Eslint #1141

Merged
merged 29 commits into from
Nov 2, 2022
Merged

Let's Fix TS & Eslint #1141

merged 29 commits into from
Nov 2, 2022

Conversation

valpinkman
Copy link
Member

@valpinkman valpinkman commented Sep 1, 2022

πŸ“ Description

βœ… What this PR is about

On Ledger Live Mobile:

  • Fixing all typescript errors
  • Fixing all eslint errors and warnings
  • Enforcing that using any explicitely is an error, not a warning.

🚫 What this PR is NOT about

  • Rewriting code and logic (excepted in extreme cases)
  • Refactoring the way we type things
  • Harmonize types all over the place
  • Impact other packages (LLC, LJS…) types (excepted in extreme cases)

This work should be done by other teams (on the parts owned by them) later on.

⚠️ Issues

There are multiple places in LLM where we seem to write code or types in a wrong - or weird - way.
We have put // FIXME comments there that will have to be checked by the relevant teams in the future.

We also took some notes about these parts while typing the code: https://github.com/LedgerHQ/ledger-live-issues/issues/32#issuecomment-1246467565

We wrote some documentation on how to type certain parts of the app here https://github.com/LedgerHQ/ledger-live/wiki/LLM:Typescript

πŸ“ Documentation

We also wrote some guides in the repository wiki about how to properly type some code parts.

❓ Context

We have already merged the work from #1054

βœ… Checklist

  • Test coverage
  • Atomic delivery
  • No breaking changes
    Maybe breaking changes... we have to carefully test this PR as some adjustment have been made while fixing the errors.

πŸ“Έ Demo

Before

Screenshot 2022-10-20 at 11 28 39

Screenshot 2022-10-20 at 11 29 08

After

Screenshot 2022-10-20 at 11 39 18

Screenshot 2022-10-20 at 11 39 24

πŸš€ Expectations to reach

Zero TS errors, strict mode enabled. Clean slate on LLM typechecker

Pull Requests must pass the CI and be internally validated in order to be merged.

Bonus Round => All the WTF we found (also linked in the comment of the issue)

During our TS rework, we spotted some parts of the app that should definitely be reviewed/refactored:

  • src/helpers/formatAccountSearchResults.ts => rework without lodash reduce and foreach, and make sure the return type means something.
  • react-native-redash => used only twice, we are using v1 (if reanimated version < 2) yet we are using reanimated v2.8.0
    • either remove or update to use the current version of the lib
    • we are using useTheme from @react-navigation/native while we are supposed to have migrated to v3 using @ledgerhq/ui, thus the migration to v3 is not finished
    • DerivationMode in @ledgerhq/types-live is broken as it only declares a string. There is another DerivationMode in live-common that is correctly typed, but we cannot import it into types-live as that would break the dependency cycle. A refacto/rework is needed to migrate this type to types-live
    • invariant on application side (LLM). should we remove ?
  • /src/components/DeviceJob/index.tsx -> very weird types here, bunch of any and confusion on the type of meta which is supposed to be a Device not a Record
  • OSKOUR -> we navigate on a NAVIGATOR without a ScreenName, passing Props to it... which is an abomination. Navigator should not take any props and we should redirect to the correct ScreenName all the time. ALED
  • SelectDevice is used in many many places and we don't know which paramater are passed to it (so we used object as a type), however I do believe a deeper understanding of the props we pass is necessary and an overview of this system is required
  • Families Flows
    • Flows are adapted so the components have the props they need, but we always spread the params when we navigate, so it'd be a good idea to rework them and type each step properly
    • ConnectDevice and SelectDevice are used in so many components, and we are pretty sure we can unify the props that are passed to them a bit better. A refacto would be nice
  • undefined | null checks => please stop with { value: something | null | undefined }. { value?: something | null } is better, but those null checks are a pain in the ass. It should either be something or undefined

@vercel
Copy link

vercel bot commented Sep 1, 2022

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated
live-common-tools ❌ Failed (Inspect) Nov 2, 2022 at 11:56AM (UTC)
3 Ignored Deployments
Name Status Preview Updated
ledger-live-github-bot ⬜️ Ignored (Inspect) Nov 2, 2022 at 11:56AM (UTC)
native-ui-storybook ⬜️ Ignored (Inspect) Nov 2, 2022 at 11:56AM (UTC)
react-ui-storybook ⬜️ Ignored (Inspect) Nov 2, 2022 at 11:56AM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Sep 1, 2022

πŸ¦‹ Changeset detected

Latest commit: b26fd81

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 65 packages
Name Type
ledger-live-desktop Patch
live-mobile Patch
@ledgerhq/live-cli Patch
dummy-live-app Patch
@ledgerhq/live-common Patch
ledger-libs Patch
@ledgerhq/cryptoassets Patch
@ledgerhq/errors Patch
@ledgerhq/hw-app-eth Patch
@ledgerhq/hw-app-helium Patch
@ledgerhq/hw-app-solana Patch
@ledgerhq/hw-transport-http Patch
@ledgerhq/hw-transport-node-hid-singleton Patch
@ledgerhq/types-cryptoassets Patch
@ledgerhq/types-live Patch
@ledgerhq/crypto-icons-ui Patch
@ledgerhq/icons-ui Patch
@ledgerhq/native-ui Patch
@ledgerhq/react-ui Patch
@ledgerhq/ui-shared Patch
@actions/change-product-name Patch
actions-root Patch
@actions/download-workflow-artifacts Patch
@actions/extract-live-common-version Patch
@actions/generate-bot-super-report Patch
@actions/generate-jira-diff Patch
@actions/generate-release-message Patch
@actions/generate-slack-screenshots-diff Patch
@actions/get-package-infos Patch
@actions/get-pr-number Patch
@actions/get-release-by-tag Patch
@actions/get-workflow-artifacts-id Patch
has-hash-commit-deps Patch
@actions/is-org-member Patch
@actions/pr-is-fork Patch
@actions/prepare-comment-screenshots Patch
@actions/prepare-comment Patch
@actions/publish-release Patch
@actions/submit-bot-report Patch
@actions/turborepo-gh-cache Patch
@actions/upload-images Patch
live-common-tools Patch
live-github-bot Patch
pnpm-utils Patch
@ledgerhq/devices Patch
@ledgerhq/hw-app-algorand Patch
@ledgerhq/hw-app-cosmos Patch
@ledgerhq/hw-app-polkadot Patch
@ledgerhq/hw-app-trx Patch
@ledgerhq/hw-transport-node-ble Patch
@ledgerhq/hw-transport-node-hid-noevents Patch
@ledgerhq/hw-transport-node-hid Patch
@ledgerhq/hw-transport-node-speculos-http Patch
@ledgerhq/hw-transport-node-speculos Patch
@ledgerhq/hw-transport-web-ble Patch
@ledgerhq/hw-transport-webhid Patch
@ledgerhq/hw-transport-webusb Patch
@ledgerhq/hw-transport Patch
@ledgerhq/react-native-hid Patch
@ledgerhq/react-native-hw-transport-ble Patch
@ledgerhq/hw-app-btc Patch
@ledgerhq/hw-app-str Patch
@ledgerhq/hw-app-tezos Patch
@ledgerhq/hw-app-xrp Patch
@ledgerhq/hw-transport-mocker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Sep 1, 2022

Codecov Report

Base: 47.94% // Head: 47.95% // Increases project coverage by +0.00% πŸŽ‰

Coverage data is based on head (b26fd81) compared to base (135838d).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1141   +/-   ##
========================================
  Coverage    47.94%   47.95%           
========================================
  Files          691      691           
  Lines        30445    30456   +11     
  Branches      7977     7989   +12     
========================================
+ Hits         14597    14605    +8     
- Misses       14636    14637    +1     
- Partials      1212     1214    +2     
Flag Coverage Ξ”
test 47.95% <ΓΈ> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
...bs/ledger-live-common/src/families/cosmos/utils.ts 66.66% <0.00%> (-33.34%) ⬇️
libs/ledger-live-common/src/derivation.ts 56.47% <0.00%> (ΓΈ)
libs/ledger-live-common/src/platform/logic.ts 71.73% <0.00%> (ΓΈ)
libs/ledger-live-common/src/bridge/jsHelpers.ts 29.85% <0.00%> (ΓΈ)
libs/ledger-live-common/src/portfolio/v2/index.ts 87.11% <0.00%> (ΓΈ)
...ibs/ledger-live-common/src/hw/signMessage/index.ts 30.88% <0.00%> (ΓΈ)
...s/ledger-live-common/src/postOnboarding/actions.ts 100.00% <0.00%> (ΓΈ)
...s/ledger-live-common/src/postOnboarding/reducer.ts 76.00% <0.00%> (ΓΈ)
...ledger-live-common/src/bridge/react/BridgeSync.tsx 77.27% <0.00%> (ΓΈ)
...ive-common/src/families/filecoin/hw-signMessage.ts 41.66% <0.00%> (ΓΈ)
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

β˜” View full report at Codecov.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link

github-actions bot commented Sep 1, 2022

@elbywan

Screenshots: βœ…

There are no changes in the screenshots for this PR. If this is expected, you are good to go.

@github-actions github-actions bot added the ledgerjs Has changes in the ledgerjs open source libs label Sep 2, 2022
@github-actions github-actions bot added the translations Translation files have been touched label Sep 2, 2022
elbywan and others added 26 commits November 2, 2022 11:58
- Created a Asset type and used it instead of recreating it every time
- Remove navigationParams prop in AssetRow as there was a typescript error and it was unused anyway
also remove some unneeded `params: undefined`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation CI/CD stuff cli common Has changes in live-common desktop Has changes in LLD ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM tools Has changes in tools translations Translation files have been touched ui Has changes in the design system library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet