fix: tracked tokens are kept per network, and bundled picks are offered on mainnet only (closes #523)
A network switch puts the outgoing network's tracked tokens away in a new persisted field, networkTrackedTokens, and brings back the incoming network's list, or an empty one, as endpoints are kept; the background's switch uses the same function. The two add-token screens offer their common-token picks on Ethereum Mainnet only. After a switch in Settings, Back renders the screen it lands on again, and the stack is cut at the first screen that cannot be rendered from saved state, or at AddressToken for any token but the native one; the cut stack is saved with the switch. ConfirmTx drawn again keeps the network it was reviewed on. A contract lookup that answers after a switch adds nothing. Model: opus-5-5
This commit was merged in pull request #572.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { $, showView, showFlash, escapeHtml, goBack } = require("./helpers");
|
||||
const { getTopTokens } = require("../../shared/tokenList");
|
||||
const { state, saveState } = require("../../shared/state");
|
||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
||||
const { lookupTokenInfo } = require("../../shared/balances");
|
||||
const { isScamAddress } = require("../../shared/scamlist");
|
||||
const { log } = require("../../shared/log");
|
||||
@@ -75,6 +75,12 @@ function show() {
|
||||
$("settings-addtoken-address").value = "";
|
||||
$("settings-addtoken-info").textContent = "";
|
||||
$("settings-addtoken-info").style.visibility = "hidden";
|
||||
// The bundled list holds Ethereum Mainnet contracts, which name no token
|
||||
// on any other network.
|
||||
$("settings-addtoken-common").classList.toggle(
|
||||
"hidden",
|
||||
state.networkId !== "mainnet",
|
||||
);
|
||||
renderTop10();
|
||||
renderDropdown();
|
||||
showView("settings-addtoken");
|
||||
@@ -130,6 +136,9 @@ function init(_ctx) {
|
||||
infoEl.textContent = "Looking up token...";
|
||||
infoEl.style.visibility = "visible";
|
||||
log.debugf("Looking up token contract", addr);
|
||||
// The network the lookup asks, which Settings may switch away from
|
||||
// before it answers, as for a transaction in confirmTx.js.
|
||||
const chainId = currentNetwork().chainId;
|
||||
try {
|
||||
const info = await lookupTokenInfo(
|
||||
addr,
|
||||
@@ -137,6 +146,15 @@ function init(_ctx) {
|
||||
state.networkId,
|
||||
ctx.pageClosed,
|
||||
);
|
||||
// A contract address names a token on one network only, so an
|
||||
// answer after a switch is not added to the new network's list.
|
||||
if (currentNetwork().chainId !== chainId) {
|
||||
showFlash(
|
||||
"The active network changed before the lookup finished," +
|
||||
" so the token was not added.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
log.infof("Adding token", info.symbol, addr);
|
||||
state.trackedTokens.push({
|
||||
address: addr,
|
||||
|
||||
Reference in New Issue
Block a user