"use strict"; /* global document, fetch, history, send, window */ document.getElementById("get-started").onclick = event => { event.preventDefault(); send({ message: "auth me with github" }); }; if (window.location.search.includes("?code=")) { document.querySelector("developer-program").innerHTML = `

Need An Address?

To receive your LBC, you'll need a wallet address. While graphical wallets are available, the recommended path for engineers is to:

  1. Download the LBRY SDK.
  2. Launch the command-line utility (./lbrynet start).
  3. Run ./lbrynet address unused and copy the id field.
`; history.replaceState({}, "", window.location.pathname); // clean up URL bar } if (document.getElementById("creditsAcquire")) { document.getElementById("walletAddress").addEventListener("keyup", event => { const key = event.keyCode ? event.keyCode : event.which; if (key === 13) document.getElementById("creditsAcquire").click(); }); document.getElementById("creditsAcquire").onclick = () => { send({ address: document.getElementById("walletAddress").value, code: document.getElementById("oauthCode").value, message: "verify github token" }); document.querySelector("developer-program").innerHTML = "

Awaiting response from LBRY server...

"; }; } function syncWithApi(data) { // eslint-disable-line no-unused-vars const address = data.address; const code = data.code; if (code === null) document.querySelector("developer-program").innerHTML = "

There was an issue with accessing GitHub's API. Please try again later.

"; fetch(`https://api.lbry.com/reward/new?github_token=${code}&reward_type=github_developer&wallet_address=${address}`) .then(response => response.json()) .then(result => { switch(true) { 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; 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 Blockchain Explorer.

`; break; default: console.log(data); // eslint-disable-line no-console document.querySelector("developer-program").innerHTML = "

The LBRY API might be down. Please try again later.

"; 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.

"; }); }