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

[LIVE-10952][Common] Refactoring of list apps #6055

Merged
merged 19 commits into from
Feb 12, 2024

Conversation

ofreyssinet-ledger
Copy link
Contributor

@ofreyssinet-ledger ofreyssinet-ledger commented Jan 31, 2024

📝 Description

  • Refactor list apps v2:
    • move entrypoint of listApps to live-common/src/device/use-cases/listAppsUseCase.ts
    • move more of the manager/api.ts logic to ManagerApiRepository
    • create StubManagerApiRepository for mocks
    • implement some unit tests for listApps/v2.ts
  • Implement getProviderIdUseCase that takes forceProvider: number as a parameter

❓ Context

✅ Checklist

Pull Requests must pass the CI and be code reviewed. Set as Draft if the PR is not ready.

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • My Ledger
    • Firmware update flow

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

Copy link

vercel bot commented Jan 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web-tools ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 7, 2024 2:04pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-docs ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2024 2:04pm
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2024 2:04pm
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2024 2:04pm
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2024 2:04pm

@@ -0,0 +1,23 @@
import { DeviceInfoEntity } from "../entities/DeviceInfoEntity";

export const PROVIDERS: Record<string, number> = {
Copy link
Contributor

@jdabbech-ledger jdabbech-ledger Feb 2, 2024

Choose a reason for hiding this comment

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

could be an enum which also stores the default provider 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it could 👍 do you see an advantage of making it an enum ?
I will add the default provider regardless, good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually using an enum breaks some tests because then you can do access stuff with an index like PROVIDERS[1] and then stuff like this behaves in an unwanted way:

const providerName = PROVIDERS[postDash] ? postDash : null;

cf. this test run https://github.com/LedgerHQ/ledger-live/actions/runs/7755719007/job/21151656301

Copy link
Contributor

@jdabbech-ledger jdabbech-ledger Feb 2, 2024

Choose a reason for hiding this comment

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

Well the only advantage I see of making it an enum is the implicit typing.
I prefer using enum for readability and I was pretty sure that this behaviour was the same for a const or an enum.

Nevertheless LGTM 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not the same behaviour because enum[x] is a reverse mapping (it maps from value to name) https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
cf playground:

(I didn't know this playground by the way, nice one)

jdabbech-ledger
jdabbech-ledger previously approved these changes Feb 2, 2024
Copy link
Contributor

@jdabbech-ledger jdabbech-ledger left a comment

Choose a reason for hiding this comment

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

nice 👍

jdabbech-ledger
jdabbech-ledger previously approved these changes Feb 2, 2024
@live-github-bot
Copy link
Contributor

live-github-bot bot commented Feb 7, 2024

Desktop Bundle Checks

Comparing 095587b against 1975deb.

🚀 renderer bundle size decreased (36.1mb -> 35.9mb). Thanks ❤️

Mobile Bundle Checks

Comparing 095587b against 487845b.

Copy link
Contributor

@gre gre left a comment

Choose a reason for hiding this comment

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

i see the creation of a new folder "device-core" in live-common, could you consider instead making a new library like "live-device-core" or even just "device-core" ?
we are taking a general direction to not add more logic into live-common but instead moving them out into dedicated library (e.g. live-countervalues, live-nft, ...)

by doing so, you can activate stricter version of typescript config that also help improving the quality. it's also a game changer for the decoupling of our stack

@ofreyssinet-ledger
Copy link
Contributor Author

@gre yes that's the direction we're taking, we will probably do this in a subsequent PR

@@ -10,7 +13,7 @@ export interface ManagerApiRepository {
userId: string;
}): Promise<OsuFirmware | null | undefined>;

fetchMcus(): Promise<any>;
fetchMcus(): Promise<any>; // TODO: type properly
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not now?

@ofreyssinet-ledger ofreyssinet-ledger added the HODL Do not merge label Feb 8, 2024
@ofreyssinet-ledger ofreyssinet-ledger merged commit a52838d into develop Feb 12, 2024
68 of 71 checks passed
@ofreyssinet-ledger ofreyssinet-ledger deleted the support/refacto-list-apps-v2 branch February 12, 2024 09:04
jdabbech-ledger pushed a commit that referenced this pull request Feb 19, 2024
[LIVE-10952][Common] Refactoring of list apps
jdabbech-ledger pushed a commit that referenced this pull request Feb 19, 2024
[LIVE-10952][Common] Refactoring of list apps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli common Has changes in live-common desktop Has changes in LLD HODL Do not merge mobile Has changes in LLM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants