From e69338ed5f877084e5896e248267893c9442e02e Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Fri, 22 Apr 2022 00:13:58 +0200 Subject: [PATCH] Make silent preload of orchestrator info not modify local browser cache and also look at delegator cache before preloading --- src/actions/livepeer.js | 10 ++-------- src/components/eventButtonAddress.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/actions/livepeer.js b/src/actions/livepeer.js index 8306e90..9477843 100644 --- a/src/actions/livepeer.js +++ b/src/actions/livepeer.js @@ -146,14 +146,8 @@ export const getCurrentOrchestratorInfo = () => async dispatch => { return dispatch(receiveErrors(data)); }; -export const getOrchestratorInfoSilent = (orchAddr) => async dispatch => { - const response = await apiUtil.getOrchestratorInfo(orchAddr); - const data = await response.json(); - if (response.ok) { - if (data && data.id) { - return dispatch(cacheNewOrch(data)); - } - } +export const getOrchestratorInfoSilent = async (orchAddr) => { + apiUtil.getOrchestratorInfo(orchAddr); }; export const getOrchestratorInfo = (orchAddr) => async dispatch => { diff --git a/src/components/eventButtonAddress.js b/src/components/eventButtonAddress.js index 6f1b515..dee93df 100644 --- a/src/components/eventButtonAddress.js +++ b/src/components/eventButtonAddress.js @@ -95,15 +95,27 @@ const EventButtonAddress = (obj) => { useEffect(() => { // Check if cached as an orchestrator + let shouldUpdate = false; if (livepeer.orchInfo) { for (const thisOrch of livepeer.orchInfo) { if (thisOrch.id === obj.address) { return; } } - // Preload Orch info + shouldUpdate = true; + } + if (livepeer.delInfo) { + for (const thisOrch of livepeer.delInfo) { + if (thisOrch.id === obj.address) { + return; + } + } + shouldUpdate = true; + } + // Preload Orch info + if (shouldUpdate){ console.log("Refresh due to non-existing orch in global state"); - dispatch(getOrchestratorInfoSilent(obj.address)); + getOrchestratorInfoSilent(obj.address); } }, [livepeer.orchInfo]);