Seed Support #56

Closed
ocnios wants to merge 173 commits from master into build
4 changed files with 22 additions and 38 deletions
Showing only changes of commit b30bfd9f61 - Show all commits

View file

@ -29,9 +29,12 @@ const SubmitEmailStage = React.createClass({
submitting: true,
});
lbryio.call('user_email', 'new', {email: this.state.email}, 'post').then(() => {
this.props.onEmailSaved();
this.props.onEmailSaved(this.state.email);
}, (error) => {
if (this._emailRow) {
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 });
@ -58,6 +61,7 @@ const ConfirmEmailStage = React.createClass({
return {
rewardType: null,
code: '',
email: '',
submitting: false,
errorMessage: null,
};
@ -80,7 +84,7 @@ const ConfirmEmailStage = React.createClass({
this.setState({ submitting: false });
}.bind(this)
lbryio.call('user_email', 'confirm', {verification_token: this.state.code}, 'post').then((userEmail) => {
lbryio.call('user_email', 'confirm', {verification_token: this.state.code, email: this.state.email}, 'post').then((userEmail) => {
if (userEmail.IsVerified) {
this.props.onEmailConfirmed();
} else {
@ -115,7 +119,6 @@ const WelcomeStage = React.createClass({
}
},
onRewardClaim: function(reward) {
console.log(reward);
this.setState({
hasReward: true,
rewardAmount: reward.amount
@ -184,7 +187,7 @@ export const AuthOverlay = React.createClass({
},
getInitialState: function() {
return {
stage: null,
stage: "pending",
stageProps: {}
};
},
@ -199,11 +202,11 @@ export const AuthOverlay = React.createClass({
this.setState({
stage: "email",
stageProps: {
onEmailSaved: function() {
onEmailSaved: function(email) {
this.setState({
stage: "confirm",
stageProps: {
onEmailConfirmed: function() { this.setState({ stage: "welcome"}) }.bind(this)
onEmailConfirmed: function() { this.setState({ stage: "welcome", email: email }) }.bind(this)
}
})
}.bind(this)

View file

@ -7,25 +7,12 @@ const lbryio = {
_accessToken: getLocal('accessToken'),
_authenticationPromise: null,
_user : null,
enabled: false
enabled: true
};
const CONNECTION_STRING = 'https://api.lbry.io/';
const CONNECTION_STRING = 'http://localhost:8080/';
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
const mocks = {
'reward_type.get': ({name}) => {
return {
name: 'link_github',
title: 'Link your GitHub account',
description: 'Link LBRY to your GitHub account',
value: 50,
claimed: false,
};
}
};
lbryio.getExchangeRates = function() {
return new Promise((resolve, reject) => {
const cached = getSession('exchangeRateCache');
@ -47,18 +34,10 @@ lbryio.getExchangeRates = function() {
lbryio.call = function(resource, action, params={}, method='get', evenIfDisabled=false) { // evenIfDisabled is just for development, when we may have some calls working and some not
return new Promise((resolve, reject) => {
if (!lbryio.enabled && !evenIfDisabled && (resource != 'discover' || action != 'list')) {
reject(new Error("LBRY interal API is disabled"))
reject(new Error("LBRY internal API is disabled"))
return
}
/* temp code for mocks */
if (`${resource}.${action}` in mocks) {
resolve(mocks[`${resource}.${action}`](params));
return;
}
/* end temp */
const xhr = new XMLHttpRequest;
xhr.addEventListener('error', function (event) {
@ -75,7 +54,9 @@ lbryio.call = function(resource, action, params={}, method='get', evenIfDisabled
if (!response.success) {
if (reject) {
reject(new Error(response.error));
let error = new Error(response.error);
error.xhr = xhr;
reject(error);
} else {
document.dispatchEvent(new CustomEvent('unhandledError', {
detail: {
@ -97,7 +78,7 @@ lbryio.call = function(resource, action, params={}, method='get', evenIfDisabled
//const fullParams = {...params, ... accessToken ? {access_token: accessToken} : {}};
// Temp app ID based auth:
const fullParams = {app_id: lbryio._accessToken, ...params};
const fullParams = {app_id: lbryio.getAccessToken(), ...params};
if (method == 'get') {
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(fullParams), true);
@ -110,9 +91,12 @@ lbryio.call = function(resource, action, params={}, method='get', evenIfDisabled
});
};
lbryio.getAccessToken = () => {
return getLocal('accessToken');
}
lbryio.setAccessToken = (token) => {
setLocal('accessToken', token)
lbryio._accessToken = token
}
lbryio.authenticate = function() {
@ -145,7 +129,7 @@ lbryio.authenticate = function() {
})
}
if (!lbryio._accessToken) {
if (!lbryio.getAccessToken()) {
lbryio.call('user', 'new', {
language: 'en',
app_id: installation_id,
@ -156,7 +140,6 @@ lbryio.authenticate = function() {
lbryio.setAccessToken(installation_id)
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

View file

@ -55,7 +55,6 @@ var RewardsPage = React.createClass({
});
},
render: function() {
console.log(this.state.userRewards);
return (
<main>
<form onSubmit={this.handleSubmit}>

View file

@ -68,7 +68,6 @@ rewards.claimReward = function (type) {
let claim = claims.find(function(claim) {
return claim.name.length && claim.name[0] == '@' && claim.txid.length
})
console.log(claim);
if (claim) {
params.transaction_id = claim.txid;
requestReward(resolve, reject, params)