diff --git a/backend/src/routes/livepeer.js b/backend/src/routes/livepeer.js index cc681ed..9ce3d21 100644 --- a/backend/src/routes/livepeer.js +++ b/backend/src/routes/livepeer.js @@ -1251,6 +1251,25 @@ apiRouter.get("/getAllOrchScores", async (req, res) => { } }); +// Returns entire orch info cache +apiRouter.get("/getAllOrchInfo", async (req, res) => { + try { + res.send(orchestratorCache); + } catch (err) { + res.status(400).send(err); + } +}); + +// Returns entire delegator info cache +apiRouter.get("/getAllDelInfo", async (req, res) => { + try { + res.send(delegatorCache); + } 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 72d2efc..66dbdfd 100644 --- a/src/actions/livepeer.js +++ b/src/actions/livepeer.js @@ -21,6 +21,7 @@ export const RECEIVE_QUOTES = "RECEIVE_QUOTES"; export const RECEIVE_BLOCKCHAIN_DATA = "RECEIVE_BLOCKCHAIN_DATA"; export const RECEIVE_EVENTS = "RECEIVE_EVENTS"; export const RECEIVE_CURRENT_ORCHESTRATOR = "RECEIVE_CURRENT_ORCHESTRATOR"; +export const CACHE_ORCHESTRATOR = "CACHE_ORCHESTRATOR"; export const RECEIVE_ORCHESTRATOR = "RECEIVE_ORCHESTRATOR"; export const CLEAR_ORCHESTRATOR = "CLEAR_ORCHESTRATOR"; export const RECEIVE_TICKETS = "RECEIVE_TICKETS"; @@ -29,6 +30,8 @@ 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"; export const SET_ALL_ORCH_SCORES = "SET_ALL_ORCH_SCORES"; +export const SET_ALL_ORCH_INFO = "SET_ALL_ORCH_INFO"; +export const SET_ALL_DEL_INFO = "SET_ALL_DEL_INFO"; const setQuotes = message => ({ type: RECEIVE_QUOTES, message @@ -42,6 +45,9 @@ const setEvents = message => ({ const setCurrentOrchestratorInfo = message => ({ type: RECEIVE_CURRENT_ORCHESTRATOR, message }); +const cacheNewOrch = message => ({ + type: CACHE_ORCHESTRATOR, message +}); const setOrchestratorInfo = message => ({ type: RECEIVE_ORCHESTRATOR, message }); @@ -66,6 +72,14 @@ const setAllThreeBoxInfo = message => ({ const setAllOrchScores = message => ({ type: SET_ALL_ORCH_SCORES, message }); +const setAllOrchInfo = message => ({ + type: SET_ALL_ORCH_INFO, message +}); + +const setAllDelInfo = message => ({ + type: SET_ALL_DEL_INFO, message +}); + export const getQuotes = () => async dispatch => { @@ -145,13 +159,13 @@ export const getEvents = () => async dispatch => { tmpAmount.toFixed(2) + " LPT stake", "round " + tmpWhen ] - eventDescription = + eventDescription = } else { const subtext = "reactivated"; const descriptions = [ "round " + tmpWhen ] - eventDescription = + eventDescription = } } // Lone Unbond => Unbond Event @@ -164,7 +178,7 @@ export const getEvents = () => async dispatch => { "round " + tmpWhen ] eventDescription = - + } // Lone Bond => Stake Event else if (eventContainsBond) { @@ -180,7 +194,7 @@ export const getEvents = () => async dispatch => { tmpAmount.toFixed(2) + " LPT" ] eventDescription = - + } // Fill description of Stake Event if it wasn't set yet @@ -191,7 +205,7 @@ export const getEvents = () => async dispatch => { tmpAmount.toFixed(2) + " LPT" ] eventDescription = - + } else if (eventFrom === eventTo) { eventFrom = ""; const subtext = "changed stake"; @@ -199,14 +213,14 @@ export const getEvents = () => async dispatch => { tmpAmount.toFixed(2) + " LPT" ] eventDescription = - + } else { const subtext = "moved stake"; const descriptions = [ tmpAmount.toFixed(2) + " LPT" ] eventDescription = - + } } @@ -263,7 +277,7 @@ export const getEvents = () => async dispatch => { "round " + eventObj.data.withdrawRound ] const txt = - + finalEventList.push({ eventType: "Withdraw", eventDescription: txt, @@ -287,7 +301,7 @@ export const getEvents = () => async dispatch => { amount.toFixed(4) + " Eth" ] const txt = - + finalEventList.push({ eventType: "Withdraw", eventDescription: txt, @@ -313,7 +327,7 @@ export const getEvents = () => async dispatch => { amount2.toFixed(2) + "% on transcoding fees" ] const txt = - + finalEventList.push({ eventType: "Update", eventDescription: txt, @@ -343,7 +357,7 @@ export const getEvents = () => async dispatch => { "+" + amount2.toFixed(4) + " Eth fees" ] let txt = - + finalEventList.push({ eventType: "Claim", eventDescription: txt, @@ -367,7 +381,7 @@ export const getEvents = () => async dispatch => { "+" + amount1.toFixed(2) + " LPT" + (Math.floor(amount1) == 69 ? "... Nice!" : "") ] const txt = - + finalEventList.push({ eventType: "Reward", eventDescription: txt, @@ -469,7 +483,7 @@ export const getTickets = () => async dispatch => { "+" + amount.toFixed(4) + " Eth" ] const txt = - + finalTicketList.push({ eventType: "RedeemTicket", eventDescription: txt, @@ -526,11 +540,14 @@ export const getOrchestratorInfo = (orchAddr) => async dispatch => { const data = await response.json(); if (response.ok) { if (data && data.id) { + console.log(data); + dispatch(cacheNewOrch(data)); return dispatch(setOrchestratorInfo(data)); } else { const response = await apiUtil.getOrchestratorByDelegator(orchAddr); const data = await response.json(); if (response.ok) { + dispatch(cacheNewOrch(data)); return dispatch(setOrchestratorInfo(data)); } } @@ -538,6 +555,10 @@ export const getOrchestratorInfo = (orchAddr) => async dispatch => { return dispatch(receiveErrors(data)); }; +export const setCachedOrch = (orchObj) => async dispatch => { + return dispatch(setOrchestratorInfo(orchObj)); +}; + export const clearOrchestrator = () => async dispatch => { return dispatch(clearOrchestratorInfo({})); }; @@ -587,9 +608,26 @@ export const getOrchestratorScores = (year, month) => async dispatch => { export const getAllOrchScores = () => async dispatch => { const response = await apiUtil.getAllOrchScores(); const data = await response.json(); - console.log(data); if (response.ok) { return dispatch(setAllOrchScores(data)); } return dispatch(receiveErrors(data)); +}; + +export const getAllOrchInfo = () => async dispatch => { + const response = await apiUtil.getAllOrchInfo(); + const data = await response.json(); + if (response.ok) { + return dispatch(setAllOrchInfo(data)); + } + return dispatch(receiveErrors(data)); +}; + +export const getAllDelInfo = () => async dispatch => { + const response = await apiUtil.getAllDelInfo(); + const data = await response.json(); + if (response.ok) { + return dispatch(setAllDelInfo(data)); + } + return dispatch(receiveErrors(data)); }; \ No newline at end of file diff --git a/src/components/TicketViewer.js b/src/components/TicketViewer.js index 4b8e04e..9b73110 100644 --- a/src/components/TicketViewer.js +++ b/src/components/TicketViewer.js @@ -17,7 +17,7 @@ const Ticket = (obj) => {
{obj.descriptions.map(function (thisTextItem, i) { return ( -

+

{thisTextItem}

) diff --git a/src/components/eventButtonAddress.js b/src/components/eventButtonAddress.js index c37fe07..4a7149b 100644 --- a/src/components/eventButtonAddress.js +++ b/src/components/eventButtonAddress.js @@ -1,6 +1,6 @@ import React, { useState } from "react"; import { - getOrchestratorInfo, getEnsInfo, getThreeBoxInfo + getOrchestratorInfo, getEnsInfo, getThreeBoxInfo, setCachedOrch } from "../actions/livepeer"; import { useDispatch, useSelector } from 'react-redux'; @@ -126,7 +126,22 @@ const EventButtonAddress = (obj) => { {obj.name} {thisIcon} -
diff --git a/src/pages/livepeer.js b/src/pages/livepeer.js index c537d9e..41c5f2c 100644 --- a/src/pages/livepeer.js +++ b/src/pages/livepeer.js @@ -23,9 +23,10 @@ const Livepeer = (obj) => { console.log("Rendering Livepeer"); useEffect(() => { - if (prefill.get('orchAddr') && prefill.get('orchAddr') !== "") { - dispatch(getOrchestratorInfo(prefill.get('orchAddr'))); - setSearchTerm(prefill.get('orchAddr')); + const searchOrch = prefill.get('orchAddr'); + if (searchOrch && searchOrch !== "") { + dispatch(getOrchestratorInfo(searchOrch)); + setSearchTerm(searchOrch); } }, [prefill]); diff --git a/src/pages/loadingScreen.js b/src/pages/loadingScreen.js index acc160e..34fe98b 100644 --- a/src/pages/loadingScreen.js +++ b/src/pages/loadingScreen.js @@ -5,7 +5,8 @@ import { } from "../actions/user"; import { getQuotes, getBlockchainData, getEvents, getCurrentOrchestratorInfo, getTickets, - getAllEnsDomains, getAllEnsInfo, getAllThreeBoxInfo, getAllOrchScores + getAllEnsDomains, getAllEnsInfo, getAllThreeBoxInfo, getAllOrchScores, getAllOrchInfo, + getAllDelInfo } from "../actions/livepeer"; import { login } from "../actions/session"; @@ -43,6 +44,14 @@ const Startup = (obj) => { dispatch(getAllThreeBoxInfo()); dispatch(getAllEnsDomains()); dispatch(getAllEnsInfo()); + }); + } + + const refreshStaticProps = () => { + console.log("Refreshing global data..."); + batch(() => { + dispatch(getAllOrchInfo()); + dispatch(getAllDelInfo()); dispatch(getAllOrchScores()); }); } @@ -51,6 +60,7 @@ const Startup = (obj) => { refreshLogin(); refreshAllZeData(); refreshENS(); + refreshStaticProps(); setIsLoaded(true); if (refreshInterval) { const interval = setInterval(refreshAllZeData, refreshInterval); diff --git a/src/pages/tickets.js b/src/pages/tickets.js index 551fada..cb9de52 100644 --- a/src/pages/tickets.js +++ b/src/pages/tickets.js @@ -202,7 +202,7 @@ const Tickets = (obj) => { return ( { + if (content.id == message.id) { + return message; + } else { + return content; + } + } + ) + } + } else { + return { + ...state, + orchInfo: [...state.orchInfo, message] + }; + } + case SET_ALL_DEL_INFO: + return { ...state, delInfo: message }; default: return { ...state }; } diff --git a/src/util/livepeer.js b/src/util/livepeer.js index 8c5a69e..ff30298 100644 --- a/src/util/livepeer.js +++ b/src/util/livepeer.js @@ -125,4 +125,22 @@ export const getAllOrchScores = () => ( "Content-Type": "application/json" } }) +); + +export const getAllOrchInfo = () => ( + fetch("api/livepeer/getAllOrchInfo", { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }) +); + +export const getAllDelInfo = () => ( + fetch("api/livepeer/getAllDelInfo", { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }) ); \ No newline at end of file