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.
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
function doShutdown() {
console.log('Asking daemon to shut down down');
console.log('Shutting down daemon');
daemonStopRequested = true;
client.request('daemon_stop', [], (err, res) => {
if (err) {

View file

@ -7,7 +7,8 @@ import Link from "component/link"
import {RewardLink} from 'component/reward-link';
import {FormRow} from "../component/form.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 {
@ -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) => {
if (userEmail.IsVerified) {
if (userEmail.is_verified) {
this.props.setStage("welcome")
} else {
onSubmitError(new Error("Your email is still not verified.")) //shouldn't happen?
@ -278,7 +279,7 @@ export class AuthOverlay extends React.Component {
componentWillMount() {
lbryio.authenticate().then((user) => {
if (!user.HasVerifiedEmail) {
if (!user.has_verified_email) {
if (getLocal('auth_bypassed')) {
this.setStage(null)
} else {
@ -287,7 +288,7 @@ export class AuthOverlay extends React.Component {
} else {
lbryio.call('reward', 'list', {}).then((userRewards) => {
userRewards.filter(function(reward) {
return reward.RewardType == "new_user" && reward.TransactionID;
return reward.reward_type == TYPE_NEW_USER && reward.transaction_id;
}).length ?
this.setStage(null) :
this.setStage("welcome")

View file

@ -10,7 +10,10 @@ const lbryio = {
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;
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
return new Promise((resolve, reject) => {
if (!lbryio.enabled && !evenIfDisabled && (resource != 'discover' || action != 'list')) {
console.log("Internal API disabled");
reject(new Error("LBRY internal API is disabled"))
return
}
@ -84,6 +88,8 @@ lbryio.call = function(resource, action, params={}, method='get', evenIfDisabled
xhr.open('post', CONNECTION_STRING + resource + '/' + action, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(querystring.stringify(fullParams));
} else {
reject(new Error("Invalid method"));
}
});
};
@ -100,8 +106,8 @@ lbryio.authenticate = function() {
if (!lbryio.enabled) {
return new Promise((resolve, reject) => {
resolve({
ID: 1,
HasVerifiedEmail: true
id: 1,
has_verified_email: true
})
})
}
@ -131,7 +137,7 @@ lbryio.authenticate = function() {
language: 'en',
app_id: installation_id,
}, 'post').then(function(responseData) {
if (!responseData.ID) {
if (!responseData.id) {
reject(new Error("Received invalid authentication response."));
}
lbryio.setAccessToken(installation_id)

View file

@ -26,7 +26,7 @@ class FileListPublished extends React.Component {
// lbryio.call('reward', 'list', {}).then(function(userRewards) {
// //already rewarded
// 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) {
// return
// }

View file

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

View file

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