Skip to content

Commit

Permalink
refacto(common): remove list apps v2 feature flag, list apps v1relate…
Browse files Browse the repository at this point in the history
…d code

fix test
  • Loading branch information
ofreyssinet-ledger committed Jul 30, 2024
1 parent a9d316e commit 87d6bb2
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 484 deletions.
9 changes: 9 additions & 0 deletions .changeset/long-dolphins-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ledgerhq/types-live": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
"@ledgerhq/live-cli": patch
---

Remove listAppsV2minor1 feature flag and all code associated to list apps v1
13 changes: 1 addition & 12 deletions apps/cli/src/commands/device/managerListApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { from } from "rxjs";
import { filter, map, mergeMap, repeat } from "rxjs/operators";
import { withDevice } from "@ledgerhq/live-common/hw/deviceAccess";
import getDeviceInfo from "@ledgerhq/live-common/hw/getDeviceInfo";
import {
enableListAppsV2,
listAppsUseCase,
} from "@ledgerhq/live-common/device/use-cases/listAppsUseCase";
import { listAppsUseCase } from "@ledgerhq/live-common/device/use-cases/listAppsUseCase";
import { deviceOpt } from "../../scan";
export default {
description: "List apps that can be installed on the device",
Expand All @@ -24,25 +21,17 @@ export default {
type: String,
typeDesc: "raw | json | default",
},
{
name: "v2",
type: Boolean,
typeDesc: "use v2 instead of v1",
},
],
job: ({
device,
format,
benchmark,
v2,
}: Partial<{
device: string;
format: string;
benchmark: boolean;
v2: boolean;
}>) => {
if (benchmark) console.log("Running the whole thing 5 times to have cache and averages.");
enableListAppsV2(!!v2);

return withDevice(device || "")(t =>
from(getDeviceInfo(t)).pipe(
Expand Down
7 changes: 0 additions & 7 deletions apps/ledger-live-desktop/src/renderer/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import FirmwareUpdateBanner from "~/renderer/components/FirmwareUpdateBanner";
import VaultSignerBanner from "~/renderer/components/VaultSignerBanner";
import { updateIdentify } from "./analytics/segment";
import { useFeature, FeatureToggle } from "@ledgerhq/live-common/featureFlags/index";
import { enableListAppsV2 } from "@ledgerhq/live-common/device/use-cases/listAppsUseCase";
import {
useFetchCurrencyAll,
useFetchCurrencyFrom,
Expand Down Expand Up @@ -199,7 +198,6 @@ export default function Default() {
useRecoverRestoreOnboarding();
useAutoDismissPostOnboardingEntryPoint();

const listAppsV2 = useFeature("listAppsV2minor1");
const analyticsFF = useFeature("lldAnalyticsOptInPrompt");
const hasSeenAnalyticsOptInPrompt = useSelector(hasSeenAnalyticsOptInPromptSelector);
const isLocked = useSelector(isLockedSelector);
Expand All @@ -218,11 +216,6 @@ export default function Default() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLocked]);

useEffect(() => {
if (!listAppsV2) return;
enableListAppsV2(listAppsV2.enabled);
}, [listAppsV2]);

useEffect(() => {
const userIsOnboardingOrSettingUp =
pathname.includes("onboarding") ||
Expand Down
10 changes: 1 addition & 9 deletions apps/ledger-live-mobile/src/components/RootNavigator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import React, { useEffect } from "react";
import React from "react";
import { useSelector } from "react-redux";
import Config from "react-native-config";
import { createStackNavigator } from "@react-navigation/stack";
import useFeature from "@ledgerhq/live-common/featureFlags/useFeature";
import { NavigatorName } from "~/const";
import { hasCompletedOnboardingSelector } from "~/reducers/settings";
import BaseNavigator from "./BaseNavigator";
import BaseOnboardingNavigator from "./BaseOnboardingNavigator";
import { RootStackParamList } from "./types/RootNavigator";
import { AnalyticsContextProvider } from "~/analytics/AnalyticsContext";
import { StartupTimeMarker } from "../../StartupTimeMarker";
import { enableListAppsV2 } from "@ledgerhq/live-common/device/use-cases/listAppsUseCase";

export default function RootNavigator() {
const hasCompletedOnboarding = useSelector(hasCompletedOnboardingSelector);
const goToOnboarding = !hasCompletedOnboarding && !Config.SKIP_ONBOARDING;

const listAppsV2 = useFeature("listAppsV2minor1");
useEffect(() => {
if (!listAppsV2) return;
enableListAppsV2(listAppsV2.enabled);
}, [listAppsV2]);

return (
<StartupTimeMarker>
<AnalyticsContextProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { from } from "rxjs";
import { UnexpectedBootloader } from "@ledgerhq/errors";
import { aTransportBuilder } from "@ledgerhq/hw-transport-mocker";
import { listApps } from "./v2";
import ManagerAPI from "../../manager/api";
import { aDeviceInfoBuilder } from "../../mock/fixtures/aDeviceInfo";
import { listApps } from "./listApps";
import ManagerAPI from "../manager/api";
import { aDeviceInfoBuilder } from "../mock/fixtures/aDeviceInfo";
import {
ManagerApiRepository,
StubManagerApiRepository,
} from "../../device/factories/HttpManagerApiRepositoryFactory";
import { supportedDeviceModelIds as clsSupportedDeviceModelIds } from "../../device/use-cases/isCustomLockScreenSupported";
} from "../device/factories/HttpManagerApiRepositoryFactory";
import { supportedDeviceModelIds as clsSupportedDeviceModelIds } from "../device/use-cases/isCustomLockScreenSupported";
import { DeviceModel } from "@ledgerhq/devices";
import customLockScreenFetchSize from "../../hw/customLockScreenFetchSize";
import { getDeviceName } from "../../device/use-cases/getDeviceNameUseCase";
import { currenciesByMarketcap, listCryptoCurrencies } from "../../currencies";
import { makeAppV2Mock } from "../mock";
import customLockScreenFetchSize from "../hw/customLockScreenFetchSize";
import { getDeviceName } from "../device/use-cases/getDeviceNameUseCase";
import { currenciesByMarketcap, listCryptoCurrencies } from "../currencies";
import { makeAppV2Mock } from "./mock";

jest.useFakeTimers();
jest.mock("../../hw/customLockScreenFetchSize");
jest.mock("../../device/use-cases/getDeviceNameUseCase");
jest.mock("../../currencies");
jest.mock("../hw/customLockScreenFetchSize");
jest.mock("../device/use-cases/getDeviceNameUseCase");
jest.mock("../currencies");

const mockedCustomLockScreenFetchSize = jest.mocked(customLockScreenFetchSize);
const mockedGetDeviceName = jest.mocked(getDeviceName);
const mockedListCryptoCurrencies = jest.mocked(listCryptoCurrencies);
const mockedCurrenciesByMarketCap = jest.mocked(currenciesByMarketcap);

describe("listApps v2", () => {
describe("listApps", () => {
let mockedManagerApiRepository: ManagerApiRepository;
let listAppsCommandSpy: jest.SpyInstance;
let listInstalledAppsSpy: jest.SpyInstance;

beforeEach(() => {
jest
.spyOn(
jest.requireActual("../../device/use-cases/getLatestFirmwareForDeviceUseCase"),
jest.requireActual("../device/use-cases/getLatestFirmwareForDeviceUseCase"),
"getLatestFirmwareForDeviceUseCase",
)
.mockReturnValue(Promise.resolve(null));
Expand All @@ -43,7 +43,7 @@ describe("listApps v2", () => {
mockedListCryptoCurrencies.mockReturnValue([]);

listAppsCommandSpy = jest
.spyOn(jest.requireActual("../../hw/listApps"), "default")
.spyOn(jest.requireActual("../hw/listApps"), "default")
.mockReturnValue(Promise.resolve([]));

listInstalledAppsSpy = jest.spyOn(ManagerAPI, "listInstalledApps").mockReturnValue(from([]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ import { UnexpectedBootloader } from "@ledgerhq/errors";
import { Observable, throwError, Subscription } from "rxjs";
import { App, DeviceInfo, idsToLanguage, languageIds } from "@ledgerhq/types-live";
import { LocalTracer } from "@ledgerhq/logs";
import type { ListAppsEvent, ListAppsResult, ListAppResponse } from "../types";
import hwListApps from "../../hw/listApps";
import customLockScreenFetchSize from "../../hw/customLockScreenFetchSize";
import {
listCryptoCurrencies,
currenciesByMarketcap,
findCryptoCurrencyById,
} from "../../currencies";
import ManagerAPI from "../../manager/api";

import { getDeviceName } from "../../device/use-cases/getDeviceNameUseCase";
import { getLatestFirmwareForDeviceUseCase } from "../../device/use-cases/getLatestFirmwareForDeviceUseCase";
import { getProviderIdUseCase } from "../../device/use-cases/getProviderIdUseCase";
import { mapApplicationV2ToApp } from "../polyfill";
import { ManagerApiRepository } from "../../device/factories/HttpManagerApiRepositoryFactory";
import { isCustomLockScreenSupported } from "../../device/use-cases/isCustomLockScreenSupported";
import type { ListAppsEvent, ListAppsResult, ListAppResponse } from "./types";
import hwListApps from "../hw/listApps";
import customLockScreenFetchSize from "../hw/customLockScreenFetchSize";
import { listCryptoCurrencies, currenciesByMarketcap, findCryptoCurrencyById } from "../currencies";
import ManagerAPI from "../manager/api";

import { getDeviceName } from "../device/use-cases/getDeviceNameUseCase";
import { getLatestFirmwareForDeviceUseCase } from "../device/use-cases/getLatestFirmwareForDeviceUseCase";
import { getProviderIdUseCase } from "../device/use-cases/getProviderIdUseCase";
import { calculateDependencies, mapApplicationV2ToApp } from "./polyfill";
import { ManagerApiRepository } from "../device/factories/HttpManagerApiRepositoryFactory";
import { isCustomLockScreenSupported } from "../device/use-cases/isCustomLockScreenSupported";

// Hash discrepancies for these apps do NOT indicate a potential update,
// these apps have a mechanism that makes their hash change every time.
Expand Down Expand Up @@ -191,6 +187,7 @@ export const listApps = ({
sortedCryptoCurrenciesPromise,
languagePackForDevicePromise,
]);
calculateDependencies();

/**
* Associate a market cap sorting index to each app of the catalog of
Expand Down
Loading

0 comments on commit 87d6bb2

Please sign in to comment.