fix: the address screen shows a token just added at its fetched balance, not 0.0000 (closes #516)
A balance refresh that returns now draws the balances on AddressDetail or AddressToken again when that screen is up, not only the wallet list. Their transaction lists are left alone. Every add path on AddToken and SettingsAddToken tracks a token through trackToken(), which gives the tracked record `balanceNotFetched: true`. While the field is set, the token's line reads `quantity unknown` instead of 0.0000. The popup's refresh deletes the field once it has read the token's balance at every address. refreshBalances() now resolves with those tokens. The field is part of the tracked record, so removing the token removes it, and each network keeps its own records. Model: opus-5-5
This commit is contained in:
+20
-4
@@ -247,7 +247,11 @@ async function fetchTokenBalances(
|
||||
// it has none. The failure is logged. A balance of zero gets no entry, as a
|
||||
// zero Blockscout reports gets none: the balance lists take a tracked token's
|
||||
// zero from the tracked list. A token whose symbol the spoof rule refuses gets
|
||||
// no entry either, as in fetchTokenBalances().
|
||||
// no entry either, as in fetchTokenBalances(), and its balance is not read.
|
||||
//
|
||||
// Resolves with `rows`, the entries, and `unread`, the tracked tokens whose
|
||||
// balance was not read, as lowercased contract addresses. A token is unread
|
||||
// when the spoof rule refuses it or its balanceOf fails.
|
||||
//
|
||||
// `signal` is as for fetchTokenBalances().
|
||||
async function fetchTrackedTokenBalances(
|
||||
@@ -288,12 +292,16 @@ async function fetchTrackedTokenBalances(
|
||||
const reported = explorerRows ?? previous;
|
||||
|
||||
const rows = [];
|
||||
const unread = trackedTokens
|
||||
.filter((token) => !listed.includes(token))
|
||||
.map((token) => token.address.toLowerCase());
|
||||
listed.forEach((token, i) => {
|
||||
const lower = token.address.toLowerCase();
|
||||
const entryIn = (list) =>
|
||||
list.find((row) => String(row.address).toLowerCase() === lower);
|
||||
const raw = balances[i];
|
||||
if (raw === null) {
|
||||
unread.push(lower);
|
||||
const kept = entryIn(previous) || entryIn(explorerRows || []);
|
||||
if (kept) rows.push(kept);
|
||||
return;
|
||||
@@ -314,12 +322,15 @@ async function fetchTrackedTokenBalances(
|
||||
holders: entry ? entry.holders : null,
|
||||
});
|
||||
});
|
||||
return rows;
|
||||
return { rows, unread };
|
||||
}
|
||||
|
||||
// Fetch ETH balances, ENS names, and ERC-20 token balances for all addresses.
|
||||
// `trackedTokens` are the tokens tracked on the active network. `signal` is as
|
||||
// for fetchTokenBalances().
|
||||
//
|
||||
// Resolves with the lowercased contract addresses of the tracked tokens whose
|
||||
// balance it read at every address.
|
||||
async function refreshBalances(
|
||||
wallets,
|
||||
rpcUrl,
|
||||
@@ -332,6 +343,8 @@ async function refreshBalances(
|
||||
const provider = getProvider(rpcUrl, networkId);
|
||||
const tracked = trackedTokens || [];
|
||||
const trackedSet = new Set(tracked.map((t) => t.address.toLowerCase()));
|
||||
// The tracked tokens whose balance was not read at some address.
|
||||
const unread = new Set();
|
||||
const updates = [];
|
||||
|
||||
for (const wallet of wallets) {
|
||||
@@ -406,12 +419,14 @@ async function refreshBalances(
|
||||
signal,
|
||||
),
|
||||
explorerRequest,
|
||||
]).then(([trackedRows, explorerRows]) => {
|
||||
]).then(([trackedResult, explorerRows]) => {
|
||||
for (const lower of trackedResult.unread) unread.add(lower);
|
||||
const untrackedRows = (explorerRows ?? previous).filter(
|
||||
(row) =>
|
||||
!trackedSet.has(String(row.address).toLowerCase()),
|
||||
);
|
||||
addr.tokenBalances = trackedRows.concat(untrackedRows);
|
||||
addr.tokenBalances =
|
||||
trackedResult.rows.concat(untrackedRows);
|
||||
log.debugf(
|
||||
"Token balances",
|
||||
addr.address,
|
||||
@@ -425,6 +440,7 @@ async function refreshBalances(
|
||||
|
||||
await Promise.all(updates);
|
||||
log.debugf("refreshBalances done");
|
||||
return [...trackedSet].filter((lower) => !unread.has(lower));
|
||||
}
|
||||
|
||||
// Drops the balance of each token not in `trackedTokens` from every address.
|
||||
|
||||
Reference in New Issue
Block a user