@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
51 lines • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePostOnboardingHubState = void 0;
const react_redux_1 = require("react-redux");
const react_1 = require("react");
const featureFlags_1 = require("../../featureFlags");
const reducer_1 = require("../reducer");
const usePostOnboardingContext_1 = require("./usePostOnboardingContext");
/**
* @returns an object representing the state that should be rendered on the post
* onboarding hub screen.
*
* This takes feature flagging into account so the logic is
* resistant to flags getting enabled/disabled over time (for a given disabled
* feature flag, the actions pointing to it will be excluded).
* */
function usePostOnboardingHubState() {
const hubState = (0, react_redux_1.useSelector)(reducer_1.hubStateSelector);
const postOnboardingContext = (0, usePostOnboardingContext_1.usePostOnboardingContext)();
const { getPostOnboardingAction } = postOnboardingContext;
const { getFeature } = (0, featureFlags_1.useFeatureFlags)();
return (0, react_1.useMemo)(() => {
if (!getPostOnboardingAction)
return {
deviceModelId: hubState.deviceModelId,
lastActionCompleted: null,
actionsState: [],
postOnboardingInProgress: hubState.postOnboardingInProgress,
};
const actionsState = hubState.actionsToComplete
.map(actionId => ({
...getPostOnboardingAction(actionId),
completed: !!hubState.actionsCompleted[actionId],
}))
.filter(actionWithState => !actionWithState.featureFlagId || getFeature(actionWithState.featureFlagId)?.enabled);
const lastActionCompleted = hubState.lastActionCompleted
? getPostOnboardingAction(hubState.lastActionCompleted)
: null;
const isLastActionCompletedEnabled = lastActionCompleted &&
(!lastActionCompleted.featureFlagId ||
getFeature(lastActionCompleted.featureFlagId)?.enabled);
return {
deviceModelId: hubState.deviceModelId,
lastActionCompleted: isLastActionCompletedEnabled ? lastActionCompleted : null,
actionsState,
postOnboardingInProgress: hubState.postOnboardingInProgress,
};
}, [getFeature, hubState, getPostOnboardingAction]);
}
exports.usePostOnboardingHubState = usePostOnboardingHubState;
//# sourceMappingURL=usePostOnboardingHubState.js.map