From 363597695b06ff12d3ae969d34a494749d3b0c25 Mon Sep 17 00:00:00 2001 From: Chelsea Sanders Date: Tue, 17 Dec 2024 10:32:37 +0000 Subject: [PATCH] fix(PROTECT-3467): recover banner link to go to login (#8685) --- .changeset/fresh-rabbits-do.md | 5 +++ .../src/components/RecoverBanner/index.tsx | 37 ++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 .changeset/fresh-rabbits-do.md diff --git a/.changeset/fresh-rabbits-do.md b/.changeset/fresh-rabbits-do.md new file mode 100644 index 000000000000..a364c532f471 --- /dev/null +++ b/.changeset/fresh-rabbits-do.md @@ -0,0 +1,5 @@ +--- +"live-mobile": patch +--- + +Redirect users to Recover Login if they have an account as they may be logged out diff --git a/apps/ledger-live-mobile/src/components/RecoverBanner/index.tsx b/apps/ledger-live-mobile/src/components/RecoverBanner/index.tsx index fb6b557e7177..89c634221166 100644 --- a/apps/ledger-live-mobile/src/components/RecoverBanner/index.tsx +++ b/apps/ledger-live-mobile/src/components/RecoverBanner/index.tsx @@ -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(); + const [storageData, setStorageData] = useState( + LedgerRecoverSubscriptionStateEnum.NO_SUBSCRIPTION, + ); const [displayBannerData, setDisplayBannerData] = useState(); const [stepNumber, setStepNumber] = useState(0); @@ -19,11 +31,10 @@ 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", ); @@ -31,7 +42,7 @@ function RecoverBanner() { 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]); @@ -39,22 +50,22 @@ function RecoverBanner() { 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: @@ -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), ); };