fix: a tracked token reads quantity unknown at an address no refresh has read (closes #720)
check / check (push) Canceled after 0s
e2e / e2e-chrome (push) Canceled after 0s
e2e / e2e-firefox (push) Canceled after 0s

A new address, a new wallet and a network switch each leave tracked tokens
with no balance entry, so their lines read 0.0000 before any refresh had read
them.

Each of these now sets `balanceNotFetched` on the tracked tokens, and a refresh
already clears it. Their lines read `quantity unknown` until then. Addresses
that the wallet scan finds get the same. A refresh that did not read every
address the page now holds leaves the field set.

Model: opus-5-5
This commit is contained in:
2026-11-03 07:16:44 +00:00
parent f79390cad5
commit a96085a2ba
13 changed files with 392 additions and 26 deletions
+8 -3
View File
@@ -98,8 +98,10 @@ let refreshTimer = null;
// not tracked if the stored setting is off by then.
//
// The save also deletes `balanceNotFetched` from each tracked token whose
// balance this refresh read at every address. trackToken() in
// src/popup/views/helpers.js sets that field. The save takes the field off the
// balance this refresh read at every address. A refresh that did not read every
// address this page now holds deletes no `balanceNotFetched`. Adding a token
// sets that field (trackToken() in src/popup/views/helpers.js). So does adding
// an address, and so does a network switch. The save takes the field off the
// matching tokens of the stored record (clearBalanceNotFetched() in
// src/shared/state.js). The rest of the stored tracked token list stays as it
// is.
@@ -149,7 +151,10 @@ async function doRefreshAndRender() {
if (!stored.useBlockscout) {
dropUntrackedTokens(state.wallets, stored.trackedTokens);
}
clearBalanceNotFetched(stored, readTokens);
const readEveryAddress = state.wallets.every((wallet) =>
wallet.addresses.every((addr) => refreshed.has(addr.address)),
);
if (readEveryAddress) clearBalanceNotFetched(stored, readTokens);
state.lastBalanceRefresh = Date.now();
return true;
});
+6
View File
@@ -7,6 +7,7 @@ const {
goBack,
clearViewStack,
onViewLeave,
markTrackedTokensNotFetched,
} = require("./helpers");
const {
generateMnemonic,
@@ -195,6 +196,7 @@ async function importMnemonic(ctx) {
],
};
state.wallets.push(wallet);
markTrackedTokensNotFetched();
state.hasWallet = true;
if (state.activeAddress === null) {
state.activeAddress = firstAddress;
@@ -220,6 +222,7 @@ async function importMnemonic(ctx) {
tokenBalances: [],
}));
wallet.nextIndex = scan.nextIndex;
markTrackedTokensNotFetched();
// The new list leaves out the first address when the scan found it
// unused. If it was the active one, the new list's first takes over,
// and the background is told as when the user picks one on Home.
@@ -266,6 +269,7 @@ async function importPrivateKey(ctx) {
encryptedSecret: encrypted,
addresses: [{ address: addr, balance: "0.0000", tokenBalances: [] }],
});
markTrackedTokensNotFetched();
state.hasWallet = true;
if (state.activeAddress === null) {
state.activeAddress = addr;
@@ -330,6 +334,7 @@ async function importXprvKey(ctx) {
],
};
state.wallets.push(wallet);
markTrackedTokensNotFetched();
state.hasWallet = true;
if (state.activeAddress === null) {
state.activeAddress = firstAddress;
@@ -355,6 +360,7 @@ async function importXprvKey(ctx) {
tokenBalances: [],
}));
wallet.nextIndex = scan.nextIndex;
markTrackedTokensNotFetched();
// As for a recovery phrase: an active first address the scan left
// out gives way to the new list's first.
const activeMoved =
+2 -2
View File
@@ -172,8 +172,8 @@ function renderBalance() {
(t) => t.address.toLowerCase() === id,
);
// null when the scale is unknown, or when no refresh has read the
// balance of a token just added: no quantity to show, and none to
// price. balanceLine() states that rather than printing 0.0000.
// token's balance: no quantity to show, and none to price.
// balanceLine() states that rather than printing 0.0000.
if (tb) amount = unknownableAmount(tb.balance);
else amount = tracked && tracked.balanceNotFetched ? null : 0;
price = getPrice(tokenId);
+8
View File
@@ -430,6 +430,13 @@ function trackToken(token) {
state.trackedTokens.push({ ...token, balanceNotFetched: true });
}
// Gives every tracked token `balanceNotFetched: true`, as trackToken() gives a
// new one. Called when an address is added, before the save: no refresh has
// read any token's balance at that address.
function markTrackedTokensNotFetched() {
for (const token of state.trackedTokens) token.balanceNotFetched = true;
}
function balanceLinesForAddress(addr, trackedTokens, showZero) {
let html = balanceLine(
nativeCurrency(),
@@ -850,6 +857,7 @@ module.exports = {
balanceLine,
balanceLinesForAddress,
trackToken,
markTrackedTokensNotFetched,
addressHoldsFunds,
keyMaterialName,
unknownableAmount,
+2
View File
@@ -3,6 +3,7 @@ const {
showView,
showFlash,
balanceLinesForAddress,
markTrackedTokensNotFetched,
isoDate,
timeAgo,
addressDotHtml,
@@ -394,6 +395,7 @@ function render(ctx) {
tokenBalances: [],
});
wallet.nextIndex++;
markTrackedTokensNotFetched();
await saveState();
render(ctx);
ctx.doRefreshAndRender();
+5 -4
View File
@@ -242,10 +242,11 @@ function updateSendBalance() {
state.trackedTokens,
currentNetwork().chainId,
);
// A null balance is a holding whose scale is unknown. Saying a figure
// for it would be a claim about the amount, so it reads as the
// confirmation screen's balance line reads it; the send itself is
// refused later by transferAmountUnits() for the same missing scale.
// A null balance is a holding whose scale is unknown, or a tracked
// token whose balance no refresh has read. Saying a figure for it would
// be a claim about the amount, so it reads as the confirmation screen's
// balance line reads it. transferAmountUnits() later refuses a send at
// a missing scale.
const bal = tokenBalanceAndDecimals(addr, token).tokenBalance;
$("send-balance").textContent =
bal == null
+5
View File
@@ -48,9 +48,14 @@ function applyChainSwitchFields(s, newNetworkId) {
// It is a copy because a save writes a changed s.networkTrackedTokens whole,
// over any list another page stored. An add or removal on the active network
// must change only s.trackedTokens.
//
// Each token of the copy gets `balanceNotFetched`, because the balances are
// cleared below and no refresh has read this network's yet. Each reads
// `quantity unknown` until one has, not 0.0000.
if (!s.networkTrackedTokens) s.networkTrackedTokens = {};
s.networkTrackedTokens[s.networkId] = s.trackedTokens;
s.trackedTokens = structuredClone(s.networkTrackedTokens[net.id] || []);
for (const token of s.trackedTokens) token.balanceNotFetched = true;
s.networkId = net.id;
s.rpcUrl = remembered.rpcUrl || net.defaultRpcUrl;