This is now working locally

This commit is contained in:
ポール ウェッブ 2019-02-22 11:41:50 -06:00
parent 2182428e2c
commit 358ee3efae
2 changed files with 27 additions and 37 deletions

View file

@ -52,7 +52,7 @@ if (document.getElementById("creditsAcquire")) {
};
}
async function syncWithApi(data) { // eslint-disable-line no-unused-vars
function syncWithApi(data) { // eslint-disable-line no-unused-vars
const address = data.address;
const code = data.code;
@ -60,37 +60,30 @@ async function syncWithApi(data) { // eslint-disable-line no-unused-vars
document.querySelector("developer-program").innerHTML =
"<p><strong>There was an issue with accessing GitHub's API. Please try again later.</strong></p>";
try {
// let result = await got(`https://${apiUrl}/reward/new?github_token=${code}&reward_type=github_developer&wallet_address=${data.address}`, { json: true });
fetch(`https://api.lbry.io/reward/new?github_token=${code}&reward_type=github_developer&wallet_address=${address}`)
.then(response => response.json())
.then(result => {
switch(true) {
case !result.success:
case result.error === "this reward is limited to 1 per person":
document.querySelector("developer-program").innerHTML =
"<p>You have already claimed this reward. This reward is limited to <strong>ONE</strong> per person. Your enthusiasm is appreciated.</p>";
break;
let result = await fetch(`https://api.lbry.io/reward/new?github_token=${code}&reward_type=github_developer&wallet_address=${address}`, {
headers: {
"Content-Type": "application/json"
},
mode: "no-cors"
}).then(response => {
console.log("————— response"); // eslint-disable-line no-console
console.log(response); // eslint-disable-line no-console
return response;
});
case result.success:
result = result.data;
document.querySelector("developer-program").innerHTML =
`<p><strong>Success!</strong> Your wallet has been credited with ${result.reward_amount} LBC.</p><p>We have a great reference for the <a href="/api/sdk">LBRY SDK here</a> to help you get started.</p><p>You can see proof of this transaction on <a href="https://explorer.lbry.io/tx/${result.transaction_id}">our Blockain Explorer</a>.</p>`;
break;
console.log("————— result"); // eslint-disable-line no-console
console.log(result); // eslint-disable-line no-console
// result = result.body.data;
// document.querySelector("developer-program").innerHTML =
// `<p><strong>Success!</strong> Your wallet has been credited with ${result.reward_amount} LBC.</p><p>We have a great reference for the <a href="/api/sdk">LBRY SDK here</a> to help you get started.</p><p>You can see proof of this transaction on <a href="https://explorer.lbry.io/tx/${result.transaction_id}">our Blockain Explorer</a>.</p>`;
} catch(error) {
console.log(error); // eslint-disable-line no-console
if (!error.body) {
default:
console.log(data); // eslint-disable-line no-console
break;
}
})
.catch(() => {
// Idk what the error would be (probably a 500) so let's just have this message
document.querySelector("developer-program").innerHTML =
"<p><strong>LBRY API is down. Please try again later.</strong></p>";
}
else {
document.querySelector("developer-program").innerHTML =
"<p>You have already claimed this reward. This reward is limited to <strong>ONE</strong> per person. Your enthusiasm is appreciated.</p>";
}
}
});
}

View file

@ -13,14 +13,11 @@ import fetchMetadata from "@helper/fetch-metadata";
import { generateGitHubFeed } from "@helper/github";
import messageSlack from "@helper/slack";
// let apiUrl = process.env.REWARD_URL;
// let apiUrl = process.env.REWARD_URL_TEST;
const githubAppId = process.env.GITHUB_APP_ID;
const githubAppSecret = process.env.GITHUB_APP_SECRET;
// let githubAppId = process.env.GITHUB_APP_ID;
// let githubAppSecret = process.env.GITHUB_APP_SECRET;
let githubAppId = process.env.GITHUB_APP_ID_TEST;
let githubAppSecret = process.env.GITHUB_APP_SECRET_TEST;
// const githubAppId = process.env.GITHUB_APP_ID_TEST;
// const githubAppSecret = process.env.GITHUB_APP_SECRET_TEST;