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 {CreditAmount} from '../component/common.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(this.state.email); }, (error) => { if (error.xhr && error.xhr.status == 409) { this.props.onEmailSaved(this.state.email); return; } else if (this._emailRow) { this._emailRow.showError(error.message) } this.setState({ submitting: false }); }); }, render: function() { return (
{ this._emailRow = ref }} type="text" label="Email" placeholder="scrwvwls@lbry.io" name="email" value={this.state.email} onChange={this.handleEmailChanged} />
); } }); const ConfirmEmailStage = React.createClass({ getInitialState: function() { return { rewardType: null, code: '', email: '', 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, email: this.state.email}, '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 (
{ this._codeRow = ref }} type="text" name="code" placeholder="a94bXXXXXXXXXXXXXX" value={this.state.code} onChange={this.handleCodeChanged} helper="A verification code is required to access this version."/>
); } }); const WelcomeStage = React.createClass({ propTypes: { endAuth: React.PropTypes.func, }, getInitialState: function() { return { hasReward: false, rewardAmount: null, } }, onRewardClaim: function(reward) { this.setState({ hasReward: true, rewardAmount: reward.amount }) }, render: function() { 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.

:

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 a beta and that it earns the name.

); } }); const ErrorStage = React.createClass({ render: function() { return (

An error was encountered that we cannot continue from.

At least we're earning the name beta.

{ this.props.errorText ?

Message: {this.props.errorText}

: '' } { 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: "pending", 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(email) { this.setState({ stage: "confirm", stageProps: { onEmailConfirmed: function() { this.setState({ stage: "welcome", email: email }) }.bind(this) } }) }.bind(this) } }) } else { lbryio.call('reward', 'list', {}).then(function(userRewards) { userRewards.filter(function(reward) { return reward.RewardType == "new_user" && reward.TransactionID; }).length ? this.endAuth() : this.setState({ stage: "welcome" }) }.bind(this)); } }.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) { return null; } const StageContent = this._stages[this.state.stage]; return ( this.state.stage != "welcome" ?

LBRY Early Access

: ); } });