fix: a second click on Add while the lookup waits tracks the token once (closes #727)
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 is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user