Skip to content

fix: preserve token icons when balance API fails - #422

Open
mj-kiwi wants to merge 2 commits into
mainfrom
fix/tokne-icon
Open

mj-kiwi wants to merge 2 commits into
mainfrom
fix/tokne-icon

Conversation

@mj-kiwi

@mj-kiwi mj-kiwi commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Description

Token metadata and balance are currently fetched in parallel by AccountApiClient. When the Account API balance request fails, for example with HTTP 403, the rejected balance promise causes the
entire Promise.all to reject. The metadata request may have succeeded, but the token metadata service then falls back to the blockchain client, which cannot provide token icon URLs.

This change makes balance resolution independent from metadata resolution:

  • Treats balance request failures as an unavailable balance instead of rejecting the combined request.
  • Preserves token metadata and icon URL resolution when the balance API fails.
  • Skips balance and fiat balance rendering when no balance is available.
  • Keeps metadata failures and unsupported-chain fallback behavior unchanged.
  • Adds regression coverage for a 403 balance response with successful metadata and icon data.

Related issues

Fixes: #

Manual testing steps

  1. Build and run the Gator Permissions Snap and the development site.
  2. Open the development site at http://localhost:8000.
  3. Request an ERC-20 permission for a token supported by the Token Metadata API.
  4. Confirm the MetaMask permission confirmation dialog displays the token symbol and icon even when the Account API balance request returns an error.
  5. Confirm that the permission confirmation flow does not fail when the balance is unavailable.

Automated verification:

  • yarn workspace @metamask/gator-permissions-snap test test/client/accountApiClient.test.ts test/services/tokenMetadataService.test.ts test/core/confirmation/ConfirmationShell.test.ts --runInBand
  • yarn eslint packages/gator-permissions-snap/src/clients/accountApiClient.ts packages/gator-permissions-snap/src/clients/types.ts packages/gator-permissions-snap/src/core/confirmation/ConfirmationShell.ts packages/gator-permissions-snap/test/client/accountApiClient.test.ts

Screenshots/Recordings

Before

The Account API balance request failure caused the combined balance and metadata request to reject, so the flow fell back to the blockchain client and the token icon was unavailable.
image

After

The balance failure is treated as an unavailable balance. Token metadata and the icon URL continue to resolve independently.
image

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

Low Risk
Scoped to permission confirmation token display and Account API error handling; grant logic is unchanged and metadata failures still propagate as before.

Overview
When the Account API balance call fails (e.g. HTTP 403), getTokenBalanceAndMetadata no longer rejects the combined fetch: the balance promise is caught, logged, and resolved as balance: undefined, while metadata (including iconUrl) still completes via Promise.all.

The confirmation flow treats a missing balance as unavailable rather than a hard failure: ConfirmationShell sets tokenBalanceUnavailable, skips token/fiat formatting, and ConfirmationShellContent hides the balance row instead of showing loading skeletons. TokenBalanceAndMetadata.balance is typed as bigint | undefined, with client and shell tests updated for partial success and unavailable-balance UI.

Reviewed by Cursor Bugbot for commit 1460d94. Bugbot is set up for automated code reviews on this repo. Configure here.

@mj-kiwi
mj-kiwi requested a review from a team as a code owner September 7, 2026 23:18
@mj-kiwi mj-kiwi changed the title feat: handle balance lookup failures gracefully in AccountApiClient fix: preserve token icons when balance API fails Sep 7, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4d5776f. Configure here.

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.

1 participant