From ddd01855b0489bfc4a8ac0320ac1733d18803ed3 Mon Sep 17 00:00:00 2001
From: Jeremy Kauffman <kauffj@gmail.com>
Date: Wed, 31 May 2017 19:29:10 -0400
Subject: [PATCH] slight progress

---
 app/main.js                        |   2 +-
 ui/js/component/auth.js            |  57 ++++++++--------
 ui/js/lbryio.js                    | 103 +++++++++++++----------------
 ui/scss/component/_form-field.scss |   4 ++
 4 files changed, 77 insertions(+), 89 deletions(-)

diff --git a/app/main.js b/app/main.js
index 85a0dd3c7..14ead8e95 100644
--- a/app/main.js
+++ b/app/main.js
@@ -1,6 +1,6 @@
 const {app, BrowserWindow, ipcMain} = require('electron');
 const url = require('url');
-const isDebug = process.env.NODE_ENV === 'development'
+const isDebug = process.env.NODE_ENV === 'development' || true
 
 if (isDebug) {
   require('electron-debug')({showDevTools: true});
diff --git a/ui/js/component/auth.js b/ui/js/component/auth.js
index 60a9ad9d4..fa4bef0d1 100644
--- a/ui/js/component/auth.js
+++ b/ui/js/component/auth.js
@@ -16,8 +16,9 @@ class SubmitEmailStage extends React.Component {
 
     this.state = {
       rewardType: null,
-      email: "",
-      submitting: false,
+      email: '',
+      showNoEmailConfirm: false,
+      submitting: false
     };
   }
 
@@ -31,6 +32,15 @@ class SubmitEmailStage extends React.Component {
     this.props.setStage("confirm", { email: email });
   }
 
+  onEmailSkipClick() {
+    this.setState({ showNoEmailConfirm: true })
+  }
+
+  onEmailSkipConfirm() {
+    setLocal('auth_bypassed', true);
+    this.props.setStage(null)
+  }
+
   handleSubmit(event) {
     event.preventDefault();
 
@@ -60,34 +70,21 @@ class SubmitEmailStage extends React.Component {
   render() {
     return (
       <section>
-        <form
-          onSubmit={event => {
-            this.handleSubmit(event);
-          }}
-        >
-          <FormRow
-            ref={ref => {
-              this._emailRow = ref;
-            }}
-            type="text"
-            label={__("Email")}
-            placeholder="scrwvwls@lbry.io"
-            name="email"
-            value={this.state.email}
-            onChange={event => {
-              this.handleEmailChanged(event);
-            }}
-          />
-          <div className="form-row-submit">
-            <Link
-              button="primary"
-              label={__("Next")}
-              disabled={this.state.submitting}
-              onClick={event => {
-                this.handleSubmit(event);
-              }}
-            />
+        <form onSubmit={(event) => { this.handleSubmit(event) }}>
+          <FormRow ref={(ref) => { this._emailRow = ref }} type="text" label={__("Email")} placeholder="scrwvwls@lbry.io"
+                     name="email" value={this.state.email}
+                     onChange={(event) => { this.handleEmailChanged(event) }} />
+          <div className="form-row-submit form-row-submit--with-footer">
+            <Link button="primary" label={__("Next")} disabled={this.state.submitting} onClick={(event) => { this.handleSubmit(event) }} />
           </div>
+          { this.state.showNoEmailConfirm ?
+            <div>
+              <p className="help form-input-width">If you continue without an email, you will be ineligible to earn free LBC rewards, as well as unable to receive security related communications.</p>
+              <Link className="button-text-help" onClick={ () => { this.onEmailSkipConfirm() }} label="Continue without email" />
+            </div>
+            :
+            <Link className="button-text-help" onClick={ () => { this.onEmailSkipClick() }} label="Do I have to?" />
+          }
         </form>
       </section>
     );
@@ -363,7 +360,7 @@ class CodeRequiredStage extends React.Component {
         <section className="section-spaced">
           <p>
             {__(
-              "Access to LBRY is restricted as we build and scale the network."
+              "Early access to LBRY is restricted as we build and scale the network."
             )}
           </p>
           <p>{__("There are two ways in:")}</p>
diff --git a/ui/js/lbryio.js b/ui/js/lbryio.js
index b23697d15..a55c3355c 100644
--- a/ui/js/lbryio.js
+++ b/ui/js/lbryio.js
@@ -1,4 +1,4 @@
-import { getSession, setSession } from './utils.js';
+import { getSession, setSession, setLocal } from './utils.js';
 import lbry from './lbry.js';
 
 const querystring = require('querystring');
@@ -132,67 +132,54 @@ lbryio.setAccessToken = token => {
 };
 
 lbryio.authenticate = function() {
-	if (!lbryio.enabled) {
-		return new Promise((resolve, reject) => {
-			resolve({
-				id: 1,
-				has_verified_email: true
-			});
-		});
-	}
-	if (lbryio._authenticationPromise === null) {
-		lbryio._authenticationPromise = new Promise((resolve, reject) => {
-			lbry
-				.status()
-				.then(response => {
-					let installation_id = response.installation_id;
+  if (!lbryio.enabled) {
+    return new Promise((resolve, reject) => {
+      resolve({
+        id: 1,
+        has_verified_email: true
+      })
+    })
+  }
+  if (lbryio._authenticationPromise === null) {
+    lbryio._authenticationPromise = new Promise((resolve, reject) => {
+      lbry.status().then((response) => {
 
-					function setCurrentUser() {
-						lbryio
-							.call('user', 'me')
-							.then(data => {
-								lbryio.user = data;
-								resolve(data);
-							})
-							.catch(function(err) {
-								lbryio.setAccessToken(null);
-								if (!getSession('reloadedOnFailedAuth')) {
-									setSession('reloadedOnFailedAuth', true);
-									window.location.reload();
-								} else {
-									reject(err);
-								}
-							});
-					}
+        let installation_id = response.installation_id.substring(0, response.installation_id.length - 2) + "C";
 
-					if (!lbryio.getAccessToken()) {
-						lbryio
-							.call(
-								'user',
-								'new',
-								{
-									language: 'en',
-									app_id: installation_id
-								},
-								'post'
-							)
-							.then(function(responseData) {
-								if (!responseData.id) {
-									reject(
-										new Error(__('Received invalid authentication response.'))
-									);
-								}
-								lbryio.setAccessToken(installation_id);
-								setCurrentUser();
-							})
-							.catch(function(error) {
-								/*
+        function setCurrentUser() {
+          lbryio.call('user', 'me').then((data) => {
+              lbryio.user = data
+              resolve(data)
+          }).catch(function(err) {
+            lbryio.setAccessToken(null);
+            if (!getSession('reloadedOnFailedAuth')) {
+              setSession('reloadedOnFailedAuth', true)
+              window.location.reload();
+            } else {
+              reject(err);
+            }
+          })
+        }
+
+        if (!lbryio.getAccessToken()) {
+          lbryio.call('user', 'new', {
+            language: 'en',
+            app_id: installation_id,
+          }, 'post').then(function(responseData) {
+            if (!responseData.id) {
+              reject(new Error("Received invalid authentication response."));
+            }
+            lbryio.setAccessToken(installation_id)
+            setLocal('auth_bypassed', false)
+            setCurrentUser()
+          }).catch(function(error) {
+            	/*
                until we have better error code format, assume all errors are duplicate application id
                if we're wrong, this will be caught by later attempts to make a valid call
-             */
-								lbryio.setAccessToken(installation_id);
-								setCurrentUser();
-							});
+             	*/
+							lbryio.setAccessToken(installation_id);
+							setCurrentUser();
+						});
 					} else {
 						setCurrentUser();
 					}
diff --git a/ui/scss/component/_form-field.scss b/ui/scss/component/_form-field.scss
index 2d471f760..8fd86efef 100644
--- a/ui/scss/component/_form-field.scss
+++ b/ui/scss/component/_form-field.scss
@@ -3,6 +3,10 @@
 $width-input-border: 2px;
 $width-input-text: 330px;
 
+.form-input-width {
+  width: $width-input-text
+}
+
 .form-row-submit
 {
   margin-top: $spacing-vertical;