fix: a second click on Add while the lookup waits tracks the token once (closes #727)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

The "already tracked" check ran only before the contract lookup, so a second click while the first lookup waited tracked the token twice. AddToken and SettingsAddToken now check again when the lookup answers. An answer for a token tracked meanwhile shows the "already tracked" flash message and tracks nothing.

Model: opus-5-5
This commit was merged in pull request #728.
This commit is contained in:
2026-11-03 06:24:14 +01:00
parent 1a4fb0803d
commit 267b69382e
3 changed files with 109 additions and 9 deletions
+18 -3
View File
@@ -17,6 +17,11 @@ const { log } = require("../../shared/log");
// AddToken was last opened changes neither the screen nor the status line.
let addTokenScreenOpenings = 0;
function findTracked(address) {
const lower = address.toLowerCase();
return state.trackedTokens.find((t) => t.address.toLowerCase() === lower);
}
function show() {
addTokenScreenOpenings++;
$("add-token-address").value = "";
@@ -50,9 +55,7 @@ function init(ctx) {
showFlash("Enter a valid contract address starting with 0x.");
return;
}
const already = state.trackedTokens.find(
(t) => t.address.toLowerCase() === contractAddr.toLowerCase(),
);
const already = findTracked(contractAddr);
if (already) {
showFlash(already.symbol + " is already being tracked.");
return;
@@ -85,6 +88,18 @@ function init(ctx) {
);
return;
}
// Another click on Add may have tracked this token while this
// lookup waited.
const trackedMeanwhile = findTracked(contractAddr);
if (trackedMeanwhile) {
showFlash(
trackedMeanwhile.symbol + " is already being tracked.",
);
if (addTokenScreenOpenings !== opening) return;
infoEl.textContent = "";
infoEl.style.visibility = "hidden";
return;
}
// The balance list never shows a token that the spoof rule
// refuses, so such a token is not tracked.
if (isSpoofedSymbol(info.symbol, contractAddr, chainId)) {
+8
View File
@@ -163,6 +163,14 @@ function init(_ctx) {
);
return;
}
// Another click on Add, or a "Top tokens:" button, may have
// tracked this token while this lookup waited.
if (isTracked(addr)) {
showFlash("Already tracked.");
infoEl.textContent = "";
infoEl.style.visibility = "hidden";
return;
}
// The balance list never shows a token that the spoof rule
// refuses, so such a token is not tracked. The rule never refuses
// a bundled token, so the "Top tokens:" buttons and the top 100