Merge branch 'api-fixes'

This commit is contained in:
Jeremy Kauffman 2017-05-24 20:10:36 -04:00
commit 51a2f4f52e
6 changed files with 30 additions and 23 deletions

View file

@ -317,7 +317,7 @@ app.on('activate', () => {
// then calls quitNow() to quit for real. // then calls quitNow() to quit for real.
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) { function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
function doShutdown() { function doShutdown() {
console.log('Asking daemon to shut down down'); console.log('Shutting down daemon');
daemonStopRequested = true; daemonStopRequested = true;
client.request('daemon_stop', [], (err, res) => { client.request('daemon_stop', [], (err, res) => {
if (err) { if (err) {

View file

@ -7,7 +7,8 @@ import Link from "component/link"
import {RewardLink} from 'component/reward-link'; import {RewardLink} from 'component/reward-link';
import {FormRow} from "../component/form.js"; import {FormRow} from "../component/form.js";
import {CreditAmount, Address} from "../component/common.js"; import {CreditAmount, Address} from "../component/common.js";
import {getLocal, getSession, setSession, setLocal} from '../utils.js'; import {getLocal, setLocal} from '../utils.js';
import {TYPE_NEW_USER} from '../rewards'
class SubmitEmailStage extends React.Component { class SubmitEmailStage extends React.Component {
@ -98,7 +99,7 @@ class ConfirmEmailStage extends React.Component {
}; };
lbryio.call('user_email', 'confirm', {verification_token: this.state.code, email: this.props.email}, 'post').then((userEmail) => { lbryio.call('user_email', 'confirm', {verification_token: this.state.code, email: this.props.email}, 'post').then((userEmail) => {
if (userEmail.IsVerified) { if (userEmail.is_verified) {
this.props.setStage("welcome") this.props.setStage("welcome")
} else { } else {
onSubmitError(new Error("Your email is still not verified.")) //shouldn't happen? onSubmitError(new Error("Your email is still not verified.")) //shouldn't happen?
@ -278,7 +279,7 @@ export class AuthOverlay extends React.Component {
componentWillMount() { componentWillMount() {
lbryio.authenticate().then((user) => { lbryio.authenticate().then((user) => {
if (!user.HasVerifiedEmail) { if (!user.has_verified_email) {
if (getLocal('auth_bypassed')) { if (getLocal('auth_bypassed')) {
this.setStage(null) this.setStage(null)
} else { } else {
@ -287,7 +288,7 @@ export class AuthOverlay extends React.Component {
} else { } else {
lbryio.call('reward', 'list', {}).then((userRewards) => { lbryio.call('reward', 'list', {}).then((userRewards) => {
userRewards.filter(function(reward) { userRewards.filter(function(reward) {
return reward.RewardType == "new_user" && reward.TransactionID; return reward.reward_type == TYPE_NEW_USER && reward.transaction_id;
}).length ? }).length ?
this.setStage(null) : this.setStage(null) :
this.setStage("welcome") this.setStage("welcome")

View file

@ -10,7 +10,10 @@ const lbryio = {
enabled: true enabled: true
}; };
const CONNECTION_STRING = 'https://api.lbry.io/';
const CONNECTION_STRING = process.env.LBRY_APP_API_URL ?
process.env.LBRY_APP_API_URL.replace(/\/*$/,'/') : // exactly one slash at the end
'https://api.lbry.io/'
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
lbryio._exchangePromise = null; lbryio._exchangePromise = null;
@ -31,6 +34,7 @@ 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 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) => { return new Promise((resolve, reject) => {
if (!lbryio.enabled && !evenIfDisabled && (resource != 'discover' || action != 'list')) { if (!lbryio.enabled && !evenIfDisabled && (resource != 'discover' || action != 'list')) {
console.log("Internal API disabled");
reject(new Error("LBRY internal API is disabled")) reject(new Error("LBRY internal API is disabled"))
return return
} }
@ -84,6 +88,8 @@ lbryio.call = function(resource, action, params={}, method='get', evenIfDisabled
xhr.open('post', CONNECTION_STRING + resource + '/' + action, true); xhr.open('post', CONNECTION_STRING + resource + '/' + action, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(querystring.stringify(fullParams)); xhr.send(querystring.stringify(fullParams));
} else {
reject(new Error("Invalid method"));
} }
}); });
}; };
@ -100,8 +106,8 @@ lbryio.authenticate = function() {
if (!lbryio.enabled) { if (!lbryio.enabled) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve({ resolve({
ID: 1, id: 1,
HasVerifiedEmail: true has_verified_email: true
}) })
}) })
} }
@ -131,7 +137,7 @@ lbryio.authenticate = function() {
language: 'en', language: 'en',
app_id: installation_id, app_id: installation_id,
}, 'post').then(function(responseData) { }, 'post').then(function(responseData) {
if (!responseData.ID) { if (!responseData.id) {
reject(new Error("Received invalid authentication response.")); reject(new Error("Received invalid authentication response."));
} }
lbryio.setAccessToken(installation_id) lbryio.setAccessToken(installation_id)

View file

@ -26,7 +26,7 @@ class FileListPublished extends React.Component {
// lbryio.call('reward', 'list', {}).then(function(userRewards) { // lbryio.call('reward', 'list', {}).then(function(userRewards) {
// //already rewarded // //already rewarded
// if (userRewards.filter(function (reward) { // if (userRewards.filter(function (reward) {
// return reward.RewardType == rewards.TYPE_FIRST_PUBLISH && reward.TransactionID // return reward.reward_type == rewards.TYPE_FIRST_PUBLISH && reward.transaction_id
// }).length) { // }).length) {
// return // return
// } // }

View file

@ -65,8 +65,8 @@ export class RewardsPage extends React.Component {
<div> <div>
{!this.state.userRewards {!this.state.userRewards
? (this.state.failed ? <div className="empty">Failed to load rewards.</div> : '') ? (this.state.failed ? <div className="empty">Failed to load rewards.</div> : '')
: this.state.userRewards.map(({RewardType, RewardTitle, RewardDescription, TransactionID, RewardAmount}) => { : this.state.userRewards.map(({reward_type, reward_title, reward_description, transaction_id, reward_amount}) => {
return <RewardTile key={RewardType} onRewardClaim={this.loadRewards} type={RewardType} title={RewardTitle} description={RewardDescription} claimed={!!TransactionID} value={RewardAmount} />; return <RewardTile key={reward_type} onRewardClaim={this.loadRewards} type={reward_type} title={reward_title} description={reward_description} claimed={!!transaction_id} value={reward_amount} />;
})} })}
</div> </div>
</main> </main>

View file

@ -70,12 +70,12 @@ function isInitialClaim(claim) {
const rewards = {}; const rewards = {};
rewards.TYPE_NEW_DEVELOPER = "new_developer", rewards.TYPE_NEW_DEVELOPER = "new_developer",
rewards.TYPE_NEW_USER = "new_user", rewards.TYPE_NEW_USER = "new_user",
rewards.TYPE_CONFIRM_EMAIL = "confirm_email", rewards.TYPE_CONFIRM_EMAIL = "confirm_email",
rewards.TYPE_FIRST_CHANNEL = "new_channel", rewards.TYPE_FIRST_CHANNEL = "new_channel",
rewards.TYPE_FIRST_STREAM = "first_stream", rewards.TYPE_FIRST_STREAM = "first_stream",
rewards.TYPE_MANY_DOWNLOADS = "many_downloads", rewards.TYPE_MANY_DOWNLOADS = "many_downloads",
rewards.TYPE_FIRST_PUBLISH = "first_publish"; rewards.TYPE_FIRST_PUBLISH = "first_publish";
rewards.claimReward = function (type) { rewards.claimReward = function (type) {
@ -84,12 +84,12 @@ rewards.claimReward = function (type) {
reject(new Error("Rewards are not enabled.")) reject(new Error("Rewards are not enabled."))
return; return;
} }
lbryio.call('reward', 'new', params, 'post').then(({RewardAmount}) => { lbryio.call('reward', 'new', params, 'post').then(({reward_amount}) => {
const const
message = rewardMessage(type, RewardAmount), message = rewardMessage(type, reward_amount),
result = { result = {
type: type, type: type,
amount: RewardAmount, amount: reward_amount,
message: message message: message
}; };
@ -161,8 +161,8 @@ rewards.claimNextPurchaseReward = function() {
types[rewards.TYPE_MANY_DOWNLOADS] = false types[rewards.TYPE_MANY_DOWNLOADS] = false
lbryio.call('reward', 'list', {}).then((userRewards) => { lbryio.call('reward', 'list', {}).then((userRewards) => {
userRewards.forEach((reward) => { userRewards.forEach((reward) => {
if (types[reward.RewardType] === false && reward.TransactionID) { if (types[reward.reward_type] === false && reward.transaction_id) {
types[reward.RewardType] = true types[reward.reward_type] = true
} }
}) })
let unclaimedType = Object.keys(types).find((type) => { let unclaimedType = Object.keys(types).find((type) => {