api returns fields in lowercase now

This commit is contained in:
Alex Grintsvayg 2017-05-11 13:46:41 -04:00
parent b28b116a24
commit df7ce9cc64
7 changed files with 31 additions and 25 deletions

View file

@ -273,7 +273,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

@ -5,7 +5,8 @@ import ModalPage from "./modal-page.js";
import {Link, RewardLink} from "../component/link.js";
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'
const SubmitEmailStage = React.createClass({
@ -86,7 +87,7 @@ const ConfirmEmailStage = React.createClass({
};
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?
@ -259,7 +260,7 @@ export const AuthOverlay = React.createClass({
},
componentWillMount: function() {
lbryio.authenticate().then((user) => {
if (!user.HasVerifiedEmail) {
if (!user.has_verified_email) {
if (getLocal('auth_bypassed')) {
this.setStage(null)
} else {
@ -268,7 +269,7 @@ export const AuthOverlay = React.createClass({
} 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,9 @@ const lbryio = {
enabled: false
};
const CONNECTION_STRING = process.env.LBRY_APP_API_URL ? process.env.LBRY_APP_API_URL : '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.getExchangeRates = function() {
@ -34,6 +36,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
}
@ -87,6 +90,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"));
}
});
};
@ -103,8 +108,8 @@ lbryio.authenticate = function() {
if (!lbryio.enabled) {
return new Promise((resolve, reject) => {
resolve({
ID: 1,
HasVerifiedEmail: true
id: 1,
has_verified_email: true
})
})
}
@ -134,7 +139,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

@ -76,7 +76,7 @@ export let FileListPublished = React.createClass({
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

@ -47,7 +47,7 @@ var RewardsPage = React.createClass({
};
},
loadRewards: function() {
lbryio.call('reward', 'list', {}).then((userRewards) => {
lbryio.call('reward', 'list').then((userRewards) => {
this.setState({
userRewards: userRewards,
});
@ -62,8 +62,8 @@ var RewardsPage = React.createClass({
<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

@ -12,7 +12,7 @@ var SearchNoResults = React.createClass({
render: function() {
return <section>
<span className="empty">
No one has checked anything in for {this.props.query} yet.
No one has checked anything in for {this.props.query} yet.&nbsp;
<Link label="Be the first" href="?publish" />
</span>
</section>;

View file

@ -16,12 +16,12 @@ function rewardMessage(type, amount) {
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) {
@ -30,12 +30,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
};
@ -108,8 +108,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) => {