UNPKG

@ledgerhq/live-common

Version:
101 lines 4.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.walletEntryPointEligibleForPortfolioSelector = exports.entryPointFirstDisplayedDateSelector = exports.walletPostOnboardingEntryPointDismissedSelector = exports.postOnboardingDeviceModelIdSelector = exports.hubStateSelector = exports.postOnboardingSelector = exports.initialState = void 0; const types_devices_1 = require("@ledgerhq/types-devices"); const redux_actions_1 = require("redux-actions"); const reselect_1 = require("reselect"); exports.initialState = { deviceModelId: null, walletEntryPointDismissed: false, entryPointFirstDisplayedDate: null, walletEntryPointEligibleForPortfolio: null, actionsToComplete: [], actionsCompleted: {}, lastActionCompleted: null, postOnboardingInProgress: false, }; const handlers = { POST_ONBOARDING_IMPORT_STATE: (_, { payload }) => ({ ...exports.initialState, ...payload.newState, }), POST_ONBOARDING_INIT: (_, { payload }) => { const { deviceModelId, actionsIds } = payload; return { deviceModelId, walletEntryPointDismissed: false, entryPointFirstDisplayedDate: new Date(), walletEntryPointEligibleForPortfolio: null, actionsToComplete: actionsIds, actionsCompleted: Object.fromEntries(actionsIds.map(id => [id, false])), lastActionCompleted: null, postOnboardingInProgress: true, }; }, POST_ONBOARDING_SET_ACTION_COMPLETED: (state, { payload }) => { const { actionId } = payload; const actionsCompleted = { ...state.actionsCompleted, [actionId]: true }; return { ...state, actionsCompleted, lastActionCompleted: actionId, }; }, POST_ONBOARDING_CLEAR_LAST_ACTION_COMPLETED: state => ({ ...state, lastActionCompleted: null, }), POST_ONBOARDING_HIDE_WALLET_ENTRY_POINT: state => ({ ...state, walletEntryPointDismissed: true, entryPointFirstDisplayedDate: null, }), POST_ONBOARDING_SET_WALLET_ENTRY_POINT_ELIGIBILITY: (state, { payload }) => { if (typeof payload !== "boolean") return state; return { ...state, walletEntryPointEligibleForPortfolio: payload, }; }, POST_ONBOARDING_SET_FINISHED: state => ({ ...state, postOnboardingInProgress: false, }), }; exports.default = (0, redux_actions_1.handleActions)(handlers, exports.initialState); /** * remove this function once we can safely assume no user has a LL holding in * storage a ref to the old identifier "nanoFTS" which was changed in this PR * https://github.com/LedgerHQ/ledger-live/pull/2144 * */ function sanitizeDeviceModelId(deviceModelId) { if (deviceModelId === null) return null; // Nb workaround to prevent crash for dev/qa that have nanoFTS references. // to be removed in a while. // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore if (deviceModelId === "nanoFTS") return types_devices_1.DeviceModelId.stax; return deviceModelId; } exports.postOnboardingSelector = (0, reselect_1.createSelector)((state) => state.postOnboarding, postOnboarding => ({ ...postOnboarding, deviceModelId: sanitizeDeviceModelId(postOnboarding.deviceModelId), })); exports.hubStateSelector = (0, reselect_1.createSelector)(exports.postOnboardingSelector, postOnboarding => { const { deviceModelId, actionsToComplete, actionsCompleted, lastActionCompleted, postOnboardingInProgress, } = postOnboarding; return { deviceModelId: sanitizeDeviceModelId(deviceModelId), actionsToComplete, actionsCompleted, lastActionCompleted, postOnboardingInProgress, }; }); exports.postOnboardingDeviceModelIdSelector = (0, reselect_1.createSelector)(exports.postOnboardingSelector, postOnboarding => sanitizeDeviceModelId(postOnboarding.deviceModelId)); exports.walletPostOnboardingEntryPointDismissedSelector = (0, reselect_1.createSelector)(exports.postOnboardingSelector, postOnboarding => postOnboarding.walletEntryPointDismissed); exports.entryPointFirstDisplayedDateSelector = (0, reselect_1.createSelector)(exports.postOnboardingSelector, postOnboarding => postOnboarding.entryPointFirstDisplayedDate); exports.walletEntryPointEligibleForPortfolioSelector = (0, reselect_1.createSelector)(exports.postOnboardingSelector, postOnboarding => postOnboarding.walletEntryPointEligibleForPortfolio); //# sourceMappingURL=reducer.js.map