import React from "react";
import lbry from "lbry.js";
import lbryio from "lbryio.js";
import Modal from "component/modal.js";
import ModalPage from "component/modal-page.js";
import Link from "component/link"
import {BusyMessage} from "component/common"
import {RewardLink} from 'component/rewardLink';
import UserEmailNew from 'component/userEmailNew';
import {FormRow} from "component/form.js";
import {CreditAmount, Address} from "component/common.js";
import {getLocal, setLocal} from 'utils.js';
class EmailStage extends React.Component {
constructor(props) {
super(props);
this.state = {
showNoEmailConfirm: false,
};
}
onEmailSkipClick() {
this.setState({ showNoEmailConfirm: true })
}
onEmailSkipConfirm() {
this.props.userEmailDecline()
}
render() {
return (
{ this.state.showNoEmailConfirm ?
If you continue without an email, you will be ineligible to earn free LBC rewards, as well as unable to receive security related communications.
{ this.onEmailSkipConfirm() }} label="Continue without email" />
:
{ this.onEmailSkipClick() }} label="Do I have to?" />
}
);
}
}
class ConfirmEmailStage extends React.Component {
constructor(props) {
super(props);
this.state = {
code: '',
submitting: false,
errorMessage: null,
};
}
handleCodeChanged(event) {
this.setState({
code: event.target.value,
});
}
handleSubmit(event) {
event.preventDefault();
this.setState({
submitting: true,
});
const onSubmitError = (error) => {
if (this._codeRow) {
this._codeRow.showError(error.message)
}
this.setState({ submitting: false });
};
lbryio.call('user_email', 'confirm', {verification_token: this.state.code, email: this.props.email}, 'post').then((userEmail) => {
if (userEmail.is_verified) {
this.props.setStage("welcome")
} else {
onSubmitError(new Error("Your email is still not verified.")) //shouldn't happen?
}
}, onSubmitError);
}
render() {
return (
);
}
}
class WelcomeStage extends React.Component {
static propTypes = {
endAuth: React.PropTypes.func,
}
constructor(props) {
super(props);
this.state = {
hasReward: false,
rewardAmount: null,
};
}
onRewardClaim(reward) {
this.setState({
hasReward: true,
rewardAmount: reward.amount
})
}
render() {
return (
!this.state.hasReward ?
Welcome to LBRY.
Using LBRY is like dating a centaur. Totally normal up top, and way different underneath.
Up top, LBRY is similar to popular media sites.
Below, LBRY is controlled by users -- you -- via blockchain and decentralization.
Thank you for making content freedom possible! Here's a nickel, kid.
{ this.onRewardClaim(event) }} onRewardFailure={() => this.props.setStage(null)} onConfirmed={() => { this.props.setStage(null) }} />
:
{ this.props.setStage(null) }}>
About Your Reward
You earned a reward of LBRY credits, or LBC.
This reward will show in your Wallet momentarily, probably while you are reading this message.
LBC is used to compensate creators, to publish, and to have say in how the network works.
No need to understand it all just yet! Try watching or downloading something next.
Finally, know that LBRY is an early beta and that it earns the name.
);
}
}
const ErrorStage = (props) => {
return
An error was encountered that we cannot continue from.
At least we're earning the name beta.
{ props.errorText ? Message: {props.errorText}
: '' }
{ window.location.reload() } } />
}
const PendingStage = (props) => {
return
}
class CodeRequiredStage extends React.Component {
constructor(props) {
super(props);
this._balanceSubscribeId = null
this.state = {
balance: 0,
address: getLocal('wallet_address')
};
}
componentWillMount() {
this._balanceSubscribeId = lbry.balanceSubscribe((balance) => {
this.setState({
balance: balance
});
})
if (!this.state.address) {
lbry.wallet_unused_address().then((address) => {
setLocal('wallet_address', address);
this.setState({ address: address });
});
}
}
componentWillUnmount() {
if (this._balanceSubscribeId) {
lbry.balanceUnsubscribe(this._balanceSubscribeId)
}
}
render() {
const disabled = this.state.balance < 1;
return (
Early access to LBRY is restricted as we build and scale the network.
There are two ways in.
Own LBRY Credits
If you own at least 1 LBC, you can get in right now.
{ setLocal('auth_bypassed', true); this.props.setStage(null); }}
disabled={disabled} label="Let Me In" button={ disabled ? "alt" : "primary" } />
Your balance is . To increase your balance, send credits to this address:
If you don't understand how to send credits, then...
Wait For A Code
If you provide your email, you'll automatically receive a notification when the system is open.
{ this.props.setStage("email"); }} label="Return" />
);
}
}
export class AuthOverlay extends React.Component {
constructor(props) {
super(props);
this._stages = {
error: ErrorStage,
nocode: CodeRequiredStage,
confirm: ConfirmEmailStage,
welcome: WelcomeStage
}
}
setStage(stage, stageProps = {}) {
this.setState({
stage: stage,
stageProps: stageProps
})
}
componentWillMount() {
// lbryio.authenticate().then((user) => {
// if (!user.has_verified_email) {
// if (getLocal('auth_bypassed')) {
// this.setStage(null)
// } else {
// this.setStage("email", {})
// }
// } else {
// lbryio.call('reward', 'list', {}).then((userRewards) => {
// userRewards.filter(function(reward) {
// return reward.reward_type == rewards.TYPE_NEW_USER && reward.transaction_id;
// }).length ?
// this.setStage(null) :
// this.setStage("welcome")
// });
// }
// }).catch((err) => {
// this.setStage("error", { errorText: err.message })
// document.dispatchEvent(new CustomEvent('unhandledError', {
// detail: {
// message: err.message,
// data: err.stack
// }
// }));
// })
}
render() {
let stageContent
const {
isPending,
isEmailDeclined,
user,
userEmailDecline
} = this.props
console.log('auth overlay render')
console.log(user)
if (isEmailDeclined) {
return null
} else if (isPending) {
stageContent = ;
} else if (!user.has_email) {
stageContent = ;
}
else {
return null
//StageContent = this._stages[this.state.stage];
}
return
LBRY Early Access
{stageContent}
;
//setStage={(stage, stageProps) => { this.setStage(stage, stageProps) }} {...this.state.stageProps}
return (
true || this.state.stage != "welcome" ?
LBRY Early Access
:
);
}
}
export default AuthOverlay