Nearly there!
This commit is contained in:
parent
48efa9da73
commit
6bddcc8ff2
3 changed files with 43 additions and 3 deletions
|
@ -3,8 +3,10 @@
|
|||
DAEMON_URL=
|
||||
|
||||
# These are for powering the LBRY Developer Program
|
||||
DEV_PROGRAM_OAUTH=
|
||||
GITHUB_APP_ID=
|
||||
GITHUB_APP_TOKEN=
|
||||
REWARD_URL=
|
||||
REWARD_URL_TEST=
|
||||
|
||||
# https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app
|
||||
# We use this to show the GitHub feed on the homepage
|
||||
|
|
2
app/dist/scripts/sockets.js
vendored
2
app/dist/scripts/sockets.js
vendored
|
@ -19,7 +19,7 @@ function checkWebSocketConnection() {
|
|||
function initializeWebSocketConnection() {
|
||||
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 => {
|
||||
const data = JSON.parse(socket.data);
|
||||
|
|
|
@ -13,10 +13,44 @@ import fetchMetadata from "@helper/fetch-metadata";
|
|||
import { generateGitHubFeed } from "@helper/github";
|
||||
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
|
||||
|
||||
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) => {
|
||||
if (typeof socket !== "object" && typeof action !== "object")
|
||||
return;
|
||||
|
@ -26,6 +60,10 @@ export default (socket, action) => {
|
|||
getGitHubUserToken(socket);
|
||||
break;
|
||||
|
||||
case action.message === "verify github auth":
|
||||
syncWithApi(action, socket);
|
||||
break;
|
||||
|
||||
case action.message === "fetch metadata":
|
||||
fetchMetadata(action, socket);
|
||||
break;
|
||||
|
@ -335,7 +373,7 @@ function generateMemeCreator(socket) {
|
|||
function getGitHubUserToken(socket) {
|
||||
send(socket, {
|
||||
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`
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue