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

Слито
sneak слито 2 коммит(ов) из fix/51-usdc-symbol-fallback в main 2026-02-28 18:04:04 +01:00
clawbot прокомментировал(а) 2026-02-28 17:44:19 +01:00
Соавтор

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 добавил(а) 1 коммит 2026-02-28 17:44:19 +01:00
fix: fall back to known token list for symbol/name/decimals
Все проверки выполнены успешно
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 добавил(а) метку needs-review 2026-02-28 17:49:10 +01:00
clawbot прокомментировал(а) 2026-02-28 17:49:11 +01:00
Автор
Соавтор

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 был(а) назначен(а) clawbot 2026-02-28 17:49:11 +01:00
sneak прокомментировал(а) 2026-02-28 17:51:01 +01:00
Владелец

@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?
clawbot прокомментировал(а) 2026-02-28 17:57:33 +01:00
Автор
Соавтор

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.
clawbot прокомментировал(а) 2026-02-28 17:58:50 +01:00
Автор
Соавтор

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.
clawbot прокомментировал(а) 2026-02-28 17:59:28 +01:00
Автор
Соавтор

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 добавил(а) 1 коммит 2026-02-28 18:01:33 +01:00
fix: add trackedTokens fallback for symbol/name/decimals resolution
Все проверки выполнены успешно
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).
clawbot прокомментировал(а) 2026-02-28 18:01:42 +01:00
Автор
Соавтор

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 слил(а) коммит 4d9a8a49b9 в main 2026-02-28 18:04:04 +01:00
sneak удалил(а) ветку fix/51-usdc-symbol-fallback 2026-02-28 18:04:04 +01:00
Войдите, чтобы присоединиться к обсуждению.
2 участников
Уведомления
Срок выполнения
Срок выполнения не установлен.
Зависимости

Зависимостей нет.

Ссылка: sneak/AutistMask#54