Skip to content

Commit

Permalink
fix: subscribe to errors/notifications after rpc.discover
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Sep 10, 2021
1 parent 0c4a63d commit 7f70ce4
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/containers/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,35 +242,6 @@ const Inspector: React.FC<IProps> = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.url]);

useEffect(() => {
if (transport) {
transport.subscribe("notification", (notification: any) => {
const responseTimestamp = new Date();
const notificationObj: JSONRPCLog = {
type: "response",
notification: true,
method: notification.method,
timestamp: responseTimestamp,
payload: notification,
};
setLogs((prevLogs) => [...prevLogs, notificationObj]);
setTabLogs(tabIndex, [...(tabs[tabIndex].logs || []), notificationObj]);
});
transport.subscribe("error", (error: any) => {
const responseTimestamp = new Date();
const notificationObj: JSONRPCLog = {
type: "response",
method: "",
timestamp: responseTimestamp,
payload: errorToJSON(error, error.id),
};
setLogs((prevLogs) => [...prevLogs, notificationObj]);
setTabLogs(tabIndex, [...(tabs[tabIndex].logs || []), notificationObj]);
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [transport]);

const handlePlayButton = async () => {
let requestTimestamp = new Date();
if (transport) {
Expand Down Expand Up @@ -355,6 +326,31 @@ const Inspector: React.FC<IProps> = (props) => {
setTabOpenRPCDocument(tabIndex, undefined);
}
}
if (transport) {
transport.subscribe("notification", (notification: any) => {
const responseTimestamp = new Date();
const notificationObj: JSONRPCLog = {
type: "response",
notification: true,
method: notification.method,
timestamp: responseTimestamp,
payload: notification,
};
setLogs((prevLogs) => [...prevLogs, notificationObj]);
setTabLogs(tabIndex, [...(tabs[tabIndex].logs || []), notificationObj]);
});
transport.subscribe("error", (error: any) => {
const responseTimestamp = new Date();
const notificationObj: JSONRPCLog = {
type: "response",
method: "",
timestamp: responseTimestamp,
payload: errorToJSON(error, null),
};
setLogs((prevLogs) => [...prevLogs, notificationObj]);
setTabLogs(tabIndex, [...(tabs[tabIndex].logs || []), notificationObj]);
});
}
};
useEffect(() => {
if (!props.openrpcDocument) {
Expand Down

0 comments on commit 7f70ce4

Please sign in to comment.