diff --git a/backend/src/routes/livepeer.js b/backend/src/routes/livepeer.js
index 14d6893..e016036 100644
--- a/backend/src/routes/livepeer.js
+++ b/backend/src/routes/livepeer.js
@@ -52,6 +52,7 @@ const provider = new ethers.providers.JsonRpcProvider(API_L1_HTTP);
// const ens = new ENS({ provider: web3layer1, ensAddress: getEnsAddress('1') });
let ensDomainCache = [];
let ensInfoCache = [];
+let threeboxCache = [];
// Update CoinMarketCap related api calls every 5 minutes
let cmcPriceGet = 0;
@@ -677,7 +678,7 @@ const parseOrchestrator = async function (reqAddr) {
return orchestratorCache[idx];
}
}
- } else{
+ } else {
console.log("Thegraph is probably acting up, but there is no cached value. Returning null...");
return {};
}
@@ -1056,7 +1057,6 @@ const getEnsInfo = async function (addr) {
}
return ensObj;
}
-
// Gets and caches info for a single address
apiRouter.get("/getENS/:orch", async (req, res) => {
try {
@@ -1090,4 +1090,75 @@ apiRouter.get("/getEnsInfo", async (req, res) => {
}
});
+
+const getThreeBoxInfo = async function (addr) {
+ const now = new Date().getTime();
+ let wasInCache = false;
+ // See if it is cached
+ for (const thisAddr of threeboxCache) {
+ if (thisAddr.address === addr) {
+ // Check timeout
+ if (now - thisAddr.timestamp < CONF_TIMEOUT_ENS_INFO) {
+ return thisAddr;
+ }
+ wasInCache = true;
+ }
+ }
+ // Else get it and cache it
+ const url = "https://explorer.livepeer.org/api/3box?account=" + addr;
+ await https.get(url, (res) => {
+ let body = "";
+ res.on("data", (chunk) => {
+ body += chunk;
+ });
+ res.on("end", () => {
+ try {
+ const data = JSON.parse(body);
+ const threeBoxObj = {
+ address: data.id,
+ name: data.name,
+ website: data.website,
+ description: data.description,
+ image: data.image,
+ timestamp: now
+ }
+ if (wasInCache) {
+ for (var idx = 0; idx < threeboxCache.length; idx++) {
+ if (threeboxCache[idx].address == addr) {
+ console.log("Updating outdated 3box info " + threeBoxObj.address + " @ " + threeBoxObj.timestamp);
+ threeboxCache[idx] = threeBoxObj;
+ break;
+ }
+ }
+ } else {
+ console.log("Caching new 3box info " + threeBoxObj.address + " @ " + threeBoxObj.timestamp);
+ threeboxCache.push(threeBoxObj);
+ }
+ } catch (error) {
+ console.error(error.message);
+ };
+ });
+ }).on("error", (error) => {
+ console.error(error.message);
+ });
+}
+// Gets and caches info for a single address
+apiRouter.get("/getThreeBox/:orch", async (req, res) => {
+ try {
+ // First resolve addr => domain name
+ const threeBoxInfo = await getThreeBoxInfo(req.params.orch);
+ res.send(threeBoxInfo);
+ } catch (err) {
+ res.status(400).send(err);
+ }
+});
+// Returns entire 3box info mapping cache
+apiRouter.get("/getAllThreeBox", async (req, res) => {
+ try {
+ res.send(threeboxCache);
+ } catch (err) {
+ res.status(400).send(err);
+ }
+});
+
export default apiRouter;
\ No newline at end of file
diff --git a/src/actions/livepeer.js b/src/actions/livepeer.js
index 34cf27c..350617a 100644
--- a/src/actions/livepeer.js
+++ b/src/actions/livepeer.js
@@ -26,6 +26,7 @@ export const CLEAR_ORCHESTRATOR = "CLEAR_ORCHESTRATOR";
export const RECEIVE_TICKETS = "RECEIVE_TICKETS";
export const SET_ALL_ENS_INFO = "SET_ALL_ENS_INFO";
export const SET_ALL_ENS_DOMAINS = "SET_ALL_ENS_DOMAINS";
+export const SET_ALL_THREEBOX_INFO = "SET_ALL_THREEBOX_INFO";
const setQuotes = message => ({
type: RECEIVE_QUOTES, message
@@ -54,6 +55,9 @@ const setAllEnsInfo = message => ({
const setAllEnsDomains = message => ({
type: SET_ALL_ENS_DOMAINS, message
});
+const setAllThreeBoxInfo = message => ({
+ type: SET_ALL_THREEBOX_INFO, message
+});
export const getQuotes = () => async dispatch => {
@@ -552,4 +556,19 @@ export const getEnsInfo = async (addr) => {
const response = await apiUtil.getEnsInfo(addr);
const data = await response.json();
};
+
+
+export const getAllThreeBoxInfo = () => async dispatch => {
+ const response = await apiUtil.getAllThreeBox();
+ const data = await response.json();
+ if (response.ok) {
+ return dispatch(setAllThreeBoxInfo(data));
+ }
+ return dispatch(receiveErrors(data));
+};
+
+export const getThreeBoxInfo = async (addr) => {
+ const response = await apiUtil.getThreeBox(addr);
+ const data = await response.json();
+};
\ No newline at end of file
diff --git a/src/components/OrchAddressViewer.js b/src/components/OrchAddressViewer.js
index bac23c5..b8762f4 100644
--- a/src/components/OrchAddressViewer.js
+++ b/src/components/OrchAddressViewer.js
@@ -5,6 +5,8 @@ import { getEnsInfo } from "../actions/livepeer";
const Address = (obj) => {
const livepeer = useSelector((state) => state.livepeerstate);
const [hasRefreshed, setRefresh] = useState(false);
+ let hasENS = false;
+ let hasThreeBox = false;
let thisDomain = null;
let thisInfo = null;
const now = new Date().getTime();
@@ -36,6 +38,7 @@ const Address = (obj) => {
for (const thisAddr of livepeer.ensInfoMapping) {
if (thisAddr.domain === thisDomain.domain) {
thisInfo = thisAddr;
+ hasENS = true;
// Check timeout
if (now - thisAddr.timestamp < 86400000) {
break;
@@ -55,9 +58,22 @@ const Address = (obj) => {
}
}
+ // Ugly shit, but temporary for now to quickly enable threebox. Sorry!
+ if (!hasENS) {
+ if (livepeer.threeBoxInfo) {
+ for (const thisAddr of livepeer.threeBoxInfo) {
+ if (thisAddr.address === obj.address) {
+ thisInfo = thisAddr;
+ hasThreeBox = true;
+ break;
+ }
+ }
+ }
+ }
+
let thisName;
let thisIcon;
- if (thisInfo) {
+ if (hasENS) {
thisName = thisInfo.domain;
console.log(thisInfo.avatar);
if (thisInfo.avatar) {
@@ -71,13 +87,24 @@ const Address = (obj) => {
}
+ } else if (hasThreeBox) {
+ if (thisInfo.name) {
+ thisName =