lbry-desktop/ui/js/selectors/user.js

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-06-08 02:56:52 +02:00
import { createSelector } from "reselect";
2017-06-01 18:20:12 +02:00
2017-06-08 02:56:52 +02:00
export const _selectState = state => state.user || {};
2017-06-01 18:20:12 +02:00
export const selectAuthenticationIsPending = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.authenticationIsPending
);
2017-06-01 18:20:12 +02:00
2017-06-08 23:15:34 +02:00
export const selectUserIsPending = createSelector(
_selectState,
state => state.userIsPending
);
2017-07-16 18:29:46 +02:00
export const selectUser = createSelector(_selectState, state => state.user);
2017-06-08 02:56:52 +02:00
export const selectEmailToVerify = createSelector(
2017-06-03 01:09:52 +02:00
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailToVerify
);
2017-07-19 01:00:13 +02:00
export const selectUserEmail = createSelector(
selectUser,
user => (user && user.email ? user.email : "fake@lbry.io")
);
2017-06-08 02:56:52 +02:00
export const selectUserHasEmail = createSelector(
selectUser,
selectEmailToVerify,
2017-06-22 02:09:30 +02:00
(user, email) => (user && user.has_email) || !!email
2017-06-08 02:56:52 +02:00
);
export const selectUserIsRewardApproved = createSelector(
selectUser,
2017-06-08 23:15:34 +02:00
user => user && user.is_reward_approved
2017-06-08 02:56:52 +02:00
);
2017-06-03 01:09:52 +02:00
export const selectEmailNewIsPending = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailNewIsPending
);
export const selectEmailNewErrorMessage = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailNewErrorMessage
);
export const selectEmailNewDeclined = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailNewDeclined
);
2017-06-03 01:09:52 +02:00
export const selectEmailVerifyIsPending = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailVerifyIsPending
);
2017-06-03 01:09:52 +02:00
export const selectEmailVerifyErrorMessage = createSelector(
_selectState,
2017-06-08 02:56:52 +02:00
state => state.emailVerifyErrorMessage
);
2017-07-19 01:00:13 +02:00
export const selectIdentityVerifyIsPending = createSelector(
_selectState,
state => state.identityVerifyIsPending
);
export const selectIdentityVerifyErrorMessage = createSelector(
_selectState,
state => state.identityVerifyErrorMessage
);
2017-06-08 02:56:52 +02:00
export const selectUserIsVerificationCandidate = createSelector(
selectUser,
2017-07-16 18:29:46 +02:00
user => user && (!user.has_verified_email || !user.is_identity_verified)
2017-06-08 02:56:52 +02:00
);
export const selectUserIsAuthRequested = createSelector(
selectEmailNewDeclined,
selectAuthenticationIsPending,
selectUserIsVerificationCandidate,
selectUserHasEmail,
(isEmailDeclined, isPending, isVerificationCandidate, hasEmail) =>
!isEmailDeclined && (isPending || !hasEmail || isVerificationCandidate)
);