-
Notifications
You must be signed in to change notification settings - Fork 104
Use watch program logs hook #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: can we use react query for storage of logs? https://tkdodo.eu/blog/using-web-sockets-with-react-query
question: does this handle deduplication when the hook is used twice at the same time and shared cache?
request: this is not done use program logs watcher in core
| try { | ||
| // Use Solana logs subscription with a program mention filter | ||
| // @solana/kit provides logsSubscribe. | ||
| const sub = (rpcSubscriptions as any).logsSubscribe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: can we remove any?
|
|
||
| export type ProgramLog = { | ||
| signature: string; | ||
| err: unknown | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: can we improve this type?
|
|
||
| export function useWatchProgramLogs( | ||
| programId: Address | string | undefined, | ||
| opts: { filter?: LogFilter; commitment?: Commitment; maxItems?: number } = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: lets call this options and move the types to a type expression above the function
| try { | ||
| unsubscribeRef.current(); | ||
| } catch { | ||
| // ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why do we have a try/catch and then ignore the error?
| }; | ||
| }, [programId, commitment, filter, maxItems, rpcSubscriptions]); | ||
|
|
||
| return { logs, error, clear, isConnected } as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: do not use as const. this should be typed correctly
Problem
The Gill React library lacked a convenient way for developers to monitor program logs in real-time. Developers needed to manually set up RPC subscriptions and manage the complex lifecycle of WebSocket connections to watch for program-specific logs, which required significant boilerplate code and error handling.
Summary of Changes
Added
useWatchProgramLogsReact hook inpackages/react/src/hooks/program-logs.tsKey Features:
logsSubscribewith program mention filter for efficient log monitoringuseSolanaClienthookFixes
Issue #280