Skip to content

Conversation

@MoMannn
Copy link
Contributor

@MoMannn MoMannn commented Nov 27, 2025

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?

  1. Relaxed Zod schema validation: Made the TokenBalanceItemSchema more 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).

  2. Automatic client fallback: Implemented a fallback mechanism in TokenMetadataService that 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

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Relax token balance schema and add client fallback in TokenMetadataService to make token fetching more resilient.

  • Services:
    • TokenMetadataService:
      • #getTokenMetadataClientForChainId now returns an ordered list of clients (Account API first if supported, then blockchain client).
      • getTokenBalanceAndMetadata iterates clients with automatic fallback and throws the last error if all fail; logs failures; uses InternalError default.
  • Clients:
    • accountApiClient.ts:
      • Relax TokenBalanceItemSchema to require only address, balance, decimals, symbol, name; mark object, type, occurrences, chainId, timestamp as optional.
  • Tests:
    • Expand tokenMetadataService.test.ts to 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.

@MoMannn MoMannn requested a review from a team as a code owner November 27, 2025 14:39
@MetaMask MetaMask deleted a comment from cursor bot Nov 27, 2025
Copy link
Contributor

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

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

Looks good! Minor nit.

@MoMannn MoMannn merged commit 40c0827 into main Nov 28, 2025
16 checks passed
@MoMannn MoMannn deleted the fix-make-fetching-token-info-more-robust branch November 28, 2025 08:48
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.

3 participants