Skip to content

Commit

Permalink
Merge pull request #5252 from LedgerHQ/bugfix/recover-onboarding-devi…
Browse files Browse the repository at this point in the history
…ce-compat

Bugfix/recover onboarding device compat
  • Loading branch information
ak-ledger committed Nov 9, 2023
2 parents 0132384 + 3bb71b8 commit 4ee9955
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .changeset/calm-lizards-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ledgerhq/types-live": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

Recover options/promotion remove for uncompatible devices
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useHistory } from "react-router-dom";
import { useTranslation, Trans } from "react-i18next";
import { Flex, Text } from "@ledgerhq/react-ui";
import { DeviceModelId } from "@ledgerhq/devices";
import { useFeature, isRecoverDisplayed } from "@ledgerhq/live-common/featureFlags/index";
import { useDispatch } from "react-redux";
import styled from "styled-components";
import { UseCaseOption } from "./UseCaseOption";
Expand All @@ -22,7 +23,6 @@ import setupNanoDark from "./assets/setupNanoDark.png";
import restoreUsingRecoverDark from "./assets/restoreUsingRecoverDark.png";

import Illustration from "~/renderer/components/Illustration";
import { FeatureToggle } from "@ledgerhq/live-common/featureFlags/index";
import { openModal } from "~/renderer/actions/modals";

registerAssets([
Expand Down Expand Up @@ -88,6 +88,7 @@ export function SelectUseCase({ setUseCase, setOpenedPedagogyModal }: Props) {
const { deviceModelId } = useContext(OnboardingContext);
const history = useHistory();
const dispatch = useDispatch();
const servicesConfig = useFeature("protectServicesDesktop");

return (
<ScrollArea withHint>
Expand Down Expand Up @@ -187,7 +188,7 @@ export function SelectUseCase({ setUseCase, setOpenedPedagogyModal }: Props) {
);
}}
/>
<FeatureToggle featureId="protectServicesDesktop">
{isRecoverDisplayed(servicesConfig, deviceModelId) && (
<UseCaseOption
dataTestId="v3-onboarding-restore-using-recover"
id="restore-device"
Expand All @@ -214,7 +215,7 @@ export function SelectUseCase({ setUseCase, setOpenedPedagogyModal }: Props) {
}
}}
/>
</FeatureToggle>
)}
</RightColumn>
</Row>
</SelectUseCaseContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { useFeature, isRecoverDisplayed } from "@ledgerhq/live-common/featureFlags/index";
import {
useAlreadySeededDevicePath,
useRestore24Path,
Expand Down Expand Up @@ -572,12 +572,14 @@ export default function Tutorial({ useCase }: Props) {
fallbackIfNoAction: () => history.push("/"),
});

if (useCase === UseCase.setupDevice && upsellPath) {
history.push(upsellPath);
} else if (useCase === UseCase.recoveryPhrase && restore24Path) {
history.push(restore24Path);
} else if (useCase === UseCase.connectDevice && devicePairingPath) {
history.push(devicePairingPath);
if (isRecoverDisplayed(recoverFF, connectedDevice?.modelId)) {
if (useCase === UseCase.setupDevice && upsellPath) {
history.push(upsellPath);
} else if (useCase === UseCase.recoveryPhrase && restore24Path) {
history.push(restore24Path);
} else if (useCase === UseCase.connectDevice && devicePairingPath) {
history.push(devicePairingPath);
}
}
}, 0);
return () => {
Expand All @@ -593,6 +595,7 @@ export default function Tutorial({ useCase }: Props) {
restore24Path,
upsellPath,
useCase,
recoverFF,
]);

const steps = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeviceModelId, getDeviceModel } from "@ledgerhq/devices";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { useFeature, isRecoverDisplayed } from "@ledgerhq/live-common/featureFlags/index";
import { Flex, Icons, Text } from "@ledgerhq/native-ui";
import { useNavigation, useRoute } from "@react-navigation/native";
import React, { useState } from "react";
Expand Down Expand Up @@ -117,7 +117,7 @@ const OnboardingStepUseCaseSelection = () => {
onPress: onPressRecoveryPhrase,
icon: <Icons.Note color={colors.primary.c80} />,
},
...(servicesConfig?.enabled
...(isRecoverDisplayed(servicesConfig, deviceModelId)
? [
{
title: t("onboarding.stepUseCase.protect.title"),
Expand Down
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/featureFlags/defaultFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const DEFAULT_FEATURES: Features = {
loginURI:
"ledgerlive://recover/protect-simu?redirectTo=login&source=lld-welcome-login&ajs_recover_source=lld-welcome-login&ajs_recover_campaign=recover-launch",
},
compatibleDevices: [],
discoverTheBenefitsLink: "https://www.ledger.com/recover",
onboardingCompleted: {
alreadySubscribedURI: "ledgerlive://recover/protect-simu?redirectTo=login",
Expand Down Expand Up @@ -290,6 +291,7 @@ export const DEFAULT_FEATURES: Features = {
enabled: false,
params: {
deeplink: "",
compatibleDevices: [],
account: {
homeURI:
"ledgerlive://recover/protect-simu?redirectTo=account&source=llm-myledger-access-card&ajs_prop_source=llm-myledger-access-card&ajs_prop_campaign=recover-launch",
Expand Down
9 changes: 9 additions & 0 deletions libs/ledger-live-common/src/featureFlags/helper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function isRecoverDisplayed(feature, deviceModelId) {
return (
feature?.enabled &&
feature?.params?.compatibleDevices?.find(
(device: { name: string; available: boolean }) =>
device.name === deviceModelId && device.available,
)
);
}
1 change: 1 addition & 0 deletions libs/ledger-live-common/src/featureFlags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./defaultFeatures";
export * from "./groupedFeatures";
export * from "./FeatureFlagsContext";
export * from "./useHasOverriddenFeatureFlags";
export * from "./helper";
8 changes: 8 additions & 0 deletions libs/ledgerjs/packages/types-live/src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,15 @@ export type Feature_NewsfeedPage = Feature<{
whitelistedLocales: string[];
}>;

export type CompatibleDevice = {
available: boolean;
comingSoon: boolean;
name: string;
};

export type Feature_ProtectServicesMobile = Feature<{
deeplink: string;
compatibleDevices: CompatibleDevice[];
onboardingRestore: {
restoreInfoDrawer: {
enabled: boolean;
Expand Down Expand Up @@ -328,6 +335,7 @@ export type Feature_ProtectServicesDesktop = Feature<{
availableOnDesktop: boolean;
openRecoverFromSidebar: boolean;
discoverTheBenefitsLink: string;
compatibleDevices: CompatibleDevice[];
onboardingRestore: {
restoreInfoDrawer: {
enabled: boolean;
Expand Down

1 comment on commit 4ee9955

@vercel
Copy link

@vercel vercel bot commented on 4ee9955 Nov 9, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.