Skip to content

Conversation

@chimalsky
Copy link
Contributor

@chimalsky chimalsky commented Sep 22, 2025

context

#154 introduced code that converted most of the actions in this sdk to not crash when one/more RPC node(s) were down. However the frontend had no way of knowing which network(s), and which actions were failing.

solution

This PR introduces a way for an action to emit a diagnostic via a diagnosticHook that the clients can define.

Since the client defines the diagnosticHook callback function... and since this callback is an optional param... no frontend clients need to be rewritten to prevent breakage. Frontend clients instead can opt-in to define the callback handlers to improve UX progressively as needed.

design decision

I chose to make diagnosticHook defined at the global client level rather than per action to reduce code changes and breakage potential. The actions in this sdk can be changed progressively rather than in one giant PR.

notes

converted actions in this PR:

  • getMarkets
  • getUserBalances
  • getUserPositions

Example of what the frontend might look like when using this dianostic emit utility

example code:

export const moonwellClient = createMoonwellClient({
	networks,
	onDiagnostics: (params) => {
		const chainNames = params.map((item: any) => item.network.charAt(0).toUpperCase() + item.network.slice(1));
		const chainNamesValue = chainNames.join(', ');
		
		// Get unique action names
		const uniqueActions = [...new Set(params.map((item) => item.action))];
		const actionNamesValue = uniqueActions.join(', ');
		
		notify.failure('RPC Node Error', `"${actionNamesValue}" on ${chainNamesValue}`);
	},
},);
Screen.Recording.2025-09-22.at.7.18.15.PM.mov

networks and emits diagnostic messages to client.

converted
- getMarkets
- getUserBalances
- getUserPositions
@chimalsky chimalsky marked this pull request as ready for review September 22, 2025 23:08
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.

4 participants