Commit 9a432009 authored by tom's avatar tom

fixes

parent b11e70b2
......@@ -14,12 +14,12 @@ export function SocketProvider({ children, options, url }: SocketProviderProps)
const [ socket, setSocket ] = useState<Socket | null>(null);
useEffect(() => {
const s = new Socket(url, options);
s.connect();
setSocket(s);
const socketInstance = new Socket(url, options);
socketInstance.connect();
setSocket(socketInstance);
return () => {
s.disconnect();
socketInstance.disconnect();
setSocket(null);
};
}, [ options, url ]);
......@@ -34,7 +34,7 @@ export function SocketProvider({ children, options, url }: SocketProviderProps)
export function useSocket() {
const context = React.useContext(SocketContext);
if (context === undefined) {
throw new Error('useCount must be used within a SocketProvider');
throw new Error('useSocket must be used within a SocketProvider');
}
return context;
}
......@@ -20,8 +20,8 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
const onCloseRef = useRef<string>();
const onErrorRef = useRef<string>();
const onJoinFun = useRef(onJoin);
onJoinFun.current = onJoin;
const onJoinRef = useRef(onJoin);
onJoinRef.current = onJoin;
useEffect(() => {
const cleanUpRefs = () => {
......@@ -31,7 +31,7 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
if (!isDisabled) {
onCloseRef.current = onSocketClose && socket?.onClose(onSocketClose);
onErrorRef.current = onSocketError && socket?.onClose(onSocketError);
onErrorRef.current = onSocketError && socket?.onError(onSocketError);
} else {
cleanUpRefs();
}
......@@ -52,7 +52,7 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
}
const ch = socket.channel(topic, params);
ch.join().receive('ok', (message) => onJoinFun.current?.(ch, message));
ch.join().receive('ok', (message) => onJoinRef.current?.(ch, message));
setChannel(ch);
return () => {
......
......@@ -3,8 +3,8 @@ import { useEffect, useRef } from 'react';
import type { SocketMessageParams } from 'lib/socket/types';
export default function useSocketMessage({ channel, event, handler }: SocketMessageParams) {
const handlerFun = useRef(handler);
handlerFun.current = handler;
const handlerRef = useRef(handler);
handlerRef.current = handler;
useEffect(() => {
if (channel === undefined) {
......@@ -12,7 +12,7 @@ export default function useSocketMessage({ channel, event, handler }: SocketMess
}
const ref = channel.on(event, (message) => {
handlerFun.current?.(message);
handlerRef.current?.(message);
});
return () => {
......
......@@ -48,7 +48,7 @@ const TransactionPageContent = () => {
return <ExternalLink key={ explorer.baseUrl } title={ `Open in ${ explorer.title }` } href={ url.toString() }/>;
});
const hasGoBackLink = false && isBrowser() && window.document.referrer.includes('/txs');
const hasGoBackLink = isBrowser() && window.document.referrer.includes('/txs');
return (
<Page>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment