Commit 9a432009 authored by tom's avatar tom

fixes

parent b11e70b2
...@@ -14,12 +14,12 @@ export function SocketProvider({ children, options, url }: SocketProviderProps) ...@@ -14,12 +14,12 @@ export function SocketProvider({ children, options, url }: SocketProviderProps)
const [ socket, setSocket ] = useState<Socket | null>(null); const [ socket, setSocket ] = useState<Socket | null>(null);
useEffect(() => { useEffect(() => {
const s = new Socket(url, options); const socketInstance = new Socket(url, options);
s.connect(); socketInstance.connect();
setSocket(s); setSocket(socketInstance);
return () => { return () => {
s.disconnect(); socketInstance.disconnect();
setSocket(null); setSocket(null);
}; };
}, [ options, url ]); }, [ options, url ]);
...@@ -34,7 +34,7 @@ export function SocketProvider({ children, options, url }: SocketProviderProps) ...@@ -34,7 +34,7 @@ export function SocketProvider({ children, options, url }: SocketProviderProps)
export function useSocket() { export function useSocket() {
const context = React.useContext(SocketContext); const context = React.useContext(SocketContext);
if (context === undefined) { 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; return context;
} }
...@@ -20,8 +20,8 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on ...@@ -20,8 +20,8 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
const onCloseRef = useRef<string>(); const onCloseRef = useRef<string>();
const onErrorRef = useRef<string>(); const onErrorRef = useRef<string>();
const onJoinFun = useRef(onJoin); const onJoinRef = useRef(onJoin);
onJoinFun.current = onJoin; onJoinRef.current = onJoin;
useEffect(() => { useEffect(() => {
const cleanUpRefs = () => { const cleanUpRefs = () => {
...@@ -31,7 +31,7 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on ...@@ -31,7 +31,7 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
if (!isDisabled) { if (!isDisabled) {
onCloseRef.current = onSocketClose && socket?.onClose(onSocketClose); onCloseRef.current = onSocketClose && socket?.onClose(onSocketClose);
onErrorRef.current = onSocketError && socket?.onClose(onSocketError); onErrorRef.current = onSocketError && socket?.onError(onSocketError);
} else { } else {
cleanUpRefs(); cleanUpRefs();
} }
...@@ -52,7 +52,7 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on ...@@ -52,7 +52,7 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
} }
const ch = socket.channel(topic, params); 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); setChannel(ch);
return () => { return () => {
......
...@@ -3,8 +3,8 @@ import { useEffect, useRef } from 'react'; ...@@ -3,8 +3,8 @@ import { useEffect, useRef } from 'react';
import type { SocketMessageParams } from 'lib/socket/types'; import type { SocketMessageParams } from 'lib/socket/types';
export default function useSocketMessage({ channel, event, handler }: SocketMessageParams) { export default function useSocketMessage({ channel, event, handler }: SocketMessageParams) {
const handlerFun = useRef(handler); const handlerRef = useRef(handler);
handlerFun.current = handler; handlerRef.current = handler;
useEffect(() => { useEffect(() => {
if (channel === undefined) { if (channel === undefined) {
...@@ -12,7 +12,7 @@ export default function useSocketMessage({ channel, event, handler }: SocketMess ...@@ -12,7 +12,7 @@ export default function useSocketMessage({ channel, event, handler }: SocketMess
} }
const ref = channel.on(event, (message) => { const ref = channel.on(event, (message) => {
handlerFun.current?.(message); handlerRef.current?.(message);
}); });
return () => { return () => {
......
...@@ -48,7 +48,7 @@ const TransactionPageContent = () => { ...@@ -48,7 +48,7 @@ const TransactionPageContent = () => {
return <ExternalLink key={ explorer.baseUrl } title={ `Open in ${ explorer.title }` } href={ url.toString() }/>; 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 ( return (
<Page> <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