2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-05-05 21:04:47 +02:00
|
|
|
import { MODALS } from 'lbry-redux';
|
2017-12-21 22:08:54 +01:00
|
|
|
import ModalError from 'modal/modalError';
|
|
|
|
import ModalAuthFailure from 'modal/modalAuthFailure';
|
|
|
|
import ModalDownloading from 'modal/modalDownloading';
|
2018-01-23 08:44:15 +01:00
|
|
|
import ModalAutoUpdateDownloaded from 'modal/modalAutoUpdateDownloaded';
|
|
|
|
import ModalAutoUpdateConfirm from 'modal/modalAutoUpdateConfirm';
|
2017-12-21 22:08:54 +01:00
|
|
|
import ModalUpgrade from 'modal/modalUpgrade';
|
|
|
|
import ModalWelcome from 'modal/modalWelcome';
|
|
|
|
import ModalFirstReward from 'modal/modalFirstReward';
|
|
|
|
import ModalRewardApprovalRequired from 'modal/modalRewardApprovalRequired';
|
|
|
|
import ModalCreditIntro from 'modal/modalCreditIntro';
|
|
|
|
import ModalRemoveFile from 'modal/modalRemoveFile';
|
|
|
|
import ModalTransactionFailed from 'modal/modalTransactionFailed';
|
|
|
|
import ModalFileTimeout from 'modal/modalFileTimeout';
|
|
|
|
import ModalAffirmPurchase from 'modal/modalAffirmPurchase';
|
|
|
|
import ModalRevokeClaim from 'modal/modalRevokeClaim';
|
2018-03-16 19:22:19 +01:00
|
|
|
import ModalEmailCollection from 'modal/modalEmailCollection';
|
|
|
|
import ModalPhoneCollection from 'modal/modalPhoneCollection';
|
|
|
|
import ModalFirstSubscription from 'modal/modalFirstSubscription';
|
2018-05-28 21:53:15 +02:00
|
|
|
import ModalConfirmTransaction from 'modal/modalConfirmTransaction';
|
2018-03-26 23:32:43 +02:00
|
|
|
import ModalSendTip from '../modalSendTip';
|
|
|
|
import ModalPublish from '../modalPublish';
|
2018-05-10 02:21:54 +02:00
|
|
|
import ModalOpenExternalLink from '../modalOpenExternalLink';
|
2018-04-02 18:03:12 +02:00
|
|
|
import ModalConfirmThumbnailUpload from 'modal/modalConfirmThumbnailUpload';
|
2018-07-18 21:48:30 +02:00
|
|
|
import ModalWalletEncrypt from 'modal/modalWalletEncrypt';
|
|
|
|
import ModalWalletDecrypt from 'modal/modalWalletDecrypt';
|
|
|
|
import ModalWalletUnlock from 'modal/modalWalletUnlock';
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2018-04-02 18:03:12 +02:00
|
|
|
type Props = {
|
|
|
|
modal: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ModalRouter extends React.PureComponent<Props> {
|
2017-08-26 05:21:26 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
lastTransitionModal: null,
|
|
|
|
lastTransitionPage: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-18 19:09:40 +02:00
|
|
|
componentWillMount() {
|
2017-08-21 05:06:26 +02:00
|
|
|
this.showTransitionModals(this.props);
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-08-21 05:06:26 +02:00
|
|
|
this.showTransitionModals(nextProps);
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 05:06:26 +02:00
|
|
|
showTransitionModals(props) {
|
2017-09-08 05:15:05 +02:00
|
|
|
const { modal, modalProps, openModal, page } = props;
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2017-08-21 05:06:26 +02:00
|
|
|
if (modal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-26 05:21:26 +02:00
|
|
|
const transitionModal = [
|
|
|
|
this.checkShowWelcome,
|
2017-12-07 19:07:30 +01:00
|
|
|
this.checkShowEmail,
|
2017-08-26 05:21:26 +02:00
|
|
|
this.checkShowCreditIntro,
|
2017-12-21 22:08:54 +01:00
|
|
|
].reduce((acc, func) => (!acc ? func.bind(this)(props) : acc), false);
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2017-08-26 05:21:26 +02:00
|
|
|
if (
|
|
|
|
transitionModal &&
|
2018-04-02 18:03:12 +02:00
|
|
|
(transitionModal !== this.state.lastTransitionModal || page !== this.state.lastTransitionPage)
|
2017-08-26 05:21:26 +02:00
|
|
|
) {
|
2018-04-19 18:51:18 +02:00
|
|
|
openModal({ id: transitionModal });
|
2017-08-26 05:21:26 +02:00
|
|
|
this.setState({
|
|
|
|
lastTransitionModal: transitionModal,
|
|
|
|
lastTransitionPage: page,
|
|
|
|
});
|
|
|
|
}
|
2017-08-21 05:06:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkShowWelcome(props) {
|
2017-08-26 05:21:26 +02:00
|
|
|
const { isWelcomeAcknowledged, user } = props;
|
2017-12-21 22:08:54 +01:00
|
|
|
if (!isWelcomeAcknowledged && user && !user.is_reward_approved && !user.is_identity_verified) {
|
2018-05-05 21:04:47 +02:00
|
|
|
return MODALS.WELCOME;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 19:07:30 +01:00
|
|
|
checkShowEmail(props) {
|
2017-12-21 22:08:54 +01:00
|
|
|
const { isEmailCollectionAcknowledged, isVerificationCandidate, user } = props;
|
2017-08-21 05:06:26 +02:00
|
|
|
if (
|
2017-12-07 19:07:30 +01:00
|
|
|
!isEmailCollectionAcknowledged &&
|
|
|
|
isVerificationCandidate &&
|
2017-08-21 05:06:26 +02:00
|
|
|
user &&
|
2017-12-07 19:07:30 +01:00
|
|
|
!user.has_verified_email
|
2017-08-21 05:06:26 +02:00
|
|
|
) {
|
2018-05-05 21:04:47 +02:00
|
|
|
return MODALS.EMAIL_COLLECTION;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 19:07:30 +01:00
|
|
|
checkShowCreditIntro(props) {
|
|
|
|
const { balance, page, isCreditIntroAcknowledged } = props;
|
2017-08-26 05:21:26 +02:00
|
|
|
|
2017-12-07 19:07:30 +01:00
|
|
|
if (
|
2018-06-18 08:34:59 +02:00
|
|
|
balance === 0 &&
|
2017-12-07 19:07:30 +01:00
|
|
|
!isCreditIntroAcknowledged &&
|
2017-12-21 22:08:54 +01:00
|
|
|
(['send', 'publish'].includes(page) || this.isPaidShowPage(props))
|
2017-12-07 19:07:30 +01:00
|
|
|
) {
|
2018-05-05 21:04:47 +02:00
|
|
|
return MODALS.INSUFFICIENT_CREDITS;
|
2017-08-26 05:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isPaidShowPage(props) {
|
|
|
|
const { page, showPageCost } = props;
|
2017-12-21 22:08:54 +01:00
|
|
|
return page === 'show' && showPageCost > 0;
|
2017-08-26 05:21:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-18 19:09:40 +02:00
|
|
|
render() {
|
2018-04-19 18:51:18 +02:00
|
|
|
const { notification, notificationProps } = this.props;
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2018-04-19 18:51:18 +02:00
|
|
|
if (!notification) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-23 07:04:11 +02:00
|
|
|
|
|
|
|
if (notification.error) {
|
|
|
|
return <ModalError {...notification} {...notificationProps} />;
|
|
|
|
}
|
|
|
|
|
2018-04-19 18:51:18 +02:00
|
|
|
switch (notification.id) {
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.UPGRADE:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalUpgrade {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.DOWNLOADING:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalDownloading {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.AUTO_UPDATE_DOWNLOADED:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalAutoUpdateDownloaded {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.AUTO_UPDATE_CONFIRM:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalAutoUpdateConfirm {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.ERROR:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalError {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.FILE_TIMEOUT:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalFileTimeout {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.INSUFFICIENT_CREDITS:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalCreditIntro {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.WELCOME:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalWelcome {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.FIRST_REWARD:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalFirstReward {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.AUTHENTICATION_FAILURE:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalAuthFailure {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.TRANSACTION_FAILED:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalTransactionFailed {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.REWARD_APPROVAL_REQUIRED:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalRewardApprovalRequired {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.CONFIRM_FILE_REMOVE:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalRemoveFile {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.AFFIRM_PURCHASE:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalAffirmPurchase {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.CONFIRM_CLAIM_REVOKE:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalRevokeClaim {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.PHONE_COLLECTION:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalPhoneCollection {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.EMAIL_COLLECTION:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalEmailCollection {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.FIRST_SUBSCRIPTION:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalFirstSubscription {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.SEND_TIP:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalSendTip {...notificationProps} />;
|
2018-05-05 21:04:47 +02:00
|
|
|
case MODALS.PUBLISH:
|
2018-04-19 18:51:18 +02:00
|
|
|
return <ModalPublish {...notificationProps} />;
|
2018-05-10 02:21:54 +02:00
|
|
|
case MODALS.CONFIRM_EXTERNAL_LINK:
|
|
|
|
return <ModalOpenExternalLink {...notificationProps} />;
|
2018-05-28 21:53:15 +02:00
|
|
|
case MODALS.CONFIRM_TRANSACTION:
|
|
|
|
return <ModalConfirmTransaction {...notificationProps} />;
|
2018-04-02 18:03:12 +02:00
|
|
|
case MODALS.CONFIRM_THUMBNAIL_UPLOAD:
|
2018-06-08 06:05:45 +02:00
|
|
|
return <ModalConfirmThumbnailUpload {...notificationProps} />;
|
2018-07-18 21:48:30 +02:00
|
|
|
case MODALS.WALLET_ENCRYPT:
|
|
|
|
return <ModalWalletEncrypt {...notificationProps} />;
|
|
|
|
case MODALS.WALLET_DECRYPT:
|
|
|
|
return <ModalWalletDecrypt {...notificationProps} />;
|
|
|
|
case MODALS.WALLET_UNLOCK:
|
|
|
|
return <ModalWalletUnlock {...notificationProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalRouter;
|