import React from 'react';
import lbryio from '../lbryio.js';
import Modal from './modal.js';
import ModalPage from './modal-page.js';
import {Link, RewardLink} from '../component/link.js';
import {FormField, FormRow} from '../component/form.js';
import rewards from '../rewards.js';
const SubmitEmailStage = React.createClass({
getInitialState: function() {
return {
rewardType: null,
email: '',
submitting: false
};
},
handleEmailChanged: function(event) {
this.setState({
email: event.target.value,
});
},
handleSubmit: function(event) {
event.preventDefault();
this.setState({
submitting: true,
});
lbryio.call('user_email', 'new', {email: this.state.email}, 'post').then(() => {
this.props.onEmailSaved();
}, (error) => {
if (this._emailRow) {
this._emailRow.showError(error.message)
}
this.setState({ submitting: false });
});
},
render: function() {
return (
);
}
});
const ConfirmEmailStage = React.createClass({
getInitialState: function() {
return {
rewardType: null,
code: '',
submitting: false,
errorMessage: null,
};
},
handleCodeChanged: function(event) {
this.setState({
code: event.target.value,
});
},
handleSubmit: function(event) {
event.preventDefault();
this.setState({
submitting: true,
});
const onSubmitError = function(error) {
if (this._codeRow) {
this._codeRow.showError(error.message)
}
this.setState({ submitting: false });
}.bind(this)
lbryio.call('user_email', 'confirm', {verification_token: this.state.code}, 'post').then((userEmail) => {
if (userEmail.IsVerified) {
this.props.onEmailConfirmed();
} else {
onSubmitError(new Error("Your email is still not verified.")) //shouldn't happen?
}
}, onSubmitError);
},
render: function() {
return (
);
}
});
const WelcomeStage = React.createClass({
render: function() {
//
Thank you
return (
Welcome to LBRY.
LBRY is kind of like a centaur. Totally normal up top, and way different underneath.
On the upper level, LBRY is like other popular video and media sites.
Below, LBRY is like nothing else. Through blockchain and decentralization, LBRY is controlled by it's users -- that is, you.
Here is a reward for reading our weird centaur metaphor:
This reward earned you LBC. LBC is used to watch stuff and to have say in how the network works.
But no need to understand it all just yet! Try watching something next.
);
}
});
const ErrorStage = React.createClass({
render: function() {
return (
An error was encountered that we cannot continue from.
At least we're earning the name beta.
{ window.location.reload() } } />
);
}
});
const PendingStage = React.createClass({
render: function() {
return (
Preparing for first access
);
}
});
export const AuthOverlay = React.createClass({
_stages: {
pending: PendingStage,
error: ErrorStage,
email: SubmitEmailStage,
confirm: ConfirmEmailStage,
welcome: WelcomeStage,
},
getInitialState: function() {
return {
stage: null,
stageProps: {}
};
},
endAuth: function() {
this.setState({
stage: null
});
},
componentWillMount: function() {
lbryio.authenticate().then(function(user) {
if (!user.HasVerifiedEmail) { //oops I fucked this up
this.setState({
stage: "email",
stageProps: {
onEmailSaved: function() {
this.setState({
stage: "confirm",
stageProps: {
onEmailConfirmed: function() { this.setState({ stage: "welcome"}) }.bind(this)
}
})
}.bind(this)
}
})
} else {
this.endAuth()
}
}.bind(this)).catch((err) => {
this.setState({
stage: "error",
stageProps: { errorText: err.message }
})
document.dispatchEvent(new CustomEvent('unhandledError', {
detail: {
message: err.message,
data: err.stack
}
}));
})
},
render: function() {
if (!this.state.stage || lbryio.user && lbryio.user.HasVerifiedEmail) {
if (this.state.stage != "welcome") {
return null;
}
}
const StageContent = this._stages[this.state.stage];
return (
this.state.stage != "welcome" ?
LBRY Early Access
:
);
}
});