Nearly there!

This commit is contained in:
ポール ウェッブ 2019-02-13 17:08:59 -06:00
parent 48efa9da73
commit 6bddcc8ff2
3 changed files with 43 additions and 3 deletions

View file

@ -3,8 +3,10 @@
DAEMON_URL= DAEMON_URL=
# These are for powering the LBRY Developer Program # These are for powering the LBRY Developer Program
DEV_PROGRAM_OAUTH=
GITHUB_APP_ID= GITHUB_APP_ID=
GITHUB_APP_TOKEN= REWARD_URL=
REWARD_URL_TEST=
# https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app # https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app
# We use this to show the GitHub feed on the homepage # We use this to show the GitHub feed on the homepage

View file

@ -19,7 +19,7 @@ function checkWebSocketConnection() {
function initializeWebSocketConnection() { function initializeWebSocketConnection() {
ws = new WebSocket(location.origin.replace(/^http/, "ws")); ws = new WebSocket(location.origin.replace(/^http/, "ws"));
ws.onopen = () => console.log("WebSocket connection established"); // eslint-disable-line // ws.onopen = () => console.log("WebSocket connection established"); // eslint-disable-line no-console
ws.onmessage = socket => { ws.onmessage = socket => {
const data = JSON.parse(socket.data); const data = JSON.parse(socket.data);

View file

@ -13,10 +13,44 @@ import fetchMetadata from "@helper/fetch-metadata";
import { generateGitHubFeed } from "@helper/github"; import { generateGitHubFeed } from "@helper/github";
import messageSlack from "@helper/slack"; import messageSlack from "@helper/slack";
const apiUrl = process.env.NODE_ENV === "development" ?
process.env.REWARD_URL_TEST :
process.env.REWARD_URL;
// P R O G R A M // P R O G R A M
async function syncWithApi(data, socket) {
try {
let result = await got(`https://${apiUrl}/reward/new?github_token=${process.env.DEV_PROGRAM_OAUTH}&reward_type=github_developer&wallet_address=${data.address}`, { json: true });
result = result.body.data;
return send(socket, {
html: `<p>Success! Your wallet has been credited with ${result.reward_amount} LBC.</p>`,
message: "updated html",
selector: "developer-program"
});
} catch(error) {
if (!error.body) {
return send(socket, {
html: "<p><strong>LBRY API is down. Please try again later.</strong></p>",
message: "updated html",
selector: "developer-program"
});
}
console.log(error.body); // eslint-disable-line no-console
return send(socket, {
html: "<p>This reward is limited to <strong>ONE</strong> per person. Your enthusiasm is appreciated.</p>",
message: "updated html",
selector: "developer-program"
});
}
}
export default (socket, action) => { export default (socket, action) => {
if (typeof socket !== "object" && typeof action !== "object") if (typeof socket !== "object" && typeof action !== "object")
return; return;
@ -26,6 +60,10 @@ export default (socket, action) => {
getGitHubUserToken(socket); getGitHubUserToken(socket);
break; break;
case action.message === "verify github auth":
syncWithApi(action, socket);
break;
case action.message === "fetch metadata": case action.message === "fetch metadata":
fetchMetadata(action, socket); fetchMetadata(action, socket);
break; break;
@ -335,7 +373,7 @@ function generateMemeCreator(socket) {
function getGitHubUserToken(socket) { function getGitHubUserToken(socket) {
send(socket, { send(socket, {
message: "redirect", message: "redirect",
url: `https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_APP_ID}` url: `https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_APP_ID}&scope=public_repo,user:email`
}); });
} }