2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import Router from "component/router";
|
|
|
|
import Header from "component/header";
|
2017-07-02 20:23:38 +02:00
|
|
|
import ModalError from "component/modalError";
|
2017-08-03 00:55:58 +02:00
|
|
|
import ModalAuthFailure from "component/modalAuthFailure";
|
2017-07-02 20:23:38 +02:00
|
|
|
import ModalDownloading from "component/modalDownloading";
|
2017-07-15 20:44:50 +02:00
|
|
|
import ModalInsufficientCredits from "component/modalInsufficientCredits";
|
2017-07-10 19:19:42 +02:00
|
|
|
import ModalUpgrade from "component/modalUpgrade";
|
|
|
|
import ModalWelcome from "component/modalWelcome";
|
2017-07-25 00:59:26 +02:00
|
|
|
import ModalFirstReward from "component/modalFirstReward";
|
2017-07-27 22:15:13 +02:00
|
|
|
import ModalTransactionFailed from "component/modalTransactionFailed";
|
|
|
|
import ModalInsufficientBalance from "component/modalInsufficientBalance";
|
2017-06-06 23:19:12 +02:00
|
|
|
import lbry from "lbry";
|
2017-07-15 20:44:50 +02:00
|
|
|
import * as modals from "constants/modal_types";
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class App extends React.PureComponent {
|
2017-05-04 05:44:08 +02:00
|
|
|
componentWillMount() {
|
2017-07-25 09:07:54 +02:00
|
|
|
const {
|
|
|
|
alertError,
|
|
|
|
checkUpgradeAvailable,
|
|
|
|
updateBalance,
|
2017-07-30 00:56:08 +02:00
|
|
|
fetchRewardedContent,
|
2017-07-25 09:07:54 +02:00
|
|
|
} = this.props;
|
2017-07-16 18:29:46 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
document.addEventListener("unhandledError", event => {
|
2017-07-16 18:29:46 +02:00
|
|
|
alertError(event.detail);
|
2017-04-07 07:15:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!this.props.upgradeSkipped) {
|
2017-07-16 18:29:46 +02:00
|
|
|
checkUpgradeAvailable();
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2017-05-15 18:34:33 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
lbry.balanceSubscribe(balance => {
|
2017-07-16 18:29:46 +02:00
|
|
|
updateBalance(balance);
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-07-16 18:29:46 +02:00
|
|
|
|
2017-07-30 00:56:08 +02:00
|
|
|
fetchRewardedContent();
|
2017-07-25 09:07:54 +02:00
|
|
|
|
2017-07-16 18:29:46 +02:00
|
|
|
this.showWelcome(this.props);
|
2017-07-20 03:07:17 +02:00
|
|
|
|
2017-07-19 10:35:03 +02:00
|
|
|
this.scrollListener = () => this.props.recordScroll(window.scrollY);
|
|
|
|
|
|
|
|
window.addEventListener("scroll", this.scrollListener);
|
2017-07-16 18:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
this.showWelcome(nextProps);
|
|
|
|
}
|
|
|
|
|
|
|
|
showWelcome(props) {
|
2017-07-28 03:13:12 +02:00
|
|
|
const { isWelcomeAcknowledged, openWelcomeModal, user } = props;
|
2017-07-16 18:29:46 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
!isWelcomeAcknowledged &&
|
|
|
|
user &&
|
2017-07-28 03:13:12 +02:00
|
|
|
!user.is_reward_approved &&
|
|
|
|
!user.is_identity_verified
|
2017-07-16 18:29:46 +02:00
|
|
|
) {
|
|
|
|
openWelcomeModal();
|
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
|
|
|
|
2017-07-19 10:35:03 +02:00
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener("scroll", this.scrollListener);
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { modal } = this.props;
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
return (
|
|
|
|
<div id="window">
|
|
|
|
<Header />
|
|
|
|
<div id="main-content">
|
|
|
|
<Router />
|
|
|
|
</div>
|
2017-07-15 20:44:50 +02:00
|
|
|
{modal == modals.UPGRADE && <ModalUpgrade />}
|
|
|
|
{modal == modals.DOWNLOADING && <ModalDownloading />}
|
|
|
|
{modal == modals.ERROR && <ModalError />}
|
|
|
|
{modal == modals.INSUFFICIENT_CREDITS && <ModalInsufficientCredits />}
|
|
|
|
{modal == modals.WELCOME && <ModalWelcome />}
|
2017-07-25 00:59:26 +02:00
|
|
|
{modal == modals.FIRST_REWARD && <ModalFirstReward />}
|
2017-08-03 00:55:58 +02:00
|
|
|
{modal == modals.AUTHENTICATION_FAILURE && <ModalAuthFailure />}
|
2017-07-27 22:15:13 +02:00
|
|
|
{modal == modals.TRANSACTION_FAILED && <ModalTransactionFailed />}
|
|
|
|
{modal == modals.INSUFFICIENT_BALANCE && <ModalInsufficientBalance />}
|
2017-04-21 04:31:50 +02:00
|
|
|
</div>
|
2017-06-06 23:19:12 +02:00
|
|
|
);
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default App;
|