diff --git a/app/components/client/devprogram-scripts.js b/app/components/client/devprogram-scripts.js index 3bea3c1..d8f4827 100644 --- a/app/components/client/devprogram-scripts.js +++ b/app/components/client/devprogram-scripts.js @@ -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 = "
There was an issue with accessing GitHub's API. Please try again later.
"; - 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 = + "You have already claimed this reward. This reward is limited to ONE per person. Your enthusiasm is appreciated.
"; + 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 = + `Success! Your wallet has been credited with ${result.reward_amount} LBC.
We have a great reference for the LBRY SDK here to help you get started.
You can see proof of this transaction on our Blockain Explorer.
`; + 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 = - // `Success! Your wallet has been credited with ${result.reward_amount} LBC.
We have a great reference for the LBRY SDK here to help you get started.
You can see proof of this transaction on our Blockain Explorer.
`; - } 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 = "LBRY API is down. Please try again later.
"; - } - - else { - document.querySelector("developer-program").innerHTML = - "You have already claimed this reward. This reward is limited to ONE per person. Your enthusiasm is appreciated.
"; - } - } + }); } diff --git a/app/sockets.js b/app/sockets.js index d61639f..c528c7c 100644 --- a/app/sockets.js +++ b/app/sockets.js @@ -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;