import React from 'react'; import lbry from '../lbry.js'; import {Link} from '../component/link.js'; import Modal from '../component/modal.js'; var referralCodeContentStyle = { display: 'inline-block', textAlign: 'left', width: '600px', }, referralCodeLabelStyle = { display: 'inline-block', cursor: 'default', width: '130px', textAlign: 'right', marginRight: '6px', }; var ReferralPage = React.createClass({ getInitialState: function() { return { submitting: false, modal: null, referralCredits: null, failureReason: null, } }, handleSubmit: function(event) { if (typeof event !== 'undefined') { event.preventDefault(); } if (!this.refs.code.value) { this.setState({ modal: 'missingCode', }); } else if (!this.refs.email.value) { this.setState({ modal: 'missingEmail', }); } this.setState({ submitting: true, }); lbry.getUnusedAddress((address) => { var code = this.refs.code.value; var email = this.refs.email.value; var xhr = new XMLHttpRequest; xhr.addEventListener('load', () => { var response = JSON.parse(xhr.responseText); if (response.success) { this.setState({ modal: 'referralInfo', referralCredits: response.referralCredits, }); } else { this.setState({ submitting: false, modal: 'lookupFailed', failureReason: response.reason, }); } }); xhr.addEventListener('error', () => { this.setState({ submitting: false, modal: 'couldNotConnect', }); }); xhr.open('POST', 'https://invites.lbry.io/check', true); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.send('code=' + encodeURIComponent(code) + '&address=' + encodeURIComponent(address) + '&email=' + encodeURIComponent(email)); }); }, closeModal: function() { this.setState({ modal: null, }); }, handleFinished: function() { localStorage.setItem('claimCodeDone', true); window.location = '?home'; }, render: function() { return (

Check your referral credits

Have you referred others to LBRY? Enter your referral code and email address below to check how many credits you've earned!

As a reminder, your referral code is the same as your LBRY invitation code.

{this.state.referralCredits > 0 ? `You have earned ${response.referralCredits} credits from referrals. We will credit your account shortly. Thanks!` : 'You have not earned any new referral credits since the last time you checked. Please check back in a week or two.'} {this.state.failureReason} LBRY couldn't connect to our servers to confirm your referral code. Please check your internet connection.
); } }); export default ReferralPage;