From 04206a2939bb8bb807a9f57a175f054c613e3d57 Mon Sep 17 00:00:00 2001 From: ofreyssinet-ledger <91890529+ofreyssinet-ledger@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:06:40 +0200 Subject: [PATCH] fix(llm/synconboarding): add device to known devices as soon as device is seeded (#4556) * fix(llm/synconboarding): add device to known devices as soon as device seeded * chore: changeset --- .changeset/poor-donuts-swim.md | 5 ++++ .../SyncOnboardingCompanion.tsx | 30 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 .changeset/poor-donuts-swim.md diff --git a/.changeset/poor-donuts-swim.md b/.changeset/poor-donuts-swim.md new file mode 100644 index 000000000000..6f1fed6e8068 --- /dev/null +++ b/.changeset/poor-donuts-swim.md @@ -0,0 +1,5 @@ +--- +"live-mobile": patch +--- + +Fix sync onboarding: if the sync onboarding is aborted after the device has been seeded, the device should appear in the list of known devices diff --git a/apps/ledger-live-mobile/src/screens/SyncOnboarding/SyncOnboardingCompanion.tsx b/apps/ledger-live-mobile/src/screens/SyncOnboarding/SyncOnboardingCompanion.tsx index 8421444c3905..3ccce78aacc2 100644 --- a/apps/ledger-live-mobile/src/screens/SyncOnboarding/SyncOnboardingCompanion.tsx +++ b/apps/ledger-live-mobile/src/screens/SyncOnboarding/SyncOnboardingCompanion.tsx @@ -226,12 +226,11 @@ export const SyncOnboardingCompanion: React.FC = ( onLostDevice(); }, [onShouldHeaderBeOverlaid, onLostDevice]); - const handleDeviceReady = useCallback(() => { - // Adds the device to the list of known devices - dispatchRedux(setReadOnlyMode(false)); - dispatchRedux(setHasOrderedNano(false)); + /** + * Adds the device to the list of known devices + */ + const addToKnownDevices = useCallback(() => { dispatchRedux(setLastConnectedDevice(device)); - dispatchRedux(completeOnboarding()); dispatchRedux( addKnownDevice({ id: device.deviceId, @@ -239,7 +238,15 @@ export const SyncOnboardingCompanion: React.FC = ( modelId: device.modelId, }), ); + }, [device, dispatchRedux]); + /** + * Triggers the end of the onboarding + */ + const handleOnboardingDone = useCallback(() => { + dispatchRedux(setReadOnlyMode(false)); + dispatchRedux(setHasOrderedNano(false)); + dispatchRedux(completeOnboarding()); navigation.navigate(ScreenName.SyncOnboardingCompletion, { device }); }, [device, dispatchRedux, navigation]); @@ -426,17 +433,24 @@ export const SyncOnboardingCompanion: React.FC = ( const preventNavigation = useRef(false); + const addedToKnownDevices = useRef(false); useEffect(() => { - // Stops the polling once the installation apps step is reached if (companionStepKey >= CompanionStepKey.Apps) { + // Stops the polling once the installation apps step is reached setIsPollingOn(false); + // At this step, device has been successfully setup so it can be saved in + // the list of known devices + if (!addedToKnownDevices.current) { + addedToKnownDevices.current = true; + addToKnownDevices(); + } } if (companionStepKey === CompanionStepKey.Exit) { preventNavigation.current = true; readyRedirectTimerRef.current = setTimeout(() => { preventNavigation.current = false; - handleDeviceReady(); + handleOnboardingDone(); }, READY_REDIRECT_DELAY_MS); } @@ -447,7 +461,7 @@ export const SyncOnboardingCompanion: React.FC = ( readyRedirectTimerRef.current = null; } }; - }, [companionStepKey, handleDeviceReady]); + }, [companionStepKey, addToKnownDevices, handleOnboardingDone]); useEffect( () =>