chore: make token fetching more robust #233
Merged
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
What is the reason for the change?
Token metadata fetching can fail when the Account API returns responses with missing optional fields or experiences transient network errors, causing permission requests to fail unnecessarily.
What is the improvement/solution?
Relaxed Zod schema validation: Made the
TokenBalanceItemSchemamore robust by only requiring fields actually used in the code (address,balance,decimals,symbol,name) while marking API metadata fields as optional (object,type,occurrences,chainId,timestamp).Automatic client fallback: Implemented a fallback mechanism in
TokenMetadataServicethat automatically tries the blockchain client when the Account API fails with network or service errors. The fallback is also done in a way that can easily add additional fallback options.Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Relax token balance schema and add client fallback in TokenMetadataService to make token fetching more resilient.
TokenMetadataService:#getTokenMetadataClientForChainIdnow returns an ordered list of clients (Account API first if supported, then blockchain client).getTokenBalanceAndMetadataiterates clients with automatic fallback and throws the last error if all fail; logs failures; usesInternalErrordefault.accountApiClient.ts:TokenBalanceItemSchemato require onlyaddress,balance,decimals,symbol,name; markobject,type,occurrences,chainId,timestampas optional.tokenMetadataService.test.tsto cover fallback behavior, unsupported chains, propagation of errors when no fallback, and last-error throwing; maintain existing success and parameter-pass-through cases.Written by Cursor Bugbot for commit 6dc8a70. This will update automatically on new commits. Configure here.