Create useApiQueries hook to manage multiple API requests to the same resource in parallel
#3136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description and Related Issue(s)
This PR introduces a new
useApiQuerieshook that enables managing multiple API requests to the same resource in parallel. The hook is built on top of React Query'suseQueriesand provides a consistent interface similar to the existinguseApiQueryhook.The primary motivation is to improve the transaction description feature (Noves integration), which previously required complex manual state management for batching multiple transaction hash requests. The new hook simplifies this by handling parallel queries automatically and providing aggregated loading, error, and success states.
Proposed Changes
New
useApiQuerieshook: A wrapper around React Query'suseQueriesthat manages multiple parallel API requests to the same resource. It provides a unified return type with aggregated loading, error, and success states, making it easy to handle multiple queries as a single unit.Refactored
useDescribeTxshook: Simplified the implementation by replacing manual Promise.all logic with the newuseApiQuerieshook. The hook now batches transaction hashes into chunks of 10 and makes parallel requests, reducing code complexity from ~96 lines to ~46 lines.Updated transaction components: Modified
TxsList,TxsTable,TxsListItem, andTxsTableItemcomponents to work with the new hook's return type structure.Type cleanup: Removed unused type definitions from
types/api/noves.tsandtypes/api/transaction.ts.Breaking or Incompatible Changes
None. This is a refactoring that maintains backward compatibility with existing functionality.
Additional Information
The
useApiQuerieshook follows the same patterns asuseApiQuery, ensuring consistency across the codebase. It supports all the same features including path params, query params, chain selection, and custom query options. The hook automatically combines results from multiple queries and provides a single aggregated state.Checklist for PR author