Skip to content

Commit

Permalink
fix(llm/synconboarding): add device to known devices as soon as devic…
Browse files Browse the repository at this point in the history
…e is seeded (#4556)

* fix(llm/synconboarding): add device to known devices as soon as device seeded

* chore: changeset
  • Loading branch information
ofreyssinet-ledger authored Sep 1, 2023
1 parent 8f99e87 commit 04206a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-donuts-swim.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,27 @@ export const SyncOnboardingCompanion: React.FC<SyncOnboardingCompanionProps> = (
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,
name: device.deviceName ?? device.modelId,
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]);

Expand Down Expand Up @@ -426,17 +433,24 @@ export const SyncOnboardingCompanion: React.FC<SyncOnboardingCompanionProps> = (

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);
}

Expand All @@ -447,7 +461,7 @@ export const SyncOnboardingCompanion: React.FC<SyncOnboardingCompanionProps> = (
readyRedirectTimerRef.current = null;
}
};
}, [companionStepKey, handleDeviceReady]);
}, [companionStepKey, addToKnownDevices, handleOnboardingDone]);

useEffect(
() =>
Expand Down

1 comment on commit 04206a2

@vercel
Copy link

@vercel vercel bot commented on 04206a2 Sep 1, 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.