Skip to content

Conversation

david0xd
Copy link
Contributor

Add way of tracking last interaction with Snap on certain request types.

@david0xd david0xd self-assigned this Feb 24, 2025
* @param snapId - ID of a Snap.
* @param handlerType - Type of Snap handler.
*/
updateLastInteraction(snapId: SnapId, handlerType: HandlerType): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have some code that tracks this, we just don't persist it in state, it is only stored in memory:

#recordSnapRpcRequestStart(snapId: SnapId, requestId: unknown, timer: Timer) {
const runtime = this.#getRuntimeExpect(snapId);
runtime.pendingInboundRequests.push({ requestId, timer });
runtime.lastRequest = null;
}
#recordSnapRpcRequestFinish(snapId: SnapId, requestId: unknown) {
const runtime = this.#getRuntimeExpect(snapId);
runtime.pendingInboundRequests = runtime.pendingInboundRequests.filter(
(request) => request.requestId !== requestId,
);
if (runtime.pendingInboundRequests.length === 0) {
runtime.lastRequest = Date.now();
}
}

Side-note: I wonder how many extra state updates this will cause? May be somewhat excessive and cause load on the clients 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it would be any better if we use SnapRuntimeData and that process around RPC. Since, we need to get this straight into the UI, easily available through the Snap object, and we need to filter which requests we want to track before recording it to state. Last request seems to be updated in different context under different use cases.

On the note: My idea was to build something that would somehow debounce the state update. If state is already available at the moment of potential timestamp update, it should be cheaper operation to first check if the update has been done in the last minute or so, then update the state only if it's not updated for more than a minute or similar timespan. Feedback and ideas on this are also welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants