Skip to content

Commit

Permalink
chore: remove in-flight session request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Dec 1, 2023
1 parent b281208 commit d677e8c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
22 changes: 0 additions & 22 deletions src/context/ServiceInfoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
useReducer,
useState,
useEffect,
useRef,
} from 'react'
import { useCurrentWallet, useClearCurrentWallet } from './WalletContext'
import { useWebsocket } from './WebsocketContext'
Expand Down Expand Up @@ -104,8 +103,6 @@ const ServiceInfoProvider = ({ children }: PropsWithChildren<{}>) => {
const clearCurrentWallet = useClearCurrentWallet()
const websocket = useWebsocket()

const fetchSessionInProgress = useRef<Promise<ServiceInfo> | null>(null)

const [serviceInfo, dispatchServiceInfo] = useReducer(
(state: ServiceInfo | null, obj: Partial<ServiceInfo>) => ({ ...state, ...obj }) as ServiceInfo | null,
null,
Expand Down Expand Up @@ -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 => {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/context/WebsocketContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const WebsocketContext = createContext<WebsocketContextEntry | undefined>(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]
Expand Down

0 comments on commit d677e8c

Please sign in to comment.