fix: fall back to known token list for symbol/name/decimals
All checks were successful
check / check (push) Successful in 22s
All checks were successful
check / check (push) Successful in 22s
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
This commit is contained in:
@@ -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 =
|
||||
`<span style="display:inline-block;width:10px;height:10px;margin-left:4px;vertical-align:middle">` +
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user