Remove 3box

This commit is contained in:
Marco van Dijk 2022-05-05 22:17:35 +02:00
parent 46ced21124
commit 6ebc31f5c0
10 changed files with 3 additions and 236 deletions

View File

@ -2489,71 +2489,6 @@ apiRouter.get("/getEnsInfo", async (req, res) => {
}); });
/*
3BOX DATA
Only stored in local cache
*/
let threeboxCache = [];
const getThreeBoxInfo = async function (addr) {
console.log("Getting 3box data for " + addr);
const now = new Date().getTime();
// See if it is cached
for (const thisAddr of threeboxCache) {
if (thisAddr.address === addr) {
return thisAddr;
}
}
// 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
}
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);
}
});
/* /*
LEADERBOARD TEST SCORES LEADERBOARD TEST SCORES

View File

@ -12,7 +12,6 @@ export const RECEIVE_TICKETS = "RECEIVE_TICKETS";
export const RECEIVE_WINNING_TICKETS = "RECEIVE_WINNING_TICKETS"; export const RECEIVE_WINNING_TICKETS = "RECEIVE_WINNING_TICKETS";
export const SET_ALL_ENS_INFO = "SET_ALL_ENS_INFO"; export const SET_ALL_ENS_INFO = "SET_ALL_ENS_INFO";
export const SET_ALL_ENS_DOMAINS = "SET_ALL_ENS_DOMAINS"; export const SET_ALL_ENS_DOMAINS = "SET_ALL_ENS_DOMAINS";
export const SET_ALL_THREEBOX_INFO = "SET_ALL_THREEBOX_INFO";
export const SET_ALL_ORCH_SCORES = "SET_ALL_ORCH_SCORES"; export const SET_ALL_ORCH_SCORES = "SET_ALL_ORCH_SCORES";
export const SET_ALL_ORCH_INFO = "SET_ALL_ORCH_INFO"; export const SET_ALL_ORCH_INFO = "SET_ALL_ORCH_INFO";
export const SET_ALL_DEL_INFO = "SET_ALL_DEL_INFO"; export const SET_ALL_DEL_INFO = "SET_ALL_DEL_INFO";
@ -63,9 +62,6 @@ const setAllEnsInfo = message => ({
const setAllEnsDomains = message => ({ const setAllEnsDomains = message => ({
type: SET_ALL_ENS_DOMAINS, message type: SET_ALL_ENS_DOMAINS, message
}); });
const setAllThreeBoxInfo = message => ({
type: SET_ALL_THREEBOX_INFO, message
});
const setAllOrchScores = message => ({ const setAllOrchScores = message => ({
type: SET_ALL_ORCH_SCORES, message type: SET_ALL_ORCH_SCORES, message
}); });
@ -209,20 +205,6 @@ export const getEnsInfo = async (addr) => {
const response = apiUtil.getEnsInfo(addr); const response = apiUtil.getEnsInfo(addr);
}; };
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 = apiUtil.getThreeBox(addr);
};
export const getOrchestratorScores = async (year, month) => { export const getOrchestratorScores = async (year, month) => {
const response = await apiUtil.getOrchestratorScores(year, month); const response = await apiUtil.getOrchestratorScores(year, month);
const data = await response.json(); const data = await response.json();

View File

@ -32,22 +32,6 @@ const MonthlyGraphs = (obj) => {
} }
} }
if (livepeer.threeBoxInfo) {
for (const thisAddr of livepeer.threeBoxInfo) {
if (thisAddr.address === address) {
if (thisAddr.name) {
if (thisAddr.name.length > 18) {
return (thisAddr.name.substring(0, 16) + "..");
}
return thisAddr.name;
} else {
return (address.substring(0, 16) + "..");
}
break;
}
}
}
return (address.substring(0, 16) + ".."); return (address.substring(0, 16) + "..");
} }

View File

@ -6,7 +6,6 @@ const Address = (obj) => {
const livepeer = useSelector((state) => state.livepeerstate); const livepeer = useSelector((state) => state.livepeerstate);
const [hasRefreshed, setRefresh] = useState(false); const [hasRefreshed, setRefresh] = useState(false);
let hasENS = false; let hasENS = false;
let hasThreeBox = false;
let thisDomain = null; let thisDomain = null;
let thisInfo = null; let thisInfo = null;
const now = new Date().getTime(); const now = new Date().getTime();
@ -58,19 +57,6 @@ 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 thisName;
let thisIcon; let thisIcon;
if (hasENS) { if (hasENS) {
@ -86,20 +72,6 @@ const Address = (obj) => {
<img alt="" src="ens.png" width="20em" height="20em" style={{ margin: '0.2em', padding: '0.2em' }} /> <img alt="" src="ens.png" width="20em" height="20em" style={{ margin: '0.2em', padding: '0.2em' }} />
</a > </a >
} }
} else if (hasThreeBox) {
if (thisInfo.name) {
thisName = <h4 className="elipsText elipsOnMobileExtra">{thisInfo.name}</h4>;
} else {
thisName = <span className="elipsText elipsOnMobileExtra">{obj.address}</span>;
}
if (thisInfo.image) {
thisIcon =
<a className="selectOrch" style={{ marginRight: '0.5em', cursor: 'grab' }} disabled>
<img alt="" src={"https://cloudflare-ipfs.com/ipfs/" + thisInfo.image} width="20em" height="20em" style={{ margin: 0, padding: 0 }} />
</a >
} else {
thisIcon = null;
}
} else { } else {
thisName = obj.address; thisName = obj.address;
thisIcon = null; thisIcon = null;

View File

@ -31,7 +31,6 @@ const OrchInfoViewer = (obj) => {
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
const livepeer = useSelector((state) => state.livepeerstate); const livepeer = useSelector((state) => state.livepeerstate);
let hasENS = false; let hasENS = false;
let hasThreeBox = false;
let rewardCut = 0; let rewardCut = 0;
let feeCut = 0; let feeCut = 0;
let totalStake = 0; let totalStake = 0;
@ -98,19 +97,6 @@ const OrchInfoViewer = (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 === thisID) {
thisInfo = thisAddr;
hasThreeBox = true;
break;
}
}
}
}
let ensDescription; let ensDescription;
let ensUrl; let ensUrl;
if (hasENS) { if (hasENS) {
@ -130,23 +116,6 @@ const OrchInfoViewer = (obj) => {
</a > </a >
</div> </div>
} }
} else if (hasThreeBox) {
if (thisInfo.description) {
ensDescription = thisInfo.description;
}
if (thisInfo.website) {
if (!thisInfo.website.startsWith('http')) {
thisInfo.website = "https://" + thisInfo.website;
}
ensUrl =
<div className="stroke">
<a className="selectOrchLight" style={{ cursor: 'alias' }} target="_blank" rel="noopener noreferrer" href={thisInfo.website} >
<div className="rowAlignLeft">
<span>{thisInfo.website}</span>
</div>
</a >
</div>
}
} }
let descriptionObj; let descriptionObj;

View File

@ -28,22 +28,6 @@ const TotalStakeGraph = (obj) => {
} }
} }
if (livepeer.threeBoxInfo) {
for (const thisAddr of livepeer.threeBoxInfo) {
if (thisAddr.address === address) {
if (thisAddr.name) {
if (thisAddr.name.length > 18) {
return (thisAddr.name.substring(0, 16) + "..");
}
return thisAddr.name;
} else {
return (address.substring(0, 16) + "..");
}
break;
}
}
}
return (address.substring(0, 16) + ".."); return (address.substring(0, 16) + "..");
} }

View File

@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { import {
getOrchestratorInfo, getEnsInfo, getThreeBoxInfo, setCachedOrch, getOrchestratorInfoSilent getOrchestratorInfo, getEnsInfo, setCachedOrch, getOrchestratorInfoSilent
} from "../actions/livepeer"; } from "../actions/livepeer";
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Text } from '@mantine/core'; import { Text } from '@mantine/core';
@ -9,7 +9,6 @@ const EventButtonAddress = (obj) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const livepeer = useSelector((state) => state.livepeerstate); const livepeer = useSelector((state) => state.livepeerstate);
const [hasRefreshed, setRefresh] = useState(false); const [hasRefreshed, setRefresh] = useState(false);
const [hasThreeBoxRefreshed, setThreeBoxRefresh] = useState(false);
const [orchInfo, setOrchInfo] = useState(null); const [orchInfo, setOrchInfo] = useState(null);
const now = new Date().getTime(); const now = new Date().getTime();
@ -17,7 +16,6 @@ const EventButtonAddress = (obj) => {
let thisInfo = null; let thisInfo = null;
let thisDomain = null; let thisDomain = null;
let hasENS = null; let hasENS = null;
let hasThreeBox = null
// Lookup domain in cache // Lookup domain in cache
if (livepeer.ensDomainMapping && !hasRefreshed) { if (livepeer.ensDomainMapping && !hasRefreshed) {
for (const thisAddr of livepeer.ensDomainMapping) { for (const thisAddr of livepeer.ensDomainMapping) {
@ -69,30 +67,7 @@ const EventButtonAddress = (obj) => {
setRefresh(true); setRefresh(true);
} }
} }
}, [livepeer.ensDomainMapping]);
// Ugly shit, but temporary for now to quickly enable threebox. Sorry!
if (!hasENS && !hasThreeBoxRefreshed) {
if (livepeer.threeBoxInfo) {
for (const thisAddr of livepeer.threeBoxInfo) {
if (thisAddr.address === obj.address) {
thisInfo = thisAddr;
hasThreeBox = true;
break;
}
}
// If it was not cached at all
if (!hasThreeBox && !hasThreeBoxRefreshed) {
console.log("Refresh due to non-existing 3BOX info");
setThreeBoxRefresh(true);
getThreeBoxInfo(obj.address);
}
}
}
if (thisInfo && thisInfo != orchInfo) {
console.log("Setting INFO obj");
setOrchInfo(thisInfo);
}
}, [livepeer.ensDomainMapping, livepeer.threeBoxInfo]);
useEffect(() => { useEffect(() => {
// Check if cached as an orchestrator // Check if cached as an orchestrator
@ -130,20 +105,6 @@ const EventButtonAddress = (obj) => {
<img alt="" src={orchInfo.avatar.url} width="20em" height="20em" style={{ margin: 0, padding: 0 }} /> <img alt="" src={orchInfo.avatar.url} width="20em" height="20em" style={{ margin: 0, padding: 0 }} />
</a > </a >
} }
} else if (orchInfo && (orchInfo.name || orchInfo.image)) {
if (orchInfo.name) {
thisName = <Text style={{ textOverflow: "ellipsis", overflow: "hidden", width: '100%' }} >{orchInfo.name}</Text>;
} else {
thisName = <Text style={{ textOverflow: "ellipsis", overflow: "hidden", width: '100%', maxWidth: '10vw' }} >{obj.address}</Text>;
}
if (orchInfo.image) {
thisIcon =
<a className="selectOrch" style={{ padding: '0.3em', cursor: 'grab' }} disabled>
<img alt="" src={"https://cloudflare-ipfs.com/ipfs/" + orchInfo.image} width="20em" height="20em" style={{ margin: 0, padding: 0 }} />
</a >
} else {
thisIcon = null;
}
} else { } else {
thisName = <Text style={{ textOverflow: "ellipsis", overflow: "hidden", width: '100%', maxWidth: '10vw' }} >{obj.address}</Text>; thisName = <Text style={{ textOverflow: "ellipsis", overflow: "hidden", width: '100%', maxWidth: '10vw' }} >{obj.address}</Text>;
thisIcon = null; thisIcon = null;

View File

@ -5,7 +5,7 @@ import {
} from "../actions/user"; } from "../actions/user";
import { import {
getQuotes, getBlockchainData, getCurrentOrchestratorInfo, getQuotes, getBlockchainData, getCurrentOrchestratorInfo,
getAllEnsDomains, getAllEnsInfo, getAllThreeBoxInfo, getAllOrchScores, getAllOrchInfo, getAllEnsDomains, getAllEnsInfo, getAllOrchScores, getAllOrchInfo,
getAllDelInfo, getAllMonthlyStats, getAllUpdateEvents, getAllRewardEvents, getAllDelInfo, getAllMonthlyStats, getAllUpdateEvents, getAllRewardEvents,
getAllClaimEvents, getAllWithdrawStakeEvents, getAllWithdrawFeesEvents, getAllClaimEvents, getAllWithdrawStakeEvents, getAllWithdrawFeesEvents,
getAllTransferTicketEvents, getAllRedeemTicketEvents, getAllActivateEvents, getAllTransferTicketEvents, getAllRedeemTicketEvents, getAllActivateEvents,
@ -42,7 +42,6 @@ const Startup = (obj) => {
const refreshENS = () => { const refreshENS = () => {
console.log("Refreshing ENS data..."); console.log("Refreshing ENS data...");
batch(() => { batch(() => {
dispatch(getAllThreeBoxInfo());
dispatch(getAllEnsDomains()); dispatch(getAllEnsDomains());
dispatch(getAllEnsInfo()); dispatch(getAllEnsInfo());
}); });

View File

@ -54,22 +54,6 @@ const Stats = (obj) => {
} }
} }
if (livepeer.threeBoxInfo) {
for (const thisAddr of livepeer.threeBoxInfo) {
if (thisAddr.address === address) {
if (thisAddr.name) {
if (thisAddr.name.length > 18) {
return thisAddr.name;
}
return thisAddr.name;
} else {
return address;
}
break;
}
}
}
return address; return address;
} }

View File

@ -9,7 +9,6 @@ import {
RECEIVE_WINNING_TICKETS, RECEIVE_WINNING_TICKETS,
SET_ALL_ENS_INFO, SET_ALL_ENS_INFO,
SET_ALL_ENS_DOMAINS, SET_ALL_ENS_DOMAINS,
SET_ALL_THREEBOX_INFO,
SET_ALL_ORCH_SCORES, SET_ALL_ORCH_SCORES,
SET_ALL_ORCH_INFO, SET_ALL_ORCH_INFO,
SET_ALL_DEL_INFO, SET_ALL_DEL_INFO,
@ -70,8 +69,6 @@ export default (state = {
return { ...state, ensInfoMapping: message }; return { ...state, ensInfoMapping: message };
case SET_ALL_ENS_DOMAINS: case SET_ALL_ENS_DOMAINS:
return { ...state, ensDomainMapping: message }; return { ...state, ensDomainMapping: message };
case SET_ALL_THREEBOX_INFO:
return { ...state, threeBoxInfo: message };
case SET_ALL_ORCH_SCORES: case SET_ALL_ORCH_SCORES:
return { ...state, orchScores: message }; return { ...state, orchScores: message };
case SET_ALL_ORCH_INFO: case SET_ALL_ORCH_INFO: