fix: fall back to known token list for symbol/name/decimals #54

Merged
sneak merged 2 commits from fix/51-usdc-symbol-fallback into main 2026-02-28 18:04:04 +01:00
Collaborator

When a token's balance entry is missing or incomplete (e.g. not yet fetched from Blockscout), the address-token view and send view now fall back to the built-in known token list for symbol, name, and decimals instead of showing ?.

Also includes token name in the balance object returned by fetchTokenBalances so the contract info well can display it.

Fixes #51

When a token's balance entry is missing or incomplete (e.g. not yet fetched from Blockscout), the address-token view and send view now fall back to the built-in known token list for symbol, name, and decimals instead of showing `?`. Also includes token `name` in the balance object returned by `fetchTokenBalances` so the contract info well can display it. Fixes #51
clawbot added 1 commit 2026-02-28 17:44:19 +01:00
fix: fall back to known token list for symbol/name/decimals
All checks were successful
check / check (push) Successful in 22s
173d75c57a
When a token's balance entry is missing or incomplete (e.g. not yet
fetched from Blockscout), the address-token view and send view now
fall back to the built-in known token list for symbol, name, and
decimals instead of showing '?'.

Also includes token name in the balance object returned by
fetchTokenBalances so the contract info well can display it.

Fixes #51
clawbot added the
needs-review
label 2026-02-28 17:49:10 +01:00
Author
Collaborator

make check passes (tests, lint, format all clean). Mergeable, no conflicts. Cannot self-review — assigning to @sneak for review.

`make check` passes (tests, lint, format all clean). Mergeable, no conflicts. Cannot self-review — assigning to @sneak for review.
sneak was assigned by clawbot 2026-02-28 17:49:11 +01:00
Owner

@clawbot will this show ? for zero-balance not-known tokens added by the user by contract address?

@clawbot will this show ? for zero-balance not-known tokens added by the user by contract address?
Author
Collaborator

Yes — if a user adds a token by contract address that is neither in TOKEN_BY_ADDRESS (the known token list) nor returns symbol/name from the Blockscout API, it will still show ?. The fallback chain is:

(tb && tb.symbol) || (knownToken && knownToken.symbol) || "?"

So ? only appears when both sources have no data. For most real ERC-20 tokens, Blockscout will return the symbol even if it's not in our known list. The ? case would mainly hit proxy contracts or very obscure tokens where Blockscout has no metadata.

Yes — if a user adds a token by contract address that is neither in `TOKEN_BY_ADDRESS` (the known token list) nor returns symbol/name from the Blockscout API, it will still show `?`. The fallback chain is: ``` (tb && tb.symbol) || (knownToken && knownToken.symbol) || "?" ``` So `?` only appears when *both* sources have no data. For most real ERC-20 tokens, Blockscout will return the symbol even if it's not in our known list. The `?` case would mainly hit proxy contracts or very obscure tokens where Blockscout has no metadata.
Author
Collaborator

You're right — this is a band-aid, not a fix. The known token list fallback only helps tokens we've hardcoded. The real bug is: why is tb.symbol empty/missing for USDC in the first place? Blockscout should be returning that metadata.

I'll dig into fetchTokenBalances in balances.js to see if we're dropping the symbol during parsing, or if the Blockscout API response genuinely lacks it. That's the actual root cause.

You're right — this is a band-aid, not a fix. The known token list fallback only helps tokens we've hardcoded. The real bug is: why is `tb.symbol` empty/missing for USDC in the first place? Blockscout should be returning that metadata. I'll dig into `fetchTokenBalances` in `balances.js` to see if we're dropping the symbol during parsing, or if the Blockscout API response genuinely lacks it. That's the actual root cause.
Author
Collaborator

Found the root cause. Two problems:

  1. fetchTokenBalances drops zero-balance tokens (if (bal === "0.0") continue at line 79 of balances.js). So if a user tracks USDC but has 0 balance, it's excluded from addr.tokenBalances entirely.

  2. The UI looks up metadata only from addr.tokenBalances, which is now empty for that token → tb is undefined → shows ?.

The known-token-list fallback in this PR only helps hardcoded tokens. A user who adds a custom token by contract address will still see ? if their balance is zero or if Blockscout hasn't indexed it yet.

Proper fix: When tb is missing, fall back to state.trackedTokens (which already stores name, symbol, decimals from the lookupTokenInfo call at add time). This covers all user-added tokens regardless of whether they're in the known list.

I'll rework this PR.

Found the root cause. Two problems: 1. **`fetchTokenBalances` drops zero-balance tokens** (`if (bal === "0.0") continue` at line 79 of `balances.js`). So if a user tracks USDC but has 0 balance, it's excluded from `addr.tokenBalances` entirely. 2. **The UI looks up metadata only from `addr.tokenBalances`**, which is now empty for that token → `tb` is `undefined` → shows `?`. The known-token-list fallback in this PR only helps hardcoded tokens. A user who adds a custom token by contract address will still see `?` if their balance is zero or if Blockscout hasn't indexed it yet. **Proper fix:** When `tb` is missing, fall back to `state.trackedTokens` (which already stores `name`, `symbol`, `decimals` from the `lookupTokenInfo` call at add time). This covers all user-added tokens regardless of whether they're in the known list. I'll rework this PR.
clawbot added 1 commit 2026-02-28 18:01:33 +01:00
fix: add trackedTokens fallback for symbol/name/decimals resolution
All checks were successful
check / check (push) Successful in 22s
996003fd79
Extends the fallback chain to: tb → state.trackedTokens → TOKEN_BY_ADDRESS → '?'

This ensures user-added custom tokens (not just hardcoded known tokens)
display correct symbol, name, and decimals even when Blockscout hasn't
returned balance data (e.g. zero-balance tracked tokens).
Author
Collaborator

Added state.trackedTokens fallback for symbol/name/decimals resolution.

Fallback chain is now: tb (Blockscout balance) → trackedTokens (user-added tokens from state) → TOKEN_BY_ADDRESS (hardcoded known tokens) → "?"

Files changed:

  • src/popup/views/addressToken.js — symbol resolution in show() + all fields in contract info section (name, symbol, decimals)
  • src/popup/views/send.js — symbol resolution in updateSendBalance() + review button handler

This ensures custom tokens added by the user display correctly even when Blockscout drops them (zero balance). make check and docker build both pass.

Added `state.trackedTokens` fallback for symbol/name/decimals resolution. **Fallback chain is now:** `tb` (Blockscout balance) → `trackedTokens` (user-added tokens from state) → `TOKEN_BY_ADDRESS` (hardcoded known tokens) → `"?"` **Files changed:** - `src/popup/views/addressToken.js` — symbol resolution in show() + all fields in contract info section (name, symbol, decimals) - `src/popup/views/send.js` — symbol resolution in updateSendBalance() + review button handler This ensures custom tokens added by the user display correctly even when Blockscout drops them (zero balance). `make check` and `docker build` both pass.
sneak merged commit 4d9a8a49b9 into main 2026-02-28 18:04:04 +01:00
sneak deleted branch fix/51-usdc-symbol-fallback 2026-02-28 18:04:04 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/AutistMask#54
No description provided.