@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
50 lines • 1.96 kB
JavaScript
import { initialSharedActionState, sharedReducer } from "./core";
import { toggleOnboardingEarlyCheckTask, } from "../tasks/toggleOnboardingEarlyCheck";
import { scan } from "rxjs/operators";
export const initialState = {
toggleStatus: "none",
...initialSharedActionState,
};
/**
* During the onboarding, makes the device enter or exit the early security check steps
*
* This action only puts (or moves out) the device to the state/step of the early security check.
* It does not starts any "security checks".
*
* If the device is not in the WELCOME or WELCOME_STEP2 onboarding state, this action will emit
* a "DeviceInInvalidState" event.
*
* @param deviceId A device id, or an empty string if device is usb plugged
* @param toggleType either "enter" or "exit"
* @returns An observable that emits updates on the of the onboarding early check toggling state
*/
export function toggleOnboardingEarlyCheckAction({ deviceId, deviceName, toggleType, }) {
return toggleOnboardingEarlyCheckTask({ deviceId, deviceName, toggleType }).pipe(scan((currentState, event) => {
switch (event.type) {
case "taskError":
return {
...initialState,
error: {
type: "ToggleOnboardingEarlyCheckError",
name: event.error,
},
toggleStatus: "failure",
};
case "success":
return {
...currentState,
error: null,
toggleStatus: "success",
};
case "error":
return {
...currentState,
...sharedReducer({
event,
}),
toggleStatus: "failure",
};
}
}, initialState));
}
//# sourceMappingURL=toggleOnboardingEarlyCheck.js.map