From 173d75c57a17bcb4fc93a09f02f3bcaec30ae604 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 28 Feb 2026 08:44:09 -0800 Subject: [PATCH] fix: fall back to known token list for symbol/name/decimals 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 --- src/popup/views/addressToken.js | 19 ++++++++++++++----- src/popup/views/send.js | 10 +++++++--- src/shared/balances.js | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/popup/views/addressToken.js b/src/popup/views/addressToken.js index 211f144..fb12ebb 100644 --- a/src/popup/views/addressToken.js +++ b/src/popup/views/addressToken.js @@ -87,6 +87,7 @@ function show() { // Determine token symbol and balance let symbol, amount, price; + const knownToken = TOKEN_BY_ADDRESS.get(tokenId.toLowerCase()); if (tokenId === "ETH") { symbol = "ETH"; amount = parseFloat(addr.balance || "0"); @@ -95,7 +96,7 @@ function show() { const tb = (addr.tokenBalances || []).find( (t) => t.address.toLowerCase() === tokenId.toLowerCase(), ); - symbol = tb ? tb.symbol : "?"; + symbol = (tb && tb.symbol) || (knownToken && knownToken.symbol) || "?"; amount = tb ? parseFloat(tb.balance || "0") : 0; price = getPrice(symbol); } @@ -138,13 +139,21 @@ function show() { const tb = (addr.tokenBalances || []).find( (t) => t.address.toLowerCase() === tokenId.toLowerCase(), ); - const tokenName = tb && tb.name ? escapeHtml(tb.name) : null; - const tokenSymbol = tb && tb.symbol ? escapeHtml(tb.symbol) : null; - const tokenDecimals = tb && tb.decimals != null ? tb.decimals : null; + const rawName = + (tb && tb.name) || (knownToken && knownToken.name) || null; + const rawSymbol = + (tb && tb.symbol) || (knownToken && knownToken.symbol) || null; + const tokenName = rawName ? escapeHtml(rawName) : null; + const tokenSymbol = rawSymbol ? escapeHtml(rawSymbol) : null; + const tokenDecimals = + tb && tb.decimals != null + ? tb.decimals + : knownToken && knownToken.decimals != null + ? knownToken.decimals + : null; const tokenHolders = tb && tb.holders != null ? tb.holders : null; const dot = addressDotHtml(tokenId); const tokenLink = `https://etherscan.io/token/${escapeHtml(tokenId)}`; - const knownToken = TOKEN_BY_ADDRESS.get(tokenId.toLowerCase()); const projectUrl = knownToken && knownToken.url ? knownToken.url : null; let infoHtml = `
Contract Address
`; infoHtml += diff --git a/src/popup/views/send.js b/src/popup/views/send.js index 6a7b630..5671c29 100644 --- a/src/popup/views/send.js +++ b/src/popup/views/send.js @@ -10,7 +10,7 @@ const { const { state, currentAddress } = require("../../shared/state"); let ctx; const { getProvider } = require("../../shared/balances"); -const { KNOWN_SYMBOLS } = require("../../shared/tokenList"); +const { KNOWN_SYMBOLS, TOKEN_BY_ADDRESS } = require("../../shared/tokenList"); const EXT_ICON = `` + @@ -73,7 +73,9 @@ function updateSendBalance() { const tb = (addr.tokenBalances || []).find( (t) => t.address.toLowerCase() === token.toLowerCase(), ); - const symbol = tb ? tb.symbol : "?"; + const knownToken = TOKEN_BY_ADDRESS.get(token.toLowerCase()); + const symbol = + (tb && tb.symbol) || (knownToken && knownToken.symbol) || "?"; const bal = tb ? tb.balance || "0" : "0"; $("send-balance").textContent = "Current balance: " + bal + " " + symbol; @@ -124,7 +126,9 @@ function init(_ctx) { const tb = (addr.tokenBalances || []).find( (t) => t.address.toLowerCase() === token.toLowerCase(), ); - tokenSymbol = tb ? tb.symbol : "?"; + const knownTk = TOKEN_BY_ADDRESS.get(token.toLowerCase()); + tokenSymbol = + (tb && tb.symbol) || (knownTk && knownTk.symbol) || "?"; tokenBalance = tb ? tb.balance || "0" : "0"; } diff --git a/src/shared/balances.js b/src/shared/balances.js index 7ad0872..73f047b 100644 --- a/src/shared/balances.js +++ b/src/shared/balances.js @@ -85,6 +85,7 @@ async function fetchTokenBalances(address, blockscoutUrl, trackedTokens) { balances.push({ address: item.token.address_hash, + name: item.token.name || "", symbol: item.token.symbol || "???", decimals: decimals, balance: bal,