From d677e8c6396978b367ba4c60abbfc32df0bc2b8f Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Fri, 1 Dec 2023 15:23:39 +0100 Subject: [PATCH] chore: remove in-flight session request handling --- src/context/ServiceInfoContext.tsx | 22 ---------------------- src/context/WebsocketContext.tsx | 2 +- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/context/ServiceInfoContext.tsx b/src/context/ServiceInfoContext.tsx index 9e18a821..23051dbb 100644 --- a/src/context/ServiceInfoContext.tsx +++ b/src/context/ServiceInfoContext.tsx @@ -7,7 +7,6 @@ import { useReducer, useState, useEffect, - useRef, } from 'react' import { useCurrentWallet, useClearCurrentWallet } from './WalletContext' import { useWebsocket } from './WebsocketContext' @@ -104,8 +103,6 @@ const ServiceInfoProvider = ({ children }: PropsWithChildren<{}>) => { const clearCurrentWallet = useClearCurrentWallet() const websocket = useWebsocket() - const fetchSessionInProgress = useRef | null>(null) - const [serviceInfo, dispatchServiceInfo] = useReducer( (state: ServiceInfo | null, obj: Partial) => ({ ...state, ...obj }) as ServiceInfo | null, null, @@ -148,20 +145,6 @@ const ServiceInfoProvider = ({ children }: PropsWithChildren<{}>) => { clearSession() } - /* - * TODO: Temporarily disabled for tests - if (fetchSessionInProgress.current !== null) { - try { - return await fetchSessionInProgress.current - } catch (err: unknown) { - // If a request was in progress but failed, retry! - // This happens e.g. when the in-progress request was aborted. - if (!(err instanceof Error) || err.name !== 'AbortError') { - console.warn('Previous session request resulted in an unexpected error. Retrying!', err) - } - } - }*/ - const fetch = Api.getSession({ signal, token: currentWallet?.token }) .then((res) => (res.ok ? res.json() : Api.Helper.throwError(res))) .then((data: JmSessionData): ServiceInfo => { @@ -188,12 +171,7 @@ const ServiceInfoProvider = ({ children }: PropsWithChildren<{}>) => { } }) - fetchSessionInProgress.current = fetch - return fetch - .finally(() => { - fetchSessionInProgress.current = null - }) .then((info: ServiceInfo) => { if (!signal.aborted) { dispatchServiceInfo(info) diff --git a/src/context/WebsocketContext.tsx b/src/context/WebsocketContext.tsx index 71bb85b7..aef82c88 100644 --- a/src/context/WebsocketContext.tsx +++ b/src/context/WebsocketContext.tsx @@ -60,7 +60,7 @@ const WebsocketContext = createContext(undefi * See Websocket docs: https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.9.5/docs/JSON-RPC-API-using-jmwalletd.md#websocket */ const WebsocketProvider = ({ children }: PropsWithChildren<{}>) => { - const [websocket, setWebsocket] = useState(createWebSocket()) + const [websocket, setWebsocket] = useState(() => createWebSocket()) const [websocketState, setWebsocketState] = useState(websocket.readyState) const [isWebsocketHealthy, setIsWebsocketHealthy] = useState(false) const setConnectionErrorCount = useState(0)[1]