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

fix(PROTECT-3467): recover banner link to go to login #8685

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fresh-rabbits-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Redirect users to Recover Login if they have an account as they may be logged out
37 changes: 24 additions & 13 deletions apps/ledger-live-mobile/src/components/RecoverBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ import { RecoverBannerType } from "./types";
import { GestureResponderEvent, Linking } from "react-native";
import { getStoreValue, setStoreValue } from "~/store";

enum LedgerRecoverSubscriptionStateEnum {
BACKUP_DEVICE_CONNECTION = "BACKUP_DEVICE_CONNECTION",
BACKUP_DONE = "BACKUP_DONE",
BACKUP_VERIFY_IDENTITY = "BACKUP_VERIFY_IDENTITY",
NO_SUBSCRIPTION = "NO_SUBSCRIPTION",
STARGATE_SUBSCRIBE = "STARGATE_SUBSCRIBE",
}

const maxStepNumber = Object.keys(LedgerRecoverSubscriptionStateEnum).length;

function RecoverBanner() {
const [storageData, setStorageData] = useState<string>();
const [storageData, setStorageData] = useState<LedgerRecoverSubscriptionStateEnum>(
LedgerRecoverSubscriptionStateEnum.NO_SUBSCRIPTION,
);
const [displayBannerData, setDisplayBannerData] = useState<boolean>();
const [stepNumber, setStepNumber] = useState<number>(0);

Expand All @@ -19,42 +31,41 @@ function RecoverBanner() {

const bannerIsEnabled = recoverServices?.params?.bannerSubscriptionNotification;
const protectID = recoverServices?.params?.protectId ?? "protect-prod";
const maxStepNumber = 5;

const recoverUnfinishedOnboardingPath = useCustomURI(
const recoverResumeActivatePath = useCustomURI(
recoverServices,
"activate",
"resumeActivate",
"llm-banner-unfinished-onboarding",
"recover-launch",
);

const getStorageSubscriptionState = useCallback(async () => {
const storage = await getStoreValue("SUBSCRIPTION_STATE", protectID);
const displayBanner = await getStoreValue("DISPLAY_BANNER", protectID);
setStorageData(storage as string);
setStorageData(storage as LedgerRecoverSubscriptionStateEnum);
setDisplayBannerData(displayBanner === "true");
}, [protectID]);

const recoverBannerSelected: RecoverBannerType | undefined = useMemo(() => {
let recoverBannerWording: RecoverBannerType;

switch (storageData) {
case "NO_SUBSCRIPTION":
case LedgerRecoverSubscriptionStateEnum.NO_SUBSCRIPTION:
setStepNumber(1);
return undefined;
case "STARGATE_SUBSCRIBE":
case LedgerRecoverSubscriptionStateEnum.STARGATE_SUBSCRIBE:
setStepNumber(2);
recoverBannerWording = t("portfolio.recoverBanner.subscribeDone", { returnObjects: true });
break;
case "BACKUP_VERIFY_IDENTITY":
case LedgerRecoverSubscriptionStateEnum.BACKUP_VERIFY_IDENTITY:
setStepNumber(3);
recoverBannerWording = t("portfolio.recoverBanner.verifyIdentity", { returnObjects: true });
break;
case "BACKUP_DEVICE_CONNECTION":
case LedgerRecoverSubscriptionStateEnum.BACKUP_DEVICE_CONNECTION:
setStepNumber(4);
recoverBannerWording = t("portfolio.recoverBanner.connectDevice", { returnObjects: true });
break;
case "BACKUP_DONE":
case LedgerRecoverSubscriptionStateEnum.BACKUP_DONE:
setStepNumber(5);
return undefined;
default:
Expand All @@ -66,9 +77,9 @@ function RecoverBanner() {
}, [storageData, t]);

const onRedirectRecover = () => {
if (recoverUnfinishedOnboardingPath)
Linking.canOpenURL(recoverUnfinishedOnboardingPath).then(() =>
Linking.openURL(recoverUnfinishedOnboardingPath),
if (recoverResumeActivatePath)
Linking.canOpenURL(recoverResumeActivatePath).then(() =>
Linking.openURL(recoverResumeActivatePath),
);
};

Expand Down
Loading