fix: a double click on a Top tokens button tracks the token once (closes #729)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

A "Top tokens:" button had no already-tracked check and stays enabled until its
save ends, so a fast double click tracked the token twice in memory. Its handler
now checks first. A second click shows "Already tracked." and tracks nothing.
The top 100 dropdown already has this check, so it is unchanged.

Model: opus-5-5
This commit was merged in pull request #731.
This commit is contained in:
2026-11-03 07:37:04 +01:00
parent ba61bedaaf
commit 21d5e42528
2 changed files with 51 additions and 1 deletions
+5
View File
@@ -45,6 +45,11 @@ function renderTop10() {
el.querySelectorAll(".settings-addtoken-quick:not([disabled])").forEach(
(btn) => {
btn.addEventListener("click", async () => {
// The button stays enabled until the first click's save ends.
if (isTracked(btn.dataset.address)) {
showFlash("Already tracked.");
return;
}
const token = {
address: btn.dataset.address,
symbol: btn.dataset.symbol,
+46 -1
View File
@@ -3,7 +3,9 @@
// (https://git.eeqj.de/sneak/AutistMask/issues/603). An answer while AddToken
// still shows goes to AddressDetail. On either add-token screen, an answer for a
// token tracked while the lookup waited tracks nothing
// (https://git.eeqj.de/sneak/AutistMask/issues/727). Driven through the real
// (https://git.eeqj.de/sneak/AutistMask/issues/727). A second click on a "Top
// tokens:" button tracks nothing
// (https://git.eeqj.de/sneak/AutistMask/issues/729). Driven through the real
// popup over a stored profile.
const {
@@ -197,6 +199,8 @@ describe.each([
await answerSecondClick();
expect(boot.text("flash-msg")).toBe(alreadyTrackedFlash);
expect(boot.storage.read("autistmask").trackedTokens).toEqual([TOKEN]);
const { state } = require("../src/shared/state");
expect(state.trackedTokens).toEqual([TOKEN]);
});
test("an answer for a token tracked while the lookup waited clears the status line", async () => {
@@ -213,3 +217,44 @@ describe.each([
expect(state.trackedTokens).toEqual([TOKEN]);
});
});
test('a double click on a "Top tokens:" button tracks the token once', async () => {
const boot = await bootPopup(
unversionedValidProfile({
currentView: "address",
selectedWallet: 0,
selectedAddress: 0,
}),
);
expect(boot.pageErrors).toEqual([]);
// The page stub does not turn the markup the screen draws into elements.
// So the list hands the screen a stand-in for TOKEN's button.
let press;
boot.node("settings-addtoken-top10").querySelectorAll = () => [
{
dataset: {
address: TOKEN.address,
symbol: TOKEN.symbol,
decimals: String(TOKEN.decimals),
name: TOKEN.name,
},
addEventListener: (name, fn) => {
press = fn;
},
},
];
await boot.click("btn-settings");
await boot.click("btn-settings-add-token");
const firstClick = press();
const secondClick = press();
const { state } = require("../src/shared/state");
expect(state.trackedTokens).toEqual([TOKEN]);
// Read before the first click's save ends, when "Added TST" replaces it.
expect(boot.text("flash-msg")).toBe("Already tracked.");
await Promise.all([firstClick, secondClick]);
await boot.settle();
expect(state.trackedTokens).toEqual([TOKEN]);
expect(boot.storage.read("autistmask").trackedTokens).toEqual([TOKEN]);
});