fix: a tracked token reads quantity unknown at an address no refresh has read (closes #720)
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 was merged in pull request #735.
This commit is contained in:
+8
-3
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user